summaryrefslogtreecommitdiffstats
path: root/lib/CodeGen/CodeGenPGO.h
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-17 21:18:30 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-17 21:18:30 +0000
commitcc7b172945b8f54294739de3198ccac9be09ea62 (patch)
tree9d165d3c7722d1b1e36a259adf0b698bfd4b41e9 /lib/CodeGen/CodeGenPGO.h
parentbbe3878c8894da9fb0f54286c42fba84e6da95c4 (diff)
PGO: Statically generate data structures
In instrumentation-based profiling, we need a set of data structures to represent the counters. Previously, these were built up during static initialization. Now, they're shoved into a specially-named section so that they show up as an array. As a consequence of the reorganizing symbols, instrumentation data structures for linkonce functions are now correctly coalesced. This is the first step in a larger project to minimize runtime overhead and dependencies in instrumentation-based profilng. The larger picture includes removing all initialization overhead and making the dependency on libc optional. <rdar://problem/15943240> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204080 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenPGO.h')
-rw-r--r--lib/CodeGen/CodeGenPGO.h21
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/CodeGen/CodeGenPGO.h b/lib/CodeGen/CodeGenPGO.h
index 51d59cf9a9..2f1fe5dba8 100644
--- a/lib/CodeGen/CodeGenPGO.h
+++ b/lib/CodeGen/CodeGenPGO.h
@@ -52,7 +52,9 @@ public:
class CodeGenPGO {
private:
CodeGenModule &CGM;
- std::string *FuncName;
+ std::string *PrefixedFuncName;
+ StringRef RawFuncName;
+ llvm::GlobalValue::LinkageTypes FuncLinkage;
unsigned NumRegionCounters;
llvm::GlobalVariable *RegionCounters;
@@ -63,11 +65,11 @@ private:
public:
CodeGenPGO(CodeGenModule &CGM)
- : CGM(CGM), FuncName(0), NumRegionCounters(0), RegionCounters(0),
+ : CGM(CGM), PrefixedFuncName(0), NumRegionCounters(0), RegionCounters(0),
RegionCounterMap(0), StmtCountMap(0), RegionCounts(0),
CurrentRegionCount(0) {}
~CodeGenPGO() {
- if (FuncName) delete FuncName;
+ if (PrefixedFuncName) delete PrefixedFuncName;
}
/// Whether or not we have PGO region data for the current function. This is
@@ -77,7 +79,10 @@ public:
/// Get the string used to identify this function in the profile data.
/// For functions with local linkage, this includes the main file name.
- const StringRef getFuncName() const { return StringRef(*FuncName); }
+ StringRef getFuncName() const { return StringRef(*PrefixedFuncName); }
+ std::string getFuncVarName(StringRef VarName) const {
+ return ("__llvm_pgo_" + VarName + "_" + RawFuncName).str();
+ }
/// Return the counter value of the current region.
uint64_t getCurrentRegionCount() const { return CurrentRegionCount; }
@@ -123,13 +128,12 @@ public:
/// generates global variables or associates PGO data with each of the
/// counters depending on whether we are generating or using instrumentation.
void assignRegionCounters(const Decl *D, llvm::Function *Fn);
- /// Emit code to write counts for a given function to disk, if necessary.
- void emitWriteoutFunction();
+ /// Emit static data structures for instrumentation data.
+ void emitInstrumentationData();
/// Clean up region counter state. Must be called if assignRegionCounters is
/// used.
void destroyRegionCounters();
- /// Emit the logic to register region counter write out functions. Returns a
- /// function that implements this logic.
+ /// Emit static initialization code, if any.
static llvm::Function *emitInitialization(CodeGenModule &CGM);
private:
@@ -139,6 +143,7 @@ private:
void applyFunctionAttributes(PGOProfileData *PGOData, llvm::Function *Fn);
void loadRegionCounts(PGOProfileData *PGOData);
void emitCounterVariables();
+ llvm::GlobalVariable *buildDataVar();
/// Emit code to increment the counter at the given index
void emitCounterIncrement(CGBuilderTy &Builder, unsigned Counter);