LLVM 24.0.0git
AMDGPUAsanInstrumentation.cpp
Go to the documentation of this file.
1//===AMDGPUAsanInstrumentation.cpp - ASAN related helper functions===//
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
10#include "AMDGPUInstrInfo.h"
11
12#define DEBUG_TYPE "amdgpu-asan-instrumentation"
13
14using namespace llvm;
15
16namespace llvm {
17namespace AMDGPU {
18
19static uint64_t getRedzoneSizeForScale(int AsanScale) {
20 // Redzone used for stack and globals is at least 32 bytes.
21 // For scales 6 and 7, the redzone has to be 64 and 128 bytes respectively.
22 return std::max(32U, 1U << AsanScale);
23}
24
25static uint64_t getMinRedzoneSizeForGlobal(int AsanScale) {
26 return getRedzoneSizeForScale(AsanScale);
27}
28
29uint64_t getRedzoneSizeForGlobal(int AsanScale, uint64_t SizeInBytes) {
30 constexpr uint64_t kMaxRZ = 1 << 18;
31 const uint64_t MinRZ = getMinRedzoneSizeForGlobal(AsanScale);
32
33 uint64_t RZ = 0;
34 if (SizeInBytes <= MinRZ / 2) {
35 // Reduce redzone size for small size objects, e.g. int, char[1]. MinRZ is
36 // at least 32 bytes, optimize when SizeInBytes is less than or equal to
37 // half of MinRZ.
38 RZ = MinRZ - SizeInBytes;
39 } else {
40 // Calculate RZ, where MinRZ <= RZ <= MaxRZ, and RZ ~ 1/4 * SizeInBytes.
41 RZ = std::clamp((SizeInBytes / MinRZ / 4) * MinRZ, MinRZ, kMaxRZ);
42
43 // Round up to multiple of MinRZ.
44 if (SizeInBytes % MinRZ)
45 RZ += MinRZ - (SizeInBytes % MinRZ);
46 }
47
48 assert((RZ + SizeInBytes) % MinRZ == 0);
49
50 return RZ;
51}
52
54 size_t Res = llvm::countr_zero(TypeSize / 8);
55 return Res;
56}
57
59 Value *Cond, bool Recover) {
60 Value *ReportCond = Cond;
61 if (!Recover) {
62 auto *Ballot =
63 IRB.CreateIntrinsic(Intrinsic::amdgcn_ballot, IRB.getInt64Ty(), {Cond});
64 ReportCond = IRB.CreateIsNotNull(Ballot);
65 }
66
67 auto *Trm = SplitBlockAndInsertIfThen(
68 ReportCond, &*IRB.GetInsertPoint(), false,
69 MDBuilder(M.getContext()).createUnlikelyBranchWeights());
70 Trm->getParent()->setName("asan.report");
71
72 if (Recover)
73 return Trm;
74
75 Trm = SplitBlockAndInsertIfThen(Cond, Trm, false);
76 IRB.SetInsertPoint(Trm);
77 return IRB.CreateIntrinsicWithoutFolding(Intrinsic::amdgcn_unreachable, {});
78}
79
80static Value *createSlowPathCmp(Module &M, IRBuilder<> &IRB, Type *IntptrTy,
81 Value *AddrLong, Value *ShadowValue,
82 uint32_t TypeStoreSize, int AsanScale) {
83 uint64_t Granularity = static_cast<uint64_t>(1) << AsanScale;
84 // Addr & (Granularity - 1)
85 Value *LastAccessedByte =
86 IRB.CreateAnd(AddrLong, ConstantInt::get(IntptrTy, Granularity - 1));
87 // (Addr & (Granularity - 1)) + size - 1
88 if (TypeStoreSize / 8 > 1)
89 LastAccessedByte = IRB.CreateAdd(
90 LastAccessedByte, ConstantInt::get(IntptrTy, TypeStoreSize / 8 - 1));
91 // (uint8_t) ((Addr & (Granularity-1)) + size - 1)
92 LastAccessedByte =
93 IRB.CreateIntCast(LastAccessedByte, ShadowValue->getType(), false);
94 // ((uint8_t) ((Addr & (Granularity-1)) + size - 1)) >= ShadowValue
95 return IRB.CreateICmpSGE(LastAccessedByte, ShadowValue);
96}
97
99 Type *IntptrTy, Instruction *InsertBefore,
100 Value *Addr, bool IsWrite,
101 size_t AccessSizeIndex,
102 Value *SizeArgument, bool Recover) {
103 IRB.SetInsertPoint(InsertBefore);
104 CallInst *Call = nullptr;
106 SmallString<64> TypeStr{IsWrite ? "store" : "load"};
107 SmallString<64> EndingStr{Recover ? "_noabort" : ""};
108
109 SmallString<128> AsanErrorCallbackSizedString;
110 raw_svector_ostream AsanErrorCallbackSizedOS(AsanErrorCallbackSizedString);
111 AsanErrorCallbackSizedOS << kAsanReportErrorTemplate << TypeStr << "_n"
112 << EndingStr;
113
114 SmallVector<Type *, 3> Args2 = {IntptrTy, IntptrTy};
115 AttributeList AL2;
116 FunctionCallee AsanErrorCallbackSized = M.getOrInsertFunction(
117 AsanErrorCallbackSizedOS.str(),
118 FunctionType::get(IRB.getVoidTy(), Args2, false), AL2);
119 SmallVector<Type *, 2> Args1{1, IntptrTy};
120 AttributeList AL1;
121
122 SmallString<128> AsanErrorCallbackString;
123 raw_svector_ostream AsanErrorCallbackOS(AsanErrorCallbackString);
124 AsanErrorCallbackOS << kAsanReportErrorTemplate << TypeStr
125 << (1ULL << AccessSizeIndex) << EndingStr;
126
127 FunctionCallee AsanErrorCallback = M.getOrInsertFunction(
128 AsanErrorCallbackOS.str(),
129 FunctionType::get(IRB.getVoidTy(), Args1, false), AL1);
130 if (SizeArgument) {
131 Call = IRB.CreateCall(AsanErrorCallbackSized, {Addr, SizeArgument});
132 } else {
133 Call = IRB.CreateCall(AsanErrorCallback, Addr);
134 }
135
136 Call->setCannotMerge();
137 return Call;
138}
139
140static Value *memToShadow(Module &M, IRBuilder<> &IRB, Type *IntptrTy,
141 Value *Shadow, int AsanScale, uint32_t AsanOffset) {
142 // Shadow >> scale
143 Shadow = IRB.CreateLShr(Shadow, AsanScale);
144 if (AsanOffset == 0)
145 return Shadow;
146 // (Shadow >> scale) | offset
147 Value *ShadowBase = ConstantInt::get(IntptrTy, AsanOffset);
148 return IRB.CreateAdd(Shadow, ShadowBase);
149}
150
152 Instruction *OrigIns,
153 Instruction *InsertBefore, Value *Addr,
154 Align Alignment, uint32_t TypeStoreSize,
155 bool IsWrite, Value *SizeArgument,
156 bool UseCalls, bool Recover, int AsanScale,
157 int AsanOffset) {
158 Type *AddrTy = Addr->getType();
159 Type *IntptrTy = M.getDataLayout().getIntPtrType(
160 M.getContext(), AddrTy->getPointerAddressSpace());
161 IRB.SetInsertPoint(InsertBefore);
162 size_t AccessSizeIndex = TypeStoreSizeToSizeIndex(TypeStoreSize);
163 Type *ShadowTy = IntegerType::get(M.getContext(),
164 std::max(8U, TypeStoreSize >> AsanScale));
165 Type *ShadowPtrTy = PointerType::get(M.getContext(), 0);
166 Value *AddrLong = IRB.CreatePtrToInt(Addr, IntptrTy);
167 Value *ShadowPtr =
168 memToShadow(M, IRB, IntptrTy, AddrLong, AsanScale, AsanOffset);
169 const uint64_t ShadowAlign =
170 std::max<uint64_t>(Alignment.value() >> AsanScale, 1);
171 Value *ShadowValue = IRB.CreateAlignedLoad(
172 ShadowTy, IRB.CreateIntToPtr(ShadowPtr, ShadowPtrTy), Align(ShadowAlign));
173 Value *Cmp = IRB.CreateIsNotNull(ShadowValue);
174 auto *Cmp2 = createSlowPathCmp(M, IRB, IntptrTy, AddrLong, ShadowValue,
175 TypeStoreSize, AsanScale);
176 Cmp = IRB.CreateAnd(Cmp, Cmp2);
177 Instruction *CrashTerm = genAMDGPUReportBlock(M, IRB, Cmp, Recover);
178 Instruction *Crash =
179 generateCrashCode(M, IRB, IntptrTy, CrashTerm, AddrLong, IsWrite,
180 AccessSizeIndex, SizeArgument, Recover);
181 Crash->setDebugLoc(OrigIns->getDebugLoc());
182}
183
185 Instruction *InsertBefore, Value *Addr, Align Alignment,
186 TypeSize TypeStoreSize, bool IsWrite,
187 Value *SizeArgument, bool UseCalls, bool Recover,
188 int AsanScale, int AsanOffset) {
189 if (!TypeStoreSize.isScalable()) {
190 unsigned Granularity = 1 << AsanScale;
191 const auto FixedSize = TypeStoreSize.getFixedValue();
192 switch (FixedSize) {
193 case 8:
194 case 16:
195 case 32:
196 case 64:
197 case 128:
198 if (Alignment.value() >= Granularity ||
199 Alignment.value() >= FixedSize / 8)
201 M, IRB, OrigIns, InsertBefore, Addr, Alignment, FixedSize, IsWrite,
202 SizeArgument, UseCalls, Recover, AsanScale, AsanOffset);
203 }
204 }
205 // Instrument unusual size or unusual alignment.
206 IRB.SetInsertPoint(InsertBefore);
207 Type *AddrTy = Addr->getType();
208 Type *IntptrTy = M.getDataLayout().getIntPtrType(AddrTy);
209 Value *NumBits = IRB.CreateTypeSize(IntptrTy, TypeStoreSize);
210 Value *Size = IRB.CreateLShr(NumBits, ConstantInt::get(IntptrTy, 3));
211 Value *AddrLong = IRB.CreatePtrToInt(Addr, IntptrTy);
212 Value *SizeMinusOne =
214 Value *LastByte =
215 IRB.CreateIntToPtr(IRB.CreateAdd(AddrLong, SizeMinusOne), AddrTy);
216 instrumentAddressImpl(M, IRB, OrigIns, InsertBefore, Addr, {}, 8, IsWrite,
217 SizeArgument, UseCalls, Recover, AsanScale, AsanOffset);
218 instrumentAddressImpl(M, IRB, OrigIns, InsertBefore, LastByte, {}, 8, IsWrite,
219 SizeArgument, UseCalls, Recover, AsanScale, AsanOffset);
220}
221
223 Module &M, Instruction *I,
225 const DataLayout &DL = M.getDataLayout();
226 if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
227 Interesting.emplace_back(I, LI->getPointerOperandIndex(), false,
228 LI->getType(), LI->getAlign());
229 } else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
230 Interesting.emplace_back(I, SI->getPointerOperandIndex(), true,
231 SI->getValueOperand()->getType(), SI->getAlign());
232 } else if (AtomicRMWInst *RMW = dyn_cast<AtomicRMWInst>(I)) {
233 Interesting.emplace_back(I, RMW->getPointerOperandIndex(), true,
234 RMW->getValOperand()->getType(), std::nullopt);
235 } else if (AtomicCmpXchgInst *XCHG = dyn_cast<AtomicCmpXchgInst>(I)) {
236 Interesting.emplace_back(I, XCHG->getPointerOperandIndex(), true,
237 XCHG->getCompareOperand()->getType(),
238 std::nullopt);
239 } else if (auto *CI = dyn_cast<CallInst>(I)) {
240 switch (CI->getIntrinsicID()) {
241 case Intrinsic::masked_load:
242 case Intrinsic::masked_store:
243 case Intrinsic::masked_gather:
244 case Intrinsic::masked_scatter: {
245 bool IsWrite = CI->getType()->isVoidTy();
246 // Masked store has an initial operand for the value.
247 unsigned OpOffset = IsWrite ? 1 : 0;
248 Type *Ty = IsWrite ? CI->getArgOperand(0)->getType() : CI->getType();
249 MaybeAlign Alignment = CI->getParamAlign(OpOffset);
250 Value *Mask = CI->getOperand(1 + OpOffset);
251 Interesting.emplace_back(I, OpOffset, IsWrite, Ty, Alignment, Mask);
252 break;
253 }
254 case Intrinsic::masked_expandload:
255 case Intrinsic::masked_compressstore: {
256 bool IsWrite = CI->getIntrinsicID() == Intrinsic::masked_compressstore;
257 unsigned OpOffset = IsWrite ? 1 : 0;
258 auto *BasePtr = CI->getOperand(OpOffset);
259 MaybeAlign Alignment = BasePtr->getPointerAlignment(DL);
260 Type *Ty = IsWrite ? CI->getArgOperand(0)->getType() : CI->getType();
261 IRBuilder<> IB(I);
262 Value *Mask = CI->getOperand(1 + OpOffset);
263 Type *IntptrTy = M.getDataLayout().getIntPtrType(
264 M.getContext(), BasePtr->getType()->getPointerAddressSpace());
265 // Use the popcount of Mask as the effective vector length.
266 Type *ExtTy = VectorType::get(IntptrTy, cast<VectorType>(Ty));
267 Value *ExtMask = IB.CreateZExt(Mask, ExtTy);
268 Value *EVL = IB.CreateAddReduce(ExtMask);
269 Value *TrueMask = ConstantInt::get(Mask->getType(), 1);
270 Interesting.emplace_back(I, OpOffset, IsWrite, Ty, Alignment, TrueMask,
271 EVL);
272 break;
273 }
274 case Intrinsic::vp_load:
275 case Intrinsic::vp_store:
276 case Intrinsic::experimental_vp_strided_load:
277 case Intrinsic::experimental_vp_strided_store: {
278 auto *VPI = cast<VPIntrinsic>(CI);
279 unsigned IID = CI->getIntrinsicID();
280 bool IsWrite = CI->getType()->isVoidTy();
281 unsigned PtrOpNo = *VPI->getMemoryPointerParamPos(IID);
282 Type *Ty = IsWrite ? CI->getArgOperand(0)->getType() : CI->getType();
283 MaybeAlign Alignment = VPI->getOperand(PtrOpNo)->getPointerAlignment(DL);
284 Value *Stride = nullptr;
285 if (IID == Intrinsic::experimental_vp_strided_store ||
286 IID == Intrinsic::experimental_vp_strided_load) {
287 Stride = VPI->getOperand(PtrOpNo + 1);
288 // Use the pointer alignment as the element alignment if the stride is a
289 // mutiple of the pointer alignment. Otherwise, the element alignment
290 // should be Align(1).
291 unsigned PointerAlign = Alignment.valueOrOne().value();
292 if (!isa<ConstantInt>(Stride) ||
293 cast<ConstantInt>(Stride)->getZExtValue() % PointerAlign != 0)
294 Alignment = Align(1);
295 }
296 Interesting.emplace_back(I, PtrOpNo, IsWrite, Ty, Alignment,
297 VPI->getMaskParam(), VPI->getVectorLengthParam(),
298 Stride);
299 break;
300 }
301 case Intrinsic::vp_gather:
302 case Intrinsic::vp_scatter: {
303 auto *VPI = cast<VPIntrinsic>(CI);
304 unsigned IID = CI->getIntrinsicID();
305 bool IsWrite = IID == Intrinsic::vp_scatter;
306 unsigned PtrOpNo = *VPI->getMemoryPointerParamPos(IID);
307 Type *Ty = IsWrite ? CI->getArgOperand(0)->getType() : CI->getType();
308 MaybeAlign Alignment = VPI->getPointerAlignment();
309 Interesting.emplace_back(I, PtrOpNo, IsWrite, Ty, Alignment,
310 VPI->getMaskParam(),
311 VPI->getVectorLengthParam());
312 break;
313 }
314 case Intrinsic::amdgcn_global_load_tr_b64:
315 case Intrinsic::amdgcn_global_load_tr_b128: {
316 unsigned PtrOpNo = 0;
317 bool IsWrite = false;
318 Type *Ty = CI->getType();
319 Value *Ptr = CI->getArgOperand(PtrOpNo);
320 MaybeAlign Alignment = Ptr->getPointerAlignment(DL);
321 Interesting.emplace_back(I, PtrOpNo, IsWrite, Ty, Alignment);
322 break;
323 }
324 default:
325 if (const AMDGPU::BufferIntrinsicInfo *BufInfo =
326 AMDGPU::lookupBufferIntrinsic(CI->getIntrinsicID());
327 BufInfo && (BufInfo->Kind == AMDGPU::BufferKindLoad ||
328 BufInfo->Kind == AMDGPU::BufferKindSLoad ||
329 BufInfo->Kind == AMDGPU::BufferKindStore)) {
330 unsigned PtrOpNo = BufInfo->RsrcArg;
331 bool IsWrite = BufInfo->Kind == AMDGPU::BufferKindStore;
332 Value *Ptr = CI->getArgOperand(PtrOpNo);
333 Type *Ty = IsWrite ? Ptr->getType() : CI->getType();
334 MaybeAlign Alignment = Ptr->getPointerAlignment(DL);
335 Interesting.emplace_back(I, PtrOpNo, IsWrite, Ty, Alignment);
336 break;
337 }
338 for (unsigned ArgNo = 0; ArgNo < CI->arg_size(); ArgNo++) {
339 if (Type *Ty = CI->getParamByRefType(ArgNo)) {
340 Interesting.emplace_back(I, ArgNo, false, Ty, Align(1));
341 } else if (Type *Ty = CI->getParamByValType(ArgNo)) {
342 Interesting.emplace_back(I, ArgNo, false, Ty, Align(1));
343 }
344 }
345 }
346 }
347}
348} // end namespace AMDGPU
349} // end namespace llvm
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Contains the definition of a TargetInstrInfo class that is common to all AMD GPUs.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
const char kAsanReportErrorTemplate[]
SmallVector< MachineOperand, 4 > Cond
An instruction that atomically checks whether a specified value is in a memory location,...
an instruction that atomically reads a memory location, combines it with another value,...
This class represents a function call, abstracting a target machine's calling convention.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
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.
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const char *Name)
Definition IRBuilder.h:1940
Value * CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2486
BasicBlock::iterator GetInsertPoint() const
Definition IRBuilder.h:177
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2314
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1534
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Definition IRBuilder.h:533
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1572
LLVM_ABI Value * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > OverloadTypes, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="", ArrayRef< OperandBundleDef > OpBundles={}, function_ref< void(CallInst *)> SetFn=[](CallInst *) {})
Variant to create a possibly constant-folded intrinsic.
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1424
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2309
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg != 0.
Definition IRBuilder.h:2842
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2640
LLVM_ABI Value * CreateTypeSize(Type *Ty, TypeSize Size)
Create an expression which evaluates to the number of units in Size at runtime.
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition IRBuilder.h:2399
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Definition IRBuilder.h:197
Type * getVoidTy()
Fetch the type representing void.
Definition IRBuilder.h:566
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2990
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:333
An instruction for reading from memory.
LLVM_ABI MDNode * createUnlikelyBranchWeights()
Return metadata containing two branch weights, with significant bias towards false destination.
Definition MDBuilder.cpp:48
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
static LLVM_ABI PointerType * get(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object in a numbered address space.
Definition Type.cpp:882
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:28
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
LLVM_ABI Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
Definition Value.cpp:985
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:201
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition TypeSize.h:169
A raw_ostream that writes to an SmallVector or SmallString.
StringRef str() const
Return a StringRef for the vector contents.
CallInst * Call
static uint64_t getMinRedzoneSizeForGlobal(int AsanScale)
static Value * memToShadow(Module &M, IRBuilder<> &IRB, Type *IntptrTy, Value *Shadow, int AsanScale, uint32_t AsanOffset)
void getInterestingMemoryOperands(Module &M, Instruction *I, SmallVectorImpl< InterestingMemoryOperand > &Interesting)
Get all the memory operands from the instruction that needs to be instrumented.
static uint64_t getRedzoneSizeForScale(int AsanScale)
static Instruction * generateCrashCode(Module &M, IRBuilder<> &IRB, Type *IntptrTy, Instruction *InsertBefore, Value *Addr, bool IsWrite, size_t AccessSizeIndex, Value *SizeArgument, bool Recover)
static Instruction * genAMDGPUReportBlock(Module &M, IRBuilder<> &IRB, Value *Cond, bool Recover)
const BufferIntrinsicInfo * lookupBufferIntrinsic(unsigned Intr)
static size_t TypeStoreSizeToSizeIndex(uint32_t TypeSize)
static Value * createSlowPathCmp(Module &M, IRBuilder<> &IRB, Type *IntptrTy, Value *AddrLong, Value *ShadowValue, uint32_t TypeStoreSize, int AsanScale)
void instrumentAddress(Module &M, IRBuilder<> &IRB, Instruction *OrigIns, Instruction *InsertBefore, Value *Addr, Align Alignment, TypeSize TypeStoreSize, bool IsWrite, Value *SizeArgument, bool UseCalls, bool Recover, int AsanScale, int AsanOffset)
Instrument the memory operand Addr.
static void instrumentAddressImpl(Module &M, IRBuilder<> &IRB, Instruction *OrigIns, Instruction *InsertBefore, Value *Addr, Align Alignment, uint32_t TypeStoreSize, bool IsWrite, Value *SizeArgument, bool UseCalls, bool Recover, int AsanScale, int AsanOffset)
uint64_t getRedzoneSizeForGlobal(int AsanScale, uint64_t SizeInBytes)
Given SizeInBytes of the Value to be instrunmented, Returns the redzone size corresponding to it.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition bit.h:204
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
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
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 ...
The argument layout of a buffer intrinsic.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:111