LLVM: lib/IR/Operator.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

17

19

20using namespace llvm;

21

24 case Instruction::Add:

25 case Instruction::Sub:

26 case Instruction::Mul:

27 case Instruction::Shl: {

29 return OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap();

30 }

31 case Instruction::Trunc: {

33 return TI->hasNoUnsignedWrap() || TI->hasNoSignedWrap();

34 return false;

35 }

36 case Instruction::UDiv:

37 case Instruction::SDiv:

38 case Instruction::AShr:

39 case Instruction::LShr:

41 case Instruction::Or:

43 case Instruction::GetElementPtr: {

45

47 GEP->getInRange() != std::nullopt;

48 }

49 case Instruction::UIToFP:

50 case Instruction::ZExt:

52 return NNI->hasNonNeg();

53 return false;

54 case Instruction::ICmp:

56 default:

58 return FP->hasNoNaNs() || FP->hasNoInfs();

59 return false;

60 }

61}

62

65 return true;

67 return I && (I->hasPoisonGeneratingReturnAttributes() ||

68 I->hasPoisonGeneratingMetadata());

69}

70

73 return I->getSourceElementType();

75}

76

79 return I->getResultElementType();

81}

82

85 return CE->getInRange();

86 return std::nullopt;

87}

88

90

91

92

95 GTI != GTE; ++GTI) {

98

99 if (StructType *STy = GTI.getStructTypeOrNull()) {

102 } else {

103 assert(GTI.isSequential() && "should be sequencial");

104

105

107 Offset = GTI.getSequentialElementStride(DL) * ElemCount;

108 }

110 }

111 return Result;

112}

113

119 "The offset bit width does not match DL specification.");

122 DL, Offset, ExternalAnalysis);

123}

124

128

129 if (SourceType->isIntegerTy(8) && !Index.empty() && !ExternalAnalysis) {

131 if (CI && CI->getType()->isIntegerTy()) {

132 Offset += CI->getValue().sextOrTrunc(Offset.getBitWidth());

133 return true;

134 }

135 return false;

136 }

137

138 bool UsedExternalAnalysis = false;

139 auto AccumulateOffset = [&](APInt Index, uint64_t Size) -> bool {

140 Index = Index.sextOrTrunc(Offset.getBitWidth());

141

142 APInt IndexedSize(Offset.getBitWidth(), Size, false,

143 true);

144

145 if (!UsedExternalAnalysis) {

146 Offset += Index * IndexedSize;

147 } else {

148

149

150 bool Overflow = false;

151 APInt OffsetPlus = Index.smul_ov(IndexedSize, Overflow);

152 if (Overflow)

153 return false;

154 Offset = Offset.sadd_ov(OffsetPlus, Overflow);

155 if (Overflow)

156 return false;

157 }

158 return true;

159 };

161 SourceType, Index.begin());

163 for (auto GTI = begin, GTE = end; GTI != GTE; ++GTI) {

164

165 bool ScalableType = GTI.getIndexedType()->isScalableTy();

166

167 Value *V = GTI.getOperand();

168 StructType *STy = GTI.getStructTypeOrNull();

169

171 if (ConstOffset && ConstOffset->getType()->isIntegerTy()) {

172 if (ConstOffset->isZero())

173 continue;

174

175

176 if (ScalableType)

177 return false;

178

179 if (STy) {

180 unsigned ElementIdx = ConstOffset->getZExtValue();

182

183 if (!AccumulateOffset(

185 1))

186 return false;

187 continue;

188 }

189 if (!AccumulateOffset(ConstOffset->getValue(),

190 GTI.getSequentialElementStride(DL)))

191 return false;

192 continue;

193 }

194

195

196

197 if (!ExternalAnalysis || STy || ScalableType)

198 return false;

199 APInt AnalysisIndex;

200 if (!ExternalAnalysis(*V, AnalysisIndex))

201 return false;

202 UsedExternalAnalysis = true;

203 if (!AccumulateOffset(AnalysisIndex, GTI.getSequentialElementStride(DL)))

204 return false;

205 }

206 return true;

207}

208

212 APInt &ConstantOffset) const {

214 "The offset bit width does not match DL specification.");

215

217 Index = Index.sextOrTrunc(BitWidth);

218

220 true);

221 ConstantOffset += Index * IndexedSize;

222 };

223

225 GTI != GTE; ++GTI) {

226

227 bool ScalableType = GTI.getIndexedType()->isScalableTy();

228

229 Value *V = GTI.getOperand();

230 StructType *STy = GTI.getStructTypeOrNull();

231

233 if (ConstOffset && ConstOffset->getType()->isIntegerTy()) {

234 if (ConstOffset->isZero())

235 continue;

236

237

238

239

240

241 if (ScalableType)

242 return false;

243

244 if (STy) {

245 unsigned ElementIdx = ConstOffset->getZExtValue();

247

249 1);

250 continue;

251 }

252 CollectConstantOffset(ConstOffset->getValue(),

253 GTI.getSequentialElementStride(DL));

254 continue;

255 }

256

257 if (STy || ScalableType)

258 return false;

259

260 APInt IndexedSize(BitWidth, GTI.getSequentialElementStride(DL),

261 false, true);

262

263

264 if (!IndexedSize.isZero()) {

266 It->second += IndexedSize;

267 }

268 }

269 return true;

270}

271

273 if (all())

274 O << " fast";

275 else {

277 O << " reassoc";

279 O << " nnan";

281 O << " ninf";

283 O << " nsz";

285 O << " arcp";

287 O << " contract";

289 O << " afn";

290 }

291}

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

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

Class for arbitrary precision integers.

bool isZero() const

Determine if this value is zero, i.e. all bits are clear.

LLVM_ABI APInt smul_ov(const APInt &RHS, bool &Overflow) const

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

This is the shared class of boolean and integer constants.

uint64_t getZExtValue() const

Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...

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

LLVM_ABI void print(raw_ostream &O) const

Print fast-math flags to O.

Definition Operator.cpp:272

bool noSignedZeros() const

bool allowReciprocal() const

bool allowReassoc() const

Flag queries.

bool allowContract() const

static GEPNoWrapFlags none()

LLVM_ABI std::optional< ConstantRange > getInRange() const

Returns the offset of the index with an inrange attachment, or std::nullopt if none.

Definition Operator.cpp:83

LLVM_ABI bool collectOffset(const DataLayout &DL, unsigned BitWidth, SmallMapVector< Value *, APInt, 4 > &VariableOffsets, APInt &ConstantOffset) const

Collect the offset of this GEP as a map of Values to their associated APInt multipliers,...

Definition Operator.cpp:209

LLVM_ABI Type * getResultElementType() const

Definition Operator.cpp:77

LLVM_ABI Type * getSourceElementType() const

Definition Operator.cpp:71

LLVM_ABI Align getMaxPreservedAlignment(const DataLayout &DL) const

Compute the maximum alignment that this GEP is garranteed to preserve.

Definition Operator.cpp:89

LLVM_ABI bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset, function_ref< bool(Value &, APInt &)> ExternalAnalysis=nullptr) const

Accumulate the constant address offset of this GEP if possible.

Definition Operator.cpp:114

unsigned getPointerAddressSpace() const

Method to return the address space of the pointer operand.

std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)

LLVM_ABI bool hasPoisonGeneratingFlags() const

Return true if this operator has flags which may cause this operator to evaluate to poison despite ha...

Definition Operator.cpp:22

unsigned getOpcode() const

Return the opcode for this Instruction or ConstantExpr.

LLVM_ABI bool hasPoisonGeneratingAnnotations() const

Return true if this operator has poison-generating flags, return attributes or metadata.

Definition Operator.cpp:63

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...

TypeSize getElementOffset(unsigned Idx) const

Class to represent struct types.

The instances of the Type class are immutable: once they are created, they are never changed.

bool isIntegerTy() const

True if this is an instance of IntegerType.

iterator_range< value_op_iterator > operand_values()

LLVM Value Representation.

static constexpr uint64_t MaximumAlignment

An efficient, type-erasing, non-owning reference to a callable.

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.

auto drop_begin(T &&RangeOrContainer, size_t N=1)

Return a range covering RangeOrContainer with the first N elements excluded.

decltype(auto) dyn_cast(const From &Val)

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

gep_type_iterator gep_type_end(const User *GEP)

constexpr T MinAlign(U A, V B)

A and B are either alignments or offsets.

generic_gep_type_iterator<> gep_type_iterator

constexpr unsigned BitWidth

decltype(auto) cast(const From &Val)

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

gep_type_iterator gep_type_begin(const User *GEP)

This struct is a compact representation of a valid (non-zero power of two) alignment.

A MapVector that performs no allocations if smaller than a certain size.