LLVM: lib/Analysis/MemoryLocation.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

14#include "llvm/IR/IntrinsicsARM.h"

16#include

17using namespace llvm;

18

20 OS << "LocationSize::";

22 OS << "beforeOrAfterPointer";

24 OS << "afterPointer";

26 OS << "mapEmpty";

28 OS << "mapTombstone";

30 OS << "precise(" << getValue() << ')';

31 else

32 OS << "upperBound(" << getValue() << ')';

33}

34

37

42}

43

45 const auto &DL = SI->getDataLayout();

46

49 SI->getValueOperand()->getType())),

50 SI->getAAMetadata());

51}

52

56}

57

60

65}

66

69

74}

75

76std::optional

79 case Instruction::Load:

80 return get(cast(Inst));

81 case Instruction::Store:

82 return get(cast(Inst));

83 case Instruction::VAArg:

84 return get(cast(Inst));

85 case Instruction::AtomicCmpXchg:

86 return get(cast(Inst));

87 case Instruction::AtomicRMW:

88 return get(cast(Inst));

89 default:

90 return std::nullopt;

91 }

92}

93

95 return getForSource(cast(MTI));

96}

97

99 return getForSource(cast(MTI));

100}

101

105}

106

108 return getForDest(cast(MI));

109}

110

112 return getForDest(cast(MI));

113}

114

116 assert(MI->getRawDest() == MI->getArgOperand(0));

118}

119

120std::optional

123 return std::nullopt;

124

126

127 return std::nullopt;

128

129 Value *UsedV = nullptr;

130 std::optional UsedIdx;

131 for (unsigned i = 0; i < CB->arg_size(); i++) {

133 continue;

135 continue;

136 if (!UsedV) {

137

139 UsedIdx = i;

140 continue;

141 }

142 UsedIdx = std::nullopt;

144

145

146

147 return std::nullopt;

148 }

149 if (!UsedV)

150

151

152 return std::nullopt;

153

154 if (UsedIdx)

157}

158

160 unsigned ArgIdx,

163 const Value *Arg = Call->getArgOperand(ArgIdx);

164

165

166 if (const IntrinsicInst *II = dyn_cast(Call)) {

168

169 switch (II->getIntrinsicID()) {

170 default:

171 break;

172 case Intrinsic::memset:

173 case Intrinsic::memcpy:

174 case Intrinsic::memcpy_inline:

175 case Intrinsic::memmove:

176 case Intrinsic::memcpy_element_unordered_atomic:

177 case Intrinsic::memmove_element_unordered_atomic:

178 case Intrinsic::memset_element_unordered_atomic:

179 assert((ArgIdx == 0 || ArgIdx == 1) &&

180 "Invalid argument index for memory intrinsic");

181 if (ConstantInt *LenCI = dyn_cast(II->getArgOperand(2)))

185

186 case Intrinsic::experimental_memset_pattern:

187 assert((ArgIdx == 0 || ArgIdx == 1) &&

188 "Invalid argument index for memory intrinsic");

189 if (ConstantInt *LenCI = dyn_cast(II->getArgOperand(2)))

191 Arg,

193 LenCI->getZExtValue() *

194 DL.getTypeAllocSize(II->getArgOperand(1)->getType())),

197

198 case Intrinsic::lifetime_start:

199 case Intrinsic::lifetime_end:

200 case Intrinsic::invariant_start:

201 assert(ArgIdx == 1 && "Invalid argument index");

203 Arg,

205 cast(II->getArgOperand(0))->getZExtValue()),

207

208 case Intrinsic::masked_load:

209 assert(ArgIdx == 0 && "Invalid argument index");

211 Arg,

214

215 case Intrinsic::masked_store:

216 assert(ArgIdx == 1 && "Invalid argument index");

218 Arg,

220 DL.getTypeStoreSize(II->getArgOperand(0)->getType())),

222

223 case Intrinsic::invariant_end:

224

225

226 if (ArgIdx == 0)

228 assert(ArgIdx == 2 && "Invalid argument index");

230 Arg,

232 cast(II->getArgOperand(1))->getZExtValue()),

234

235 case Intrinsic::arm_neon_vld1:

236 assert(ArgIdx == 0 && "Invalid argument index");

237

238

242

243 case Intrinsic::arm_neon_vst1:

244 assert(ArgIdx == 0 && "Invalid argument index");

247 II->getArgOperand(1)->getType())),

249 }

250

252 !isa(II) &&

253 "all memory transfer intrinsics should be handled by the switch above");

254 }

255

256

257

258

259

262 switch (F) {

263 case LibFunc_strcpy:

264 case LibFunc_strcat:

265 case LibFunc_strncat:

266 assert((ArgIdx == 0 || ArgIdx == 1) && "Invalid argument index for str function");

268

269 case LibFunc_memset_chk:

270 assert(ArgIdx == 0 && "Invalid argument index for memset_chk");

271 [[fallthrough]];

272 case LibFunc_memcpy_chk: {

273 assert((ArgIdx == 0 || ArgIdx == 1) &&

274 "Invalid argument index for memcpy_chk");

276 if (const auto *Len = dyn_cast(Call->getArgOperand(2))) {

277

278

279

281 }

283 }

284 case LibFunc_strncpy: {

285 assert((ArgIdx == 0 || ArgIdx == 1) &&

286 "Invalid argument index for strncpy");

288 if (const auto *Len = dyn_cast(Call->getArgOperand(2))) {

289

290

293 }

295 }

296 case LibFunc_memset_pattern16:

297 case LibFunc_memset_pattern4:

298 case LibFunc_memset_pattern8:

299 assert((ArgIdx == 0 || ArgIdx == 1) &&

300 "Invalid argument index for memset_pattern16");

301 if (ArgIdx == 1) {

302 unsigned Size = 16;

303 if (F == LibFunc_memset_pattern4)

305 else if (F == LibFunc_memset_pattern8)

308 }

310 dyn_cast(Call->getArgOperand(2)))

314 case LibFunc_bcmp:

315 case LibFunc_memcmp:

316 assert((ArgIdx == 0 || ArgIdx == 1) &&

317 "Invalid argument index for memcmp/bcmp");

319 dyn_cast(Call->getArgOperand(2)))

323 case LibFunc_memchr:

324 assert((ArgIdx == 0) && "Invalid argument index for memchr");

326 dyn_cast(Call->getArgOperand(2)))

330 case LibFunc_memccpy:

331 assert((ArgIdx == 0 || ArgIdx == 1) &&

332 "Invalid argument index for memccpy");

333

335 dyn_cast(Call->getArgOperand(3)))

339 default:

340 break;

341 };

342 }

343

345}

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

This file provides utility analysis objects describing memory locations.

uint64_t IntrinsicInst * II

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

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...

bool onlyReadsMemory(unsigned OpNo) const

Value * getArgOperand(unsigned i) const

bool onlyAccessesArgMemory() const

Determine if the call can access memmory only using pointers based on its arguments.

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.

AAMDNodes getAAMetadata() const

Returns the AA metadata for this instruction.

unsigned getOpcode() const

Returns a member of one of the enums like Instruction::Add.

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

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.

Representation for a specific memory location.

static MemoryLocation get(const LoadInst *LI)

Return a location with information about the memory reference by the given instruction.

static 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 MemoryLocation getForDest(const MemIntrinsic *MI)

Return a location representing the destination of a memory set or transfer.

static std::optional< MemoryLocation > getOrNone(const Instruction *Inst)

static 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...