LLVM: include/llvm/IR/Operator.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_IR_OPERATOR_H
15#define LLVM_IR_OPERATOR_H
16
25#include
26#include
27
28namespace llvm {
29
30
31
33public:
34
35
38
39 void *operator new(size_t s) = delete;
40
41
43 if (const Instruction *I = dyn_cast(this))
44 return I->getOpcode();
45 return cast(this)->getOpcode();
46 }
47
48
49
51 if (const Instruction *I = dyn_cast(V))
52 return I->getOpcode();
53 if (const ConstantExpr *CE = dyn_cast(V))
54 return CE->getOpcode();
55 return Instruction::UserOp1;
56 }
57
61 return isa(V) || isa(V);
62 }
63
64
65
67
68
69
70
72};
73
74
75
76
78public:
79 enum {
84
85private:
88
89 void setHasNoUnsignedWrap(bool B) {
92 }
93 void setHasNoSignedWrap(bool B) {
96 }
97
98public:
99
101
102
103
106 }
107
108
109
112 }
113
114
116 unsigned NoWrapKind = 0;
119
122
123 return NoWrapKind;
124 }
125
126
128
130 return I->getOpcode() == Instruction::Add ||
131 I->getOpcode() == Instruction::Sub ||
132 I->getOpcode() == Instruction::Mul ||
133 I->getOpcode() == Instruction::Shl;
134 }
136 return CE->getOpcode() == Instruction::Add ||
137 CE->getOpcode() == Instruction::Sub ||
138 CE->getOpcode() == Instruction::Mul ||
139 CE->getOpcode() == Instruction::Shl;
140 }
142 return (isa(V) && classof(cast(V))) ||
143 (isa(V) && classof(cast(V)));
144 }
145};
146
147template <>
150
152
153
154
156public:
157 enum {
158 IsExact = (1 << 0)
160
161private:
164
165 void setIsExact(bool B) {
166 SubclassOptionalData = (SubclassOptionalData & ~IsExact) | (B * IsExact);
167 }
168
169public:
170
172
173
175 return SubclassOptionalData & IsExact;
176 }
177
179 return OpC == Instruction::SDiv ||
180 OpC == Instruction::UDiv ||
181 OpC == Instruction::AShr ||
182 OpC == Instruction::LShr;
183 }
184
186 return isPossiblyExactOpcode(CE->getOpcode());
187 }
189 return isPossiblyExactOpcode(I->getOpcode());
190 }
192 return (isa(V) && classof(cast(V))) ||
193 (isa(V) && classof(cast(V)));
194 }
195};
196
197template <>
200
202
203
204
206private:
208
209
210 void setFast(bool B) {
211 setHasAllowReassoc(B);
212 setHasNoNaNs(B);
213 setHasNoInfs(B);
214 setHasNoSignedZeros(B);
215 setHasAllowReciprocal(B);
216 setHasAllowContract(B);
217 setHasApproxFunc(B);
218 }
219
220 void setHasAllowReassoc(bool B) {
221 SubclassOptionalData =
222 (SubclassOptionalData & ~FastMathFlags::AllowReassoc) |
224 }
225
226 void setHasNoNaNs(bool B) {
227 SubclassOptionalData =
228 (SubclassOptionalData & ~FastMathFlags::NoNaNs) |
230 }
231
232 void setHasNoInfs(bool B) {
233 SubclassOptionalData =
234 (SubclassOptionalData & ~FastMathFlags::NoInfs) |
236 }
237
238 void setHasNoSignedZeros(bool B) {
239 SubclassOptionalData =
240 (SubclassOptionalData & ~FastMathFlags::NoSignedZeros) |
242 }
243
244 void setHasAllowReciprocal(bool B) {
245 SubclassOptionalData =
246 (SubclassOptionalData & ~FastMathFlags::AllowReciprocal) |
248 }
249
250 void setHasAllowContract(bool B) {
251 SubclassOptionalData =
252 (SubclassOptionalData & ~FastMathFlags::AllowContract) |
254 }
255
256 void setHasApproxFunc(bool B) {
257 SubclassOptionalData =
258 (SubclassOptionalData & ~FastMathFlags::ApproxFunc) |
260 }
261
262
263
264 void setFastMathFlags(FastMathFlags FMF) {
265 SubclassOptionalData |= FMF.Flags;
266 }
267
268
269
270 void copyFastMathFlags(FastMathFlags FMF) {
271 SubclassOptionalData = FMF.Flags;
272 }
273
274
275
276 static bool isComposedOfHomogeneousFloatingPointTypes(Type *Ty) {
277 if (auto *StructTy = dyn_cast(Ty)) {
278 if (!StructTy->isLiteral() || !StructTy->containsHomogeneousTypes())
279 return false;
280 Ty = StructTy->elements().front();
281 } else if (auto *ArrayTy = dyn_cast(Ty)) {
282 do {
283 Ty = ArrayTy->getElementType();
284 } while ((ArrayTy = dyn_cast(Ty)));
285 }
286 return Ty->isFPOrFPVectorTy();
287 };
288
289public:
290
299 }
300
301
304 }
305
306
309 }
310
311
314 }
315
316
319 }
320
321
324 }
325
326
329 }
330
331
332
335 }
336
337
340 }
341
342
343
344
345 float getFPAccuracy() const;
346
347
348
351 isComposedOfHomogeneousFloatingPointTypes(Ty);
352 }
353
355 unsigned Opcode;
356 if (auto *I = dyn_cast(V))
357 Opcode = I->getOpcode();
358 else
359 return false;
360
361 switch (Opcode) {
362 case Instruction::FNeg:
363 case Instruction::FAdd:
364 case Instruction::FSub:
365 case Instruction::FMul:
366 case Instruction::FDiv:
367 case Instruction::FRem:
368 case Instruction::FPTrunc:
369 case Instruction::FPExt:
370
371
372
373
374
375 case Instruction::FCmp:
376 return true;
377 case Instruction::PHI:
378 case Instruction::Select:
379 case Instruction::Call: {
380 return isSupportedFloatingPointType(V->getType());
381 }
382 default:
383 return false;
384 }
385 }
386};
387
388
389template<typename SuperClass, unsigned Opc>
391public:
393 return I->getOpcode() == Opc;
394 }
396 return CE->getOpcode() == Opc;
397 }
399 return (isa(V) && classof(cast(V))) ||
400 (isa(V) && classof(cast(V)));
401 }
402};
403
405 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Add> {
406};
408 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Sub> {
409};
411 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Mul> {
412};
414 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Shl> {
415};
416
418 : public ConcreteOperator<PossiblyExactOperator, Instruction::AShr> {
419};
421 : public ConcreteOperator<PossiblyExactOperator, Instruction::LShr> {
422};
423
425 : public ConcreteOperator<Operator, Instruction::GetElementPtr> {
426public:
427
429
432 }
433
434
436
439 }
440
443 }
444
445
446
447 std::optional getInRange() const;
448
453
456 }
457
460 }
461
464 }
467 }
469 return 0U;
470 }
471
472
475 }
476
479
480
483 }
484
485 unsigned getNumIndices() const {
487 }
488
491 }
492
493
494
495
499 if (C->isZero())
500 continue;
501 return false;
502 }
503 return true;
504 }
505
506
507
508
511 if (!isa(I))
512 return false;
513 }
514 return true;
515 }
516
519 return !isa(*use);
520 });
521 }
522
523
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
546
551
552
553
556 APInt &ConstantOffset) const;
557};
558
559template <>
561};
562
564
567 friend class PtrToInt;
569
570public:
571
573
575 return getOperand(0);
576 }
578 return getOperand(0);
579 }
580
582 return 0U;
583 }
584
585
588 }
589
590
592 return cast(getPointerOperandType())->getAddressSpace();
593 }
594};
595
596template <>
599
601
606
607public:
608
610
612 return getOperand(0)->getType();
613 }
614
617 }
618};
619
620template <>
623
625
630
631public:
632
634
636
638
641 }
642
644 return getType()->getPointerAddressSpace();
645 }
646};
647
648template <>
651
653
654}
655
656#endif
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
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
std::optional< ConstantRange > getInRange() const
Returns the offset of the index with an inrange attachment, or std::nullopt if none.
unsigned countNonConstantIndices() const
Type * getSourceElementType() const
Type * getResultElementType() const
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
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()
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 *)
bool hasPoisonGeneratingAnnotations() const
Return true if this operator has poison-generating flags, return attributes or metadata.
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 or sdiv instruction, which can be marked as "exact", indicating that no bits are destroyed.
static bool classof(const ConstantExpr *CE)
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)
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.
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...