diff --git a/bolt/lib/Passes/Instrumentation.cpp b/bolt/lib/Passes/Instrumentation.cpp --- a/bolt/lib/Passes/Instrumentation.cpp +++ b/bolt/lib/Passes/Instrumentation.cpp @@ -349,6 +349,11 @@ VisitedSet.insert(BB); if (Pred) STOutSet[Pred].insert(BB); + else if (BB->succ_empty()) { + // Add BB directly if the one doesn't have pred and successors + // example, main function in file basic-instrumentation.s + STOutSet[BB]; + } for (BinaryBasicBlock *SuccBB : BB->successors()) Stack.push(std::make_pair(BB, SuccBB)); @@ -486,11 +491,16 @@ // Instrument spanning tree leaves if (!opts::ConservativeInstrumentation) { - for (auto BBI = Function.begin(), BBE = Function.end(); BBI != BBE; ++BBI) { - BinaryBasicBlock &BB = *BBI; - if (STOutSet[&BB].size() == 0) - instrumentLeafNode(BB, BB.begin(), IsLeafFunction, *FuncDesc, - BBToID[&BB]); + using STOutSetTy = std::unordered_map>; + for (STOutSetTy::iterator it = STOutSet.begin(); it != STOutSet.end(); + ++it) { + BinaryBasicBlock *BB = const_cast(it->first); + std::set SuccBBs = it->second; + if (SuccBBs.size() == 0) { + instrumentLeafNode(*BB, BB->begin(), IsLeafFunction, *FuncDesc, + BBToID[BB]); + } } } diff --git a/bolt/test/X86/asm-dump.c b/bolt/test/X86/asm-dump.c --- a/bolt/test/X86/asm-dump.c +++ b/bolt/test/X86/asm-dump.c @@ -7,7 +7,8 @@ * RUN: %clang -fPIC %s -o %t.exe -Wl,-q * * Profile collection: instrument the binary - * RUN: llvm-bolt %t.exe --instrument --instrumentation-file=%t.fdata -o %t.instr + * RUN: llvm-bolt %t.exe --instrument --conservative-instrumentation \ + * RUN: --instrumentation-file=%t.fdata -o %t.instr * * Profile collection: run instrumented binary (and capture output) * RUN: %t.instr > %t.result diff --git a/bolt/test/runtime/X86/fdata-escape-chars.ll b/bolt/test/runtime/X86/fdata-escape-chars.ll --- a/bolt/test/runtime/X86/fdata-escape-chars.ll +++ b/bolt/test/runtime/X86/fdata-escape-chars.ll @@ -57,7 +57,7 @@ ; RUN: llvm-objcopy --redefine-syms=%p/Inputs/fdata-escape-chars-syms.txt %t.exe ; ; RUN: llvm-bolt %t.exe -o %t.exe.instrumented --instrument \ -; RUN: --instrumentation-file=%t.fdata +; RUN: --conservative-instrumentation --instrumentation-file=%t.fdata ; RUN: %t.exe.instrumented ; RUN: cat %t.fdata | \ ; RUN: FileCheck --check-prefix="FDATA_CHECK" %s diff --git a/bolt/test/runtime/X86/instrumentation-dup-jts.s b/bolt/test/runtime/X86/instrumentation-dup-jts.s --- a/bolt/test/runtime/X86/instrumentation-dup-jts.s +++ b/bolt/test/runtime/X86/instrumentation-dup-jts.s @@ -63,8 +63,8 @@ # Check that our two indirect jumps are recorded in the fdata file and that # each has its own independent profile -# CHECK: Successors: .Ltmp1 (mispreds: 0, count: 1), .Ltmp0 (mispreds: 0, count: 0), .Ltmp2 (mispreds: 0, count: 0) -# CHECK: Successors: .Ltmp0 (mispreds: 0, count: 1), .Ltmp2 (mispreds: 0, count: 1), .Ltmp1 (mispreds: 0, count: 0) +# CHECK: Successors: .Ltmp{{[0-2]}} {{.*}}, .Ltmp{{[0-2]}} {{.*}}, .Ltmp{{[0-2]}} {{.*}} +# CHECK: Successors: .Ltmp{{[0-2]}} {{.*}}, .Ltmp{{[0-2]}} {{.*}}, .Ltmp{{[0-2]}} {{.*}} .file "test.c" .text