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

1

2

3

4

5

6

7

8

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

17#include

18using namespace llvm;

19

21 OS << "LocationSize::";

23 OS << "beforeOrAfterPointer";

25 OS << "afterPointer";

27 OS << "mapEmpty";

29 OS << "mapTombstone";

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

32 else

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

34}

35

44

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

47

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

51 SI->getAAMetadata());

52}

53

58

67

76

77std::optional

80 case Instruction::Load:

82 case Instruction::Store:

84 case Instruction::VAArg:

86 case Instruction::AtomicCmpXchg:

88 case Instruction::AtomicRMW:

90 default:

91 return std::nullopt;

92 }

93}

94

98

103

107

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

111}

112

113std::optional

115

118 return std::nullopt;

119

121

122 return std::nullopt;

123

124 Value *UsedV = nullptr;

125 std::optional UsedIdx;

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

128 continue;

130 continue;

131 if (!UsedV) {

132

134 UsedIdx = i;

135 continue;

136 }

137 UsedIdx = std::nullopt;

139

140

141

142 return std::nullopt;

143 }

144 if (!UsedV)

145

146

147 return std::nullopt;

148

149 if (UsedIdx)

152}

153

154

155

156static std::optional<FixedVectorType *>

162 return std::nullopt;

163

166 if (LaneMaskHi.ule(LaneMaskLo))

167 return std::nullopt;

168

169 APInt NumElts = LaneMaskHi - LaneMaskLo;

170 if (NumElts.ugt(Ty->getElementCount().getKnownMinValue())) {

172 return std::nullopt;

173

174

175 NumElts = Ty->getElementCount().getKnownMinValue();

176 }

177

179}

180

182 unsigned ArgIdx,

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

186

187

190

191 switch (II->getIntrinsicID()) {

192 default:

193 break;

194 case Intrinsic::memset:

195 case Intrinsic::memcpy:

196 case Intrinsic::memcpy_inline:

197 case Intrinsic::memmove:

198 case Intrinsic::memcpy_element_unordered_atomic:

199 case Intrinsic::memmove_element_unordered_atomic:

200 case Intrinsic::memset_element_unordered_atomic:

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

202 "Invalid argument index for memory intrinsic");

207

208 case Intrinsic::experimental_memset_pattern:

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

210 "Invalid argument index for memory intrinsic");

213 Arg,

215 LenCI->getZExtValue() *

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

219

220 case Intrinsic::lifetime_start:

221 case Intrinsic::lifetime_end: {

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

224 if (!AI)

225

227

228 std::optional AllocSize =

229 AI->getAllocationSize(II->getDataLayout());

234 }

235

236 case Intrinsic::invariant_start:

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

239 Arg,

243

244 case Intrinsic::masked_load: {

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

246

250

253 }

254 case Intrinsic::masked_store: {

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

256

260

263 }

264

265 case Intrinsic::invariant_end:

266

267

268 if (ArgIdx == 0)

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

272 Arg,

276

277 case Intrinsic::arm_neon_vld1:

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

279

280

284

285 case Intrinsic::arm_neon_vst1:

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

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

291 case Intrinsic::matrix_column_major_load:

292 case Intrinsic::matrix_column_major_store: {

293 bool IsLoad = II->getIntrinsicID() == Intrinsic::matrix_column_major_load;

294 assert(ArgIdx == (IsLoad ? 0 : 1) && "Invalid argument index");

295

301

302

303 if (!Stride)

305

306 uint64_t ConstStride = Stride->getZExtValue();

308 : II->getArgOperand(0)->getType());

309 assert(Cols != 0 && "Matrix cannot have 0 columns");

310 TypeSize Size = DL.getTypeAllocSize(VT->getScalarType()) *

311 (ConstStride * (Cols - 1) + Rows);

312

313

314 if (ConstStride == Rows)

316

318 }

319 }

320

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

324 }

325

326

327

328

329

330 LibFunc F;

332 switch (F) {

333 case LibFunc_strcpy:

334 case LibFunc_strcat:

335 case LibFunc_strncat:

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

338

339 case LibFunc_memset_chk:

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

341 [[fallthrough]];

342 case LibFunc_memcpy_chk: {

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

344 "Invalid argument index for memcpy_chk");

347

348

349

351 }

353 }

354 case LibFunc_strncpy: {

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

356 "Invalid argument index for strncpy");

359

360

363 }

365 }

366 case LibFunc_memset_pattern16:

367 case LibFunc_memset_pattern4:

368 case LibFunc_memset_pattern8:

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

370 "Invalid argument index for memset_pattern16");

371 if (ArgIdx == 1) {

372 unsigned Size = 16;

373 if (F == LibFunc_memset_pattern4)

375 else if (F == LibFunc_memset_pattern8)

378 }

384 case LibFunc_bcmp:

385 case LibFunc_memcmp:

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

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

393 case LibFunc_memchr:

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

400 case LibFunc_memccpy:

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

402 "Invalid argument index for memccpy");

403

409 default:

410 break;

411 };

412 }

413

415}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

static std::optional< FixedVectorType * > getKnownTypeFromMaskedOp(Value *Mask, VectorType *Ty)

Definition MemoryLocation.cpp:157

This file provides utility analysis objects describing memory locations.

uint64_t IntrinsicInst * II

Class for arbitrary precision integers.

uint64_t getZExtValue() const

Get zero extended value.

bool ugt(const APInt &RHS) const

Unsigned greater than comparison.

bool ule(const APInt &RHS) const

Unsigned less or equal comparison.

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.

const APInt & getValue() const

Return the constant as an APInt value reference.

A parsed version of the target data layout string in and methods for querying it.

static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)

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

Definition MemoryLocation.cpp:20

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()

static LLVM_ABI MemoryLocation get(const LoadInst *LI)

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

Definition MemoryLocation.cpp:36

static LLVM_ABI MemoryLocation getForSource(const MemTransferInst *MTI)

Return a location representing the source of a memory transfer.

Definition MemoryLocation.cpp:95

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.

Definition MemoryLocation.cpp:104

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

Definition MemoryLocation.cpp:78

static LLVM_ABI MemoryLocation getForArgument(const CallBase *Call, unsigned ArgIdx, const TargetLibraryInfo *TLI)

Return a location representing a particular argument of a call.

Definition MemoryLocation.cpp:181

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.

bool match(Val *V, const Pattern &P)

class_match< ConstantInt > m_ConstantInt()

Match an arbitrary ConstantInt and ignore it.

IntrinsicID_match m_Intrinsic()

Match intrinsic calls like this: m_IntrinsicIntrinsic::fabs(m_Value(X))

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

MemoryEffectsBase< IRMemLocation > MemoryEffects

Summary of how a function affects memory in the program.

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

A collection of metadata nodes that might be associated with a memory access used by the alias-analys...