18 #include "llvm/IR/Intrinsics.h" 19 #include "llvm/IR/MDBuilder.h" 20 #include "llvm/Support/CommandLine.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; }
171 TraverseLambdaCapture(LE, &std::get<0>(C), std::get<1>(C));
174 bool TraverseCapturedStmt(
CapturedStmt *CS) {
return true; }
176 bool VisitDecl(
const Decl *D) {
181 case Decl::CXXMethod:
182 case Decl::CXXConstructor:
183 case Decl::CXXDestructor:
184 case Decl::CXXConversion:
185 case Decl::ObjCMethod:
188 CounterMap[D->
getBody()] = NextCounter++;
196 PGOHash::HashType updateCounterMappings(
Stmt *S) {
199 CounterMap[S] = NextCounter++;
204 bool VisitStmt(
Stmt *S) {
205 auto Type = updateCounterMappings(S);
207 Type = getHashType(Hash.getHashVersion(), S);
213 bool TraverseIfStmt(
IfStmt *If) {
216 return Base::TraverseIfStmt(If);
224 Hash.combine(PGOHash::IfThenBranch);
226 Hash.combine(PGOHash::IfElseBranch);
229 Hash.combine(PGOHash::EndOfScope);
236 #define DEFINE_NESTABLE_TRAVERSAL(N) \ 237 bool Traverse##N(N *S) { \ 238 Base::Traverse##N(S); \ 239 if (Hash.getHashVersion() != PGO_HASH_V1) \ 240 Hash.combine(PGOHash::EndOfScope); \ 257 case Stmt::LabelStmtClass:
258 return PGOHash::LabelStmt;
259 case Stmt::WhileStmtClass:
260 return PGOHash::WhileStmt;
261 case Stmt::DoStmtClass:
262 return PGOHash::DoStmt;
263 case Stmt::ForStmtClass:
264 return PGOHash::ForStmt;
265 case Stmt::CXXForRangeStmtClass:
266 return PGOHash::CXXForRangeStmt;
267 case Stmt::ObjCForCollectionStmtClass:
268 return PGOHash::ObjCForCollectionStmt;
269 case Stmt::SwitchStmtClass:
270 return PGOHash::SwitchStmt;
271 case Stmt::CaseStmtClass:
272 return PGOHash::CaseStmt;
273 case Stmt::DefaultStmtClass:
274 return PGOHash::DefaultStmt;
275 case Stmt::IfStmtClass:
276 return PGOHash::IfStmt;
277 case Stmt::CXXTryStmtClass:
278 return PGOHash::CXXTryStmt;
279 case Stmt::CXXCatchStmtClass:
280 return PGOHash::CXXCatchStmt;
281 case Stmt::ConditionalOperatorClass:
282 return PGOHash::ConditionalOperator;
283 case Stmt::BinaryConditionalOperatorClass:
284 return PGOHash::BinaryConditionalOperator;
285 case Stmt::BinaryOperatorClass: {
288 return PGOHash::BinaryOperatorLAnd;
290 return PGOHash::BinaryOperatorLOr;
296 return PGOHash::BinaryOperatorLT;
298 return PGOHash::BinaryOperatorGT;
300 return PGOHash::BinaryOperatorLE;
302 return PGOHash::BinaryOperatorGE;
304 return PGOHash::BinaryOperatorEQ;
306 return PGOHash::BinaryOperatorNE;
317 case Stmt::GotoStmtClass:
318 return PGOHash::GotoStmt;
319 case Stmt::IndirectGotoStmtClass:
320 return PGOHash::IndirectGotoStmt;
321 case Stmt::BreakStmtClass:
322 return PGOHash::BreakStmt;
323 case Stmt::ContinueStmtClass:
324 return PGOHash::ContinueStmt;
325 case Stmt::ReturnStmtClass:
326 return PGOHash::ReturnStmt;
327 case Stmt::CXXThrowExprClass:
328 return PGOHash::ThrowExpr;
329 case Stmt::UnaryOperatorClass: {
332 return PGOHash::UnaryOperatorLNot;
350 bool RecordNextStmtCount;
353 uint64_t CurrentCount;
356 llvm::DenseMap<const Stmt *, uint64_t> &
CountMap;
359 struct BreakContinue {
361 uint64_t ContinueCount;
362 BreakContinue() : BreakCount(0), ContinueCount(0) {}
366 ComputeRegionCounts(llvm::DenseMap<const Stmt *, uint64_t> &CountMap,
368 : PGO(PGO), RecordNextStmtCount(
false),
CountMap(CountMap) {}
370 void RecordStmtCount(
const Stmt *S) {
371 if (RecordNextStmtCount) {
372 CountMap[S] = CurrentCount;
373 RecordNextStmtCount =
false;
378 uint64_t setCount(uint64_t Count) {
379 CurrentCount = Count;
383 void VisitStmt(
const Stmt *S) {
393 CountMap[D->
getBody()] = BodyCount;
405 CountMap[D->
getBody()] = BodyCount;
412 CountMap[D->
getBody()] = BodyCount;
416 void VisitBlockDecl(
const BlockDecl *D) {
419 CountMap[D->
getBody()] = BodyCount;
428 RecordNextStmtCount =
true;
436 RecordNextStmtCount =
true;
439 void VisitGotoStmt(
const GotoStmt *S) {
442 RecordNextStmtCount =
true;
445 void VisitLabelStmt(
const LabelStmt *S) {
446 RecordNextStmtCount =
false;
449 CountMap[S] = BlockCount;
453 void VisitBreakStmt(
const BreakStmt *S) {
455 assert(!BreakContinueStack.empty() &&
"break not in a loop or switch!");
456 BreakContinueStack.back().BreakCount += CurrentCount;
458 RecordNextStmtCount =
true;
463 assert(!BreakContinueStack.empty() &&
"continue stmt not in a loop!");
464 BreakContinueStack.back().ContinueCount += CurrentCount;
466 RecordNextStmtCount =
true;
469 void VisitWhileStmt(
const WhileStmt *S) {
471 uint64_t ParentCount = CurrentCount;
473 BreakContinueStack.push_back(BreakContinue());
477 CountMap[S->
getBody()] = CurrentCount;
479 uint64_t BackedgeCount = CurrentCount;
485 BreakContinue BC = BreakContinueStack.pop_back_val();
487 setCount(ParentCount + BackedgeCount + BC.ContinueCount);
488 CountMap[S->
getCond()] = CondCount;
490 setCount(BC.BreakCount + CondCount - BodyCount);
491 RecordNextStmtCount =
true;
494 void VisitDoStmt(
const DoStmt *S) {
498 BreakContinueStack.push_back(BreakContinue());
500 uint64_t BodyCount = setCount(LoopCount + CurrentCount);
501 CountMap[S->
getBody()] = BodyCount;
503 uint64_t BackedgeCount = CurrentCount;
505 BreakContinue BC = BreakContinueStack.pop_back_val();
508 uint64_t CondCount = setCount(BackedgeCount + BC.ContinueCount);
509 CountMap[S->
getCond()] = CondCount;
511 setCount(BC.BreakCount + CondCount - LoopCount);
512 RecordNextStmtCount =
true;
515 void VisitForStmt(
const ForStmt *S) {
520 uint64_t ParentCount = CurrentCount;
522 BreakContinueStack.push_back(BreakContinue());
526 CountMap[S->
getBody()] = BodyCount;
528 uint64_t BackedgeCount = CurrentCount;
529 BreakContinue BC = BreakContinueStack.pop_back_val();
534 uint64_t IncCount = setCount(BackedgeCount + BC.ContinueCount);
535 CountMap[S->
getInc()] = IncCount;
541 setCount(ParentCount + BackedgeCount + BC.ContinueCount);
543 CountMap[S->
getCond()] = CondCount;
546 setCount(BC.BreakCount + CondCount - BodyCount);
547 RecordNextStmtCount =
true;
559 uint64_t ParentCount = CurrentCount;
560 BreakContinueStack.push_back(BreakContinue());
564 CountMap[S->
getBody()] = BodyCount;
566 uint64_t BackedgeCount = CurrentCount;
567 BreakContinue BC = BreakContinueStack.pop_back_val();
571 uint64_t IncCount = setCount(BackedgeCount + BC.ContinueCount);
572 CountMap[S->
getInc()] = IncCount;
577 setCount(ParentCount + BackedgeCount + BC.ContinueCount);
578 CountMap[S->
getCond()] = CondCount;
580 setCount(BC.BreakCount + CondCount - BodyCount);
581 RecordNextStmtCount =
true;
587 uint64_t ParentCount = CurrentCount;
588 BreakContinueStack.push_back(BreakContinue());
591 CountMap[S->
getBody()] = BodyCount;
593 uint64_t BackedgeCount = CurrentCount;
594 BreakContinue BC = BreakContinueStack.pop_back_val();
596 setCount(BC.BreakCount + ParentCount + BackedgeCount + BC.ContinueCount -
598 RecordNextStmtCount =
true;
607 BreakContinueStack.push_back(BreakContinue());
610 BreakContinue BC = BreakContinueStack.pop_back_val();
611 if (!BreakContinueStack.empty())
612 BreakContinueStack.back().ContinueCount += BC.ContinueCount;
615 RecordNextStmtCount =
true;
619 RecordNextStmtCount =
false;
624 setCount(CurrentCount + CaseCount);
627 CountMap[S] = CaseCount;
628 RecordNextStmtCount =
true;
632 void VisitIfStmt(
const IfStmt *S) {
634 uint64_t ParentCount = CurrentCount;
642 CountMap[S->
getThen()] = ThenCount;
644 uint64_t OutCount = CurrentCount;
646 uint64_t ElseCount = ParentCount - ThenCount;
649 CountMap[S->
getElse()] = ElseCount;
651 OutCount += CurrentCount;
653 OutCount += ElseCount;
655 RecordNextStmtCount =
true;
665 RecordNextStmtCount =
true;
669 RecordNextStmtCount =
false;
672 CountMap[S] = CatchCount;
678 uint64_t ParentCount = CurrentCount;
686 uint64_t OutCount = CurrentCount;
688 uint64_t FalseCount = setCount(ParentCount - TrueCount);
691 OutCount += CurrentCount;
694 RecordNextStmtCount =
true;
699 uint64_t ParentCount = CurrentCount;
703 CountMap[E->
getRHS()] = RHSCount;
705 setCount(ParentCount + RHSCount - CurrentCount);
706 RecordNextStmtCount =
true;
711 uint64_t ParentCount = CurrentCount;
715 CountMap[E->
getRHS()] = RHSCount;
717 setCount(ParentCount + RHSCount - CurrentCount);
718 RecordNextStmtCount =
true;
723 void PGOHash::combine(HashType
Type) {
725 assert(Type &&
"Hash is invalid: unexpected type 0");
726 assert(
unsigned(Type) < TooBig &&
"Hash is invalid: too many types");
729 if (Count && Count % NumTypesPerWord == 0) {
730 using namespace llvm::support;
731 uint64_t Swapped = endian::byte_swap<uint64_t, little>(Working);
732 MD5.update(llvm::makeArrayRef((uint8_t *)&Swapped,
sizeof(Swapped)));
738 Working = Working << NumBitsPerType |
Type;
743 if (Count <= NumTypesPerWord)
754 llvm::MD5::MD5Result Result;
756 using namespace llvm::support;
765 bool InstrumentRegions = CGM.getCodeGenOpts().hasProfileClangInstr();
766 llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader();
767 if (!InstrumentRegions && !PGOReader)
774 if (CGM.getTarget().getCXXABI().hasConstructorVariants()) {
775 if (
const auto *CCD = dyn_cast<CXXConstructorDecl>(D))
783 CGM.ClearUnusedCoverageMapping(D);
786 mapRegionCounters(D);
787 if (CGM.getCodeGenOpts().CoverageMapping)
788 emitCounterRegionMapping(D);
792 computeRegionCounts(D);
793 applyFunctionAttributes(PGOReader, Fn);
797 void CodeGenPGO::mapRegionCounters(
const Decl *D) {
801 if (
auto *PGOReader = CGM.getPGOReader())
802 HashVersion = getPGOHashVersion(PGOReader, CGM);
804 RegionCounterMap.reset(
new llvm::DenseMap<const Stmt *, unsigned>);
805 MapRegionCounters Walker(HashVersion, *RegionCounterMap);
806 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
807 Walker.TraverseDecl(const_cast<FunctionDecl *>(FD));
808 else if (
const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D))
809 Walker.TraverseDecl(const_cast<ObjCMethodDecl *>(MD));
810 else if (
const BlockDecl *BD = dyn_cast_or_null<BlockDecl>(D))
811 Walker.TraverseDecl(const_cast<BlockDecl *>(BD));
812 else if (
const CapturedDecl *CD = dyn_cast_or_null<CapturedDecl>(D))
813 Walker.TraverseDecl(const_cast<CapturedDecl *>(CD));
814 assert(Walker.NextCounter > 0 &&
"no entry counter mapped for decl");
815 NumRegionCounters = Walker.NextCounter;
816 FunctionHash = Walker.Hash.finalize();
819 bool CodeGenPGO::skipRegionMappingForDecl(
const Decl *D) {
824 const auto &
SM = CGM.getContext().getSourceManager();
829 void CodeGenPGO::emitCounterRegionMapping(
const Decl *D) {
830 if (skipRegionMappingForDecl(D))
833 std::string CoverageMapping;
834 llvm::raw_string_ostream OS(CoverageMapping);
836 CGM.getContext().getSourceManager(),
837 CGM.getLangOpts(), RegionCounterMap.get());
841 if (CoverageMapping.empty())
844 CGM.getCoverageMapping()->addFunctionMappingRecord(
845 FuncNameVar, FuncName, FunctionHash, CoverageMapping);
850 llvm::GlobalValue::LinkageTypes Linkage) {
851 if (skipRegionMappingForDecl(D))
854 std::string CoverageMapping;
855 llvm::raw_string_ostream OS(CoverageMapping);
857 CGM.getContext().getSourceManager(),
862 if (CoverageMapping.empty())
865 setFuncName(Name, Linkage);
866 CGM.getCoverageMapping()->addFunctionMappingRecord(
867 FuncNameVar, FuncName, FunctionHash, CoverageMapping,
false);
870 void CodeGenPGO::computeRegionCounts(
const Decl *D) {
871 StmtCountMap.reset(
new llvm::DenseMap<const Stmt *, uint64_t>);
872 ComputeRegionCounts Walker(*StmtCountMap, *
this);
873 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
874 Walker.VisitFunctionDecl(FD);
875 else if (
const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D))
876 Walker.VisitObjCMethodDecl(MD);
877 else if (
const BlockDecl *BD = dyn_cast_or_null<BlockDecl>(D))
878 Walker.VisitBlockDecl(BD);
879 else if (
const CapturedDecl *CD = dyn_cast_or_null<CapturedDecl>(D))
880 Walker.VisitCapturedDecl(const_cast<CapturedDecl *>(CD));
884 CodeGenPGO::applyFunctionAttributes(llvm::IndexedInstrProfReader *PGOReader,
885 llvm::Function *Fn) {
890 Fn->setEntryCount(FunctionCount);
895 if (!CGM.getCodeGenOpts().hasProfileClangInstr() || !RegionCounterMap)
897 if (!Builder.GetInsertBlock())
900 unsigned Counter = (*RegionCounterMap)[S];
901 auto *I8PtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
903 llvm::Value *Args[] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
904 Builder.getInt64(FunctionHash),
905 Builder.getInt32(NumRegionCounters),
906 Builder.getInt32(Counter), StepV};
908 Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::instrprof_increment),
909 makeArrayRef(Args, 4));
912 CGM.getIntrinsic(llvm::Intrinsic::instrprof_increment_step),
919 llvm::Instruction *ValueSite,
llvm::Value *ValuePtr) {
924 if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock())
927 if (isa<llvm::Constant>(ValuePtr))
930 bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr();
931 if (InstrumentValueSites && RegionCounterMap) {
932 auto BuilderInsertPoint = Builder.saveIP();
933 Builder.SetInsertPoint(ValueSite);
935 llvm::ConstantExpr::getBitCast(FuncNameVar, Builder.getInt8PtrTy()),
936 Builder.getInt64(FunctionHash),
937 Builder.CreatePtrToInt(ValuePtr, Builder.getInt64Ty()),
938 Builder.getInt32(ValueKind),
939 Builder.getInt32(NumValueSites[ValueKind]++)
942 CGM.getIntrinsic(llvm::Intrinsic::instrprof_value_profile), Args);
943 Builder.restoreIP(BuilderInsertPoint);
947 llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader();
955 if (NumValueSites[ValueKind] >= ProfRecord->getNumValueSites(ValueKind))
958 llvm::annotateValueSite(CGM.getModule(), *ValueSite, *ProfRecord,
959 (llvm::InstrProfValueKind)ValueKind,
960 NumValueSites[ValueKind]);
962 NumValueSites[ValueKind]++;
966 void CodeGenPGO::loadRegionCounts(llvm::IndexedInstrProfReader *PGOReader,
968 CGM.getPGOStats().addVisited(IsInMainFile);
969 RegionCounts.clear();
971 PGOReader->getInstrProfRecord(FuncName, FunctionHash);
972 if (
auto E = RecordExpected.takeError()) {
973 auto IPE = llvm::InstrProfError::take(std::move(E));
974 if (IPE == llvm::instrprof_error::unknown_function)
975 CGM.getPGOStats().addMissing(IsInMainFile);
976 else if (IPE == llvm::instrprof_error::hash_mismatch)
977 CGM.getPGOStats().addMismatched(IsInMainFile);
978 else if (IPE == llvm::instrprof_error::malformed)
980 CGM.getPGOStats().addMismatched(IsInMainFile);
984 std::make_unique<llvm::InstrProfRecord>(std::move(RecordExpected.get()));
985 RegionCounts = ProfRecord->Counts;
993 return MaxWeight < UINT32_MAX ? 1 : MaxWeight / UINT32_MAX + 1;
1006 assert(Scale &&
"scale by 0?");
1007 uint64_t Scaled = Weight / Scale + 1;
1008 assert(Scaled <= UINT32_MAX &&
"overflow 32-bits");
1012 llvm::MDNode *CodeGenFunction::createProfileWeights(uint64_t TrueCount,
1013 uint64_t FalseCount) {
1015 if (!TrueCount && !FalseCount)
1021 llvm::MDBuilder MDHelper(CGM.getLLVMContext());
1029 if (Weights.size() < 2)
1033 uint64_t MaxWeight = *std::max_element(Weights.begin(), Weights.end());
1041 ScaledWeights.reserve(Weights.size());
1042 for (uint64_t W : Weights)
1045 llvm::MDBuilder MDHelper(CGM.getLLVMContext());
1046 return MDHelper.createBranchWeights(ScaledWeights);
1049 llvm::MDNode *CodeGenFunction::createProfileWeightsForLoop(
const Stmt *Cond,
1050 uint64_t LoopCount) {
1051 if (!PGO.haveRegionCounts())
1054 assert(CondCount.hasValue() &&
"missing expected loop condition count");
1055 if (*CondCount == 0)
1057 return createProfileWeights(LoopCount,
1058 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