14 #ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENPGO_H
15 #define LLVM_CLANG_LIB_CODEGEN_CODEGENPGO_H
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/ProfileData/InstrProfReader.h"
23 #include "llvm/Support/MemoryBuffer.h"
35 llvm::GlobalVariable *FuncNameVar;
37 std::array <unsigned, llvm::IPVK_Last + 1> NumValueSites;
38 unsigned NumRegionCounters;
39 uint64_t FunctionHash;
40 std::unique_ptr<llvm::DenseMap<const Stmt *, unsigned>> RegionCounterMap;
41 std::unique_ptr<llvm::DenseMap<const Stmt *, uint64_t>> StmtCountMap;
42 std::unique_ptr<llvm::InstrProfRecord> ProfRecord;
43 std::vector<uint64_t> RegionCounts;
44 uint64_t CurrentRegionCount;
47 bool SkipCoverageMapping;
51 : CGM(CGM), NumValueSites({{0}}), NumRegionCounters(0),
72 auto I = StmtCountMap->find(S);
73 if (
I == StmtCountMap->end())
93 llvm::GlobalValue::LinkageTypes
Linkage);
96 llvm::Instruction *ValueSite,
llvm::Value *ValuePtr);
98 void setFuncName(llvm::Function *Fn);
99 void setFuncName(StringRef
Name, llvm::GlobalValue::LinkageTypes
Linkage);
100 void mapRegionCounters(
const Decl *D);
101 void computeRegionCounts(
const Decl *D);
102 void applyFunctionAttributes(llvm::IndexedInstrProfReader *PGOReader,
104 void loadRegionCounts(llvm::IndexedInstrProfReader *PGOReader,
106 bool skipRegionMappingForDecl(
const Decl *D);
107 void emitCounterRegionMapping(
const Decl *D);
114 if (!RegionCounterMap)
118 return RegionCounts[(*RegionCounterMap)[
S]];
Optional< uint64_t > getStmtCount(const Stmt *S)
Check if an execution count is known for a given statement.
void emitCounterIncrement(CGBuilderTy &Builder, const Stmt *S)
uint64_t getCurrentRegionCount() const
Return the counter value of the current region.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
void setCurrentRegionCount(uint64_t Count)
Set the counter value for the current region.
void assignRegionCounters(GlobalDecl GD, llvm::Function *Fn)
Assign counters to regions and configure them for PGO of a given function.
detail::InMemoryDirectory::const_iterator I
void valueProfile(CGBuilderTy &Builder, uint32_t ValueKind, llvm::Instruction *ValueSite, llvm::Value *ValuePtr)
bool haveRegionCounts() const
Whether or not we have PGO region data for the current function.
GlobalDecl - represents a global declaration.
SkipCoverageMapping(false)
This class organizes the cross-function state that is used while generating LLVM code.
void emitEmptyCounterMapping(const Decl *D, StringRef FuncName, llvm::GlobalValue::LinkageTypes Linkage)
Emit a coverage mapping range with a counter zero for an unused declaration.
void setCurrentStmt(const Stmt *S)
If the execution count for the current statement is known, record that as the current count...
BoundNodesTreeBuilder *const Builder
uint64_t getRegionCount(const Stmt *S)
Return the region count for the counter at the given index.
CodeGenPGO(CodeGenModule &CGM)