[llvm] c55c148 - [gcov] Clean up by getting llvm.dbg.cu earlier
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 12 12:21:43 PDT 2020
Author: Fangrui Song
Date: 2020-09-12T12:21:32-07:00
New Revision: c55c14837e148b817de989106560328219df342b
URL: https://github.com/llvm/llvm-project/commit/c55c14837e148b817de989106560328219df342b
DIFF: https://github.com/llvm/llvm-project/commit/c55c14837e148b817de989106560328219df342b.diff
LOG: [gcov] Clean up by getting llvm.dbg.cu earlier
Added:
Modified:
llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index cc8b92e21c7c..15355ff8efd1 100644
--- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -112,11 +112,11 @@ class GCOVProfiler {
private:
// Create the .gcno files for the Module based on DebugInfo.
- void emitProfileNotes();
+ void emitProfileNotes(NamedMDNode *CUNode);
// Modify the program to track transitions along edges and call into the
// profiling runtime to emit .gcda files when run.
- bool emitProfileArcs();
+ bool emitProfileArcs(NamedMDNode *CUNode);
bool isFunctionInstrumented(const Function &F);
std::vector<Regex> createRegexesFromString(StringRef RegexesStr);
@@ -550,14 +550,19 @@ bool GCOVProfiler::runOnModule(
this->GetTLI = std::move(GetTLI);
Ctx = &M.getContext();
+ NamedMDNode *CUNode = M.getNamedMetadata("llvm.dbg.cu");
+ if (!CUNode)
+ return false;
+
bool Modified = AddFlushBeforeForkAndExec();
FilterRe = createRegexesFromString(Options.Filter);
ExcludeRe = createRegexesFromString(Options.Exclude);
- if (Options.EmitNotes) emitProfileNotes();
+ if (Options.EmitNotes)
+ emitProfileNotes(CUNode);
if (Options.EmitData)
- Modified |= emitProfileArcs();
+ Modified |= emitProfileArcs(CUNode);
return Modified;
}
@@ -683,10 +688,7 @@ bool GCOVProfiler::AddFlushBeforeForkAndExec() {
return !Forks.empty() || !Execs.empty();
}
-void GCOVProfiler::emitProfileNotes() {
- NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu");
- if (!CU_Nodes) return;
-
+void GCOVProfiler::emitProfileNotes(NamedMDNode *CUNode) {
int Version;
{
uint8_t c3 = Options.Version[0];
@@ -696,12 +698,12 @@ void GCOVProfiler::emitProfileNotes() {
: (c3 - '0') * 10 + c1 - '0';
}
- for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
+ for (unsigned i = 0, e = CUNode->getNumOperands(); i != e; ++i) {
// Each compile unit gets its own .gcno file. This means that whether we run
// this pass over the original .o's as they're produced, or run it after
// LTO, we'll generate the same .gcno files.
- auto *CU = cast<DICompileUnit>(CU_Nodes->getOperand(i));
+ auto *CU = cast<DICompileUnit>(CUNode->getOperand(i));
// Skip module skeleton (and module) CUs.
if (CU->getDWOId())
@@ -818,12 +820,9 @@ void GCOVProfiler::emitProfileNotes() {
}
}
-bool GCOVProfiler::emitProfileArcs() {
- NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu");
- if (!CU_Nodes) return false;
-
+bool GCOVProfiler::emitProfileArcs(NamedMDNode *CUNode) {
bool Result = false;
- for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
+ for (unsigned i = 0, e = CUNode->getNumOperands(); i != e; ++i) {
SmallVector<std::pair<GlobalVariable *, MDNode *>, 8> CountersBySP;
for (auto &F : M->functions()) {
DISubprogram *SP = F.getSubprogram();
More information about the llvm-commits
mailing list