LLVM 24.0.0git
AArch64StackTagging.cpp
Go to the documentation of this file.
1//===- AArch64StackTagging.cpp - Stack tagging in IR --===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//===----------------------------------------------------------------------===//
9
10#include "AArch64.h"
11#include "AArch64Subtarget.h"
12#include "llvm/ADT/APInt.h"
13#include "llvm/ADT/MapVector.h"
15#include "llvm/ADT/Statistic.h"
17#include "llvm/Analysis/CFG.h"
29#include "llvm/IR/DebugLoc.h"
30#include "llvm/IR/Dominators.h"
31#include "llvm/IR/Function.h"
32#include "llvm/IR/IRBuilder.h"
34#include "llvm/IR/Instruction.h"
37#include "llvm/IR/IntrinsicsAArch64.h"
38#include "llvm/IR/Metadata.h"
39#include "llvm/IR/PassManager.h"
40#include "llvm/IR/Value.h"
42#include "llvm/Pass.h"
44#include "llvm/Support/Debug.h"
48#include <cassert>
49#include <memory>
50
51using namespace llvm;
52
53#define DEBUG_TYPE "aarch64-stack-tagging"
54
55static const Align kTagGranuleSize = Align(16);
56
57namespace {
58
59class InitializerBuilder {
61 const DataLayout *DL;
62 Value *BasePtr;
63 Function *SetTagFn;
64 Function *SetTagZeroFn;
65 Function *StgpFn;
66
67 // List of initializers sorted by start offset.
68 struct Range {
69 uint64_t Start, End;
70 Instruction *Inst;
71 };
73 // 8-aligned offset => 8-byte initializer
74 // Missing keys are zero initialized.
75 std::map<uint64_t, Value *> Out;
76
77public:
78 InitializerBuilder(uint64_t Size, const DataLayout *DL, Value *BasePtr,
79 Function *SetTagFn, Function *SetTagZeroFn,
80 Function *StgpFn)
81 : Size(Size), DL(DL), BasePtr(BasePtr), SetTagFn(SetTagFn),
82 SetTagZeroFn(SetTagZeroFn), StgpFn(StgpFn) {}
83
84 bool addRange(uint64_t Start, uint64_t End, Instruction *Inst) {
85 auto I =
86 llvm::lower_bound(Ranges, Start, [](const Range &LHS, uint64_t RHS) {
87 return LHS.End <= RHS;
88 });
89 if (I != Ranges.end() && End > I->Start) {
90 // Overlap - bail.
91 return false;
92 }
93 Ranges.insert(I, {Start, End, Inst});
94 return true;
95 }
96
97 bool addStore(uint64_t Offset, StoreInst *SI, const DataLayout *DL) {
98 int64_t StoreSize = DL->getTypeStoreSize(SI->getOperand(0)->getType());
99 if (!addRange(Offset, Offset + StoreSize, SI))
100 return false;
101 IRBuilder<> IRB(SI);
102 applyStore(IRB, Offset, Offset + StoreSize, SI->getOperand(0));
103 return true;
104 }
105
106 bool addMemSet(uint64_t Offset, MemSetInst *MSI) {
107 uint64_t StoreSize = cast<ConstantInt>(MSI->getLength())->getZExtValue();
108 if (!addRange(Offset, Offset + StoreSize, MSI))
109 return false;
110 IRBuilder<> IRB(MSI);
111 applyMemSet(IRB, Offset, Offset + StoreSize,
113 return true;
114 }
115
116 void applyMemSet(IRBuilder<> &IRB, int64_t Start, int64_t End,
117 ConstantInt *V) {
118 // Out[] does not distinguish between zero and undef, and we already know
119 // that this memset does not overlap with any other initializer. Nothing to
120 // do for memset(0).
121 if (V->isZero())
122 return;
123 for (int64_t Offset = Start - Start % 8; Offset < End; Offset += 8) {
124 uint64_t Cst = 0x0101010101010101UL;
125 int LowBits = Offset < Start ? (Start - Offset) * 8 : 0;
126 if (LowBits)
127 Cst = (Cst >> LowBits) << LowBits;
128 int HighBits = End - Offset < 8 ? (8 - (End - Offset)) * 8 : 0;
129 if (HighBits)
130 Cst = (Cst << HighBits) >> HighBits;
131 ConstantInt *C =
132 ConstantInt::get(IRB.getInt64Ty(), Cst * V->getZExtValue());
133
134 Value *&CurrentV = Out[Offset];
135 if (!CurrentV) {
136 CurrentV = C;
137 } else {
138 CurrentV = IRB.CreateOr(CurrentV, C);
139 }
140 }
141 }
142
143 // Take a 64-bit slice of the value starting at the given offset (in bytes).
144 // Offset can be negative. Pad with zeroes on both sides when necessary.
145 Value *sliceValue(IRBuilder<> &IRB, Value *V, int64_t Offset) {
146 if (Offset > 0) {
147 V = IRB.CreateLShr(V, Offset * 8);
148 V = IRB.CreateZExtOrTrunc(V, IRB.getInt64Ty());
149 } else if (Offset < 0) {
150 V = IRB.CreateZExtOrTrunc(V, IRB.getInt64Ty());
151 V = IRB.CreateShl(V, -Offset * 8);
152 } else {
153 V = IRB.CreateZExtOrTrunc(V, IRB.getInt64Ty());
154 }
155 return V;
156 }
157
158 void applyStore(IRBuilder<> &IRB, int64_t Start, int64_t End,
159 Value *StoredValue) {
160 StoredValue = flatten(IRB, StoredValue);
161 for (int64_t Offset = Start - Start % 8; Offset < End; Offset += 8) {
162 Value *V = sliceValue(IRB, StoredValue, Offset - Start);
163 Value *&CurrentV = Out[Offset];
164 if (!CurrentV) {
165 CurrentV = V;
166 } else {
167 CurrentV = IRB.CreateOr(CurrentV, V);
168 }
169 }
170 }
171
172 void generate(IRBuilder<> &IRB) {
173 LLVM_DEBUG(dbgs() << "Combined initializer\n");
174 // No initializers => the entire allocation is undef.
175 if (Ranges.empty()) {
176 emitUndef(IRB, 0, Size);
177 return;
178 }
179
180 // Look through 8-byte initializer list 16 bytes at a time;
181 // If one of the two 8-byte halves is non-zero non-undef, emit STGP.
182 // Otherwise, emit zeroes up to next available item.
183 uint64_t LastOffset = 0;
184 for (uint64_t Offset = 0; Offset < Size; Offset += 16) {
185 auto I1 = Out.find(Offset);
186 auto I2 = Out.find(Offset + 8);
187 if (I1 == Out.end() && I2 == Out.end())
188 continue;
189
190 if (Offset > LastOffset)
191 emitZeroes(IRB, LastOffset, Offset - LastOffset);
192
193 Value *Store1 = I1 == Out.end() ? Constant::getNullValue(IRB.getInt64Ty())
194 : I1->second;
195 Value *Store2 = I2 == Out.end() ? Constant::getNullValue(IRB.getInt64Ty())
196 : I2->second;
197 emitPair(IRB, Offset, Store1, Store2);
198 LastOffset = Offset + 16;
199 }
200
201 // memset(0) does not update Out[], therefore the tail can be either undef
202 // or zero.
203 if (LastOffset < Size)
204 emitZeroes(IRB, LastOffset, Size - LastOffset);
205
206 for (const auto &R : Ranges) {
207 R.Inst->eraseFromParent();
208 }
209 }
210
211 void emitZeroes(IRBuilder<> &IRB, uint64_t Offset, uint64_t Size) {
212 LLVM_DEBUG(dbgs() << " [" << Offset << ", " << Offset + Size
213 << ") zero\n");
214 Value *Ptr = BasePtr;
215 if (Offset)
216 Ptr = IRB.CreateConstGEP1_32(IRB.getInt8Ty(), Ptr, Offset);
217 IRB.CreateCall(SetTagZeroFn,
218 {Ptr, ConstantInt::get(IRB.getInt64Ty(), Size)});
219 }
220
221 void emitUndef(IRBuilder<> &IRB, uint64_t Offset, uint64_t Size) {
222 LLVM_DEBUG(dbgs() << " [" << Offset << ", " << Offset + Size
223 << ") undef\n");
224 Value *Ptr = BasePtr;
225 if (Offset)
226 Ptr = IRB.CreateConstGEP1_32(IRB.getInt8Ty(), Ptr, Offset);
227 IRB.CreateCall(SetTagFn, {Ptr, ConstantInt::get(IRB.getInt64Ty(), Size)});
228 }
229
230 void emitPair(IRBuilder<> &IRB, uint64_t Offset, Value *A, Value *B) {
231 LLVM_DEBUG(dbgs() << " [" << Offset << ", " << Offset + 16 << "):\n");
232 LLVM_DEBUG(dbgs() << " " << *A << "\n " << *B << "\n");
233 Value *Ptr = BasePtr;
234 if (Offset)
235 Ptr = IRB.CreateConstGEP1_32(IRB.getInt8Ty(), Ptr, Offset);
236 IRB.CreateCall(StgpFn, {Ptr, A, B});
237 }
238
239 Value *flatten(IRBuilder<> &IRB, Value *V) {
240 if (V->getType()->isIntegerTy())
241 return V;
242 // vector of pointers -> vector of ints
243 if (VectorType *VecTy = dyn_cast<VectorType>(V->getType())) {
244 LLVMContext &Ctx = IRB.getContext();
245 Type *EltTy = VecTy->getElementType();
246 if (EltTy->isPointerTy()) {
247 uint32_t EltSize = DL->getTypeSizeInBits(EltTy);
248 auto *NewTy = FixedVectorType::get(
249 IntegerType::get(Ctx, EltSize),
251 V = IRB.CreatePointerCast(V, NewTy);
252 }
253 }
254 return IRB.CreateBitOrPointerCast(
255 V, IRB.getIntNTy(DL->getTypeStoreSize(V->getType()) * 8));
256 }
257};
258
259class AArch64StackTagging : public FunctionPass {
260 const bool MergeInit;
261 const bool UseStackSafety;
262
263public:
264 static char ID; // Pass ID, replacement for typeid
265
266 AArch64StackTagging(bool IsOptNone = false)
267 : FunctionPass(ID),
268 MergeInit(valueOr(AArch64Options::Global.stack_tagging_merge_init,
269 !IsOptNone)),
270 UseStackSafety(
271 valueOr(AArch64Options::Global.stack_tagging_use_stack_safety,
272 !IsOptNone)) {}
273
274 void tagAlloca(AllocaInst *AI, Instruction *InsertBefore, Value *Ptr,
275 uint64_t Size);
276 void untagAlloca(AllocaInst *AI, Instruction *InsertBefore, uint64_t Size);
277
278 Instruction *collectInitializers(Instruction *StartInst, Value *StartPtr,
279 uint64_t Size, InitializerBuilder &IB);
280
281 Instruction *insertBaseTaggedPointer(
282 const Module &M,
283 const MapVector<AllocaInst *, memtag::AllocaInfo> &Allocas,
284 const DominatorTree *DT);
285 bool runOnFunction(Function &F) override;
286
287 StringRef getPassName() const override { return "AArch64 Stack Tagging"; }
288
289private:
290 Function *F = nullptr;
291 Function *SetTagFunc = nullptr;
292 const DataLayout *DL = nullptr;
293 AAResults *AA = nullptr;
294 const StackSafetyGlobalInfo *SSI = nullptr;
295
296 void getAnalysisUsage(AnalysisUsage &AU) const override {
297 AU.setPreservesCFG();
298 if (UseStackSafety)
299 AU.addRequired<StackSafetyGlobalInfoWrapperPass>();
300 if (MergeInit)
301 AU.addRequired<AAResultsWrapperPass>();
302 AU.addUsedIfAvailable<OptimizationRemarkEmitterWrapperPass>();
303 }
304};
305
306} // end anonymous namespace
307
308char AArch64StackTagging::ID = 0;
309
310INITIALIZE_PASS_BEGIN(AArch64StackTagging, DEBUG_TYPE, "AArch64 Stack Tagging",
311 false, false)
315INITIALIZE_PASS_END(AArch64StackTagging, DEBUG_TYPE, "AArch64 Stack Tagging",
317
319 return new AArch64StackTagging(IsOptNone);
320}
321
322Instruction *AArch64StackTagging::collectInitializers(Instruction *StartInst,
323 Value *StartPtr,
325 InitializerBuilder &IB) {
326 MemoryLocation AllocaLoc{StartPtr, Size};
327 Instruction *LastInst = StartInst;
328 BasicBlock::iterator BI(StartInst);
329
330 unsigned Count = 0;
331 for (; Count < AArch64Options::Global.stack_tagging_merge_init_scan_limit &&
332 !BI->isTerminator();
333 ++BI) {
334 ++Count;
335
336 if (isNoModRef(AA->getModRefInfo(&*BI, AllocaLoc)))
337 continue;
338
339 if (!isa<StoreInst>(BI) && !isa<MemSetInst>(BI)) {
340 // If the instruction is readnone, ignore it, otherwise bail out. We
341 // don't even allow readonly here because we don't want something like:
342 // A[1] = 2; strlen(A); A[2] = 2; -> memcpy(A, ...); strlen(A).
343 if (BI->mayWriteToMemory() || BI->mayReadFromMemory())
344 break;
345 continue;
346 }
347
348 if (StoreInst *NextStore = dyn_cast<StoreInst>(BI)) {
349 if (!NextStore->isSimple())
350 break;
351
352 // Check to see if this store is to a constant offset from the start ptr.
353 std::optional<int64_t> Offset =
354 NextStore->getPointerOperand()->getPointerOffsetFrom(StartPtr, *DL);
355 if (!Offset)
356 break;
357
358 if (!IB.addStore(*Offset, NextStore, DL))
359 break;
360 LastInst = NextStore;
361 } else {
362 MemSetInst *MSI = cast<MemSetInst>(BI);
363
364 if (MSI->isVolatile() || !isa<ConstantInt>(MSI->getLength()))
365 break;
366
367 if (!isa<ConstantInt>(MSI->getValue()))
368 break;
369
370 // Check to see if this store is to a constant offset from the start ptr.
371 std::optional<int64_t> Offset =
372 MSI->getDest()->getPointerOffsetFrom(StartPtr, *DL);
373 if (!Offset)
374 break;
375
376 if (!IB.addMemSet(*Offset, MSI))
377 break;
378 LastInst = MSI;
379 }
380 }
381 return LastInst;
382}
383
384void AArch64StackTagging::tagAlloca(AllocaInst *AI, Instruction *InsertBefore,
385 Value *Ptr, uint64_t Size) {
386 auto SetTagZeroFunc = Intrinsic::getOrInsertDeclaration(
387 F->getParent(), Intrinsic::aarch64_settag_zero);
388 auto StgpFunc = Intrinsic::getOrInsertDeclaration(F->getParent(),
389 Intrinsic::aarch64_stgp);
390
391 InitializerBuilder IB(Size, DL, Ptr, SetTagFunc, SetTagZeroFunc, StgpFunc);
392 bool LittleEndian = AI->getModule()->getTargetTriple().isLittleEndian();
393 // Current implementation of initializer merging assumes little endianness.
394 if (MergeInit && !F->hasOptNone() && LittleEndian &&
395 Size < AArch64Options::Global.stack_tagging_merge_init_size_limit) {
396 LLVM_DEBUG(dbgs() << "collecting initializers for " << *AI
397 << ", size = " << Size << "\n");
398 InsertBefore = collectInitializers(InsertBefore, Ptr, Size, IB);
399 }
400
401 IRBuilder<> IRB(InsertBefore);
402 IB.generate(IRB);
403}
404
405void AArch64StackTagging::untagAlloca(AllocaInst *AI, Instruction *InsertBefore,
406 uint64_t Size) {
407 IRBuilder<> IRB(InsertBefore);
408 IRB.CreateCall(SetTagFunc, {IRB.CreatePointerCast(AI, IRB.getPtrTy()),
409 ConstantInt::get(IRB.getInt64Ty(), Size)});
410}
411
412static Value *getSlotPtr(IRBuilder<> &IRB, const Triple &TargetTriple,
413 bool HasInstrumentedAllocas) {
414 if (!HasInstrumentedAllocas)
415 return nullptr;
416
417 auto Mode = AArch64Options::Global.stack_tagging_record_stack_history;
419 (!Mode && TargetTriple.isOSDarwin())) {
420 if (TargetTriple.isAndroid() && TargetTriple.isAArch64() &&
421 !TargetTriple.isAndroidVersionLT(35))
422 return memtag::getAndroidSlotPtr(IRB, -3);
423 if (TargetTriple.isOSDarwin() && TargetTriple.isAArch64() &&
424 !TargetTriple.isSimulatorEnvironment())
425 return memtag::getDarwinSlotPtr(IRB, 231);
426 }
427 return nullptr;
428}
429
430Instruction *AArch64StackTagging::insertBaseTaggedPointer(
431 const Module &M,
432 const MapVector<AllocaInst *, memtag::AllocaInfo> &AllocasToInstrument,
433 const DominatorTree *DT) {
434 BasicBlock *PrologueBB = nullptr;
435 // Try sinking IRG as deep as possible to avoid hurting shrink wrap.
436 for (auto &I : AllocasToInstrument) {
437 const memtag::AllocaInfo &Info = I.second;
438 AllocaInst *AI = Info.AI;
439 if (!PrologueBB) {
440 PrologueBB = AI->getParent();
441 continue;
442 }
443 PrologueBB = DT->findNearestCommonDominator(PrologueBB, AI->getParent());
444 }
445 assert(PrologueBB);
446
447 IRBuilder<> IRB(&PrologueBB->front());
449 Intrinsic::aarch64_irg_sp, {},
451 Base->setName("basetag");
452 const Triple &TargetTriple = M.getTargetTriple();
453 // This ABI will make it into Android API level 35.
454 // The ThreadLong format is the same as with HWASan, but the entries for
455 // stack MTE take two slots (16 bytes).
456 //
457 // Stack history is recorded by default on Darwin.
458 if (Value *SlotPtr =
459 getSlotPtr(IRB, TargetTriple, !AllocasToInstrument.empty())) {
460 constexpr uint64_t TagMask = 0xFULL << 56;
461 auto *IntptrTy = IRB.getIntPtrTy(M.getDataLayout());
462 auto *ThreadLong = IRB.CreateLoad(IntptrTy, SlotPtr);
463 Value *FP = memtag::getFP(IRB);
464 Value *Tag = IRB.CreateAnd(IRB.CreatePtrToInt(Base, IntptrTy), TagMask);
465 Value *TaggedFP = IRB.CreateOr(FP, Tag);
466 Value *PC = memtag::getPC(TargetTriple, IRB);
467 Value *RecordPtr = IRB.CreateIntToPtr(ThreadLong, IRB.getPtrTy(0));
468 IRB.CreateStore(PC, RecordPtr);
469 IRB.CreateStore(TaggedFP, IRB.CreateConstGEP1_64(IntptrTy, RecordPtr, 1));
470
471 IRB.CreateStore(memtag::incrementThreadLong(IRB, ThreadLong, 16,
472 TargetTriple.isOSDarwin()),
473 SlotPtr);
474 }
475 return Base;
476}
477
478// FIXME: check for MTE extension
479bool AArch64StackTagging::runOnFunction(Function &Fn) {
480 if (!Fn.hasFnAttribute(Attribute::SanitizeMemTag))
481 return false;
482
483 if (UseStackSafety)
484 SSI = &getAnalysis<StackSafetyGlobalInfoWrapperPass>().getResult();
485 F = &Fn;
486 DL = &Fn.getDataLayout();
487 if (MergeInit)
488 AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
489
490 std::unique_ptr<OptimizationRemarkEmitter> DeleteORE;
491 OptimizationRemarkEmitter *ORE = nullptr;
492 if (auto *P = getAnalysisIfAvailable<OptimizationRemarkEmitterWrapperPass>())
493 ORE = &P->getORE();
494
495 if (ORE == nullptr) {
496 DeleteORE = std::make_unique<OptimizationRemarkEmitter>(F);
497 ORE = DeleteORE.get();
498 }
499
500 memtag::StackInfoBuilder SIB(SSI, DEBUG_TYPE);
501 for (Instruction &I : instructions(F))
502 SIB.visit(*ORE, I);
503 memtag::StackInfo &SInfo = SIB.get();
504
505 if (SInfo.AllocasToInstrument.empty())
506 return false;
507
508 std::unique_ptr<DominatorTree> DeleteDT;
509 DominatorTree *DT = nullptr;
510 if (auto *P = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
511 DT = &P->getDomTree();
512
513 if (DT == nullptr) {
514 DeleteDT = std::make_unique<DominatorTree>(*F);
515 DT = DeleteDT.get();
516 }
517
518 std::unique_ptr<PostDominatorTree> DeletePDT;
519 PostDominatorTree *PDT = nullptr;
520 if (auto *P = getAnalysisIfAvailable<PostDominatorTreeWrapperPass>())
521 PDT = &P->getPostDomTree();
522
523 if (PDT == nullptr) {
524 DeletePDT = std::make_unique<PostDominatorTree>(*F);
525 PDT = DeletePDT.get();
526 }
527
528 std::unique_ptr<LoopInfo> DeleteLI;
529 LoopInfo *LI = nullptr;
530 if (auto *LIWP = getAnalysisIfAvailable<LoopInfoWrapperPass>()) {
531 LI = &LIWP->getLoopInfo();
532 } else {
533 DeleteLI = std::make_unique<LoopInfo>(*DT);
534 LI = DeleteLI.get();
535 }
536
537 SetTagFunc = Intrinsic::getOrInsertDeclaration(F->getParent(),
538 Intrinsic::aarch64_settag);
539
541 insertBaseTaggedPointer(*Fn.getParent(), SInfo.AllocasToInstrument, DT);
542
543 unsigned int NextTag = 0;
544 for (auto &I : SInfo.AllocasToInstrument) {
545 memtag::AllocaInfo &Info = I.second;
546 assert(Info.AI && SIB.getAllocaInterestingness(*Info.AI) ==
549 AllocaInst *AI = Info.AI;
550 unsigned int Tag = NextTag;
551 NextTag = (NextTag + 1) % 16;
552 // Replace alloca with tagp(alloca).
553 IRBuilder<> IRB(Info.AI->getNextNode());
555 Intrinsic::aarch64_tagp, {Info.AI->getType()},
556 {Constant::getNullValue(Info.AI->getType()), Base,
557 ConstantInt::get(IRB.getInt64Ty(), Tag)});
558 if (Info.AI->hasName())
559 TagPCall->setName(Info.AI->getName() + ".tag");
560 // Does not replace metadata, so we don't have to handle DbgVariableRecords.
561 Info.AI->replaceUsesWithIf(TagPCall, [&](const Use &U) {
562 return !isa<LifetimeIntrinsic>(U.getUser());
563 });
564 TagPCall->setOperand(0, Info.AI);
565
566 // Calls to functions that may return twice (e.g. setjmp) confuse the
567 // postdominator analysis, and will leave us to keep memory tagged after
568 // function return. Work around this by always untagging at every return
569 // statement if return_twice functions are called.
570 bool StandardLifetime =
571 !SInfo.CallsReturnTwice && memtag::isSupportedLifetime(Info, DT, LI);
572 if (StandardLifetime) {
573 uint64_t Size = *Info.AI->getAllocationSize(*DL);
575 for (IntrinsicInst *Start : Info.LifetimeStart)
576 tagAlloca(AI, Start->getNextNode(), TagPCall, Size);
577
578 auto TagEnd = [&](Instruction *Node) { untagAlloca(AI, Node, Size); };
579 memtag::forAllReachableExits(*DT, *PDT, *LI, Info, SInfo.RetVec, TagEnd);
580 } else {
581 uint64_t Size = *Info.AI->getAllocationSize(*DL);
582 Value *Ptr = IRB.CreatePointerCast(TagPCall, IRB.getPtrTy());
583 tagAlloca(AI, &*IRB.GetInsertPoint(), Ptr, Size);
584 for (auto *RI : SInfo.RetVec) {
585 untagAlloca(AI, RI, Size);
586 }
587 // We may have inserted tag/untag outside of any lifetime interval.
588 // Remove all lifetime intrinsics for this alloca.
589 for (auto *II : Info.LifetimeStart)
590 II->eraseFromParent();
591 for (auto *II : Info.LifetimeEnd)
592 II->eraseFromParent();
593 }
594
596 }
597
598 return true;
599}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static Value * getSlotPtr(IRBuilder<> &IRB, const Triple &TargetTriple, bool HasInstrumentedAllocas)
static const Align kTagGranuleSize
unsigned uint64_t
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")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains constants used for implementing Dwarf debug support.
static bool runOnFunction(Function &F, bool PostInlining)
#define DEBUG_TYPE
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Machine Check Debug Module
This file implements a map that provides insertion order iteration.
static void addRange(SmallVectorImpl< ConstantInt * > &EndPoints, ConstantInt *Low, ConstantInt *High)
This file contains the declarations for metadata subclasses.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
#define P(N)
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define LLVM_DEBUG(...)
Definition Debug.h:119
Value * RHS
Value * LHS
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
ModRefInfo getModRefInfo(const Instruction *I, const std::optional< MemoryLocation > &OptLoc)
Check whether or not an instruction may read or write the optionally specified memory location.
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:278
const Instruction & front() const
Definition BasicBlock.h:469
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
LLVM_ABI Instruction * findNearestCommonDominator(Instruction *I1, Instruction *I2) const
Find the nearest instruction I that dominates both I1 and I2, in the sense that a result produced bef...
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:843
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
const DataLayout & getDataLayout() const
Get the data layout of the module this function belongs to.
Definition Function.cpp:360
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition Function.cpp:734
Module * getParent()
Get the module that this global value is contained inside of...
LLVM_ABI CallInst * CreateIntrinsicWithoutFolding(Intrinsic::ID ID, ArrayRef< Type * > OverloadTypes, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="", ArrayRef< OperandBundleDef > OpBundles={})
Create a call to intrinsic ID with Args, mangled using OverloadTypes.
Value * CreateConstGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
Definition IRBuilder.h:2064
Value * CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name="")
Definition IRBuilder.h:2033
IntegerType * getIntNTy(unsigned N)
Fetch the type representing an N-bit integer.
Definition IRBuilder.h:544
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
Definition IRBuilder.h:2148
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2306
BasicBlock::iterator GetInsertPoint() const
Definition IRBuilder.h:180
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2247
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1537
IntegerType * getIntPtrTy(const DataLayout &DL, unsigned AddrSpace=0)
Fetch the type of an integer with size at least as big as that of a pointer in the given address spac...
Definition IRBuilder.h:586
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Definition IRBuilder.h:536
Value * CreateBitOrPointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2341
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
Definition IRBuilder.h:1916
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1516
LLVMContext & getContext() const
Definition IRBuilder.h:181
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1575
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition IRBuilder.h:1934
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2242
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2570
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
Definition IRBuilder.h:574
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="", bool IsDisjoint=false)
Definition IRBuilder.h:1597
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Definition IRBuilder.h:521
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2918
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:338
Value * getLength() const
Value * getDest() const
This is just like getRawDest, but it strips off any cast instructions (including addrspacecast) that ...
bool isVolatile() const
Value * getValue() const
Representation for a specific memory location.
const Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition Module.h:328
OptimizationRemarkEmitter legacy analysis pass.
This pass performs the global (interprocedural) stack safety analysis (legacy pass manager).
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
bool isAndroidVersionLT(unsigned Major) const
Definition Triple.h:913
bool isAndroid() const
Tests whether the target is Android.
Definition Triple.h:911
LLVM_ABI bool isLittleEndian() const
Tests whether the target triple is little endian.
Definition Triple.cpp:2213
bool isSimulatorEnvironment() const
Definition Triple.h:731
bool isOSDarwin() const
Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, DriverKit, XROS, or bridgeOS).
Definition Triple.h:724
bool isAArch64() const
Tests whether the target is AArch64 (little and big endian).
Definition Triple.h:1099
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:277
void setOperand(unsigned i, Value *Val)
Definition User.h:212
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
Definition Value.cpp:394
LLVM_ABI std::optional< int64_t > getPointerOffsetFrom(const Value *Other, const DataLayout &DL) const
If this ptr is provably equal to Other plus a constant offset, return that offset in bytes.
Definition Value.cpp:1098
const ParentTy * getParent() const
Definition ilist_node.h:34
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:83
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
LLVM_ABI Value * getFP(IRBuilder<> &IRB)
LLVM_ABI void forAllReachableExits(const DominatorTree &DT, const PostDominatorTree &PDT, const LoopInfo &LI, const AllocaInfo &AInfo, const SmallVectorImpl< Instruction * > &RetVec, llvm::function_ref< void(Instruction *)> Callback)
LLVM_ABI bool isSupportedLifetime(const AllocaInfo &AInfo, const DominatorTree *DT, const LoopInfo *LI)
LLVM_ABI Value * getDarwinSlotPtr(IRBuilder<> &IRB, int Slot)
LLVM_ABI Value * getAndroidSlotPtr(IRBuilder<> &IRB, int Slot)
LLVM_ABI void annotateDebugRecords(AllocaInfo &Info, unsigned int Tag)
LLVM_ABI void alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Align)
LLVM_ABI Value * getPC(const Triple &TargetTriple, IRBuilder<> &IRB)
LLVM_ABI Value * incrementThreadLong(IRBuilder<> &IRB, Value *ThreadLong, unsigned int Inc, bool IsMemtagDarwin=false)
NodeAddr< NodeBase * > Node
Definition RDFGraph.h:381
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
unsigned getNumElements(Type *Ty)
Definition SLPUtils.cpp:103
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:149
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...
Definition Casting.h:547
@ Global
Append to llvm.global_dtors.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:2068
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
constexpr bool valueOr(BoolOrDefault X, bool Default)
FunctionPass * createAArch64StackTaggingPass(bool IsOptNone)
bool isNoModRef(const ModRefInfo MRI)
Definition ModRef.h:40
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
MapVector< AllocaInst *, AllocaInfo > AllocasToInstrument
SmallVector< Instruction *, 8 > RetVec