19 #include "llvm/IR/Intrinsics.h" 20 #include "llvm/IR/MDBuilder.h" 21 #include "llvm/Support/Endian.h" 22 #include "llvm/Support/FileSystem.h" 23 #include "llvm/Support/MD5.h" 25 static llvm::cl::opt<bool>
27 llvm::cl::desc(
"Enable value profiling"),
28 llvm::cl::Hidden, llvm::cl::init(
false));
30 using namespace clang;
31 using namespace CodeGen;
33 void CodeGenPGO::setFuncName(StringRef Name,
34 llvm::GlobalValue::LinkageTypes
Linkage) {
35 llvm::IndexedInstrProfReader *PGOReader = CGM.
getPGOReader();
36 FuncName = llvm::getPGOFuncName(
38 PGOReader ? PGOReader->getVersion() : llvm::IndexedInstrProf::Version);
42 FuncNameVar = llvm::createPGOFuncNameVar(CGM.
getModule(),
Linkage, FuncName);
45 void CodeGenPGO::setFuncName(llvm::Function *Fn) {
46 setFuncName(Fn->getName(), Fn->getLinkage());
48 llvm::createPGOFuncNameMetadata(*Fn, FuncName);
77 static const int NumBitsPerType = 6;
78 static const unsigned NumTypesPerWord =
sizeof(uint64_t) * 8 / NumBitsPerType;
79 static const unsigned TooBig = 1u << NumBitsPerType;
89 enum HashType :
unsigned char {
130 static_assert(LastHashType <= TooBig,
"Too many types in HashType");
133 : Working(0), Count(0), HashVersion(HashVersion), MD5() {}
134 void combine(HashType
Type);
138 const int PGOHash::NumBitsPerType;
139 const unsigned PGOHash::NumTypesPerWord;
140 const unsigned PGOHash::TooBig;
143 static PGOHashVersion getPGOHashVersion(llvm::IndexedInstrProfReader *PGOReader,
145 if (PGOReader->getVersion() <= 4)
155 unsigned NextCounter;
159 llvm::DenseMap<const Stmt *, unsigned> &CounterMap;
162 llvm::DenseMap<const Stmt *, unsigned> &CounterMap)
163 : NextCounter(0), Hash(HashVersion), CounterMap(CounterMap) {}
167 bool TraverseBlockExpr(
BlockExpr *BE) {
return true; }
168 bool TraverseLambdaBody(
LambdaExpr *LE) {
return true; }
169 bool TraverseCapturedStmt(
CapturedStmt *CS) {
return true; }
171 bool VisitDecl(
const Decl *D) {
176 case Decl::CXXMethod:
177 case Decl::CXXConstructor:
178 case Decl::CXXDestructor:
179 case Decl::CXXConversion:
180 case Decl::ObjCMethod:
183 CounterMap[D->
getBody()] = NextCounter++;
191 PGOHash::HashType updateCounterMappings(
Stmt *S) {
194 CounterMap[S] = NextCounter++;
199 bool VisitStmt(
Stmt *S) {
200 auto Type = updateCounterMappings(S);
202 Type = getHashType(Hash.getHashVersion(), S);
208 bool TraverseIfStmt(
IfStmt *If) {
211 return Base::TraverseIfStmt(If);
219 Hash.combine(PGOHash::IfThenBranch);
221 Hash.combine(PGOHash::IfElseBranch);
224 Hash.combine(PGOHash::EndOfScope);
231 #define DEFINE_NESTABLE_TRAVERSAL(N) \ 232 bool Traverse##N(N *S) { \ 233 Base::Traverse##N(S); \ 234 if (Hash.getHashVersion() != PGO_HASH_V1) \ 235 Hash.combine(PGOHash::EndOfScope); \ 252 case Stmt::LabelStmtClass:
253 return PGOHash::LabelStmt;
254 case Stmt::WhileStmtClass:
255 return PGOHash::WhileStmt;
256 case Stmt::DoStmtClass:
257 return PGOHash::DoStmt;
258 case Stmt::ForStmtClass:
259 return PGOHash::ForStmt;
260 case Stmt::CXXForRangeStmtClass:
261 return PGOHash::CXXForRangeStmt;
262 case Stmt::ObjCForCollectionStmtClass:
263 return PGOHash::ObjCForCollectionStmt;
264 case Stmt::SwitchStmtClass:
265 return PGOHash::SwitchStmt;
266 case Stmt::CaseStmtClass:
267 return PGOHash::CaseStmt;
268 case Stmt::DefaultStmtClass:
269 return PGOHash::DefaultStmt;
270 case Stmt::IfStmtClass:
271 return PGOHash::IfStmt;
272 case Stmt::CXXTryStmtClass:
273 return PGOHash::CXXTryStmt;
274 case Stmt::CXXCatchStmtClass:
275 return PGOHash::CXXCatchStmt;
276 case Stmt::ConditionalOperatorClass:
277 return PGOHash::ConditionalOperator;
278 case Stmt::BinaryConditionalOperatorClass:
279 return PGOHash::BinaryConditionalOperator;
280 case Stmt::BinaryOperatorClass: {
283 return PGOHash::BinaryOperatorLAnd;
285 return PGOHash::BinaryOperatorLOr;
291 return PGOHash::BinaryOperatorLT;
293 return PGOHash::BinaryOperatorGT;
295 return PGOHash::BinaryOperatorLE;
297 return PGOHash::BinaryOperatorGE;
299 return PGOHash::BinaryOperatorEQ;
301 return PGOHash::BinaryOperatorNE;
312 case Stmt::GotoStmtClass:
313 return PGOHash::GotoStmt;
314 case Stmt::IndirectGotoStmtClass:
315 return PGOHash::IndirectGotoStmt;
316 case Stmt::BreakStmtClass:
317 return PGOHash::BreakStmt;
318 case Stmt::ContinueStmtClass:
319 return PGOHash::ContinueStmt;
320 case Stmt::ReturnStmtClass:
321 return PGOHash::ReturnStmt;
322 case Stmt::CXXThrowExprClass:
323 return PGOHash::ThrowExpr;
324 case Stmt::UnaryOperatorClass: {
327 return PGOHash::UnaryOperatorLNot;
345 bool RecordNextStmtCount;
348 uint64_t CurrentCount;
351 llvm::DenseMap<const Stmt *, uint64_t> &
CountMap;
354 struct BreakContinue {
356 uint64_t ContinueCount;
357 BreakContinue() : BreakCount(0), ContinueCount(0) {}
361 ComputeRegionCounts(llvm::DenseMap<const Stmt *, uint64_t> &CountMap,
363 : PGO(PGO), RecordNextStmtCount(
false),
CountMap(CountMap) {}
365 void RecordStmtCount(
const Stmt *S) {
366 if (RecordNextStmtCount) {
367 CountMap[S] = CurrentCount;
368 RecordNextStmtCount =
false;
373 uint64_t setCount(uint64_t Count) {
374 CurrentCount = Count;
378 void VisitStmt(
const Stmt *S) {
388 CountMap[D->
getBody()] = BodyCount;
400 CountMap[D->
getBody()] = BodyCount;
407 CountMap[D->
getBody()] = BodyCount;
411 void VisitBlockDecl(
const BlockDecl *D) {
414 CountMap[D->
getBody()] = BodyCount;
423 RecordNextStmtCount =
true;
431 RecordNextStmtCount =
true;
434 void VisitGotoStmt(
const GotoStmt *S) {
437 RecordNextStmtCount =
true;
440 void VisitLabelStmt(
const LabelStmt *S) {
441 RecordNextStmtCount =
false;
444 CountMap[S] = BlockCount;
448 void VisitBreakStmt(
const BreakStmt *S) {
450 assert(!BreakContinueStack.empty() &&
"break not in a loop or switch!");
451 BreakContinueStack.back().BreakCount += CurrentCount;
453 RecordNextStmtCount =
true;
458 assert(!BreakContinueStack.empty() &&
"continue stmt not in a loop!");
459 BreakContinueStack.back().ContinueCount += CurrentCount;
461 RecordNextStmtCount =
true;
464 void VisitWhileStmt(
const WhileStmt *S) {
466 uint64_t ParentCount = CurrentCount;
468 BreakContinueStack.push_back(BreakContinue());
472 CountMap[S->
getBody()] = CurrentCount;
474 uint64_t BackedgeCount = CurrentCount;
480 BreakContinue BC = BreakContinueStack.pop_back_val();
482 setCount(ParentCount + BackedgeCount + BC.ContinueCount);
483 CountMap[S->
getCond()] = CondCount;
485 setCount(BC.BreakCount + CondCount - BodyCount);
486 RecordNextStmtCount =
true;
489 void VisitDoStmt(
const DoStmt *S) {
493 BreakContinueStack.push_back(BreakContinue());
495 uint64_t BodyCount = setCount(LoopCount + CurrentCount);
496 CountMap[S->
getBody()] = BodyCount;
498 uint64_t BackedgeCount = CurrentCount;
500 BreakContinue BC = BreakContinueStack.pop_back_val();
503 uint64_t CondCount = setCount(BackedgeCount + BC.ContinueCount);
504 CountMap[S->
getCond()] = CondCount;
506 setCount(BC.BreakCount + CondCount - LoopCount);
507 RecordNextStmtCount =
true;
510 void VisitForStmt(
const ForStmt *S) {
515 uint64_t ParentCount = CurrentCount;
517 BreakContinueStack.push_back(BreakContinue());
521 CountMap[S->
getBody()] = BodyCount;
523 uint64_t BackedgeCount = CurrentCount;
524 BreakContinue BC = BreakContinueStack.pop_back_val();
529 uint64_t IncCount = setCount(BackedgeCount + BC.ContinueCount);
530 CountMap[S->
getInc()] = IncCount;
536 setCount(ParentCount + BackedgeCount + BC.ContinueCount);
538 CountMap[S->
getCond()] = CondCount;
541 setCount(BC.BreakCount + CondCount - BodyCount);
542 RecordNextStmtCount =
true;
552 uint64_t ParentCount = CurrentCount;
553 BreakContinueStack.push_back(BreakContinue());
557 CountMap[S->
getBody()] = BodyCount;
559 uint64_t BackedgeCount = CurrentCount;
560 BreakContinue BC = BreakContinueStack.pop_back_val();
564 uint64_t IncCount = setCount(BackedgeCount + BC.ContinueCount);
565 CountMap[S->
getInc()] = IncCount;
570 setCount(ParentCount + BackedgeCount + BC.ContinueCount);
571 CountMap[S->
getCond()] = CondCount;
573 setCount(BC.BreakCount + CondCount - BodyCount);
574 RecordNextStmtCount =
true;
580 uint64_t ParentCount = CurrentCount;
581 BreakContinueStack.push_back(BreakContinue());
584 CountMap[S->
getBody()] = BodyCount;
586 uint64_t BackedgeCount = CurrentCount;
587 BreakContinue BC = BreakContinueStack.pop_back_val();
589 setCount(BC.BreakCount + ParentCount + BackedgeCount + BC.ContinueCount -
591 RecordNextStmtCount =
true;
600 BreakContinueStack.push_back(BreakContinue());
603 BreakContinue BC = BreakContinueStack.pop_back_val();
604 if (!BreakContinueStack.empty())
605 BreakContinueStack.back().ContinueCount += BC.ContinueCount;
608 RecordNextStmtCount =
true;
612 RecordNextStmtCount =
false;
617 setCount(CurrentCount + CaseCount);
620 CountMap[S] = CaseCount;
621 RecordNextStmtCount =
true;
625 void VisitIfStmt(
const IfStmt *S) {
627 uint64_t ParentCount = CurrentCount;
635 CountMap[S->
getThen()] = ThenCount;
637 uint64_t OutCount = CurrentCount;
639 uint64_t ElseCount = ParentCount - ThenCount;
642 CountMap[S->
getElse()] = ElseCount;
644 OutCount += CurrentCount;
646 OutCount += ElseCount;
648 RecordNextStmtCount =
true;
658 RecordNextStmtCount =
true;
662 RecordNextStmtCount =
false;
665 CountMap[S] = CatchCount;
671 uint64_t ParentCount = CurrentCount;
679 uint64_t OutCount = CurrentCount;
681 uint64_t FalseCount = setCount(ParentCount - TrueCount);
684 OutCount += CurrentCount;
687 RecordNextStmtCount =
true;
692 uint64_t ParentCount = CurrentCount;
696 CountMap[E->
getRHS()] = RHSCount;
698 setCount(ParentCount + RHSCount - CurrentCount);
699 RecordNextStmtCount =
true;
704 uint64_t ParentCount = CurrentCount;
708 CountMap[E->
getRHS()] = RHSCount;
710 setCount(ParentCount + RHSCount - CurrentCount);
711 RecordNextStmtCount =
true;
716 void PGOHash::combine(HashType
Type) {
718 assert(Type &&
"Hash is invalid: unexpected type 0");
719 assert(
unsigned(Type) < TooBig &&
"Hash is invalid: too many types");
722 if (Count && Count % NumTypesPerWord == 0) {
723 using namespace llvm::support;
724 uint64_t Swapped = endian::byte_swap<uint64_t, little>(Working);
725 MD5.update(llvm::makeArrayRef((uint8_t *)&Swapped,
sizeof(Swapped)));
731 Working = Working << NumBitsPerType |
Type;
736 if (Count <= NumTypesPerWord)
747 llvm::MD5::MD5Result Result;
749 using namespace llvm::support;
758 bool InstrumentRegions = CGM.getCodeGenOpts().hasProfileClangInstr();
759 llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader();
760 if (!InstrumentRegions && !PGOReader)
767 if (CGM.getTarget().getCXXABI().hasConstructorVariants()) {
771 if (
const auto *CCD = dyn_cast<CXXConstructorDecl>(D))
776 CGM.ClearUnusedCoverageMapping(D);
779 mapRegionCounters(D);
780 if (CGM.getCodeGenOpts().CoverageMapping)
781 emitCounterRegionMapping(D);
785 computeRegionCounts(D);
786 applyFunctionAttributes(PGOReader, Fn);
790 void CodeGenPGO::mapRegionCounters(
const Decl *D) {
794 if (
auto *PGOReader = CGM.getPGOReader())
795 HashVersion = getPGOHashVersion(PGOReader, CGM);
797 RegionCounterMap.reset(
new llvm::DenseMap<const Stmt *, unsigned>);
798 MapRegionCounters Walker(HashVersion, *RegionCounterMap);
799 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
800 Walker.TraverseDecl(const_cast<FunctionDecl *>(FD));
801 else if (
const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D))
802 Walker.TraverseDecl(const_cast<ObjCMethodDecl *>(MD));
803 else if (
const BlockDecl *BD = dyn_cast_or_null<BlockDecl>(D))
804 Walker.TraverseDecl(const_cast<BlockDecl *>(BD));
805 else if (
const CapturedDecl *CD = dyn_cast_or_null<CapturedDecl>(D))
806 Walker.TraverseDecl(const_cast<CapturedDecl *>(CD));
807 assert(Walker.NextCounter > 0 &&
"no entry counter mapped for decl");
808 NumRegionCounters = Walker.NextCounter;
809 FunctionHash = Walker.Hash.finalize();
812 bool CodeGenPGO::skipRegionMappingForDecl(
const Decl *D) {
817 const auto &
SM = CGM.getContext().getSourceManager();
822 void CodeGenPGO::emitCounterRegionMapping(
const Decl *D) {
823 if (skipRegionMappingForDecl(D))
826 std::string CoverageMapping;
827 llvm::raw_string_ostream OS(CoverageMapping);
829 CGM.getContext().getSourceManager(),
830 CGM.getLangOpts(), RegionCounterMap.get());
834 if (CoverageMapping.empty())
837 CGM.getCoverageMapping()->addFunctionMappingRecord(
838 FuncNameVar, FuncName, FunctionHash, CoverageMapping);
843 llvm::GlobalValue::LinkageTypes Linkage) {
844 if (skipRegionMappingForDecl(D))
847 std::string CoverageMapping;
848 llvm::raw_string_ostream OS(CoverageMapping);
850 CGM.getContext().getSourceManager(),
855 if (CoverageMapping.empty())
858 setFuncName(Name, Linkage);
859 CGM.getCoverageMapping()->addFunctionMappingRecord(
860 FuncNameVar, FuncName, FunctionHash, CoverageMapping,
false);
863 void CodeGenPGO::computeRegionCounts(
const Decl *D) {
864 StmtCountMap.reset(
new llvm::DenseMap<const Stmt *, uint64_t>);
865 ComputeRegionCounts Walker(*StmtCountMap, *
this);
866 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
867 Walker.VisitFunctionDecl(FD);
868 else if (
const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D))
869 Walker.VisitObjCMethodDecl(MD);
870 else if (
const BlockDecl *BD = dyn_cast_or_null<BlockDecl>(D))
871 Walker.VisitBlockDecl(BD);
872 else if (
const CapturedDecl *CD = dyn_cast_or_null<CapturedDecl>(D))
873 Walker.VisitCapturedDecl(const_cast<CapturedDecl *>(CD));
877 CodeGenPGO::applyFunctionAttributes(llvm::IndexedInstrProfReader *PGOReader,
878 llvm::Function *Fn) {
883 Fn->setEntryCount(FunctionCount);
888 if (!CGM.getCodeGenOpts().hasProfileClangInstr() || !RegionCounterMap)
890 if (!Builder.GetInsertBlock())
893 unsigned Counter = (*RegionCounterMap)[S];
894 auto *I8PtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
896 llvm::Value *Args[] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
897 Builder.getInt64(FunctionHash),
898 Builder.getInt32(NumRegionCounters),
899 Builder.getInt32(Counter), StepV};
901 Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::instrprof_increment),
902 makeArrayRef(Args, 4));
905 CGM.getIntrinsic(llvm::Intrinsic::instrprof_increment_step),
912 llvm::Instruction *ValueSite,
llvm::Value *ValuePtr) {
917 if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock())
920 if (isa<llvm::Constant>(ValuePtr))
923 bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr();
924 if (InstrumentValueSites && RegionCounterMap) {
925 auto BuilderInsertPoint = Builder.saveIP();
926 Builder.SetInsertPoint(ValueSite);
928 llvm::ConstantExpr::getBitCast(FuncNameVar, Builder.getInt8PtrTy()),
929 Builder.getInt64(FunctionHash),
930 Builder.CreatePtrToInt(ValuePtr, Builder.getInt64Ty()),
931 Builder.getInt32(ValueKind),
932 Builder.getInt32(NumValueSites[ValueKind]++)
935 CGM.getIntrinsic(llvm::Intrinsic::instrprof_value_profile), Args);
936 Builder.restoreIP(BuilderInsertPoint);
940 llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader();
948 if (NumValueSites[ValueKind] >= ProfRecord->getNumValueSites(ValueKind))
951 llvm::annotateValueSite(CGM.getModule(), *ValueSite, *ProfRecord,
952 (llvm::InstrProfValueKind)ValueKind,
953 NumValueSites[ValueKind]);
955 NumValueSites[ValueKind]++;
959 void CodeGenPGO::loadRegionCounts(llvm::IndexedInstrProfReader *PGOReader,
961 CGM.getPGOStats().addVisited(IsInMainFile);
962 RegionCounts.clear();
964 PGOReader->getInstrProfRecord(FuncName, FunctionHash);
965 if (
auto E = RecordExpected.takeError()) {
966 auto IPE = llvm::InstrProfError::take(std::move(E));
967 if (IPE == llvm::instrprof_error::unknown_function)
968 CGM.getPGOStats().addMissing(IsInMainFile);
969 else if (IPE == llvm::instrprof_error::hash_mismatch)
970 CGM.getPGOStats().addMismatched(IsInMainFile);
971 else if (IPE == llvm::instrprof_error::malformed)
973 CGM.getPGOStats().addMismatched(IsInMainFile);
977 llvm::make_unique<llvm::InstrProfRecord>(std::move(RecordExpected.get()));
978 RegionCounts = ProfRecord->Counts;
986 return MaxWeight < UINT32_MAX ? 1 : MaxWeight / UINT32_MAX + 1;
999 assert(Scale &&
"scale by 0?");
1000 uint64_t Scaled = Weight / Scale + 1;
1001 assert(Scaled <= UINT32_MAX &&
"overflow 32-bits");
1005 llvm::MDNode *CodeGenFunction::createProfileWeights(uint64_t TrueCount,
1006 uint64_t FalseCount) {
1008 if (!TrueCount && !FalseCount)
1014 llvm::MDBuilder MDHelper(CGM.getLLVMContext());
1022 if (Weights.size() < 2)
1026 uint64_t MaxWeight = *std::max_element(Weights.begin(), Weights.end());
1034 ScaledWeights.reserve(Weights.size());
1035 for (uint64_t W : Weights)
1038 llvm::MDBuilder MDHelper(CGM.getLLVMContext());
1039 return MDHelper.createBranchWeights(ScaledWeights);
1042 llvm::MDNode *CodeGenFunction::createProfileWeightsForLoop(
const Stmt *Cond,
1043 uint64_t LoopCount) {
1044 if (!PGO.haveRegionCounts())
1047 assert(CondCount.hasValue() &&
"missing expected loop condition count");
1048 if (*CondCount == 0)
1050 return createProfileWeights(LoopCount,
1051 std::max(*CondCount, LoopCount) - LoopCount);
Represents a function declaration or definition.
const Stmt * getElse() const
const CodeGenOptions & getCodeGenOpts() const
const Expr * getSubExpr() const
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
static uint64_t calculateWeightScale(uint64_t MaxWeight)
Calculate what to divide by to scale weights.
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
CXXDtorType getDtorType() const
Stmt - This represents one statement.
CXXCatchStmt * getHandler(unsigned i)
IfStmt - This represents an if/then/else.
Organizes the per-function state that is used while generating code coverage mapping data...
Decl - This represents one declaration (or definition), e.g.
Stmt * getHandlerBlock() const
Expr * getFalseExpr() const
The base class of the type hierarchy.
constexpr XRayInstrMask Function
void finalize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)
void emitCounterIncrement(CGBuilderTy &Builder, const Stmt *S, llvm::Value *StepV)
ObjCMethodDecl - Represents an instance or class method declaration.
llvm::ImmutableMap< CountKey, unsigned > CountMap
A C++ throw-expression (C++ [except.throw]).
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
LabelStmt - Represents a label, which has a substatement.
PGOHashVersion
The version of the PGO hash algorithm.
static llvm::cl::opt< bool > EnableValueProfiling("enable-value-profiling", llvm::cl::ZeroOrMore, llvm::cl::desc("Enable value profiling"), llvm::cl::Hidden, llvm::cl::init(false))
const Expr * getRetValue() const
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
llvm::IndexedInstrProfReader * getPGOReader() const
IndirectGotoStmt - This represents an indirect goto.
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
A builtin binary operation expression such as "x + y" or "x <= y".
CXXCtorType getCtorType() const
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
void assignRegionCounters(GlobalDecl GD, llvm::Function *Fn)
Assign counters to regions and configure them for PGO of a given function.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Represents the body of a CapturedStmt, and serves as its DeclContext.
ConditionalOperator - The ?: ternary operator.
void valueProfile(CGBuilderTy &Builder, uint32_t ValueKind, llvm::Instruction *ValueSite, llvm::Value *ValuePtr)
Pepresents a block literal declaration, which is like an unnamed FunctionDecl.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
#define DEFINE_NESTABLE_TRAVERSAL(N)
const Stmt * getThen() const
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
CXXTryStmt - A C++ try block, including all handlers.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Expr * getTrueExpr() const
GlobalDecl - represents a global declaration.
DoStmt - This represents a 'do/while' stmt.
virtual bool hasBody() const
Returns true if this Decl represents a declaration for a body of code, such as a function or method d...
The l-value was considered opaque, so the alignment was determined from a type.
This captures a statement into a function.
unsigned getNumHandlers() const
SourceLocation getLocStart() const LLVM_READONLY
const Decl * getDecl() const
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
bool isInMainFile(SourceLocation Loc) const
Returns whether the PresumedLoc for a given SourceLocation is in the main file.
This class organizes the cross-function state that is used while generating LLVM code.
Dataflow Directional Tag Classes.
StmtClass getStmtClass() const
llvm::Module & getModule() const
bool hasProfileClangInstr() const
Check if Clang profile instrumenation is on.
const Stmt * getBody() const
void emitEmptyCounterMapping(const Decl *D, StringRef FuncName, llvm::GlobalValue::LinkageTypes Linkage)
Emit a coverage mapping range with a counter zero for an unused declaration.
SwitchStmt - This represents a 'switch' stmt.
Represents Objective-C's collection statement.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
DeclStmt * getRangeStmt()
GotoStmt - This represents a direct goto.
static uint32_t scaleBranchWeight(uint64_t Weight, uint64_t Scale)
Scale an individual branch weight (and add 1).
void emitCounterMapping(const Decl *D, llvm::raw_ostream &OS)
Emit the coverage mapping data which maps the regions of code to counters that will be used to find t...
ContinueStmt - This represents a continue.
std::string MainFileName
The user provided name for the "main file", if non-empty.
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
CXXCatchStmt - This represents a C++ catch block.
static bool IsConstructorDelegationValid(const CXXConstructorDecl *Ctor)
Checks whether the given constructor is a valid subject for the complete-to-base constructor delegati...
WhileStmt - This represents a 'while' stmt.
CompoundStmt * getTryBlock()
__DEVICE__ int max(int __a, int __b)
uint64_t getRegionCount(const Stmt *S)
Return the region count for the counter at the given index.
BreakStmt - This represents a break.
DeclStmt * getLoopVarStmt()
const Expr * getCond() const
DeclStmt * getBeginStmt()
void emitEmptyMapping(const Decl *D, llvm::raw_ostream &OS)
Emit the coverage mapping data for an unused function.
const Expr * getCond() const
This class handles loading and caching of source files into memory.
bool haveRegionCounts() const
Whether or not we have PGO region data for the current function.
SourceLocation getLocation() const