clang API Documentation
#include <CodeGenPGO.h>
Public Member Functions | |
CodeGenPGO (CodeGenModule &CGM) | |
bool | haveRegionCounts () const |
StringRef | getFuncName () const |
std::string | getFuncVarName (StringRef VarName) const |
uint64_t | getCurrentRegionCount () const |
Return the counter value of the current region. | |
void | setCurrentRegionCount (uint64_t Count) |
void | setCurrentRegionUnreachable () |
bool | getStmtCount (const Stmt *S, uint64_t &Count) |
void | setCurrentStmt (const Stmt *S) |
llvm::MDNode * | createBranchWeights (uint64_t TrueCount, uint64_t FalseCount) |
Calculate branch weights appropriate for PGO data. | |
llvm::MDNode * | createBranchWeights (ArrayRef< uint64_t > Weights) |
llvm::MDNode * | createLoopWeights (const Stmt *Cond, RegionCounter &Cnt) |
void | checkGlobalDecl (GlobalDecl GD) |
Check if we need to emit coverage mapping for a given declaration. | |
void | assignRegionCounters (const Decl *D, llvm::Function *Fn) |
void | emitInstrumentationData () |
Emit static data structures for instrumentation data. | |
void | destroyRegionCounters () |
void | emitEmptyCounterMapping (const Decl *D, StringRef FuncName, llvm::GlobalValue::LinkageTypes Linkage) |
Static Public Member Functions | |
static llvm::Function * | emitInitialization (CodeGenModule &CGM) |
Emit static initialization code, if any. | |
Friends | |
class | RegionCounter |
Per-function PGO state. This class should generally not be used directly, but instead through the CodeGenFunction and RegionCounter types.
Definition at line 31 of file CodeGenPGO.h.
clang::CodeGen::CodeGenPGO::CodeGenPGO | ( | CodeGenModule & | CGM | ) | [inline] |
Definition at line 51 of file CodeGenPGO.h.
void CodeGenPGO::assignRegionCounters | ( | const Decl * | D, |
llvm::Function * | Fn | ||
) |
Assign counters to regions and configure them for PGO of a given function. Does nothing if instrumentation is not enabled and either generates global variables or associates PGO data with each of the counters depending on whether we are generating or using instrumentation.
Definition at line 858 of file CodeGenPGO.cpp.
References clang::CodeGen::CodeGenModule::ClearUnusedCoverageMapping(), emitRuntimeHook(), clang::CodeGen::CodeGenModule::getCodeGenOpts(), clang::CodeGen::CodeGenModule::getContext(), clang::Decl::getLocation(), clang::CodeGen::CodeGenModule::getPGOReader(), clang::ASTContext::getSourceManager(), clang::Decl::isImplicit(), clang::SourceManager::isInMainFile(), and SM.
Referenced by clang::CodeGen::CodeGenFunction::GenerateCapturedStmtFunction(), clang::CodeGen::CodeGenFunction::GenerateCode(), and clang::CodeGen::CodeGenFunction::GenerateObjCMethod().
void CodeGenPGO::checkGlobalDecl | ( | GlobalDecl | GD | ) |
Check if we need to emit coverage mapping for a given declaration.
Definition at line 844 of file CodeGenPGO.cpp.
References clang::Ctor_Base, clang::Dtor_Base, clang::GlobalDecl::getCtorType(), clang::GlobalDecl::getDecl(), and clang::GlobalDecl::getDtorType().
Referenced by clang::CodeGen::CodeGenFunction::GenerateCode().
llvm::MDNode * CodeGenPGO::createBranchWeights | ( | uint64_t | TrueCount, |
uint64_t | FalseCount | ||
) |
Calculate branch weights appropriate for PGO data.
Definition at line 1039 of file CodeGenPGO.cpp.
References calculateWeightScale(), clang::CodeGen::CodeGenModule::getLLVMContext(), and scaleBranchWeight().
Referenced by createLoopWeights(), clang::CodeGen::CodeGenFunction::EmitBranchOnBoolExpr(), clang::CodeGen::CodeGenFunction::EmitCaseStmtRange(), clang::CodeGen::CodeGenFunction::EmitObjCForCollectionStmt(), and clang::CodeGen::CodeGenFunction::EmitSwitchStmt().
llvm::MDNode * CodeGenPGO::createBranchWeights | ( | ArrayRef< uint64_t > | Weights | ) |
Definition at line 1053 of file CodeGenPGO.cpp.
References calculateWeightScale(), clang::CodeGen::CodeGenModule::getLLVMContext(), and scaleBranchWeight().
llvm::MDNode * CodeGenPGO::createLoopWeights | ( | const Stmt * | Cond, |
RegionCounter & | Cnt | ||
) |
Definition at line 1075 of file CodeGenPGO.cpp.
References createBranchWeights(), clang::CodeGen::RegionCounter::getCount(), getStmtCount(), and haveRegionCounts().
Referenced by clang::CodeGen::CodeGenFunction::EmitCXXForRangeStmt(), clang::CodeGen::CodeGenFunction::EmitDoStmt(), clang::CodeGen::CodeGenFunction::EmitForStmt(), clang::CodeGen::CodeGenFunction::EmitOMPInnerLoop(), and clang::CodeGen::CodeGenFunction::EmitWhileStmt().
void CodeGenPGO::destroyRegionCounters | ( | ) |
Clean up region counter state. Must be called if assignRegionCounters is used.
Definition at line 1008 of file CodeGenPGO.cpp.
Referenced by clang::CodeGen::CodeGenFunction::GenerateCapturedStmtFunction(), clang::CodeGen::CodeGenFunction::GenerateCode(), and clang::CodeGen::CodeGenFunction::GenerateObjCMethod().
void CodeGenPGO::emitEmptyCounterMapping | ( | const Decl * | D, |
StringRef | FuncName, | ||
llvm::GlobalValue::LinkageTypes | Linkage | ||
) |
Emit a coverage mapping range with a counter zero for an unused declaration.
Definition at line 917 of file CodeGenPGO.cpp.
References clang::CodeGen::CoverageMappingGen::emitEmptyMapping(), clang::Decl::getBody(), clang::CodeGen::CodeGenModule::getContext(), clang::CodeGen::CodeGenModule::getCoverageMapping(), clang::CodeGen::CodeGenModule::getLangOpts(), clang::Stmt::getLocStart(), clang::ASTContext::getSourceManager(), and clang::SourceManager::isInSystemHeader().
Referenced by clang::CodeGen::CodeGenModule::EmitDeferredUnusedCoverageMappings().
llvm::Function * CodeGenPGO::emitInitialization | ( | CodeGenModule & | CGM | ) | [static] |
Emit static initialization code, if any.
Definition at line 208 of file CodeGenPGO.cpp.
References Builder, clang::CodeGen::CodeGenModule::getCodeGenOpts(), clang::CodeGen::CodeGenModule::getLLVMContext(), clang::CodeGen::CodeGenModule::getModule(), getRegisterFunc(), and clang::InternalLinkage.
Referenced by clang::CodeGen::CodeGenModule::Release().
void CodeGenPGO::emitInstrumentationData | ( | ) |
Emit static data structures for instrumentation data.
Definition at line 191 of file CodeGenPGO.cpp.
References Builder, clang::CodeGen::CodeGenModule::getLLVMContext(), getOrInsertRegisterBB(), and getOrInsertRuntimeRegister().
Referenced by clang::CodeGen::CodeGenFunction::GenerateCapturedStmtFunction(), clang::CodeGen::CodeGenFunction::GenerateCode(), and clang::CodeGen::CodeGenFunction::GenerateObjCMethod().
uint64_t clang::CodeGen::CodeGenPGO::getCurrentRegionCount | ( | ) | const [inline] |
Return the counter value of the current region.
Definition at line 69 of file CodeGenPGO.h.
Referenced by clang::CodeGen::RegionCounter::adjustForControlFlow(), clang::CodeGen::RegionCounter::beginRegion(), clang::CodeGen::CodeGenFunction::EmitBranchOnBoolExpr(), and clang::CodeGen::CodeGenFunction::EmitObjCForCollectionStmt().
StringRef clang::CodeGen::CodeGenPGO::getFuncName | ( | ) | const [inline] |
Get the string used to identify this function in the profile data. For functions with local linkage, this includes the main file name.
Definition at line 63 of file CodeGenPGO.h.
std::string clang::CodeGen::CodeGenPGO::getFuncVarName | ( | StringRef | VarName | ) | const [inline] |
Definition at line 64 of file CodeGenPGO.h.
bool clang::CodeGen::CodeGenPGO::getStmtCount | ( | const Stmt * | S, |
uint64_t & | Count | ||
) | [inline] |
Check if an execution count is known for a given statement. If so, return true and put the value in Count; else return false.
Definition at line 83 of file CodeGenPGO.h.
Referenced by createLoopWeights(), and setCurrentStmt().
bool clang::CodeGen::CodeGenPGO::haveRegionCounts | ( | ) | const [inline] |
Whether or not we have PGO region data for the current function. This is false both when we have no data at all and when our data has been discarded.
Definition at line 59 of file CodeGenPGO.h.
Referenced by createLoopWeights(), and clang::CodeGen::CodeGenFunction::EmitSwitchStmt().
void clang::CodeGen::CodeGenPGO::setCurrentRegionCount | ( | uint64_t | Count | ) | [inline] |
Set the counter value for the current region. This is used to keep track of changes to the most recent counter from control flow and non-local exits.
Definition at line 74 of file CodeGenPGO.h.
References clang::LangAS::Count.
Referenced by clang::CodeGen::RegionCounter::applyAdjustmentsToRegion(), clang::CodeGen::RegionCounter::beginElseRegion(), clang::CodeGen::RegionCounter::beginRegion(), clang::CodeGen::RegionCounter::setCurrentRegionCount(), setCurrentRegionUnreachable(), and setCurrentStmt().
void clang::CodeGen::CodeGenPGO::setCurrentRegionUnreachable | ( | ) | [inline] |
Indicate that the current region is never reached, and thus should have a counter value of zero. This is important so that subsequent regions can correctly track their parent counts.
Definition at line 79 of file CodeGenPGO.h.
References setCurrentRegionCount().
void clang::CodeGen::CodeGenPGO::setCurrentStmt | ( | const Stmt * | S | ) | [inline] |
If the execution count for the current statement is known, record that as the current count.
Definition at line 96 of file CodeGenPGO.h.
References clang::LangAS::Count, getStmtCount(), and setCurrentRegionCount().
Referenced by clang::CodeGen::CodeGenFunction::EmitStmt(), and clang::CodeGen::CodeGenFunction::EvaluateExprAsBool().
friend class RegionCounter [friend] |
Definition at line 157 of file CodeGenPGO.h.