reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
// Blocks that we have no profile data for (ie, it was never reached in training
// runs) shouldn't have any branch weight metadata added.

// RUN: llvm-profdata merge %S/Inputs/c-unprofiled-blocks.proftext -o %t.profdata
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-unprofiled-blocks.c %s -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata | FileCheck -check-prefix=PGOUSE %s

// PGOUSE-LABEL: @never_called(i32 %i)
int never_called(int i) {
  // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
  if (i) {}

  // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
  for (i = 0; i < 100; ++i) {
  }

  // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
  while (--i) {}

  // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
  do {} while (i++ < 75);

  // PGOUSE: switch {{.*}} [
  // PGOUSE-NEXT: i32 12
  // PGOUSE-NEXT: i32 82
  // PGOUSE-NEXT: ]{{$}}
  switch (i) {
  case 12: return 3;
  case 82: return 0;
  default: return 89;
  }
}

// PGOUSE-LABEL: @dead_code(i32 %i)
int dead_code(int i) {
  // PGOUSE: br {{.*}}, !prof !{{[0-9]+}}
  if (i) {
    // This branch is never reached.

    // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
    if (!i) {}

    // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
    for (i = 0; i < 100; ++i) {
    }

    // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
    while (--i) {}

    // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
    do {} while (i++ < 75);

    // PGOUSE: switch {{.*}} [
    // PGOUSE-NEXT: i32 12
    // PGOUSE-NEXT: i32 82
    // PGOUSE-NEXT: ]{{$}}
    switch (i) {
    case 12: return 3;
    case 82: return 0;
    default: return 89;
    }
  }
  return 2;
}

// PGOUSE-LABEL: @main(i32 %argc, i8** %argv)
int main(int argc, const char *argv[]) {
  dead_code(0);
  return 0;
}