14#ifndef LLVM_IR_OPERATOR_H
15#define LLVM_IR_OPERATOR_H
40 void *
operator new(
size_t s) =
delete;
45 return I->getOpcode();
46 return cast<ConstantExpr>(
this)->getOpcode();
53 return I->getOpcode();
55 return CE->getOpcode();
56 return Instruction::UserOp1;
62 return isa<Instruction>(V) || isa<ConstantExpr>(V);
90 void setHasNoUnsignedWrap(
bool B) {
94 void setHasNoSignedWrap(
bool B) {
117 unsigned NoWrapKind = 0;
131 return I->getOpcode() == Instruction::Add ||
132 I->getOpcode() == Instruction::Sub ||
133 I->getOpcode() == Instruction::Mul ||
134 I->getOpcode() == Instruction::Shl;
137 return CE->getOpcode() == Instruction::Add ||
138 CE->getOpcode() == Instruction::Sub;
141 return (isa<Instruction>(V) &&
classof(cast<Instruction>(V))) ||
142 (isa<ConstantExpr>(V) &&
classof(cast<ConstantExpr>(V)));
164 void setIsExact(
bool B) {
165 SubclassOptionalData = (SubclassOptionalData & ~IsExact) | (
B * IsExact);
174 return SubclassOptionalData & IsExact;
178 return OpC == Instruction::SDiv ||
179 OpC == Instruction::UDiv ||
180 OpC == Instruction::AShr ||
181 OpC == Instruction::LShr;
185 return isPossiblyExactOpcode(
I->getOpcode());
188 return (isa<Instruction>(V) && classof(cast<Instruction>(V)));
205 void setFast(
bool B) {
206 setHasAllowReassoc(
B);
209 setHasNoSignedZeros(
B);
210 setHasAllowReciprocal(
B);
211 setHasAllowContract(
B);
215 void setHasAllowReassoc(
bool B) {
216 SubclassOptionalData =
221 void setHasNoNaNs(
bool B) {
222 SubclassOptionalData =
223 (SubclassOptionalData & ~FastMathFlags::NoNaNs) |
227 void setHasNoInfs(
bool B) {
228 SubclassOptionalData =
229 (SubclassOptionalData & ~FastMathFlags::NoInfs) |
233 void setHasNoSignedZeros(
bool B) {
234 SubclassOptionalData =
235 (SubclassOptionalData & ~FastMathFlags::NoSignedZeros) |
239 void setHasAllowReciprocal(
bool B) {
240 SubclassOptionalData =
241 (SubclassOptionalData & ~FastMathFlags::AllowReciprocal) |
245 void setHasAllowContract(
bool B) {
246 SubclassOptionalData =
247 (SubclassOptionalData & ~FastMathFlags::AllowContract) |
251 void setHasApproxFunc(
bool B) {
252 SubclassOptionalData =
253 (SubclassOptionalData & ~FastMathFlags::ApproxFunc) |
259 void setFastMathFlags(FastMathFlags FMF) {
260 SubclassOptionalData |= FMF.Flags;
265 void copyFastMathFlags(FastMathFlags FMF) {
266 SubclassOptionalData = FMF.Flags;
271 static bool isComposedOfHomogeneousFloatingPointTypes(
Type *Ty) {
272 if (
auto *StructTy = dyn_cast<StructType>(Ty)) {
273 if (!StructTy->isLiteral() || !StructTy->containsHomogeneousTypes())
275 Ty = StructTy->elements().front();
276 }
else if (
auto *ArrayTy = dyn_cast<ArrayType>(Ty)) {
278 Ty = ArrayTy->getElementType();
279 }
while ((ArrayTy = dyn_cast<ArrayType>(Ty)));
281 return Ty->isFPOrFPVectorTy();
340 LLVM_ABI float getFPAccuracy()
const;
346 isComposedOfHomogeneousFloatingPointTypes(Ty);
351 if (
auto *
I = dyn_cast<Instruction>(V))
352 Opcode =
I->getOpcode();
357 case Instruction::FNeg:
358 case Instruction::FAdd:
359 case Instruction::FSub:
360 case Instruction::FMul:
361 case Instruction::FDiv:
362 case Instruction::FRem:
363 case Instruction::FPTrunc:
364 case Instruction::FPExt:
370 case Instruction::FCmp:
372 case Instruction::PHI:
373 case Instruction::Select:
374 case Instruction::Call: {
375 return isSupportedFloatingPointType(V->getType());
384template<
typename SuperClass,
unsigned Opc>
388 return I->getOpcode() ==
Opc;
391 return CE->getOpcode() ==
Opc;
394 return (isa<Instruction>(V) &&
classof(cast<Instruction>(V))) ||
395 (isa<ConstantExpr>(V) &&
classof(cast<ConstantExpr>(V)));
506 if (!isa<ConstantInt>(
I))
514 return !isa<ConstantInt>(*
use);
552 APInt &ConstantOffset)
const;
563 friend class PtrToInt;
571 return getOperand(0);
574 return getOperand(0);
588 return cast<PointerType>(getPointerOperandType())->getAddressSpace();
600 friend class PtrToAddr;
619 return cast<PointerType>(getPointerOperandType())->getAddressSpace();
639 return getOperand(0)->getType();
671 return getType()->getPointerAddressSpace();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Move duplicate certain instructions close to their use
This file implements a map that provides insertion order iteration.
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
static SymbolRef::Type getType(const Symbol *Sym)
Class for arbitrary precision integers.
This class represents a conversion between pointers from one address space to another.
const Value * getPointerOperand() const
unsigned getDestAddressSpace() const
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
unsigned getSrcAddressSpace() const
Value * getPointerOperand()
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
This class represents a no-op cast from one type to another.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
A helper template for defining operators for individual opcodes.
static bool classof(const Value *V)
static bool classof(const ConstantExpr *CE)
static bool classof(const Instruction *I)
A constant value that is initialized with an expression using other constant values.
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.
Utility class for floating point operations which can have information about relaxed accuracy require...
bool hasAllowReassoc() const
Test if this operation may be simplified with reassociative transforms.
bool isFast() const
Test if this operation allows all non-strict floating-point transforms.
static bool classof(const Value *V)
bool hasNoNaNs() const
Test if this operation's arguments and results are assumed not-NaN.
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags.
bool hasAllowReciprocal() const
Test if this operation can use reciprocal multiply instead of division.
bool hasNoSignedZeros() const
Test if this operation can ignore the sign of zero.
static bool isSupportedFloatingPointType(Type *Ty)
Returns true if Ty is a supported floating-point type for phi, select, or call FPMathOperators.
bool hasAllowContract() const
Test if this operation can be floating-point contracted (FMA).
bool hasNoInfs() const
Test if this operation's arguments and results are assumed not-infinite.
bool hasApproxFunc() const
Test if this operation allows approximations of math library functions or intrinsics.
Convenience struct for specifying and reasoning about fast-math flags.
Represents flags for the getelementptr instruction/expression.
static GEPNoWrapFlags fromRaw(unsigned Flags)
bool hasNoUnsignedSignedWrap() const
bool hasNoUnsignedWrap() const
bool hasNoUnsignedSignedWrap() const
const_op_iterator idx_end() const
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,...
const Value * getPointerOperand() const
const_op_iterator idx_begin() const
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
unsigned getNumIndices() const
LLVM_ABI std::optional< ConstantRange > getInRange() const
Returns the offset of the index with an inrange attachment, or std::nullopt if none.
unsigned countNonConstantIndices() const
LLVM_ABI Type * getSourceElementType() const
LLVM_ABI Type * getResultElementType() const
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.
bool hasNoUnsignedWrap() const
bool hasAllZeroIndices() const
Return true if all of the indices of this GEP are zeros.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Value * getPointerOperand()
GEPNoWrapFlags getNoWrapFlags() const
bool hasAllConstantIndices() const
Return true if all of the indices of this GEP are constant integers.
iterator_range< op_iterator > indices()
iterator_range< const_op_iterator > indices() const
LLVM_ABI Align getMaxPreservedAlignment(const DataLayout &DL) const
Compute the maximum alignment that this GEP is garranteed to preserve.
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
static unsigned getPointerOperandIndex()
LLVM_ABI bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
This is a utility class that provides an abstraction for the common functionality between Instruction...
static bool classof(const ConstantExpr *)
LLVM_ABI bool hasPoisonGeneratingAnnotations() const
Return true if this operator has poison-generating flags, return attributes or metadata.
LLVM_ABI bool hasPoisonGeneratingFlags() const
Return true if this operator has flags which may cause this operator to evaluate to poison despite ha...
static bool classof(const Instruction *)
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
static bool classof(const Value *V)
static unsigned getOpcode(const Value *V)
If V is an Instruction or ConstantExpr, return its opcode.
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl.
static bool classof(const Value *V)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
bool hasNoSignedWrap() const
Test whether this operation is known to never undergo signed overflow, aka the nsw property.
unsigned getNoWrapKind() const
Returns the no-wrap kind of the operation.
bool hasNoUnsignedWrap() const
Test whether this operation is known to never undergo unsigned overflow, aka the nuw property.
bool isCommutative() const
Return true if the instruction is commutative.
static bool classof(const ConstantExpr *CE)
static bool classof(const Instruction *I)
A udiv, sdiv, lshr, or ashr instruction, which can be marked as "exact", indicating that no bits are ...
bool isExact() const
Test whether this division is known to be exact, with zero remainder.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static bool isPossiblyExactOpcode(unsigned OpC)
static bool classof(const Value *V)
static bool classof(const Instruction *I)
static unsigned getPointerOperandIndex()
Value * getPointerOperand()
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
const Value * getPointerOperand() const
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
static unsigned getPointerOperandIndex()
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
const Value * getPointerOperand() const
Value * getPointerOperand()
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
A Use represents the edge between a Value definition and its users.
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
const Value * getPointerOperand(const Value *V)
A helper function that returns the pointer operand of a load, store or GEP instruction.
constexpr unsigned BitWidth
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
This struct is a compact representation of a valid (non-zero power of two) alignment.
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Compile-time customization of User operands.
A MapVector that performs no allocations if smaller than a certain size.
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...