LLVM: lib/CodeGen/SafeStack.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
67#include
68#include
69#include
70#include
71#include
72
73using namespace llvm;
75
76#define DEBUG_TYPE "safe-stack"
77
78STATISTIC(NumFunctions, "Total number of functions");
79STATISTIC(NumUnsafeStackFunctions, "Number of functions with unsafe stack");
80STATISTIC(NumUnsafeStackRestorePointsFunctions,
81 "Number of functions that use setjmp or exceptions");
82
83STATISTIC(NumAllocas, "Total number of allocas");
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");
88
89
90
94
96 cl::desc("enable safe stack coloring"),
98
99namespace {
100
101
102
103
104
105
106class SafeStack {
112
113 Type *StackPtrTy;
114 Type *IntPtrTy;
116
117 Value *UnsafeStackPtr = nullptr;
118
119
120
121
122
123
124
126
127
129
130
133
134
135
136
142
143
144
146
147
148
149
150
151
157
158
159
160
161
162
166 Value *StaticTop, bool NeedDynamicTop);
167
168
169
170
171 void moveDynamicAllocasToUnsafeStack(Function &F, Value *UnsafeStackPtr,
174
175 bool IsSafeStackAlloca(const Value *AllocaPtr, uint64_t AllocaSize);
176
181
182 bool ShouldInlinePointerAddress(CallInst &CI);
183 void TryInlinePointerAddress();
184
185public:
188 : F(F), TL(TL), DL(DL), DTU(DTU), SE(SE),
189 StackPtrTy(DL.getAllocaPtrType(F.getContext())),
190 IntPtrTy(DL.getIntPtrType(F.getContext())),
192
193
194
195 bool run();
196};
197
198uint64_t SafeStack::getStaticAllocaAllocationSize(const AllocaInst* AI) {
202 if ()
203 return 0;
204 Size *= C->getZExtValue();
205 }
207}
208
209bool SafeStack::IsAccessSafe(Value *Addr, uint64_t AccessSize,
210 const Value *AllocaPtr, uint64_t AllocaSize) {
211 const SCEV *AddrExpr = SE.getSCEV(Addr);
213 if ( || Base->getValue() != AllocaPtr) {
215 dbgs() << "[SafeStack] "
216 << (isa(AllocaPtr) ? "Alloca " : "ByValArgument ")
217 << *AllocaPtr << "\n"
218 << "SCEV " << *AddrExpr << " not directly based on alloca\n");
219 return false;
220 }
221
225 ConstantRange SizeRange =
226 ConstantRange(APInt(BitWidth, 0), APInt(BitWidth, AccessSize));
227 ConstantRange AccessRange = AccessStartRange.add(SizeRange);
228 ConstantRange AllocaRange =
229 ConstantRange(APInt(BitWidth, 0), APInt(BitWidth, AllocaSize));
230 bool Safe = AllocaRange.contains(AccessRange);
231
233 dbgs() << "[SafeStack] "
234 << (isa(AllocaPtr) ? "Alloca " : "ByValArgument ")
235 << *AllocaPtr << "\n"
236 << " Access " << *Addr << "\n"
237 << " SCEV " << *Expr
240 << " Range " << AccessRange << "\n"
241 << " AllocaRange " << AllocaRange << "\n"
242 << " " << (Safe ? "safe" : "unsafe") << "\n");
243
244 return Safe;
245}
246
247bool SafeStack::IsMemIntrinsicSafe(const MemIntrinsic *MI, const Use &U,
248 const Value *AllocaPtr,
249 uint64_t AllocaSize) {
251 if (MTI->getRawSource() != U && MTI->getRawDest() != U)
252 return true;
253 } else {
254 if (MI->getRawDest() != U)
255 return true;
256 }
257
258 auto Len = MI->getLengthInBytes();
259
260 if (!Len) return false;
261 return IsAccessSafe(U, Len->getZExtValue(), AllocaPtr, AllocaSize);
262}
263
264
265
266
267bool SafeStack::IsSafeStackAlloca(const Value *AllocaPtr, uint64_t AllocaSize) {
268
269
270
271 SmallPtrSet<const Value *, 16> Visited;
272 SmallVector<const Value *, 8> WorkList;
274
275
276 while (!WorkList.empty()) {
278 for (const Use &UI : V->uses()) {
280 assert(V == UI.get());
281
282 switch (I->getOpcode()) {
283 case Instruction::Load:
284 if (!IsAccessSafe(UI, DL.getTypeStoreSize(I->getType()), AllocaPtr,
285 AllocaSize))
286 return false;
287 break;
288
289 case Instruction::VAArg:
290
291 break;
292 case Instruction::Store:
293 if (V == I->getOperand(0)) {
294
296 << "[SafeStack] Unsafe alloca: " << *AllocaPtr
297 << "\n store of address: " << *I << "\n");
298 return false;
299 }
300
301 if (!IsAccessSafe(UI, DL.getTypeStoreSize(I->getOperand(0)->getType()),
302 AllocaPtr, AllocaSize))
303 return false;
304 break;
305
306 case Instruction::Ret:
307
308 return false;
309
310 case Instruction::Call:
311 case Instruction::Invoke: {
313
314 if (I->isLifetimeStartOrEnd())
315 continue;
316
318 if (!IsMemIntrinsicSafe(MI, UI, AllocaPtr, AllocaSize)) {
320 << "[SafeStack] Unsafe alloca: " << *AllocaPtr
321 << "\n unsafe memintrinsic: " << *I << "\n");
322 return false;
323 }
324 continue;
325 }
326
327
328
329
330
331
332
333
335 for (const auto *A = B; A != E; ++A)
336 if (A->get() == V)
339 LLVM_DEBUG(dbgs() << "[SafeStack] Unsafe alloca: " << *AllocaPtr
340 << "\n unsafe call: " << *I << "\n");
341 return false;
342 }
343 continue;
344 }
345
346 default:
347 if (Visited.insert(I).second)
349 }
350 }
351 }
352
353
354 return true;
355}
356
360
361 if (!StackGuardVar) {
364 }
365
366 return IRB.CreateLoad(StackPtrTy, StackGuardVar, "StackGuard");
367}
368
369void SafeStack::findInsts(Function &F,
370 SmallVectorImpl<AllocaInst *> &StaticAllocas,
371 SmallVectorImpl<AllocaInst *> &DynamicAllocas,
372 SmallVectorImpl<Argument *> &ByValArguments,
373 SmallVectorImpl<Instruction *> &Returns,
374 SmallVectorImpl<Instruction *> &StackRestorePoints) {
377 ++NumAllocas;
378
379 uint64_t Size = getStaticAllocaAllocationSize(AI);
380 if (IsSafeStackAlloca(AI, Size))
381 continue;
382
384 ++NumUnsafeStaticAllocas;
386 } else {
387 ++NumUnsafeDynamicAllocas;
389 }
391 if (CallInst *CI = I.getParent()->getTerminatingMustTailCall())
393 else
396
397 if (CI->getCalledFunction() && CI->canReturnTwice())
398 StackRestorePoints.push_back(CI);
400
401 StackRestorePoints.push_back(LP);
403 if (II->getIntrinsicID() == Intrinsic::gcroot)
405 "gcroot intrinsic not compatible with safestack attribute");
406 }
407 }
408 for (Argument &Arg : F.args()) {
409 if (!Arg.hasByValAttr())
410 continue;
411 uint64_t Size = DL.getTypeStoreSize(Arg.getParamByValType());
412 if (IsSafeStackAlloca(&Arg, Size))
413 continue;
414
415 ++NumUnsafeByValArguments;
417 }
418}
419
420AllocaInst *
421SafeStack::createStackRestorePoints(IRBuilder<> &IRB, Function &F,
423 Value *StaticTop, bool NeedDynamicTop) {
424 assert(StaticTop && "The stack top isn't set.");
425
426 if (StackRestorePoints.empty())
427 return nullptr;
428
429
430
431
432
433
434
435 AllocaInst *DynamicTop = nullptr;
436 if (NeedDynamicTop) {
437
438
439 DynamicTop = IRB.CreateAlloca(StackPtrTy, nullptr,
440 "unsafe_stack_dynamic_ptr");
442 }
443
444
445 for (Instruction *I : StackRestorePoints) {
446 ++NumUnsafeStackRestorePoints;
447
449 Value *CurrentTop =
450 DynamicTop ? IRB.CreateLoad(StackPtrTy, DynamicTop) : StaticTop;
451 IRB.CreateStore(CurrentTop, UnsafeStackPtr);
452 }
453
454 return DynamicTop;
455}
456
457void SafeStack::checkStackGuard(IRBuilder<> &IRB, Function &F, Instruction &RI,
458 AllocaInst *StackGuardSlot, Value *StackGuard) {
461
464 MDNode *Weights = MDBuilder(F.getContext())
465 .createBranchWeights(SuccessProb.getNumerator(),
466 FailureProb.getNumerator());
470
471 const char *StackChkFailName =
473 if (!StackChkFailName) {
474 F.getContext().emitError(
475 "no libcall available for stackprotector check fail");
476 return;
477 }
478
479 FunctionCallee StackChkFail =
480 F.getParent()->getOrInsertFunction(StackChkFailName, IRB.getVoidTy());
481 IRBFail.CreateCall(StackChkFail, {});
482}
483
484
485
486
487Value *SafeStack::moveStaticAllocasToUnsafeStack(
490 AllocaInst *StackGuardSlot) {
491 if (StaticAllocas.empty() && ByValArguments.empty())
492 return BasePointer;
493
494 DIBuilder DIB(*F.getParent());
495
496 StackLifetime SSC(F, StaticAllocas, StackLifetime::LivenessType::May);
497 static const StackLifetime::LiveRange NoColoringRange(1, true);
499 SSC.run();
500
501 for (const auto *I : SSC.getMarkers()) {
503 const_cast<IntrinsicInst *>(I)->eraseFromParent();
504
505 if (Op && Op->use_empty())
506 Op->eraseFromParent();
507 }
508
509
510 StackLayout SSL(StackAlignment);
511 if (StackGuardSlot) {
514 SSL.addObject(StackGuardSlot, getStaticAllocaAllocationSize(StackGuardSlot),
515 Align, SSC.getFullLiveRange());
516 }
517
518 for (Argument *Arg : ByValArguments) {
519 Type *Ty = Arg->getParamByValType();
520 uint64_t Size = DL.getTypeStoreSize(Ty);
521 if (Size == 0)
522 Size = 1;
523
524
526 if (auto A = Arg->getParamAlign())
527 Align = std::max(Align, *A);
528 SSL.addObject(Arg, Size, Align, SSC.getFullLiveRange());
529 }
530
531 for (AllocaInst *AI : StaticAllocas) {
533 uint64_t Size = getStaticAllocaAllocationSize(AI);
534 if (Size == 0)
535 Size = 1;
536
537
539
540 SSL.addObject(AI, Size, Align,
541 ClColoring ? SSC.getLiveRange(AI) : NoColoringRange);
542 }
543
544 SSL.computeLayout();
545 Align FrameAlignment = SSL.getFrameAlignment();
546
547
548
549 if (FrameAlignment > StackAlignment) {
550
555 ConstantInt::get(IntPtrTy, ~(FrameAlignment.value() - 1))),
556 StackPtrTy));
557 }
558
560
561 if (StackGuardSlot) {
562 unsigned Offset = SSL.getObjectOffset(StackGuardSlot);
567
568
571 }
572
573 for (Argument *Arg : ByValArguments) {
574 unsigned Offset = SSL.getObjectOffset(Arg);
575 MaybeAlign Align(SSL.getObjectAlignment(Arg));
576 Type *Ty = Arg->getParamByValType();
577
578 uint64_t Size = DL.getTypeStoreSize(Ty);
579 if (Size == 0)
580 Size = 1;
581
585 Arg->getName() + ".unsafe-byval");
586
587
590 Arg->replaceAllUsesWith(NewArg);
592 IRB.CreateMemCpy(Off, Align, Arg, Arg->getParamAlign(), Size);
593 }
594
595
596 for (AllocaInst *AI : StaticAllocas) {
598 unsigned Offset = SSL.getObjectOffset(AI);
599
602
603
604
605 std::string Name = std::string(AI->getName()) + ".unsafe";
609
610
611
612 if (User->isLifetimeStartOrEnd()) {
613 User->eraseFromParent();
614 continue;
615 }
616
619 InsertBefore = PHI->getIncomingBlock(U)->getTerminator();
620 else
621 InsertBefore = User;
622
625 IRBUser.CreatePtrAdd(BasePointer, ConstantInt::get(Int32Ty, -Offset));
626 Value *Replacement =
627 IRBUser.CreateAddrSpaceCast(Off, AI->getType(), Name);
628
630
631
632 PHI->setIncomingValueForBlock(PHI->getIncomingBlock(U), Replacement);
633 else
634 U.set(Replacement);
635 }
636
638 }
639
640
641
642
643 unsigned FrameSize = alignTo(SSL.getFrameSize(), StackAlignment);
644
645 MDBuilder MDB(F.getContext());
647 Data.push_back(MDB.createString("unsafe-stack-size"));
648 Data.push_back(MDB.createConstant(ConstantInt::get(Int32Ty, FrameSize)));
650 F.setMetadata(LLVMContext::MD_annotation, MD);
651
652
654
655 Value *StaticTop =
657 "unsafe_stack_static_top");
658 IRB.CreateStore(StaticTop, UnsafeStackPtr);
659 return StaticTop;
660}
661
662void SafeStack::moveDynamicAllocasToUnsafeStack(
663 Function &F, Value *UnsafeStackPtr, AllocaInst *DynamicTop,
665 DIBuilder DIB(*F.getParent());
666
667 for (AllocaInst *AI : DynamicAllocas) {
669
670
672 if (ArraySize->getType() != IntPtrTy)
673 ArraySize = IRB.CreateIntCast(ArraySize, IntPtrTy, false);
674
676 uint64_t TySize = DL.getTypeAllocSize(Ty);
677 Value *Size = IRB.CreateMul(ArraySize, ConstantInt::get(IntPtrTy, TySize));
678
680 IntPtrTy);
682
683
684 auto Align = std::max(std::max(DL.getPrefTypeAlign(Ty), AI->getAlign()),
685 StackAlignment);
686
689 ConstantInt::get(IntPtrTy, ~uint64_t(Align.value() - 1))),
690 StackPtrTy);
691
692
694 if (DynamicTop)
696
700
704 }
705
706 if (!DynamicAllocas.empty()) {
707
710 if ()
711 continue;
712
713 if (II->getIntrinsicID() == Intrinsic::stacksave) {
717 II->replaceAllUsesWith(LI);
718 II->eraseFromParent();
719 } else if (II->getIntrinsicID() == Intrinsic::stackrestore) {
724 II->eraseFromParent();
725 }
726 }
727 }
728}
729
730bool SafeStack::ShouldInlinePointerAddress(CallInst &CI) {
732 if (CI.hasFnAttr(Attribute::AlwaysInline) &&
734 return true;
735 if (Callee->isInterposable() || Callee->hasFnAttribute(Attribute::NoInline) ||
737 return false;
738 return true;
739}
740
741void SafeStack::TryInlinePointerAddress() {
743 if (!CI)
744 return;
745
746 if(F.hasOptNone())
747 return;
748
750 if (!Callee || Callee->isDeclaration())
751 return;
752
753 if (!ShouldInlinePointerAddress(*CI))
754 return;
755
756 InlineFunctionInfo IFI;
758}
759
760bool SafeStack::run() {
761 assert(F.hasFnAttribute(Attribute::SafeStack) &&
762 "Can't run SafeStack on a function without the attribute");
763 assert(.isDeclaration() && "Can't run SafeStack on a function declaration");
764
765 ++NumFunctions;
766
770 SmallVector<Instruction *, 4> Returns;
771
772
773
774
775
776
777 SmallVector<Instruction *, 4> StackRestorePoints;
778
779
780
781 findInsts(F, StaticAllocas, DynamicAllocas, ByValArguments, Returns,
782 StackRestorePoints);
783
784 if (StaticAllocas.empty() && DynamicAllocas.empty() &&
785 ByValArguments.empty() && StackRestorePoints.empty())
786 return false;
787
788 if (!StaticAllocas.empty() || !DynamicAllocas.empty() ||
789 !ByValArguments.empty())
790 ++NumUnsafeStackFunctions;
791
792 if (!StackRestorePoints.empty())
793 ++NumUnsafeStackRestorePointsFunctions;
794
795 IRBuilder<> IRB(&F.front(), F.begin()->getFirstInsertionPt());
796
797
798 if (DISubprogram *SP = F.getSubprogram())
800 DILocation::get(SP->getContext(), SP->getScopeLine(), 0, SP));
802 const char *SafestackPointerAddressName =
804 if (!SafestackPointerAddressName) {
805 F.getContext().emitError(
806 "no libcall available for safestack pointer address");
807 return false;
808 }
809
810 FunctionCallee Fn = F.getParent()->getOrInsertFunction(
811 SafestackPointerAddressName, IRB.getPtrTy(0));
813 } else {
815 }
816
817
818
820 IRB.CreateLoad(StackPtrTy, UnsafeStackPtr, false, "unsafe_stack_ptr");
822
823 AllocaInst *StackGuardSlot = nullptr;
824
825 if (F.hasFnAttribute(Attribute::StackProtect) ||
826 F.hasFnAttribute(Attribute::StackProtectStrong) ||
827 F.hasFnAttribute(Attribute::StackProtectReq)) {
829 StackGuardSlot = IRB.CreateAlloca(StackPtrTy, nullptr);
830 IRB.CreateStore(StackGuard, StackGuardSlot);
831
832 for (Instruction *RI : Returns) {
834 checkStackGuard(IRBRet, F, *RI, StackGuardSlot, StackGuard);
835 }
836 }
837
838
839
840 Value *StaticTop = moveStaticAllocasToUnsafeStack(
841 IRB, F, StaticAllocas, ByValArguments, BasePointer, StackGuardSlot);
842
843
844
845
846
847
848
849 AllocaInst *DynamicTop = createStackRestorePoints(
850 IRB, F, StackRestorePoints, StaticTop, !DynamicAllocas.empty());
851
852
853 moveDynamicAllocasToUnsafeStack(F, UnsafeStackPtr, DynamicTop,
854 DynamicAllocas);
855
856
857 for (Instruction *RI : Returns) {
859 IRB.CreateStore(BasePointer, UnsafeStackPtr);
860 }
861
862 TryInlinePointerAddress();
863
864 LLVM_DEBUG(dbgs() << "[SafeStack] safestack applied\n");
865 return true;
866}
867
868class SafeStackLegacyPass : public FunctionPass {
869 const TargetMachine *TM = nullptr;
870
871public:
872 static char ID;
873
874 SafeStackLegacyPass() : FunctionPass(ID) {
876 }
877
878 void getAnalysisUsage(AnalysisUsage &AU) const override {
880 AU.addRequired();
881 AU.addRequired();
883 }
884
886 LLVM_DEBUG(dbgs() << "[SafeStack] Function: " << F.getName() << "\n");
887
888 if (.hasFnAttribute(Attribute::SafeStack)) {
889 LLVM_DEBUG(dbgs() << "[SafeStack] safestack is not requested"
890 " for this function\n");
891 return false;
892 }
893
894 if (F.isDeclaration()) {
895 LLVM_DEBUG(dbgs() << "[SafeStack] function definition"
896 " is not available\n");
897 return false;
898 }
899
900 TM = &getAnalysis().getTM();
902 if (!TL)
904
905 auto *DL = &F.getDataLayout();
906 auto &TLI = getAnalysis().getTLI(F);
907 auto &ACT = getAnalysis().getAssumptionCache(F);
908
909
910
911
912
913 DominatorTree *DT;
914 bool ShouldPreserveDominatorTree;
915 std::optional LazilyComputedDomTree;
916
917
918
919
920 if (auto *DTWP = getAnalysisIfAvailable()) {
921 DT = &DTWP->getDomTree();
922 ShouldPreserveDominatorTree = true;
923 } else {
924
925 LazilyComputedDomTree.emplace(F);
926 DT = &*LazilyComputedDomTree;
927 ShouldPreserveDominatorTree = false;
928 }
929
930
931 LoopInfo LI(*DT);
932
933 DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
934
935 ScalarEvolution SE(F, TLI, ACT, *DT, LI);
936
937 return SafeStack(F, *TL, *DL, ShouldPreserveDominatorTree ? &DTU : nullptr,
938 SE)
939 .run();
940 }
941};
942
943}
944
947 LLVM_DEBUG(dbgs() << "[SafeStack] Function: " << F.getName() << "\n");
948
949 if (.hasFnAttribute(Attribute::SafeStack)) {
950 LLVM_DEBUG(dbgs() << "[SafeStack] safestack is not requested"
951 " for this function\n");
953 }
954
955 if (F.isDeclaration()) {
956 LLVM_DEBUG(dbgs() << "[SafeStack] function definition"
957 " is not available\n");
959 }
960
962 if (!TL)
964
965 auto &DL = F.getDataLayout();
966
967
970 DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
971
972 bool Changed = SafeStack(F, *TL, DL, &DTU, SE).run();
973
978 return PA;
979}
980
981char SafeStackLegacyPass::ID = 0;
982
984 "Safe Stack instrumentation pass", false, false)
989
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, 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.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
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.
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.
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="")
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 * CreateIntToPtr(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="")
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 * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
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...
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
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.
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
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.
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
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.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
This is the common base class for memset/memcpy/memmove.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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)
Definition SafeStack.cpp:945
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 * getSafeStackPointerLocation(IRBuilderBase &IRB) const
Returns the target-specific address of the unsafe stack pointer.
virtual Value * getIRStackGuard(IRBuilderBase &IRB) const
If the target has a standard location for the stack protector guard, returns the address of that loca...
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
virtual void insertSSPDeclarations(Module &M) const
Inserts necessary declarations for SSP (stack protection) purpose.
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.
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.
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.
@ C
The default llvm calling convention, compatible with C.
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...
Definition SafeStack.cpp:990
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
FunctionAddr VTableAddr uintptr_t uintptr_t Int32Ty
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 void initializeSafeStackLegacyPassPass(PassRegistry &)
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 - 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 - 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.