38#define DEBUG_TYPE "stack-safety"
40STATISTIC(NumAllocaStackSafe,
"Number of safe allocas");
41STATISTIC(NumAllocaTotal,
"Number of total allocas");
44 "Number of total callee lookups on combined index.");
46 "Number of failed callee lookups on combined index.");
48 "Number of total callee lookups on module index.");
50 "Number of failed callee lookups on module index.");
52 "Number of total param accesses before generateParamAccessSummary.");
54 "Number of total param accesses after generateParamAccessSummary.");
56 "Number of total nodes in combined index for dataflow processing.");
57STATISTIC(NumIndexCalleeUnhandled,
"Number of index callee which are unhandled.");
58STATISTIC(NumIndexCalleeMultipleWeak,
"Number of index callee non-unique weak.");
59STATISTIC(NumIndexCalleeMultipleExternal,
"Number of index callee non-unique external.");
66 return R.isEmptySet() || R.isFullSet() || R.isUpperSignWrapped();
72 if (
L.signedAddMayOverflow(R) !=
74 return ConstantRange::getFull(
L.getBitWidth());
85 if (
Result.isSignWrappedSet())
91template <
typename CalleeTy>
struct CallInfo {
93 const CalleeTy *Callee =
nullptr;
97 CallInfo(
const CalleeTy *Callee,
size_t ParamNo)
98 : Callee(Callee), ParamNo(ParamNo) {}
101 bool operator()(
const CallInfo &L,
const CallInfo &R)
const {
102 return std::tie(
L.ParamNo,
L.Callee) < std::tie(
R.ParamNo,
R.Callee);
108template <
typename CalleeTy>
struct UseInfo {
112 std::set<const Instruction *> UnsafeAccesses;
119 using CallsTy = std::map<CallInfo<CalleeTy>, ConstantRange,
120 typename CallInfo<CalleeTy>::Less>;
125 void updateRange(
const ConstantRange &R) { Range = unionNoWrap(Range, R); }
126 void addRange(
const Instruction *
I,
const ConstantRange &R,
bool IsSafe) {
128 UnsafeAccesses.insert(
I);
133template <
typename CalleeTy>
136 for (
auto &
Call : U.Calls)
138 <<
"@" <<
Call.first.Callee->getName() <<
"(arg" <<
Call.first.ParamNo
139 <<
", " <<
Call.second <<
")";
154 if (APSize.isNonPositive())
160 bool Overflow =
false;
162 if (
Mul.isNonPositive())
164 Mul =
Mul.sextOrTrunc(PointerSize);
165 APSize = APSize.smul_ov(
Mul, Overflow);
174template <
typename CalleeTy>
struct FunctionInfo {
175 std::map<const AllocaInst *, UseInfo<CalleeTy>> Allocas;
176 std::map<uint32_t, UseInfo<CalleeTy>> Params;
182 void print(raw_ostream &O, StringRef Name,
const Function *
F)
const {
185 O <<
" @" <<
Name << ((
F &&
F->isDSOLocal()) ?
"" :
" dso_preemptable")
186 << ((
F &&
F->isInterposable()) ?
" interposable" :
"") <<
"\n";
188 O <<
" args uses:\n";
189 for (
auto &KV : Params) {
192 O <<
F->getArg(KV.first)->getName();
195 O <<
"[]: " << KV.second <<
"\n";
198 O <<
" allocas uses:\n";
202 auto &AS = Allocas.find(AI)->second;
204 << getStaticAllocaSizeRange(*AI).getUpper() <<
"]: " << AS <<
"\n";
213using GVToSSI = std::map<const GlobalValue *, FunctionInfo<GlobalValue>>;
218 FunctionInfo<GlobalValue>
Info;
229class StackSafetyLocalAnalysis {
233 unsigned PointerSize = 0;
243 const SCEV *getSCEVAsPointer(
Value *Val);
252 void analyzeAllUses(
Value *Ptr, UseInfo<GlobalValue> &AS,
262 :
F(
F),
DL(
F.getDataLayout()), SE(SE),
263 PointerSize(
DL.getPointerSizeInBits()),
264 UnknownRange(PointerSize,
true) {}
267 FunctionInfo<GlobalValue> run();
270const SCEV *StackSafetyLocalAnalysis::getSCEVAsPointer(
Value *Val) {
284ConstantRange StackSafetyLocalAnalysis::offsetFrom(
Value *Addr,
Value *
Base) {
288 const SCEV *AddrExp = getSCEVAsPointer(Addr);
289 const SCEV *BaseExp = getSCEVAsPointer(
Base);
290 if (!AddrExp || !BaseExp)
305 const ConstantRange &SizeRange) {
308 return ConstantRange::getEmpty(PointerSize);
309 assert(!isUnsafe(SizeRange));
312 if (isUnsafe(Offsets))
315 Offsets = addOverflowNever(Offsets, SizeRange);
316 if (isUnsafe(Offsets))
321ConstantRange StackSafetyLocalAnalysis::getAccessRange(
Value *Addr,
Value *
Base,
323 if (
Size.isScalable())
325 APInt APSize(PointerSize,
Size.getFixedValue(),
true);
326 if (APSize.isNegative())
328 return getAccessRange(Addr,
Base,
332ConstantRange StackSafetyLocalAnalysis::getMemIntrinsicAccessRange(
333 const MemIntrinsic *
MI,
const Use &U,
Value *
Base) {
335 if (MTI->getRawSource() != U && MTI->getRawDest() != U)
336 return ConstantRange::getEmpty(PointerSize);
338 if (
MI->getRawDest() != U)
339 return ConstantRange::getEmpty(PointerSize);
342 auto *CalculationTy = IntegerType::getIntNTy(SE.
getContext(), PointerSize);
349 if (!
Sizes.getUpper().isStrictlyPositive() || isUnsafe(Sizes))
353 return getAccessRange(U,
Base, SizeRange);
356bool StackSafetyLocalAnalysis::isSafeAccess(
const Use &U, AllocaInst *AI,
358 return isSafeAccess(U, AI, SE.
getSCEV(V));
361bool StackSafetyLocalAnalysis::isSafeAccess(
const Use &U, AllocaInst *AI,
365 auto *CalculationTy = IntegerType::getIntNTy(SE.
getContext(), PointerSize);
367 return isSafeAccess(U, AI, SV);
370bool StackSafetyLocalAnalysis::isSafeAccess(
const Use &U, AllocaInst *AI,
371 const SCEV *AccessSize) {
380 const SCEV *AddrExp = getSCEVAsPointer(
U.get());
381 const SCEV *BaseExp = getSCEVAsPointer(AI);
382 if (!AddrExp || !BaseExp)
389 auto Size = getStaticAllocaSizeRange(*AI);
391 auto *CalculationTy = IntegerType::getIntNTy(SE.
getContext(), PointerSize);
392 auto ToDiffTy = [&](
const SCEV *
V) {
397 ToDiffTy(AccessSize));
406void StackSafetyLocalAnalysis::analyzeAllUses(
Value *Ptr,
407 UseInfo<GlobalValue> &US,
408 const StackLifetime &SL) {
409 SmallPtrSet<const Value *, 16> Visited;
410 SmallVector<const Value *, 8> WorkList;
415 while (!WorkList.
empty()) {
417 for (
const Use &UI :
V->uses()) {
424 auto RecordStore = [&](
const Value* StoredVal) {
425 if (V == StoredVal) {
427 US.addRange(
I, UnknownRange,
false);
431 US.addRange(
I, UnknownRange,
false);
434 auto TypeSize =
DL.getTypeStoreSize(StoredVal->getType());
435 auto AccessRange = getAccessRange(UI, Ptr, TypeSize);
436 bool Safe = isSafeAccess(UI, AI, TypeSize);
437 US.addRange(
I, AccessRange, Safe);
441 switch (
I->getOpcode()) {
442 case Instruction::Load: {
444 US.addRange(
I, UnknownRange,
false);
447 auto TypeSize =
DL.getTypeStoreSize(
I->getType());
448 auto AccessRange = getAccessRange(UI, Ptr, TypeSize);
449 bool Safe = isSafeAccess(UI, AI, TypeSize);
450 US.addRange(
I, AccessRange, Safe);
454 case Instruction::VAArg:
457 case Instruction::Store:
460 case Instruction::AtomicCmpXchg:
463 case Instruction::AtomicRMW:
467 case Instruction::Ret:
471 US.addRange(
I, UnknownRange,
false);
474 case Instruction::Call:
475 case Instruction::Invoke: {
476 if (
I->isLifetimeStartOrEnd())
480 US.addRange(
I, UnknownRange,
false);
484 auto AccessRange = getMemIntrinsicAccessRange(
MI, UI, Ptr);
487 if (MTI->getRawSource() != UI && MTI->getRawDest() != UI)
489 }
else if (
MI->getRawDest() != UI) {
492 Safe =
Safe || isSafeAccess(UI, AI,
MI->getLength());
493 US.addRange(
I, AccessRange, Safe);
498 if (CB.getReturnedArgOperand() == V) {
503 if (!CB.isArgOperand(&UI)) {
504 US.addRange(
I, UnknownRange,
false);
508 unsigned ArgNo = CB.getArgOperandNo(&UI);
509 if (CB.isByValArgument(ArgNo)) {
510 auto TypeSize =
DL.getTypeStoreSize(CB.getParamByValType(ArgNo));
511 auto AccessRange = getAccessRange(UI, Ptr, TypeSize);
512 bool Safe = isSafeAccess(UI, AI, TypeSize);
513 US.addRange(
I, AccessRange, Safe);
520 const GlobalValue *
Callee =
524 US.addRange(
I, UnknownRange,
false);
529 ConstantRange
Offsets = offsetFrom(UI, Ptr);
531 US.Calls.emplace(CallInfo<GlobalValue>(Callee, ArgNo), Offsets);
533 Insert.first->second =
Insert.first->second.unionWith(Offsets);
545FunctionInfo<GlobalValue> StackSafetyLocalAnalysis::run() {
546 FunctionInfo<GlobalValue>
Info;
548 "Can't run StackSafety on a function declaration");
556 StackLifetime SL(
F, Allocas, StackLifetime::LivenessType::Must);
559 for (
auto *AI : Allocas) {
560 auto &UI =
Info.Allocas.emplace(AI, PointerSize).first->second;
561 analyzeAllUses(AI, UI, SL);
564 for (Argument &
A :
F.args()) {
567 if (
A.getType()->isPointerTy() && !
A.hasByValAttr()) {
568 auto &UI =
Info.Params.emplace(
A.getArgNo(), PointerSize).first->second;
569 analyzeAllUses(&
A, UI, SL);
578template <
typename CalleeTy>
class StackSafetyDataFlowAnalysis {
579 using FunctionMap = std::map<const CalleeTy *, FunctionInfo<CalleeTy>>;
581 FunctionMap Functions;
582 const ConstantRange UnknownRange;
583 const int MaxIterations;
586 DenseMap<const CalleeTy *, SmallVector<const CalleeTy *, 4>> Callers;
587 SetVector<const CalleeTy *> WorkList;
589 bool updateOneUse(UseInfo<CalleeTy> &US,
bool UpdateToFullSet);
590 void updateOneNode(
const CalleeTy *Callee, FunctionInfo<CalleeTy> &FS);
591 void updateOneNode(
const CalleeTy *Callee) {
592 updateOneNode(Callee, Functions.find(Callee)->second);
594 void updateAllNodes() {
595 for (
auto &
F : Functions)
596 updateOneNode(
F.first,
F.second);
600 void verifyFixedPoint();
604 StackSafetyDataFlowAnalysis(uint32_t PointerBitWidth, FunctionMap Functions,
606 : Functions(std::
move(Functions)),
607 UnknownRange(ConstantRange::getFull(PointerBitWidth)),
608 MaxIterations(MaxIterations) {}
610 const FunctionMap &
run();
612 ConstantRange getArgumentAccessRange(
const CalleeTy *Callee,
unsigned ParamNo,
613 const ConstantRange &Offsets)
const;
616template <
typename CalleeTy>
617ConstantRange StackSafetyDataFlowAnalysis<CalleeTy>::getArgumentAccessRange(
618 const CalleeTy *Callee,
unsigned ParamNo,
619 const ConstantRange &Offsets)
const {
620 auto FnIt = Functions.find(Callee);
622 if (FnIt == Functions.end())
624 auto &
FS = FnIt->second;
625 auto ParamIt =
FS.Params.find(ParamNo);
626 if (ParamIt ==
FS.Params.end())
628 auto &
Access = ParamIt->second.Range;
633 return addOverflowNever(
Access, Offsets);
636template <
typename CalleeTy>
637bool StackSafetyDataFlowAnalysis<CalleeTy>::updateOneUse(UseInfo<CalleeTy> &US,
638 bool UpdateToFullSet) {
640 for (
auto &KV : US.Calls) {
641 assert(!KV.second.isEmptySet() &&
642 "Param range can't be empty-set, invalid offset range");
644 ConstantRange CalleeRange =
645 getArgumentAccessRange(KV.first.Callee, KV.first.ParamNo, KV.second);
646 if (!US.Range.
contains(CalleeRange)) {
649 US.Range = UnknownRange;
651 US.updateRange(CalleeRange);
657template <
typename CalleeTy>
658void StackSafetyDataFlowAnalysis<CalleeTy>::updateOneNode(
659 const CalleeTy *Callee, FunctionInfo<CalleeTy> &FS) {
660 bool UpdateToFullSet =
FS.UpdateCount > MaxIterations;
662 for (
auto &KV :
FS.Params)
663 Changed |= updateOneUse(KV.second, UpdateToFullSet);
667 << (UpdateToFullSet ?
", full-set" :
"") <<
"] " << &FS
676template <
typename CalleeTy>
677void StackSafetyDataFlowAnalysis<CalleeTy>::runDataFlow() {
679 for (
auto &
F : Functions) {
682 for (
auto &KV :
FS.Params)
683 for (
auto &CS : KV.second.Calls)
689 for (
auto &Callee : Callees)
690 Callers[
Callee].push_back(
F.first);
695 while (!WorkList.
empty()) {
697 updateOneNode(Callee);
702template <
typename CalleeTy>
703void StackSafetyDataFlowAnalysis<CalleeTy>::verifyFixedPoint() {
710template <
typename CalleeTy>
711const typename StackSafetyDataFlowAnalysis<CalleeTy>::FunctionMap &
712StackSafetyDataFlowAnalysis<CalleeTy>::run() {
718FunctionSummary *findCalleeFunctionSummary(ValueInfo VI, StringRef ModuleId) {
721 auto SummaryList =
VI.getSummaryList();
722 GlobalValueSummary* S =
nullptr;
723 for (
const auto& GVS : SummaryList) {
727 if (!AS->hasAliasee())
732 if (GVS->modulePath() == ModuleId) {
738 ++NumIndexCalleeMultipleExternal;
744 ++NumIndexCalleeMultipleWeak;
750 if (SummaryList.size() == 1)
754 ++NumIndexCalleeUnhandled;
772const Function *findCalleeInModule(
const GlobalValue *GV) {
788const ConstantRange *findParamAccess(
const FunctionSummary &FS,
792 for (
const auto &PS :
FS.paramAccesses())
793 if (ParamNo == PS.ParamNo)
798void resolveAllCalls(UseInfo<GlobalValue> &Use,
799 const ModuleSummaryIndex *Index) {
800 ConstantRange FullSet(
Use.Range.getBitWidth(),
true);
803 UseInfo<GlobalValue>::CallsTy TmpCalls;
805 for (
const auto &
C : TmpCalls) {
806 const Function *
F = findCalleeInModule(
C.first.Callee);
808 Use.Calls.emplace(CallInfo<GlobalValue>(
F,
C.first.ParamNo),
C.second);
813 return Use.updateRange(FullSet);
814 FunctionSummary *
FS =
815 findCalleeFunctionSummary(
Index->getValueInfo(
C.first.Callee->getGUID()),
816 C.first.Callee->getParent()->getModuleIdentifier());
817 ++NumModuleCalleeLookupTotal;
819 ++NumModuleCalleeLookupFailed;
820 return Use.updateRange(FullSet);
822 const ConstantRange *Found = findParamAccess(*FS,
C.first.ParamNo);
824 return Use.updateRange(FullSet);
827 Use.updateRange(addOverflowNever(
Access,
C.second));
831GVToSSI createGlobalStackSafetyInfo(
832 std::map<
const GlobalValue *, FunctionInfo<GlobalValue>> Functions,
833 const ModuleSummaryIndex *Index) {
835 if (Functions.empty())
839 auto Copy = Functions;
841 for (
auto &FnKV : Copy)
842 for (
auto &KV : FnKV.second.Params) {
843 resolveAllCalls(KV.second, Index);
844 if (KV.second.Range.isFullSet())
845 KV.second.Calls.clear();
849 Copy.begin()->first->getDataLayout().getPointerSizeInBits();
851 .stack_safety_max_iterations;
852 StackSafetyDataFlowAnalysis<GlobalValue> SSDFA(PointerSize, std::move(Copy),
855 for (
const auto &
F : SSDFA.run()) {
857 auto &SrcF = Functions[
F.first];
858 for (
auto &KV : FI.Allocas) {
860 resolveAllCalls(
A, Index);
861 for (
auto &
C :
A.Calls) {
862 A.updateRange(SSDFA.getArgumentAccessRange(
C.first.Callee,
863 C.first.ParamNo,
C.second));
866 A.Calls = SrcF.Allocas.find(KV.first)->second.Calls;
868 for (
auto &KV : FI.Params) {
870 P.Calls = SrcF.Params.find(KV.first)->second.Calls;
872 SSI[
F.first] = std::move(FI);
884 : F(F), GetSE(GetSE) {}
894 StackSafetyLocalAnalysis SSLA(*F, GetSE());
895 Info.reset(
new InfoTy{SSLA.run()});
907 std::map<const GlobalValue *, FunctionInfo<GlobalValue>> Functions;
908 for (
auto &
F : M->functions()) {
909 if (!
F.isDeclaration()) {
910 auto FI = GetSSI(
F).getInfo().Info;
911 Functions.emplace(&
F, std::move(FI));
915 createGlobalStackSafetyInfo(std::move(Functions), Index), {}, {}});
917 for (
auto &FnKV : Info->Info) {
918 for (
auto &KV : FnKV.second.Allocas) {
920 const AllocaInst *AI = KV.first;
921 auto AIRange = getStaticAllocaSizeRange(*AI);
922 if (AIRange.contains(KV.second.Range)) {
923 Info->SafeAllocas.insert(AI);
924 ++NumAllocaStackSafe;
926 Info->UnsafeAccesses.insert(KV.second.UnsafeAccesses.begin(),
927 KV.second.UnsafeAccesses.end());
937std::vector<FunctionSummary::ParamAccess>
941 std::vector<FunctionSummary::ParamAccess> ParamAccesses;
942 for (
const auto &KV :
getInfo().Info.Params) {
943 auto &PS = KV.second;
947 if (PS.Range.isFullSet())
950 ParamAccesses.emplace_back(KV.first, PS.Range);
953 Param.Calls.reserve(PS.Calls.size());
954 for (
const auto &
C : PS.Calls) {
959 if (
C.second.isFullSet()) {
960 ParamAccesses.pop_back();
963 Param.Calls.emplace_back(
C.first.ParamNo,
964 Index.getOrInsertValueInfo(
C.first.Callee),
971 return std::tie(L.ParamNo, L.Callee) < std::tie(R.ParamNo, R.Callee);
974 return ParamAccesses;
982 : M(M), GetSSI(GetSSI), Index(Index) {
996 const auto &Info = getInfo();
997 return Info.SafeAllocas.count(&AI);
1001 const auto &Info = getInfo();
1002 return Info.UnsafeAccesses.find(&
I) == Info.UnsafeAccesses.end();
1006 auto &SSI = getInfo().Info;
1009 const Module &M = *SSI.begin()->first->getParent();
1010 for (
const auto &
F : M.functions()) {
1011 if (!
F.isDeclaration()) {
1012 SSI.find(&
F)->second.print(O,
F.getName(), &
F);
1013 O <<
" safe accesses:"
1019 (
Call &&
Call->hasByValArgument())) &&
1021 O <<
" " <<
I <<
"\n";
1042 OS <<
"'Stack Safety Local Analysis' for function '" <<
F.getName() <<
"'\n";
1073 if (
auto *IndexPass =
1075 Index = IndexPass->getIndex();
1085 OS <<
"'Stack Safety Analysis' for module '" << M.getName() <<
"'\n";
1110 if (
auto *IndexWrapperPass =
1112 ImportSummary = IndexWrapperPass->getIndex();
1125 for (
const auto &
F : M.functions())
1126 if (
F.hasFnAttribute(Attribute::SanitizeMemTag))
1134 if (!Index.hasParamAccess())
1138 auto CountParamAccesses = [&](
auto &Stat) {
1141 for (
auto &GVS : Index)
1142 for (
auto &GV : GVS.second.getSummaryList())
1144 Stat += FS->paramAccesses().size();
1147 CountParamAccesses(NumCombinedParamAccessesBefore);
1149 std::map<const FunctionSummary *, FunctionInfo<FunctionSummary>> Functions;
1152 for (
auto &GVS : Index) {
1153 for (
auto &GV : GVS.second.getSummaryList()) {
1155 if (!FS || FS->paramAccesses().empty())
1157 if (FS->isLive() && FS->isDSOLocal()) {
1158 FunctionInfo<FunctionSummary> FI;
1159 for (
const auto &PS : FS->paramAccesses()) {
1165 for (
const auto &
Call : PS.Calls) {
1168 findCalleeFunctionSummary(
Call.Callee, FS->modulePath());
1169 ++NumCombinedCalleeLookupTotal;
1171 ++NumCombinedCalleeLookupFailed;
1180 Functions.emplace(FS, std::move(FI));
1185 FS->setParamAccesses({});
1188 NumCombinedDataFlowNodes += Functions.size();
1189 StackSafetyDataFlowAnalysis<FunctionSummary> SSDFA(
1192 .stack_safety_max_iterations);
1193 for (
const auto &KV : SSDFA.run()) {
1194 std::vector<FunctionSummary::ParamAccess> NewParams;
1195 NewParams.reserve(KV.second.Params.size());
1196 for (
const auto &Param : KV.second.Params) {
1198 if (Param.second.Range.isFullSet())
1200 NewParams.emplace_back();
1202 New.ParamNo = Param.first;
1203 New.Use = Param.second.Range;
1206 std::move(NewParams));
1209 CountParamAccesses(NumCombinedParamAccessesAfter);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Expand Atomic instructions
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This is the interface to build a ModuleSummaryIndex for a module.
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
FunctionAnalysisManager FAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
static const char LocalPassArg[]
static const char LocalPassName[]
static true const char GlobalPassName[]
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Class for arbitrary precision integers.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
an instruction to allocate memory on the stack
LLVM_ABI TypeSize getAllocationBaseSize(const DataLayout &DL) const
Get the size of the allocated type.
PointerType * getType() const
Overload to return most specific pointer type.
LLVM_ABI bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1.
const Value * getArraySize() const
Get the number of elements allocated.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
AnalysisUsage & addRequiredTransitive()
This class represents a function call, abstracting a target machine's calling convention.
This class represents a range of values.
LLVM_ABI bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type.
LLVM_ABI bool isEmptySet() const
Return true if this set contains no members.
LLVM_ABI bool contains(const APInt &Val) const
Return true if the specified value is in the set.
@ NeverOverflows
Never overflows.
LLVM_ABI ConstantRange sextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
A parsed version of the target data layout string in and methods for querying it.
Function summary information to aid decisions and implementation of importing.
GlobalValueSummary * getBaseObject()
If this is an alias summary, returns the summary of the aliased object (a global variable or function...
static bool isLocalLinkage(LinkageTypes Linkage)
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
static bool isLinkOnceLinkage(LinkageTypes Linkage)
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
LLVM_ABI const GlobalObject * getAliaseeObject() const
static bool isExternalLinkage(LinkageTypes Linkage)
static bool isWeakLinkage(LinkageTypes Linkage)
LLVM_ABI bool isInterposable(bool CheckNoIPA=true) const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
NPM analysis to provide an externally-built ModuleSummaryIndex (e.g.
Legacy wrapper pass to provide the ModuleSummaryIndex object.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
This is the common base class for memset/memcpy/memmove.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
A Module instance is used to store all the information related to an LLVM module.
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
AnalysisType * getAnalysisIfAvailable() const
getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to get analysis information tha...
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
This class represents an analyzed expression in the program.
Analysis pass that exposes the ScalarEvolution for a function.
The main scalar evolution driver.
LLVM_ABI const SCEV * getMinusSCEV(SCEVUse LHS, SCEVUse RHS, SCEVFlags Flags=SCEV::FlagNone, unsigned Depth=0)
Return LHS-RHS.
LLVM_ABI const SCEV * getConstant(ConstantInt *V)
LLVM_ABI const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
ConstantRange getSignedRange(const SCEV *S)
Determine the signed range for a particular SCEV.
LLVM_ABI std::optional< bool > evaluatePredicateAt(CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS, const Instruction *CtxI)
Check whether the condition described by Pred, LHS, and RHS is true or false in the given Context.
LLVM_ABI bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
LLVM_ABI const SCEV * getTruncateOrZeroExtend(const SCEV *V, Type *Ty, unsigned Depth=0)
Return a SCEV corresponding to a conversion of the input value to the specified type.
LLVMContext & getContext() const
void insert_range(Range &&R)
void clear()
Completely clear the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
value_type pop_back_val()
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
iterator erase(const_iterator CI)
void push_back(const T &Elt)
Compute live ranges of allocas.
LLVM_ABI bool isReachable(const Instruction *I) const
Returns true if instruction is reachable from entry.
LLVM_ABI bool isAliveAfter(const AllocaInst *AI, const Instruction *I) const
Returns true if the alloca is alive after the instruction.
StackSafetyInfo wrapper for the new pass manager.
LLVM_ABI StackSafetyInfo run(Function &F, FunctionAnalysisManager &AM)
This pass performs the global (interprocedural) stack safety analysis (new pass manager).
LLVM_ABI Result run(Module &M, ModuleAnalysisManager &AM)
This pass performs the global (interprocedural) stack safety analysis (legacy pass manager).
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
StackSafetyGlobalInfoWrapperPass()
~StackSafetyGlobalInfoWrapperPass() override
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
void print(raw_ostream &O, const Module *M) const override
print - Print out the internal state of the pass.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI bool stackAccessIsSafe(const Instruction &I) const
LLVM_ABI void dump() const
LLVM_ABI bool isSafe(const AllocaInst &AI) const
LLVM_ABI StackSafetyGlobalInfo & operator=(StackSafetyGlobalInfo &&)
LLVM_ABI StackSafetyGlobalInfo()
LLVM_ABI ~StackSafetyGlobalInfo()
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
StackSafetyInfo wrapper for the legacy pass manager.
void print(raw_ostream &O, const Module *M) const override
print - Print out the internal state of the pass.
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
StackSafetyInfoWrapperPass()
Interface to access stack safety analysis results for single function.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI ~StackSafetyInfo()
LLVM_ABI const InfoTy & getInfo() const
LLVM_ABI StackSafetyInfo()
LLVM_ABI StackSafetyInfo & operator=(StackSafetyInfo &&)
LLVM_ABI std::vector< FunctionSummary::ParamAccess > getParamAccesses(ModuleSummaryIndex &Index) const
Parameters use for a FunctionSummary.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
The instances of the Type class are immutable: once they are created, they are never changed.
bool isPointerTy() const
True if this is an instance of PointerType.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
constexpr ScalarTy getFixedValue() const
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
This class implements an extremely fast bulk output stream that can only output to a stream.
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
constexpr uint64_t PointerSize
aarch64 pointer size.
NodeAddr< UseNode * > Use
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool needsParamAccessSummary(const Module &M)
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
auto unique(Range &&R, Predicate P)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
const AnalysisOptions & getAnalysisOptions(const LLVMContext &C)
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI bool AreStatisticsEnabled()
Check if statistics are enabled.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI void generateParamAccessSummary(const cl::LibraryOptionsContext *LibraryOptions, ModuleSummaryIndex &Index)
Reads -stack-safety-max-iterations from LibraryOptions, or its global value if null.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
std::set< const Instruction * > UnsafeAccesses
SmallPtrSet< const AllocaInst *, 8 > SafeAllocas
FunctionInfo< GlobalValue > Info
A special type used by analysis passes to provide an address that identifies that particular analysis...
Describes the use of a value in a call instruction, specifying the call's target, the value's paramet...
Describes the uses of a parameter by the function.
static constexpr uint32_t RangeWidth