18 #include "llvm/IR/Intrinsics.h" 19 #include "llvm/IR/MDBuilder.h" 20 #include "llvm/Support/Endian.h" 21 #include "llvm/Support/FileSystem.h" 22 #include "llvm/Support/MD5.h" 24 static llvm::cl::opt<bool>
26 llvm::cl::desc(
"Enable value profiling"),
27 llvm::cl::Hidden, llvm::cl::init(
false));
29 using namespace clang;
30 using namespace CodeGen;
32 void CodeGenPGO::setFuncName(StringRef Name,
33 llvm::GlobalValue::LinkageTypes
Linkage) {
34 llvm::IndexedInstrProfReader *PGOReader = CGM.
getPGOReader();
35 FuncName = llvm::getPGOFuncName(
37 PGOReader ? PGOReader->getVersion() : llvm::IndexedInstrProf::Version);
41 FuncNameVar = llvm::createPGOFuncNameVar(CGM.
getModule(),
Linkage, FuncName);
44 void CodeGenPGO::setFuncName(llvm::Function *Fn) {
45 setFuncName(Fn->getName(), Fn->getLinkage());
47 llvm::createPGOFuncNameMetadata(*Fn, FuncName);
76 static const int NumBitsPerType = 6;
77 static const unsigned NumTypesPerWord =
sizeof(uint64_t) * 8 / NumBitsPerType;
78 static const unsigned TooBig = 1u << NumBitsPerType;
88 enum HashType :
unsigned char {
129 static_assert(LastHashType <= TooBig,
"Too many types in HashType");
132 : Working(0), Count(0), HashVersion(HashVersion), MD5() {}
133 void combine(HashType
Type);
137 const int PGOHash::NumBitsPerType;
138 const unsigned PGOHash::NumTypesPerWord;
139 const unsigned PGOHash::TooBig;
142 static PGOHashVersion getPGOHashVersion(llvm::IndexedInstrProfReader *PGOReader,
144 if (PGOReader->getVersion() <= 4)
154 unsigned NextCounter;
158 llvm::DenseMap<const Stmt *, unsigned> &CounterMap;
161 llvm::DenseMap<const Stmt *, unsigned> &CounterMap)
162 : NextCounter(0), Hash(HashVersion), CounterMap(CounterMap) {}
166 bool TraverseBlockExpr(
BlockExpr *BE) {
return true; }
170 TraverseLambdaCapture(LE, &std::get<0>(C), std::get<1>(C));
173 bool TraverseCapturedStmt(
CapturedStmt *CS) {
return true; }
175 bool VisitDecl(
const Decl *D) {
180 case Decl::CXXMethod:
181 case Decl::CXXConstructor:
182 case Decl::CXXDestructor:
183 case Decl::CXXConversion:
184 case Decl::ObjCMethod:
187 CounterMap[D->
getBody()] = NextCounter++;
195 PGOHash::HashType updateCounterMappings(
Stmt *S) {
198 CounterMap[S] = NextCounter++;
203 bool VisitStmt(
Stmt *S) {
204 auto Type = updateCounterMappings(S);
206 Type = getHashType(Hash.getHashVersion(), S);
212 bool TraverseIfStmt(
IfStmt *If) {
215 return Base::TraverseIfStmt(If);
223 Hash.combine(PGOHash::IfThenBranch);
225 Hash.combine(PGOHash::IfElseBranch);
228 Hash.combine(PGOHash::EndOfScope);
235 #define DEFINE_NESTABLE_TRAVERSAL(N) \ 236 bool Traverse##N(N *S) { \ 237 Base::Traverse##N(S); \ 238 if (Hash.getHashVersion() != PGO_HASH_V1) \ 239 Hash.combine(PGOHash::EndOfScope); \ 256 case Stmt::LabelStmtClass:
257 return PGOHash::LabelStmt;
258 case Stmt::WhileStmtClass:
259 return PGOHash::WhileStmt;
260 case Stmt::DoStmtClass:
261 return PGOHash::DoStmt;
262 case Stmt::ForStmtClass:
263 return PGOHash::ForStmt;
264 case Stmt::CXXForRangeStmtClass:
265 return PGOHash::CXXForRangeStmt;
266 case Stmt::ObjCForCollectionStmtClass:
267 return PGOHash::ObjCForCollectionStmt;
268 case Stmt::SwitchStmtClass:
269 return PGOHash::SwitchStmt;
270 case Stmt::CaseStmtClass:
271 return PGOHash::CaseStmt;
272 case Stmt::DefaultStmtClass:
273 return PGOHash::DefaultStmt;
274 case Stmt::IfStmtClass:
275 return PGOHash::IfStmt;
276 case Stmt::CXXTryStmtClass:
277 return PGOHash::CXXTryStmt;
278 case Stmt::CXXCatchStmtClass:
279 return PGOHash::CXXCatchStmt;
280 case Stmt::ConditionalOperatorClass:
281 return PGOHash::ConditionalOperator;
282 case Stmt::BinaryConditionalOperatorClass:
283 return PGOHash::BinaryConditionalOperator;
284 case Stmt::BinaryOperatorClass: {
287 return PGOHash::BinaryOperatorLAnd;
289 return PGOHash::BinaryOperatorLOr;
295 return PGOHash::BinaryOperatorLT;
297 return PGOHash::BinaryOperatorGT;
299 return PGOHash::BinaryOperatorLE;
301 return PGOHash::BinaryOperatorGE;
303 return PGOHash::BinaryOperatorEQ;
305 return PGOHash::BinaryOperatorNE;
316 case Stmt::GotoStmtClass:
317 return PGOHash::GotoStmt;
318 case Stmt::IndirectGotoStmtClass:
319 return PGOHash::IndirectGotoStmt;
320 case Stmt::BreakStmtClass:
321 return PGOHash::BreakStmt;
322 case Stmt::ContinueStmtClass:
323 return PGOHash::ContinueStmt;
324 case Stmt::ReturnStmtClass:
325 return PGOHash::ReturnStmt;
326 case Stmt::CXXThrowExprClass:
327 return PGOHash::ThrowExpr;
328 case Stmt::UnaryOperatorClass: {
331 return PGOHash::UnaryOperatorLNot;
349 bool RecordNextStmtCount;
352 uint64_t CurrentCount;
355 llvm::DenseMap<const Stmt *, uint64_t> &
CountMap;
358 struct BreakContinue {
360 uint64_t ContinueCount;
361 BreakContinue() : BreakCount(0), ContinueCount(0) {}
365 ComputeRegionCounts(llvm::DenseMap<const Stmt *, uint64_t> &CountMap,
367 : PGO(PGO), RecordNextStmtCount(
false),
CountMap(CountMap) {}
369 void RecordStmtCount(
const Stmt *S) {
370 if (RecordNextStmtCount) {
371 CountMap[S] = CurrentCount;
372 RecordNextStmtCount =
false;
377 uint64_t setCount(uint64_t Count) {
378 CurrentCount = Count;
382 void VisitStmt(
const Stmt *S) {
392 CountMap[D->
getBody()] = BodyCount;
404 CountMap[D->
getBody()] = BodyCount;
411 CountMap[D->
getBody()] = BodyCount;
415 void VisitBlockDecl(
const BlockDecl *D) {
418 CountMap[D->
getBody()] = BodyCount;
427 RecordNextStmtCount =
true;
435 RecordNextStmtCount =
true;
438 void VisitGotoStmt(
const GotoStmt *S) {
441 RecordNextStmtCount =
true;
444 void VisitLabelStmt(
const LabelStmt *S) {
445 RecordNextStmtCount =
false;
448 CountMap[S] = BlockCount;
452 void VisitBreakStmt(
const BreakStmt *S) {
454 assert(!BreakContinueStack.empty() &&
"break not in a loop or switch!");
455 BreakContinueStack.back().BreakCount += CurrentCount;
457 RecordNextStmtCount =
true;
462 assert(!BreakContinueStack.empty() &&
"continue stmt not in a loop!");
463 BreakContinueStack.back().ContinueCount += CurrentCount;
465 RecordNextStmtCount =
true;
468 void VisitWhileStmt(
const WhileStmt *S) {
470 uint64_t ParentCount = CurrentCount;
472 BreakContinueStack.push_back(BreakContinue());
476 CountMap[S->
getBody()] = CurrentCount;
478 uint64_t BackedgeCount = CurrentCount;
484 BreakContinue BC = BreakContinueStack.pop_back_val();
486 setCount(ParentCount + BackedgeCount + BC.ContinueCount);
487 CountMap[S->
getCond()] = CondCount;
489 setCount(BC.BreakCount + CondCount - BodyCount);
490 RecordNextStmtCount =
true;
493 void VisitDoStmt(
const DoStmt *S) {
497 BreakContinueStack.push_back(BreakContinue());
499 uint64_t BodyCount = setCount(LoopCount + CurrentCount);
500 CountMap[S->
getBody()] = BodyCount;
502 uint64_t BackedgeCount = CurrentCount;
504 BreakContinue BC = BreakContinueStack.pop_back_val();
507 uint64_t CondCount = setCount(BackedgeCount + BC.ContinueCount);
508 CountMap[S->
getCond()] = CondCount;
510 setCount(BC.BreakCount + CondCount - LoopCount);
511 RecordNextStmtCount =
true;
514 void VisitForStmt(
const ForStmt *S) {
519 uint64_t ParentCount = CurrentCount;
521 BreakContinueStack.push_back(BreakContinue());
525 CountMap[S->
getBody()] = BodyCount;
527 uint64_t BackedgeCount = CurrentCount;
528 BreakContinue BC = BreakContinueStack.pop_back_val();
533 uint64_t IncCount = setCount(BackedgeCount + BC.ContinueCount);
534 CountMap[S->
getInc()] = IncCount;
540 setCount(ParentCount + BackedgeCount + BC.ContinueCount);
542 CountMap[S->
getCond()] = CondCount;
545 setCount(BC.BreakCount + CondCount - BodyCount);
546 RecordNextStmtCount =
true;
558 uint64_t ParentCount = CurrentCount;
559 BreakContinueStack.push_back(BreakContinue());
563 CountMap[S->
getBody()] = BodyCount;
565 uint64_t BackedgeCount = CurrentCount;
566 BreakContinue BC = BreakContinueStack.pop_back_val();
570 uint64_t IncCount = setCount(BackedgeCount + BC.ContinueCount);
571 CountMap[S->
getInc()] = IncCount;
576 setCount(ParentCount + BackedgeCount + BC.ContinueCount);
577 CountMap[S->
getCond()] = CondCount;
579 setCount(BC.BreakCount + CondCount - BodyCount);
580 RecordNextStmtCount =
true;
586 uint64_t ParentCount = CurrentCount;
587 BreakContinueStack.push_back(BreakContinue());
590 CountMap[S->
getBody()] = BodyCount;
592 uint64_t BackedgeCount = CurrentCount;
593 BreakContinue BC = BreakContinueStack.pop_back_val();
595 setCount(BC.BreakCount + ParentCount + BackedgeCount + BC.ContinueCount -
597 RecordNextStmtCount =
true;
606 BreakContinueStack.push_back(BreakContinue());
609 BreakContinue BC = BreakContinueStack.pop_back_val();
610 if (!BreakContinueStack.empty())
611 BreakContinueStack.back().ContinueCount += BC.ContinueCount;
614 RecordNextStmtCount =
true;
618 RecordNextStmtCount =
false;
623 setCount(CurrentCount + CaseCount);
626 CountMap[S] = CaseCount;
627 RecordNextStmtCount =
true;
631 void VisitIfStmt(
const IfStmt *S) {
633 uint64_t ParentCount = CurrentCount;
641 CountMap[S->
getThen()] = ThenCount;
643 uint64_t OutCount = CurrentCount;
645 uint64_t ElseCount = ParentCount - ThenCount;
648 CountMap[S->
getElse()] = ElseCount;
650 OutCount += CurrentCount;
652 OutCount += ElseCount;
654 RecordNextStmtCount =
true;
664 RecordNextStmtCount =
true;
668 RecordNextStmtCount =
false;
671 CountMap[S] = CatchCount;
677 uint64_t ParentCount = CurrentCount;
685 uint64_t OutCount = CurrentCount;
687 uint64_t FalseCount = setCount(ParentCount - TrueCount);
690 OutCount += CurrentCount;
693 RecordNextStmtCount =
true;
698 uint64_t ParentCount = CurrentCount;
702 CountMap[E->
getRHS()] = RHSCount;
704 setCount(ParentCount + RHSCount - CurrentCount);
705 RecordNextStmtCount =
true;
710 uint64_t ParentCount = CurrentCount;
714 CountMap[E->
getRHS()] = RHSCount;
716 setCount(ParentCount + RHSCount - CurrentCount);
717 RecordNextStmtCount =
true;
722 void PGOHash::combine(HashType
Type) {
724 assert(Type &&
"Hash is invalid: unexpected type 0");
725 assert(
unsigned(Type) < TooBig &&
"Hash is invalid: too many types");
728 if (Count && Count % NumTypesPerWord == 0) {
729 using namespace llvm::support;
730 uint64_t Swapped = endian::byte_swap<uint64_t, little>(Working);
731 MD5.update(llvm::makeArrayRef((uint8_t *)&Swapped,
sizeof(Swapped)));
737 Working = Working << NumBitsPerType |
Type;
742 if (Count <= NumTypesPerWord)
753 llvm::MD5::MD5Result Result;
755 using namespace llvm::support;
764 bool InstrumentRegions = CGM.getCodeGenOpts().hasProfileClangInstr();
765 llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader();
766 if (!InstrumentRegions && !PGOReader)
773 if (CGM.getTarget().getCXXABI().hasConstructorVariants()) {
774 if (
const auto *CCD = dyn_cast<CXXConstructorDecl>(D))
782 CGM.ClearUnusedCoverageMapping(D);
785 mapRegionCounters(D);
786 if (CGM.getCodeGenOpts().CoverageMapping)
787 emitCounterRegionMapping(D);
791 computeRegionCounts(D);
792 applyFunctionAttributes(PGOReader, Fn);
796 void CodeGenPGO::mapRegionCounters(
const Decl *D) {
800 if (
auto *PGOReader = CGM.getPGOReader())
801 HashVersion = getPGOHashVersion(PGOReader, CGM);
803 RegionCounterMap.reset(
new llvm::DenseMap<const Stmt *, unsigned>);
804 MapRegionCounters Walker(HashVersion, *RegionCounterMap);
805 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
806 Walker.TraverseDecl(const_cast<FunctionDecl *>(FD));
807 else if (
const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D))
808 Walker.TraverseDecl(const_cast<ObjCMethodDecl *>(MD));
809 else if (
const BlockDecl *BD = dyn_cast_or_null<BlockDecl>(D))
810 Walker.TraverseDecl(const_cast<BlockDecl *>(BD));
811 else if (
const CapturedDecl *CD = dyn_cast_or_null<CapturedDecl>(D))
812 Walker.TraverseDecl(const_cast<CapturedDecl *>(CD));
813 assert(Walker.NextCounter > 0 &&
"no entry counter mapped for decl");
814 NumRegionCounters = Walker.NextCounter;
815 FunctionHash = Walker.Hash.finalize();
818 bool CodeGenPGO::skipRegionMappingForDecl(
const Decl *D) {
823 const auto &
SM = CGM.getContext().getSourceManager();
828 void CodeGenPGO::emitCounterRegionMapping(
const Decl *D) {
829 if (skipRegionMappingForDecl(D))
832 std::string CoverageMapping;
833 llvm::raw_string_ostream OS(CoverageMapping);
835 CGM.getContext().getSourceManager(),
836 CGM.getLangOpts(), RegionCounterMap.get());
840 if (CoverageMapping.empty())
843 CGM.getCoverageMapping()->addFunctionMappingRecord(
844 FuncNameVar, FuncName, FunctionHash, CoverageMapping);
849 llvm::GlobalValue::LinkageTypes Linkage) {
850 if (skipRegionMappingForDecl(D))
853 std::string CoverageMapping;
854 llvm::raw_string_ostream OS(CoverageMapping);
856 CGM.getContext().getSourceManager(),
861 if (CoverageMapping.empty())
864 setFuncName(Name, Linkage);
865 CGM.getCoverageMapping()->addFunctionMappingRecord(
866 FuncNameVar, FuncName, FunctionHash, CoverageMapping,
false);
869 void CodeGenPGO::computeRegionCounts(
const Decl *D) {
870 StmtCountMap.reset(
new llvm::DenseMap<const Stmt *, uint64_t>);
871 ComputeRegionCounts Walker(*StmtCountMap, *
this);
872 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
873 Walker.VisitFunctionDecl(FD);
874 else if (
const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D))
875 Walker.VisitObjCMethodDecl(MD);
876 else if (
const BlockDecl *BD = dyn_cast_or_null<BlockDecl>(D))
877 Walker.VisitBlockDecl(BD);
878 else if (
const CapturedDecl *CD = dyn_cast_or_null<CapturedDecl>(D))
879 Walker.VisitCapturedDecl(const_cast<CapturedDecl *>(CD));
883 CodeGenPGO::applyFunctionAttributes(llvm::IndexedInstrProfReader *PGOReader,
884 llvm::Function *Fn) {
889 Fn->setEntryCount(FunctionCount);
894 if (!CGM.getCodeGenOpts().hasProfileClangInstr() || !RegionCounterMap)
896 if (!Builder.GetInsertBlock())
899 unsigned Counter = (*RegionCounterMap)[S];
900 auto *I8PtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
902 llvm::Value *Args[] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
903 Builder.getInt64(FunctionHash),
904 Builder.getInt32(NumRegionCounters),
905 Builder.getInt32(Counter), StepV};
907 Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::instrprof_increment),
908 makeArrayRef(Args, 4));
911 CGM.getIntrinsic(llvm::Intrinsic::instrprof_increment_step),
918 llvm::Instruction *ValueSite,
llvm::Value *ValuePtr) {
923 if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock())
926 if (isa<llvm::Constant>(ValuePtr))
929 bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr();
930 if (InstrumentValueSites && RegionCounterMap) {
931 auto BuilderInsertPoint = Builder.saveIP();
932 Builder.SetInsertPoint(ValueSite);
934 llvm::ConstantExpr::getBitCast(FuncNameVar, Builder.getInt8PtrTy()),
935 Builder.getInt64(FunctionHash),
936 Builder.CreatePtrToInt(ValuePtr, Builder.getInt64Ty()),
937 Builder.getInt32(ValueKind),
938 Builder.getInt32(NumValueSites[ValueKind]++)
941 CGM.getIntrinsic(llvm::Intrinsic::instrprof_value_profile), Args);
942 Builder.restoreIP(BuilderInsertPoint);
946 llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader();
954 if (NumValueSites[ValueKind] >= ProfRecord->getNumValueSites(ValueKind))
957 llvm::annotateValueSite(CGM.getModule(), *ValueSite, *ProfRecord,
958 (llvm::InstrProfValueKind)ValueKind,
959 NumValueSites[ValueKind]);
961 NumValueSites[ValueKind]++;
965 void CodeGenPGO::loadRegionCounts(llvm::IndexedInstrProfReader *PGOReader,
967 CGM.getPGOStats().addVisited(IsInMainFile);
968 RegionCounts.clear();
970 PGOReader->getInstrProfRecord(FuncName, FunctionHash);
971 if (
auto E = RecordExpected.takeError()) {
972 auto IPE = llvm::InstrProfError::take(std::move(E));
973 if (IPE == llvm::instrprof_error::unknown_function)
974 CGM.getPGOStats().addMissing(IsInMainFile);
975 else if (IPE == llvm::instrprof_error::hash_mismatch)
976 CGM.getPGOStats().addMismatched(IsInMainFile);
977 else if (IPE == llvm::instrprof_error::malformed)
979 CGM.getPGOStats().addMismatched(IsInMainFile);
983 std::make_unique<llvm::InstrProfRecord>(std::move(RecordExpected.get()));
984 RegionCounts = ProfRecord->Counts;
992 return MaxWeight < UINT32_MAX ? 1 : MaxWeight / UINT32_MAX + 1;
1005 assert(Scale &&
"scale by 0?");
1006 uint64_t Scaled = Weight / Scale + 1;
1007 assert(Scaled <= UINT32_MAX &&
"overflow 32-bits");
1011 llvm::MDNode *CodeGenFunction::createProfileWeights(uint64_t TrueCount,
1012 uint64_t FalseCount) {
1014 if (!TrueCount && !FalseCount)
1020 llvm::MDBuilder MDHelper(CGM.getLLVMContext());
1028 if (Weights.size() < 2)
1032 uint64_t MaxWeight = *std::max_element(Weights.begin(), Weights.end());
1040 ScaledWeights.reserve(Weights.size());
1041 for (uint64_t W : Weights)
1044 llvm::MDBuilder MDHelper(CGM.getLLVMContext());
1045 return MDHelper.createBranchWeights(ScaledWeights);
1048 llvm::MDNode *CodeGenFunction::createProfileWeightsForLoop(
const Stmt *Cond,
1049 uint64_t LoopCount) {
1050 if (!PGO.haveRegionCounts())
1053 assert(CondCount.hasValue() &&
"missing expected loop condition count");
1054 if (*CondCount == 0)
1056 return createProfileWeights(LoopCount,
1057 std::max(*CondCount, LoopCount) - LoopCount);
Represents a function declaration or definition.
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))
SourceLocation getBeginLoc() const LLVM_READONLY
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
__DEVICE__ int max(int __a, int __b)
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...
CaseStmt - Represent a case statement.
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)
Represents 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)
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
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
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.
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.
bool LE(InterpState &S, CodePtr OpPC)
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()
capture_range captures() const
Retrieve this lambda's captures.
uint64_t getRegionCount(const Stmt *S)
Return the region count for the counter at the given index.
BreakStmt - This represents a break.
DeclStmt * getLoopVarStmt()
DeclStmt * getBeginStmt()
void emitEmptyMapping(const Decl *D, llvm::raw_ostream &OS)
Emit the coverage mapping data for an unused function.
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