14#include "llvm/IR/IntrinsicsARM.h"
20 OS <<
"LocationSize::";
22 OS <<
"beforeOrAfterPointer";
45 const auto &
DL = SI->getDataLayout();
49 SI->getValueOperand()->getType())),
76std::optional<MemoryLocation>
79 case Instruction::Load:
80 return get(cast<LoadInst>(Inst));
81 case Instruction::Store:
82 return get(cast<StoreInst>(Inst));
83 case Instruction::VAArg:
84 return get(cast<VAArgInst>(Inst));
85 case Instruction::AtomicCmpXchg:
86 return get(cast<AtomicCmpXchgInst>(Inst));
87 case Instruction::AtomicRMW:
88 return get(cast<AtomicRMWInst>(Inst));
108 assert(
MI->getRawDest() ==
MI->getArgOperand(0));
112std::optional<MemoryLocation>
123 Value *UsedV =
nullptr;
124 std::optional<unsigned> UsedIdx;
125 for (
unsigned i = 0; i < CB->
arg_size(); i++) {
136 UsedIdx = std::nullopt;
157 const Value *Arg = Call->getArgOperand(ArgIdx);
163 switch (
II->getIntrinsicID()) {
166 case Intrinsic::memset:
167 case Intrinsic::memcpy:
168 case Intrinsic::memcpy_inline:
169 case Intrinsic::memmove:
170 case Intrinsic::memcpy_element_unordered_atomic:
171 case Intrinsic::memmove_element_unordered_atomic:
172 case Intrinsic::memset_element_unordered_atomic:
173 assert((ArgIdx == 0 || ArgIdx == 1) &&
174 "Invalid argument index for memory intrinsic");
175 if (
ConstantInt *LenCI = dyn_cast<ConstantInt>(
II->getArgOperand(2)))
180 case Intrinsic::experimental_memset_pattern:
181 assert((ArgIdx == 0 || ArgIdx == 1) &&
182 "Invalid argument index for memory intrinsic");
183 if (
ConstantInt *LenCI = dyn_cast<ConstantInt>(
II->getArgOperand(2)))
187 LenCI->getZExtValue() *
188 DL.getTypeAllocSize(
II->getArgOperand(1)->getType())),
192 case Intrinsic::lifetime_start:
193 case Intrinsic::lifetime_end: {
194 assert(ArgIdx == 0 &&
"Invalid argument index");
195 auto *AI = dyn_cast<AllocaInst>(Arg);
200 std::optional<TypeSize> AllocSize =
201 AI->getAllocationSize(
II->getDataLayout());
208 case Intrinsic::invariant_start:
209 assert(ArgIdx == 1 &&
"Invalid argument index");
213 cast<ConstantInt>(
II->getArgOperand(0))->getZExtValue()),
216 case Intrinsic::masked_load:
217 assert(ArgIdx == 0 &&
"Invalid argument index");
223 case Intrinsic::masked_store:
224 assert(ArgIdx == 1 &&
"Invalid argument index");
228 DL.getTypeStoreSize(
II->getArgOperand(0)->getType())),
231 case Intrinsic::invariant_end:
236 assert(ArgIdx == 2 &&
"Invalid argument index");
240 cast<ConstantInt>(
II->getArgOperand(1))->getZExtValue()),
243 case Intrinsic::arm_neon_vld1:
244 assert(ArgIdx == 0 &&
"Invalid argument index");
251 case Intrinsic::arm_neon_vst1:
252 assert(ArgIdx == 0 &&
"Invalid argument index");
255 II->getArgOperand(1)->getType())),
260 !isa<AnyMemTransferInst>(
II) &&
261 "all memory transfer intrinsics should be handled by the switch above");
273 case LibFunc_strncat:
274 assert((ArgIdx == 0 || ArgIdx == 1) &&
"Invalid argument index for str function");
277 case LibFunc_memset_chk:
278 assert(ArgIdx == 0 &&
"Invalid argument index for memset_chk");
280 case LibFunc_memcpy_chk: {
281 assert((ArgIdx == 0 || ArgIdx == 1) &&
282 "Invalid argument index for memcpy_chk");
284 if (
const auto *Len = dyn_cast<ConstantInt>(Call->getArgOperand(2))) {
292 case LibFunc_strncpy: {
293 assert((ArgIdx == 0 || ArgIdx == 1) &&
294 "Invalid argument index for strncpy");
296 if (
const auto *Len = dyn_cast<ConstantInt>(Call->getArgOperand(2))) {
304 case LibFunc_memset_pattern16:
305 case LibFunc_memset_pattern4:
306 case LibFunc_memset_pattern8:
307 assert((ArgIdx == 0 || ArgIdx == 1) &&
308 "Invalid argument index for memset_pattern16");
311 if (
F == LibFunc_memset_pattern4)
313 else if (
F == LibFunc_memset_pattern8)
318 dyn_cast<ConstantInt>(Call->getArgOperand(2)))
324 assert((ArgIdx == 0 || ArgIdx == 1) &&
325 "Invalid argument index for memcmp/bcmp");
327 dyn_cast<ConstantInt>(Call->getArgOperand(2)))
332 assert((ArgIdx == 0) &&
"Invalid argument index for memchr");
334 dyn_cast<ConstantInt>(Call->getArgOperand(2)))
338 case LibFunc_memccpy:
339 assert((ArgIdx == 0 || ArgIdx == 1) &&
340 "Invalid argument index for memccpy");
343 dyn_cast<ConstantInt>(Call->getArgOperand(3)))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file provides utility analysis objects describing memory locations.
uint64_t IntrinsicInst * II
An instruction that atomically checks whether a specified value is in a memory location,...
Value * getCompareOperand()
Value * getPointerOperand()
an instruction that atomically reads a memory location, combines it with another value,...
Value * getPointerOperand()
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
LLVM_ABI MemoryEffects getMemoryEffects() const
bool onlyReadsMemory(unsigned OpNo) const
Value * getArgOperand(unsigned i) const
unsigned arg_size() const
bool hasOperandBundles() const
Return true if this User has any operand bundles.
This is the shared class of boolean and integer constants.
A parsed version of the target data layout string in and methods for querying it.
LLVM_ABI AAMDNodes getAAMetadata() const
Returns the AA metadata for this instruction.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
A wrapper class for inspecting calls to intrinsic functions.
An instruction for reading from memory.
Value * getPointerOperand()
static LocationSize precise(uint64_t Value)
static constexpr LocationSize mapEmpty()
static constexpr LocationSize beforeOrAfterPointer()
Any location before or after the base pointer (but still within the underlying object).
TypeSize getValue() const
LLVM_ABI void print(raw_ostream &OS) const
static constexpr LocationSize afterPointer()
Any location after the base pointer (but still within the underlying object).
static LocationSize upperBound(uint64_t Value)
static constexpr LocationSize mapTombstone()
This is the common base class for memset/memcpy/memmove.
Value * getRawSource() const
Return the arguments to the instruction.
This class wraps the llvm.memcpy/memmove intrinsics.
bool onlyAccessesArgPointees() const
Whether this function only (at most) accesses argument memory.
static MemoryEffectsBase writeOnly()
Create MemoryEffectsBase that can write any memory.
Representation for a specific memory location.
static LLVM_ABI MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
static LLVM_ABI MemoryLocation getForSource(const MemTransferInst *MTI)
Return a location representing the source of a memory transfer.
LocationSize Size
The maximum size of the location, in address-units, or UnknownSize if the size is not known.
static MemoryLocation getBeforeOrAfter(const Value *Ptr, const AAMDNodes &AATags=AAMDNodes())
Return a location that may access any location before or after Ptr, while remaining within the underl...
static MemoryLocation getAfter(const Value *Ptr, const AAMDNodes &AATags=AAMDNodes())
Return a location that may access any location after Ptr, while remaining within the underlying objec...
AAMDNodes AATags
The metadata nodes which describes the aliasing of the location (each member is null if that kind of ...
static LLVM_ABI MemoryLocation getForDest(const MemIntrinsic *MI)
Return a location representing the destination of a memory set or transfer.
static LLVM_ABI std::optional< MemoryLocation > getOrNone(const Instruction *Inst)
static LLVM_ABI MemoryLocation getForArgument(const CallBase *Call, unsigned ArgIdx, const TargetLibraryInfo *TLI)
Return a location representing a particular argument of a call.
An instruction for storing to memory.
Provides information about what library functions are available for the current target.
bool has(LibFunc F) const
Tests whether a library function is available.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
bool isPointerTy() const
True if this is an instance of PointerType.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...