comparison llvm/lib/IR/Operator.cpp @ 239:173fe712db74

merge LLVM16
author kono
date Wed, 09 Nov 2022 18:03:41 +0900 (2022-11-09)
parents c4bab56944e8
children 1f2b6ac9f198
comparison
equal deleted inserted replaced
238:8222e65f95b1 239:173fe712db74
12 12
13 #include "llvm/IR/Operator.h" 13 #include "llvm/IR/Operator.h"
14 #include "llvm/IR/DataLayout.h" 14 #include "llvm/IR/DataLayout.h"
15 #include "llvm/IR/GetElementPtrTypeIterator.h" 15 #include "llvm/IR/GetElementPtrTypeIterator.h"
16 #include "llvm/IR/Instructions.h" 16 #include "llvm/IR/Instructions.h"
17 #include "llvm/IR/Type.h"
18 17
19 #include "ConstantsContext.h" 18 #include "ConstantsContext.h"
20 19
21 namespace llvm { 20 namespace llvm {
21 bool Operator::hasPoisonGeneratingFlags() const {
22 switch (getOpcode()) {
23 case Instruction::Add:
24 case Instruction::Sub:
25 case Instruction::Mul:
26 case Instruction::Shl: {
27 auto *OBO = cast<OverflowingBinaryOperator>(this);
28 return OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap();
29 }
30 case Instruction::UDiv:
31 case Instruction::SDiv:
32 case Instruction::AShr:
33 case Instruction::LShr:
34 return cast<PossiblyExactOperator>(this)->isExact();
35 case Instruction::GetElementPtr: {
36 auto *GEP = cast<GEPOperator>(this);
37 // Note: inrange exists on constexpr only
38 return GEP->isInBounds() || GEP->getInRangeIndex() != None;
39 }
40 default:
41 if (const auto *FP = dyn_cast<FPMathOperator>(this))
42 return FP->hasNoNaNs() || FP->hasNoInfs();
43 return false;
44 }
45 }
46
22 Type *GEPOperator::getSourceElementType() const { 47 Type *GEPOperator::getSourceElementType() const {
23 if (auto *I = dyn_cast<GetElementPtrInst>(this)) 48 if (auto *I = dyn_cast<GetElementPtrInst>(this))
24 return I->getSourceElementType(); 49 return I->getSourceElementType();
25 return cast<GetElementPtrConstantExpr>(this)->getSourceElementType(); 50 return cast<GetElementPtrConstantExpr>(this)->getSourceElementType();
26 } 51 }
62 const DataLayout &DL, APInt &Offset, 87 const DataLayout &DL, APInt &Offset,
63 function_ref<bool(Value &, APInt &)> ExternalAnalysis) const { 88 function_ref<bool(Value &, APInt &)> ExternalAnalysis) const {
64 assert(Offset.getBitWidth() == 89 assert(Offset.getBitWidth() ==
65 DL.getIndexSizeInBits(getPointerAddressSpace()) && 90 DL.getIndexSizeInBits(getPointerAddressSpace()) &&
66 "The offset bit width does not match DL specification."); 91 "The offset bit width does not match DL specification.");
67 SmallVector<const Value *> Index(value_op_begin() + 1, value_op_end()); 92 SmallVector<const Value *> Index(llvm::drop_begin(operand_values()));
68 return GEPOperator::accumulateConstantOffset(getSourceElementType(), Index, 93 return GEPOperator::accumulateConstantOffset(getSourceElementType(), Index,
69 DL, Offset, ExternalAnalysis); 94 DL, Offset, ExternalAnalysis);
70 } 95 }
71 96
72 bool GEPOperator::accumulateConstantOffset( 97 bool GEPOperator::accumulateConstantOffset(
188 continue; 213 continue;
189 } 214 }
190 215
191 if (STy || ScalableType) 216 if (STy || ScalableType)
192 return false; 217 return false;
218 APInt IndexedSize =
219 APInt(BitWidth, DL.getTypeAllocSize(GTI.getIndexedType()));
193 // Insert an initial offset of 0 for V iff none exists already, then 220 // Insert an initial offset of 0 for V iff none exists already, then
194 // increment the offset by IndexedSize. 221 // increment the offset by IndexedSize.
195 VariableOffsets.insert({V, APInt(BitWidth, 0)}); 222 if (!IndexedSize.isZero()) {
196 APInt IndexedSize = 223 VariableOffsets.insert({V, APInt(BitWidth, 0)});
197 APInt(BitWidth, DL.getTypeAllocSize(GTI.getIndexedType())); 224 VariableOffsets[V] += IndexedSize;
198 VariableOffsets[V] += IndexedSize; 225 }
199 } 226 }
200 return true; 227 return true;
201 } 228 }
229
230 void FastMathFlags::print(raw_ostream &O) const {
231 if (all())
232 O << " fast";
233 else {
234 if (allowReassoc())
235 O << " reassoc";
236 if (noNaNs())
237 O << " nnan";
238 if (noInfs())
239 O << " ninf";
240 if (noSignedZeros())
241 O << " nsz";
242 if (allowReciprocal())
243 O << " arcp";
244 if (allowContract())
245 O << " contract";
246 if (approxFunc())
247 O << " afn";
248 }
249 }
202 } // namespace llvm 250 } // namespace llvm