76#define DEBUG_TYPE "safe-stack"
78STATISTIC(NumFunctions,
"Total number of functions");
79STATISTIC(NumUnsafeStackFunctions,
"Number of functions with unsafe stack");
81 "Number of functions that use setjmp or exceptions");
84STATISTIC(NumUnsafeStaticAllocas,
"Number of unsafe static allocas");
85STATISTIC(NumUnsafeDynamicAllocas,
"Number of unsafe dynamic allocas");
86STATISTIC(NumUnsafeByValArguments,
"Number of unsafe byval arguments");
87STATISTIC(NumUnsafeStackRestorePoints,
"Number of setjmps and landingpads");
96 cl::desc(
"enable safe stack coloring"),
118 Value *UnsafeStackPtr =
nullptr;
167 Value *StaticTop,
bool NeedDynamicTop);
172 void moveDynamicAllocasToUnsafeStack(
Function &
F,
Value *UnsafeStackPtr,
176 bool IsSafeStackAlloca(
const Value *AllocaPtr,
uint64_t AllocaSize);
185 bool ShouldInlinePointerAddress(
CallInst &CI);
186 void TryInlinePointerAddress();
192 :
F(
F), TL(TL), Libcalls(Libcalls),
DL(
DL), DTU(DTU), SE(SE),
193 StackPtrTy(
DL.getAllocaPtrType(
F.getContext())),
194 AddrTy(
DL.getAddressType(StackPtrTy)),
205 return Size->getFixedValue();
209bool SafeStack::IsAccessSafe(
Value *Addr, TypeSize AccessSize,
210 const Value *AllocaPtr, uint64_t AllocaSize) {
216 return IsAccessSafe(Addr, AccessSize.
getFixedValue(), AllocaPtr, AllocaSize);
219bool SafeStack::IsAccessSafe(
Value *Addr, uint64_t AccessSize,
220 const Value *AllocaPtr, uint64_t AllocaSize) {
221 const SCEV *AddrExpr = SE.
getSCEV(Addr);
223 if (!
Base ||
Base->getValue() != AllocaPtr) {
225 dbgs() <<
"[SafeStack] "
227 << *AllocaPtr <<
"\n"
228 <<
"SCEV " << *AddrExpr <<
" not directly based on alloca\n");
235 ConstantRange SizeRange =
237 ConstantRange AccessRange = AccessStartRange.
add(SizeRange);
238 ConstantRange AllocaRange =
240 bool Safe = AllocaRange.
contains(AccessRange);
243 dbgs() <<
"[SafeStack] "
245 << *AllocaPtr <<
"\n"
246 <<
" Access " << *Addr <<
"\n"
250 <<
" Range " << AccessRange <<
"\n"
251 <<
" AllocaRange " << AllocaRange <<
"\n"
252 <<
" " << (Safe ?
"safe" :
"unsafe") <<
"\n");
257bool SafeStack::IsMemIntrinsicSafe(
const MemIntrinsic *
MI,
const Use &U,
258 const Value *AllocaPtr,
259 uint64_t AllocaSize) {
261 if (MTI->getRawSource() != U && MTI->getRawDest() != U)
264 if (
MI->getRawDest() != U)
268 auto Len =
MI->getLengthInBytes();
270 if (!Len)
return false;
271 return IsAccessSafe(U,
Len->getZExtValue(), AllocaPtr, AllocaSize);
277bool SafeStack::IsSafeStackAlloca(
const Value *AllocaPtr, uint64_t AllocaSize) {
281 SmallPtrSet<const Value *, 16> Visited;
282 SmallVector<const Value *, 8> WorkList;
286 while (!WorkList.
empty()) {
288 for (
const Use &UI :
V->uses()) {
292 switch (
I->getOpcode()) {
293 case Instruction::Load:
294 if (!IsAccessSafe(UI,
DL.getTypeStoreSize(
I->getType()), AllocaPtr,
299 case Instruction::VAArg:
302 case Instruction::Store:
303 if (V ==
I->getOperand(0)) {
306 <<
"[SafeStack] Unsafe alloca: " << *AllocaPtr
307 <<
"\n store of address: " << *
I <<
"\n");
311 if (!IsAccessSafe(UI,
DL.getTypeStoreSize(
I->getOperand(0)->getType()),
312 AllocaPtr, AllocaSize))
316 case Instruction::Ret:
320 case Instruction::Call:
321 case Instruction::Invoke: {
324 if (
I->isLifetimeStartOrEnd())
328 if (!IsMemIntrinsicSafe(
MI, UI, AllocaPtr, AllocaSize)) {
330 <<
"[SafeStack] Unsafe alloca: " << *AllocaPtr
331 <<
"\n unsafe memintrinsic: " << *
I <<
"\n");
345 for (
const auto *
A =
B;
A !=
E; ++
A)
350 <<
"\n unsafe call: " << *
I <<
"\n");
371 if (!StackGuardVar) {
376 return IRB.
CreateLoad(StackPtrTy, StackGuardVar,
"StackGuard");
379void SafeStack::findInsts(Function &
F,
380 SmallVectorImpl<AllocaInst *> &StaticAllocas,
381 SmallVectorImpl<AllocaInst *> &DynamicAllocas,
382 SmallVectorImpl<Argument *> &ByValArguments,
383 SmallVectorImpl<Instruction *> &Returns,
384 SmallVectorImpl<Instruction *> &StackRestorePoints) {
389 uint64_t
Size = getStaticAllocaAllocationSize(AI);
390 if (IsSafeStackAlloca(AI,
Size))
394 ++NumUnsafeStaticAllocas;
397 ++NumUnsafeDynamicAllocas;
401 if (CallInst *CI =
I.getParent()->getTerminatingMustTailCall())
407 if (CI->getCalledFunction() && CI->canReturnTwice())
413 if (
II->getIntrinsicID() == Intrinsic::gcroot)
415 "gcroot intrinsic not compatible with safestack attribute");
418 for (Argument &Arg :
F.args()) {
419 if (!Arg.hasByValAttr())
421 uint64_t
Size =
DL.getTypeStoreSize(Arg.getParamByValType());
422 if (IsSafeStackAlloca(&Arg,
Size))
425 ++NumUnsafeByValArguments;
431SafeStack::createStackRestorePoints(
IRBuilder<> &IRB, Function &
F,
433 Value *StaticTop,
bool NeedDynamicTop) {
434 assert(StaticTop &&
"The stack top isn't set.");
436 if (StackRestorePoints.
empty())
445 AllocaInst *DynamicTop =
nullptr;
446 if (NeedDynamicTop) {
450 "unsafe_stack_dynamic_ptr");
455 for (Instruction *
I : StackRestorePoints) {
456 ++NumUnsafeStackRestorePoints;
460 DynamicTop ? IRB.
CreateLoad(StackPtrTy, DynamicTop) : StaticTop;
467void SafeStack::checkStackGuard(
IRBuilder<> &IRB, Function &
F, Instruction &RI,
468 AllocaInst *StackGuardSlot,
Value *StackGuard) {
474 MDNode *Weights = MDBuilder(
F.getContext())
475 .createBranchWeights(SuccessProb.getNumerator(),
476 FailureProb.getNumerator());
481 RTLIB::LibcallImpl StackChkFailImpl =
483 if (StackChkFailImpl == RTLIB::Unsupported) {
484 F.getContext().emitError(
485 "no libcall available for stackprotector check fail");
489 StringRef StackChkFailName =
492 FunctionCallee StackChkFail =
493 F.getParent()->getOrInsertFunction(StackChkFailName, IRB.
getVoidTy());
494 IRBFail.CreateCall(StackChkFail, {});
500Value *SafeStack::moveStaticAllocasToUnsafeStack(
503 AllocaInst *StackGuardSlot) {
504 if (StaticAllocas.
empty() && ByValArguments.
empty())
507 DIBuilder DIB(*
F.getParent());
509 StackLifetime SSC(
F, StaticAllocas, StackLifetime::LivenessType::May);
510 static const StackLifetime::LiveRange NoColoringRange(1,
true);
514 for (
const auto *
I : SSC.getMarkers()) {
516 const_cast<IntrinsicInst *
>(
I)->eraseFromParent();
518 if (
Op &&
Op->use_empty())
519 Op->eraseFromParent();
523 StackLayout SSL(StackAlignment);
524 if (StackGuardSlot) {
525 SSL.addObject(StackGuardSlot, getStaticAllocaAllocationSize(StackGuardSlot),
526 StackGuardSlot->
getAlign(), SSC.getFullLiveRange());
529 for (Argument *Arg : ByValArguments) {
530 Type *Ty = Arg->getParamByValType();
531 uint64_t
Size =
DL.getTypeStoreSize(Ty);
537 if (
auto A = Arg->getParamAlign())
538 Align = std::max(Align, *
A);
539 SSL.addObject(Arg,
Size, Align, SSC.getFullLiveRange());
542 for (AllocaInst *AI : StaticAllocas) {
543 uint64_t
Size = getStaticAllocaAllocationSize(AI);
548 ClColoring ? SSC.getLiveRange(AI) : NoColoringRange);
552 Align FrameAlignment = SSL.getFrameAlignment();
556 if (FrameAlignment > StackAlignment) {
560 StackPtrTy, Intrinsic::ptrmask,
561 {BasePointer, ConstantInt::get(AddrTy, ~(FrameAlignment.
value() - 1))});
566 if (StackGuardSlot) {
567 unsigned Offset = SSL.getObjectOffset(StackGuardSlot);
578 for (Argument *Arg : ByValArguments) {
579 unsigned Offset = SSL.getObjectOffset(Arg);
580 MaybeAlign
Align(SSL.getObjectAlignment(Arg));
581 Type *Ty = Arg->getParamByValType();
583 uint64_t
Size =
DL.getTypeStoreSize(Ty);
590 Arg->getName() +
".unsafe-byval");
595 Arg->replaceAllUsesWith(NewArg);
601 for (AllocaInst *AI : StaticAllocas) {
603 unsigned Offset = SSL.getObjectOffset(AI);
610 std::string
Name = std::string(AI->
getName()) +
".unsafe";
617 if (
User->isLifetimeStartOrEnd()) {
618 User->eraseFromParent();
624 InsertBefore =
PHI->getIncomingBlock(U)->getTerminator();
630 IRBUser.CreatePtrAdd(BasePointer, ConstantInt::get(
Int32Ty, -
Offset));
632 IRBUser.CreateAddrSpaceCast(Off, AI->
getType(), Name);
637 PHI->setIncomingValueForBlock(
PHI->getIncomingBlock(U), Replacement);
648 unsigned FrameSize =
alignTo(SSL.getFrameSize(), StackAlignment);
650 MDBuilder MDB(
F.getContext());
652 Data.push_back(MDB.createString(
"unsafe-stack-size"));
653 Data.push_back(MDB.createConstant(ConstantInt::get(
Int32Ty, FrameSize)));
655 F.setMetadata(LLVMContext::MD_annotation, MD);
662 "unsafe_stack_static_top");
667void SafeStack::moveDynamicAllocasToUnsafeStack(
668 Function &
F,
Value *UnsafeStackPtr, AllocaInst *DynamicTop,
670 DIBuilder DIB(*
F.getParent());
672 for (AllocaInst *AI : DynamicAllocas) {
684 StackPtrTy, Intrinsic::ptrmask,
701 if (!DynamicAllocas.empty()) {
708 if (
II->getIntrinsicID() == Intrinsic::stacksave) {
712 II->replaceAllUsesWith(LI);
713 II->eraseFromParent();
714 }
else if (
II->getIntrinsicID() == Intrinsic::stackrestore) {
719 II->eraseFromParent();
725bool SafeStack::ShouldInlinePointerAddress(CallInst &CI) {
727 if (CI.
hasFnAttr(Attribute::AlwaysInline) &&
730 if (
Callee->isInterposable() ||
Callee->hasFnAttribute(Attribute::NoInline) ||
736void SafeStack::TryInlinePointerAddress() {
745 if (!Callee ||
Callee->isDeclaration())
748 if (!ShouldInlinePointerAddress(*CI))
751 InlineFunctionInfo IFI;
755bool SafeStack::run() {
756 assert(
F.hasFnAttribute(Attribute::SafeStack) &&
757 "Can't run SafeStack on a function without the attribute");
758 assert(!
F.isDeclaration() &&
"Can't run SafeStack on a function declaration");
765 SmallVector<Instruction *, 4> Returns;
772 SmallVector<Instruction *, 4> StackRestorePoints;
776 findInsts(
F, StaticAllocas, DynamicAllocas, ByValArguments, Returns,
779 if (StaticAllocas.
empty() && DynamicAllocas.
empty() &&
780 ByValArguments.
empty() && StackRestorePoints.
empty())
783 if (!StaticAllocas.
empty() || !DynamicAllocas.
empty() ||
784 !ByValArguments.
empty())
785 ++NumUnsafeStackFunctions;
787 if (!StackRestorePoints.
empty())
788 ++NumUnsafeStackRestorePointsFunctions;
790 IRBuilder<> IRB(&
F.front(),
F.begin()->getFirstInsertionPt());
793 if (DISubprogram *SP =
F.getSubprogram())
795 DILocation::get(
SP->getContext(),
SP->getScopeLine(), 0, SP));
799 StringRef SafestackPointerAddressName =
801 RTLIB::impl___safestack_pointer_address);
803 FunctionCallee Fn =
F.getParent()->getOrInsertFunction(
804 SafestackPointerAddressName, IRB.
getPtrTy(0));
808 if (!UnsafeStackPtr) {
809 F.getContext().emitError(
810 "no location available for safestack pointer address");
818 IRB.
CreateLoad(StackPtrTy, UnsafeStackPtr,
false,
"unsafe_stack_ptr");
821 AllocaInst *StackGuardSlot =
nullptr;
823 if (
F.hasFnAttribute(Attribute::StackProtect) ||
824 F.hasFnAttribute(Attribute::StackProtectStrong) ||
825 F.hasFnAttribute(Attribute::StackProtectReq)) {
830 for (Instruction *RI : Returns) {
832 checkStackGuard(IRBRet,
F, *RI, StackGuardSlot, StackGuard);
838 Value *StaticTop = moveStaticAllocasToUnsafeStack(
839 IRB,
F, StaticAllocas, ByValArguments, BasePointer, StackGuardSlot);
847 AllocaInst *DynamicTop = createStackRestorePoints(
848 IRB,
F, StackRestorePoints, StaticTop, !DynamicAllocas.
empty());
851 moveDynamicAllocasToUnsafeStack(
F, UnsafeStackPtr, DynamicTop,
855 for (Instruction *RI : Returns) {
860 TryInlinePointerAddress();
866class SafeStackLegacyPass :
public FunctionPass {
867 const TargetMachine *TM =
nullptr;
872 SafeStackLegacyPass() : FunctionPass(
ID) {}
874 void getAnalysisUsage(AnalysisUsage &AU)
const override {
885 if (!
F.hasFnAttribute(Attribute::SafeStack)) {
887 " for this function\n");
891 if (
F.isDeclaration()) {
893 " is not available\n");
897 TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
903 const LibcallLoweringInfo &Libcalls =
904 getAnalysis<LibcallLoweringInfoWrapper>().getLibcallLowering(
905 *
F.getParent(), *Subtarget);
907 auto *
DL = &
F.getDataLayout();
908 auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
F);
909 auto &ACT = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
F);
916 bool ShouldPreserveDominatorTree;
917 std::optional<DominatorTree> LazilyComputedDomTree;
922 if (
auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>()) {
923 DT = &DTWP->getDomTree();
924 ShouldPreserveDominatorTree =
true;
927 LazilyComputedDomTree.emplace(
F);
928 DT = &*LazilyComputedDomTree;
929 ShouldPreserveDominatorTree =
false;
935 DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
937 ScalarEvolution SE(
F, TLI, ACT, *DT, LI);
939 return SafeStack(
F, *TL, Libcalls, *
DL,
940 ShouldPreserveDominatorTree ? &DTU :
nullptr, SE)
951 if (!
F.hasFnAttribute(Attribute::SafeStack)) {
953 " for this function\n");
957 if (
F.isDeclaration()) {
959 " is not available\n");
966 auto &
DL =
F.getDataLayout();
976 if (!LibcallLowering) {
978 "' analysis required");
983 LibcallLowering->getLibcallLowering(*Subtarget);
987 bool Changed = SafeStack(
F, *TL, Libcalls,
DL, &DTU, SE).run();
996char SafeStackLegacyPass::ID = 0;
999 "Safe Stack instrumentation pass",
false,
false)
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
VarLocInsertPt getNextNode(const DbgRecord *DVR)
Expand Atomic instructions
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool runOnFunction(Function &F, bool PostInlining)
Module.h This file contains the declarations for the Module class.
This defines the Use class.
Machine Check Debug Module
uint64_t IntrinsicInst * II
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)
static cl::opt< bool > SafeStackUsePointerAddress("safestack-use-pointer-address", cl::init(false), cl::Hidden)
Use __safestack_pointer_address even if the platform has a faster way of access safe stack pointer.
static cl::opt< bool > ClColoring("safe-stack-coloring", cl::desc("enable safe stack coloring"), cl::Hidden, cl::init(true))
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
static Value * getStackGuard(const TargetLoweringBase &TLI, const LibcallLoweringInfo &Libcalls, Module *M, IRBuilder<> &B, bool *SupportsSelectionDAGSP=nullptr)
Create a stack guard loading and populate whether SelectionDAG SSP is supported.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
This file describes how to lower LLVM code to machine code.
Target-Independent Code Generator Pass Configuration Options pass.
an instruction to allocate memory on the stack
LLVM_ABI bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
PointerType * getType() const
Overload to return most specific pointer type.
LLVM_ABI std::optional< TypeSize > getAllocationSize(const DataLayout &DL) const
Get allocation size in bytes.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
empty - Check if the array is empty.
static BranchProbability getBranchProbStackProtector(bool IsLikely)
bool doesNotCapture(unsigned OpNo) const
Determine whether this data operand is not captured.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
bool doesNotAccessMemory(unsigned OpNo) const
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
bool isNoInline() const
Return true if the call should not be inlined.
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
This class represents a function call, abstracting a target machine's calling convention.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V, bool ImplicitTrunc=false)
Return a ConstantInt with the specified value for the specified type.
LLVM_ABI ConstantRange add(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an addition of a value in this ran...
LLVM_ABI bool contains(const APInt &Val) const
Return true if the specified value is in the set.
A parsed version of the target data layout string in and methods for querying it.
Analysis pass which computes a DominatorTree.
Legacy analysis pass which computes a DominatorTree.
FunctionPass class - This class is used to implement most global optimizations.
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
LLVM_ABI Value * CreateAllocationSize(Type *DestTy, AllocaInst *AI)
Get allocation size of an alloca as a runtime Value* (handles both static and dynamic allocas and vsc...
CallInst * CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, uint64_t Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Create and insert a memcpy between the specified pointers.
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
Value * CreatePtrAdd(Value *Ptr, Value *Offset, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
void SetCurrentDebugLocation(DebugLoc L)
Set location information used by debugging information.
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNSW=false)
LLVM_ABI CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Type * getVoidTy()
Fetch the type representing void.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Tracks which library functions to use for a particular subtarget.
LLVM_ABI RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const
Return the lowering's selection of implementation call for Call.
Record a mapping from subtarget to LibcallLoweringInfo.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
This is the common base class for memset/memcpy/memmove.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
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.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
LLVM_ABI Type * getType() const
Return the LLVM type of this SCEV expression.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
Analysis pass that exposes the ScalarEvolution for a function.
The main scalar evolution driver.
LLVM_ABI const SCEV * removePointerBase(const SCEV *S)
Compute an expression equivalent to S - getPointerBase(S).
LLVM_ABI uint64_t getTypeSizeInBits(Type *Ty) const
Return the size in bits of the specified type, for which isSCEVable must return true.
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.
ConstantRange getUnsignedRange(const SCEV *S)
Determine the unsigned range for a particular SCEV.
LLVM_ABI const SCEV * getPointerBase(const SCEV *V)
Transitively follow the chain of pointer-type operands until reaching a SCEV that does not have a sin...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This base class for TargetLowering contains the SelectionDAG-independent parts that can be used from ...
virtual Value * getIRStackGuard(IRBuilderBase &IRB, const LibcallLoweringInfo &Libcalls) const
If the target has a standard location for the stack protector guard, returns the address of that loca...
virtual void insertSSPDeclarations(Module &M, const LibcallLoweringInfo &Libcalls) const
Inserts necessary declarations for SSP (stack protection) purpose.
virtual Value * getSafeStackPointerLocation(IRBuilderBase &IRB, const LibcallLoweringInfo &Libcalls) const
Returns the target-specific address of the unsafe stack pointer.
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
Target-Independent Code Generator Pass Configuration Options.
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetLowering * getTargetLowering() const
The instances of the Type class are immutable: once they are created, they are never changed.
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 void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
constexpr ScalarTy getFixedValue() const
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
@ User
could "use" a pointer
NodeAddr< UseNode * > Use
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
LLVM_ABI InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, bool MergeAttributes=false, AAResults *CalleeAAR=nullptr, bool InsertLifetime=true, Function *ForwardVarArgsTo=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
This function inlines the called function into the basic block of the caller.
LLVM_ABI FunctionPass * createSafeStackPass()
This pass splits the stack into a safe stack and an unsafe stack to protect against stack-based overf...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
FunctionAddr VTableAddr uintptr_t uintptr_t Int32Ty
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
LLVM_ABI InlineResult isInlineViable(Function &Callee)
Check if it is mechanically possible to inline the function Callee, based on the contents of the func...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
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...
FunctionAddr VTableAddr uintptr_t uintptr_t Data
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
DWARFExpression::Operation Op
LLVM_ABI void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress, DIBuilder &Builder, int Offset=0)
Replaces multiple dbg.value records when the alloca it describes is replaced with a new value.
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI Instruction * SplitBlockAndInsertIfThen(Value *Cond, BasicBlock::iterator SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI bool replaceDbgDeclare(Value *Address, Value *NewAddress, DIBuilder &Builder, uint8_t DIExprFlags, int Offset)
Replaces dbg.declare record when the address it describes is replaced with a new value.
This struct is a compact representation of a valid (non-zero power of two) alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
static constexpr Align Constant()
Allow constructions of constexpr Align.
static StringRef getLibcallImplName(RTLIB::LibcallImpl CallImpl)
Get the libcall routine name for the specified libcall implementation.