llvm.org GIT mirror llvm / a0a6def
Merging r232438: ------------------------------------------------------------------------ r232438 | mail | 2015-03-16 19:52:03 -0400 (Mon, 16 Mar 2015) | 6 lines GCOV: Make the exit block placement from r223193 optional By default we want our gcov emission to stay 4.2 compatible, which means we need to continue emit the exit block last by default. We add an option to emit it before the body for users that need it. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_36@236303 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 4 years ago
3 changed file(s) with 34 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
5858 // Emit the name of the function in the .gcda files. This is redundant, as
5959 // the function identifier can be used to find the name from the .gcno file.
6060 bool FunctionNamesInData;
61
62 // Emit the exit block immediately after the start block, rather than after
63 // all of the function body's blocks.
64 bool ExitBlockBeforeBody;
6165 };
6266 ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
6367 GCOVOptions::getDefault());
4646 static cl::opt
4747 DefaultGCOVVersion("default-gcov-version", cl::init("402*"), cl::Hidden,
4848 cl::ValueRequired);
49 static cl::opt DefaultExitBlockBeforeBody("gcov-exit-block-before-body",
50 cl::init(false), cl::Hidden);
4951
5052 GCOVOptions GCOVOptions::getDefault() {
5153 GCOVOptions Options;
5456 Options.UseCfgChecksum = false;
5557 Options.NoRedZone = false;
5658 Options.FunctionNamesInData = true;
59 Options.ExitBlockBeforeBody = DefaultExitBlockBeforeBody;
5760
5861 if (DefaultGCOVVersion.size() != 4) {
5962 llvm::report_fatal_error(std::string("Invalid -default-gcov-version: ") +
311314 class GCOVFunction : public GCOVRecord {
312315 public:
313316 GCOVFunction(DISubprogram SP, raw_ostream *os, uint32_t Ident,
314 bool UseCfgChecksum)
317 bool UseCfgChecksum, bool ExitBlockBeforeBody)
315318 : SP(SP), Ident(Ident), UseCfgChecksum(UseCfgChecksum), CfgChecksum(0),
316319 ReturnBlock(1, os) {
317320 this->os = os;
321324
322325 uint32_t i = 0;
323326 for (auto &BB : *F) {
324 // Skip index 1 (0, 2, 3, 4, ...) because that's assigned to the
325 // ReturnBlock.
326 bool first = i == 0;
327 Blocks.insert(std::make_pair(&BB, GCOVBlock(i++ + !first, os)));
328 }
327 // Skip index 1 if it's assigned to the ReturnBlock.
328 if (i == 1 && ExitBlockBeforeBody)
329 ++i;
330 Blocks.insert(std::make_pair(&BB, GCOVBlock(i++, os)));
331 }
332 if (!ExitBlockBeforeBody)
333 ReturnBlock.Number = i;
329334
330335 std::string FunctionNameAndLine;
331336 raw_string_ostream FNLOS(FunctionNameAndLine);
468473 if (Loc.isUnknown()) continue;
469474
470475 // Artificial lines such as calls to the global constructors.
471 if (Loc.getLine() == 0) continue;
476 if (Loc.getLine() == 0) continue;
472477
473478 return true;
474479 }
512517 EntryBlock.splitBasicBlock(It);
513518
514519 Funcs.push_back(make_unique(SP, &out, FunctionIdent++,
515 Options.UseCfgChecksum));
520 Options.UseCfgChecksum,
521 Options.ExitBlockBeforeBody));
516522 GCOVFunction &Func = *Funcs.back();
517523
518524 for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
0 ; Inject metadata to set the .gcno file location
11 ; RUN: echo '!19 = !{!"%/T/return-block.ll", !0}' > %t1
22 ; RUN: cat %s %t1 > %t2
3
4 ; By default, the return block is last.
35 ; RUN: opt -insert-gcov-profiling -disable-output %t2
4 ; RUN: llvm-cov gcov -n -dump %T/return-block.gcno 2>&1 | FileCheck %s
6 ; RUN: llvm-cov gcov -n -dump %T/return-block.gcno 2>&1 | FileCheck -check-prefix=CHECK -check-prefix=RETURN-LAST %s
7
8 ; But we can optionally emit it second, to match newer gcc versions.
9 ; RUN: opt -insert-gcov-profiling -gcov-exit-block-before-body -disable-output %t2
10 ; RUN: llvm-cov gcov -n -dump %T/return-block.gcno 2>&1 | FileCheck -check-prefix=CHECK -check-prefix=RETURN-SECOND %s
511
612 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
713 target triple = "x86_64-unknown-linux-gnu"
5763 !17 = !{!"0xb\007\007\000", !1, !4} ; [ DW_TAG_lexical_block ] [return-block.c]
5864 !18 = !MDLocation(line: 9, column: 1, scope: !4)
5965
60 ; There should be no destination edges for block 1.
61 ; CHECK: Block : 0 Counter : 0
62 ; CHECK-NEXT: Destination Edges : 2 (0),
63 ; CHECK-NEXT: Block : 1 Counter : 0
64 ; CHECK-NEXT: Source Edges : 4 (0),
65 ; CHECK-NEXT: Block : 2 Counter : 0
66 ; There should be no destination edges for the exit block.
67 ; CHECK: Block : 1 Counter : 0
68 ; RETURN-LAST: Destination Edges
69 ; RETURN-SECOND-NOT: Destination Edges
70 ; CHECK: Block : 2 Counter : 0
71 ; CHECK: Block : 4 Counter : 0
72 ; RETURN-LAST-NOT: Destination Edges
73 ; RETURN-SECOND: Destination Edges
74 ; CHECK-NOT: Block :