r207203 - CodeGen: Avoid instrumenting implicit Decls more effectively
Justin Bogner
mail at justinbogner.com
Fri Apr 25 00:20:06 PDT 2014
Author: bogner
Date: Fri Apr 25 02:20:05 2014
New Revision: 207203
URL: http://llvm.org/viewvc/llvm-project?rev=207203&view=rev
Log:
CodeGen: Avoid instrumenting implicit Decls more effectively
We don't assign counters for implicit Decls, but we were emitting code
to increment the (non-existent) counters and adding empty counter
lists in the output. This fixes the checks in assignRegionCounters and
emitInstrumentationData to do the right thing, and adds an assert for
the pathological case of emitting zero counters.
Added:
cfe/trunk/test/Profile/cxx-implicit.cpp
Modified:
cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=207203&r1=207202&r2=207203&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Fri Apr 25 02:20:05 2014
@@ -146,7 +146,7 @@ llvm::GlobalVariable *CodeGenPGO::buildD
}
void CodeGenPGO::emitInstrumentationData() {
- if (!CGM.getCodeGenOpts().ProfileInstrGenerate)
+ if (!RegionCounters)
return;
// Build the data.
@@ -803,7 +803,7 @@ void CodeGenPGO::assignRegionCounters(co
llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader();
if (!InstrumentRegions && !PGOReader)
return;
- if (!D)
+ if (D->isImplicit())
return;
setFuncName(Fn);
@@ -845,6 +845,7 @@ void CodeGenPGO::mapRegionCounters(const
Walker.TraverseDecl(const_cast<BlockDecl *>(BD));
else if (const CapturedDecl *CD = dyn_cast_or_null<CapturedDecl>(D))
Walker.TraverseDecl(const_cast<CapturedDecl *>(CD));
+ assert(Walker.NextCounter > 0 && "no entry counter mapped for decl");
NumRegionCounters = Walker.NextCounter;
FunctionHash = Walker.Hash.finalize();
}
@@ -920,6 +921,7 @@ void CodeGenPGO::destroyRegionCounters()
RegionCounterMap.reset();
StmtCountMap.reset();
RegionCounts.reset();
+ RegionCounters = nullptr;
}
/// \brief Calculate what to divide by to scale weights.
Added: cfe/trunk/test/Profile/cxx-implicit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/cxx-implicit.cpp?rev=207203&view=auto
==============================================================================
--- cfe/trunk/test/Profile/cxx-implicit.cpp (added)
+++ cfe/trunk/test/Profile/cxx-implicit.cpp Fri Apr 25 02:20:05 2014
@@ -0,0 +1,17 @@
+// Ensure that implicit methods aren't instrumented.
+
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-implicit.cpp -o - -emit-llvm -fprofile-instr-generate | FileCheck %s
+
+// An implicit constructor is generated for Base. We should not emit counters
+// for it.
+// CHECK-NOT: @__llvm_profile_counters__ZN4BaseC2Ev =
+
+struct Base {
+ virtual void foo();
+};
+
+struct Derived : public Base {
+ Derived();
+};
+
+Derived::Derived() {}
More information about the cfe-commits
mailing list