LLVM 22.0.0git
Operator.h
Go to the documentation of this file.
1//===-- llvm/Operator.h - Operator utility subclass -------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines various classes for working with Instructions and
10// ConstantExprs.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_IR_OPERATOR_H
15#define LLVM_IR_OPERATOR_H
16
17#include "llvm/ADT/MapVector.h"
18#include "llvm/IR/Constants.h"
19#include "llvm/IR/FMF.h"
21#include "llvm/IR/Instruction.h"
22#include "llvm/IR/Type.h"
23#include "llvm/IR/Value.h"
26#include <cstddef>
27#include <optional>
28
29namespace llvm {
30
31/// This is a utility class that provides an abstraction for the common
32/// functionality between Instructions and ConstantExprs.
33class Operator : public User {
34public:
35 // The Operator class is intended to be used as a utility, and is never itself
36 // instantiated.
37 Operator() = delete;
38 ~Operator() = delete;
39
40 void *operator new(size_t s) = delete;
41
42 /// Return the opcode for this Instruction or ConstantExpr.
43 unsigned getOpcode() const {
44 if (const Instruction *I = dyn_cast<Instruction>(this))
45 return I->getOpcode();
46 return cast<ConstantExpr>(this)->getOpcode();
47 }
48
49 /// If V is an Instruction or ConstantExpr, return its opcode.
50 /// Otherwise return UserOp1.
51 static unsigned getOpcode(const Value *V) {
52 if (const Instruction *I = dyn_cast<Instruction>(V))
53 return I->getOpcode();
54 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
55 return CE->getOpcode();
56 return Instruction::UserOp1;
57 }
58
59 static bool classof(const Instruction *) { return true; }
60 static bool classof(const ConstantExpr *) { return true; }
61 static bool classof(const Value *V) {
62 return isa<Instruction>(V) || isa<ConstantExpr>(V);
63 }
64
65 /// Return true if this operator has flags which may cause this operator
66 /// to evaluate to poison despite having non-poison inputs.
68
69 /// Return true if this operator has poison-generating flags,
70 /// return attributes or metadata. The latter two is only possible for
71 /// instructions.
73};
74
75/// Utility class for integer operators which may exhibit overflow - Add, Sub,
76/// Mul, and Shl. It does not include SDiv, despite that operator having the
77/// potential for overflow.
79public:
80 enum {
82 NoUnsignedWrap = (1 << 0),
83 NoSignedWrap = (1 << 1)
84 };
85
86private:
87 friend class Instruction;
88 friend class ConstantExpr;
89
90 void setHasNoUnsignedWrap(bool B) {
92 (SubclassOptionalData & ~NoUnsignedWrap) | (B * NoUnsignedWrap);
93 }
94 void setHasNoSignedWrap(bool B) {
96 (SubclassOptionalData & ~NoSignedWrap) | (B * NoSignedWrap);
97 }
98
99public:
100 /// Transparently provide more efficient getOperand methods.
102
103 /// Test whether this operation is known to never
104 /// undergo unsigned overflow, aka the nuw property.
105 bool hasNoUnsignedWrap() const {
107 }
108
109 /// Test whether this operation is known to never
110 /// undergo signed overflow, aka the nsw property.
111 bool hasNoSignedWrap() const {
112 return (SubclassOptionalData & NoSignedWrap) != 0;
113 }
114
115 /// Returns the no-wrap kind of the operation.
116 unsigned getNoWrapKind() const {
117 unsigned NoWrapKind = 0;
118 if (hasNoUnsignedWrap())
119 NoWrapKind |= NoUnsignedWrap;
120
121 if (hasNoSignedWrap())
122 NoWrapKind |= NoSignedWrap;
123
124 return NoWrapKind;
125 }
126
127 /// Return true if the instruction is commutative
129
130 static bool classof(const Instruction *I) {
131 return I->getOpcode() == Instruction::Add ||
132 I->getOpcode() == Instruction::Sub ||
133 I->getOpcode() == Instruction::Mul ||
134 I->getOpcode() == Instruction::Shl;
135 }
136 static bool classof(const ConstantExpr *CE) {
137 return CE->getOpcode() == Instruction::Add ||
138 CE->getOpcode() == Instruction::Sub;
139 }
140 static bool classof(const Value *V) {
141 return (isa<Instruction>(V) && classof(cast<Instruction>(V))) ||
142 (isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V)));
143 }
144};
145
146template <>
148 : public FixedNumOperandTraits<OverflowingBinaryOperator, 2> {};
149
151
152/// A udiv, sdiv, lshr, or ashr instruction, which can be marked as "exact",
153/// indicating that no bits are destroyed.
155public:
156 enum {
157 IsExact = (1 << 0)
158 };
159
160private:
161 friend class Instruction;
162 friend class ConstantExpr;
163
164 void setIsExact(bool B) {
165 SubclassOptionalData = (SubclassOptionalData & ~IsExact) | (B * IsExact);
166 }
167
168public:
169 /// Transparently provide more efficient getOperand methods.
171
172 /// Test whether this division is known to be exact, with zero remainder.
173 bool isExact() const {
174 return SubclassOptionalData & IsExact;
175 }
176
177 static bool isPossiblyExactOpcode(unsigned OpC) {
178 return OpC == Instruction::SDiv ||
179 OpC == Instruction::UDiv ||
180 OpC == Instruction::AShr ||
181 OpC == Instruction::LShr;
182 }
183
184 static bool classof(const Instruction *I) {
185 return isPossiblyExactOpcode(I->getOpcode());
186 }
187 static bool classof(const Value *V) {
188 return (isa<Instruction>(V) && classof(cast<Instruction>(V)));
189 }
190};
191
192template <>
194 : public FixedNumOperandTraits<PossiblyExactOperator, 2> {};
195
197
198/// Utility class for floating point operations which can have
199/// information about relaxed accuracy requirements attached to them.
200class FPMathOperator : public Operator {
201private:
202 friend class Instruction;
203
204 /// 'Fast' means all bits are set.
205 void setFast(bool B) {
206 setHasAllowReassoc(B);
207 setHasNoNaNs(B);
208 setHasNoInfs(B);
209 setHasNoSignedZeros(B);
210 setHasAllowReciprocal(B);
211 setHasAllowContract(B);
212 setHasApproxFunc(B);
213 }
214
215 void setHasAllowReassoc(bool B) {
216 SubclassOptionalData =
217 (SubclassOptionalData & ~FastMathFlags::AllowReassoc) |
219 }
220
221 void setHasNoNaNs(bool B) {
222 SubclassOptionalData =
223 (SubclassOptionalData & ~FastMathFlags::NoNaNs) |
225 }
226
227 void setHasNoInfs(bool B) {
228 SubclassOptionalData =
229 (SubclassOptionalData & ~FastMathFlags::NoInfs) |
231 }
232
233 void setHasNoSignedZeros(bool B) {
234 SubclassOptionalData =
235 (SubclassOptionalData & ~FastMathFlags::NoSignedZeros) |
237 }
238
239 void setHasAllowReciprocal(bool B) {
240 SubclassOptionalData =
241 (SubclassOptionalData & ~FastMathFlags::AllowReciprocal) |
243 }
244
245 void setHasAllowContract(bool B) {
246 SubclassOptionalData =
247 (SubclassOptionalData & ~FastMathFlags::AllowContract) |
249 }
250
251 void setHasApproxFunc(bool B) {
252 SubclassOptionalData =
253 (SubclassOptionalData & ~FastMathFlags::ApproxFunc) |
255 }
256
257 /// Convenience function for setting multiple fast-math flags.
258 /// FMF is a mask of the bits to set.
259 void setFastMathFlags(FastMathFlags FMF) {
260 SubclassOptionalData |= FMF.Flags;
261 }
262
263 /// Convenience function for copying all fast-math flags.
264 /// All values in FMF are transferred to this operator.
265 void copyFastMathFlags(FastMathFlags FMF) {
266 SubclassOptionalData = FMF.Flags;
267 }
268
269 /// Returns true if `Ty` is composed of a single kind of float-poing type
270 /// (possibly repeated within an aggregate).
271 static bool isComposedOfHomogeneousFloatingPointTypes(Type *Ty) {
272 if (auto *StructTy = dyn_cast<StructType>(Ty)) {
273 if (!StructTy->isLiteral() || !StructTy->containsHomogeneousTypes())
274 return false;
275 Ty = StructTy->elements().front();
276 } else if (auto *ArrayTy = dyn_cast<ArrayType>(Ty)) {
277 do {
278 Ty = ArrayTy->getElementType();
279 } while ((ArrayTy = dyn_cast<ArrayType>(Ty)));
280 }
281 return Ty->isFPOrFPVectorTy();
282 };
283
284public:
285 /// Test if this operation allows all non-strict floating-point transforms.
286 bool isFast() const {
287 return ((SubclassOptionalData & FastMathFlags::AllowReassoc) != 0 &&
288 (SubclassOptionalData & FastMathFlags::NoNaNs) != 0 &&
289 (SubclassOptionalData & FastMathFlags::NoInfs) != 0 &&
290 (SubclassOptionalData & FastMathFlags::NoSignedZeros) != 0 &&
291 (SubclassOptionalData & FastMathFlags::AllowReciprocal) != 0 &&
292 (SubclassOptionalData & FastMathFlags::AllowContract) != 0 &&
293 (SubclassOptionalData & FastMathFlags::ApproxFunc) != 0);
294 }
295
296 /// Test if this operation may be simplified with reassociative transforms.
297 bool hasAllowReassoc() const {
298 return (SubclassOptionalData & FastMathFlags::AllowReassoc) != 0;
299 }
300
301 /// Test if this operation's arguments and results are assumed not-NaN.
302 bool hasNoNaNs() const {
303 return (SubclassOptionalData & FastMathFlags::NoNaNs) != 0;
304 }
305
306 /// Test if this operation's arguments and results are assumed not-infinite.
307 bool hasNoInfs() const {
308 return (SubclassOptionalData & FastMathFlags::NoInfs) != 0;
309 }
310
311 /// Test if this operation can ignore the sign of zero.
312 bool hasNoSignedZeros() const {
313 return (SubclassOptionalData & FastMathFlags::NoSignedZeros) != 0;
314 }
315
316 /// Test if this operation can use reciprocal multiply instead of division.
317 bool hasAllowReciprocal() const {
318 return (SubclassOptionalData & FastMathFlags::AllowReciprocal) != 0;
319 }
320
321 /// Test if this operation can be floating-point contracted (FMA).
322 bool hasAllowContract() const {
323 return (SubclassOptionalData & FastMathFlags::AllowContract) != 0;
324 }
325
326 /// Test if this operation allows approximations of math library functions or
327 /// intrinsics.
328 bool hasApproxFunc() const {
329 return (SubclassOptionalData & FastMathFlags::ApproxFunc) != 0;
330 }
331
332 /// Convenience function for getting all the fast-math flags
334 return FastMathFlags(SubclassOptionalData);
335 }
336
337 /// Get the maximum error permitted by this operation in ULPs. An accuracy of
338 /// 0.0 means that the operation should be performed with the default
339 /// precision.
340 LLVM_ABI float getFPAccuracy() const;
341
342 /// Returns true if `Ty` is a supported floating-point type for phi, select,
343 /// or call FPMathOperators.
345 return Ty->isFPOrFPVectorTy() ||
346 isComposedOfHomogeneousFloatingPointTypes(Ty);
347 }
348
349 static bool classof(const Value *V) {
350 unsigned Opcode;
351 if (auto *I = dyn_cast<Instruction>(V))
352 Opcode = I->getOpcode();
353 else
354 return false;
355
356 switch (Opcode) {
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:
365 // FIXME: To clean up and correct the semantics of fast-math-flags, FCmp
366 // should not be treated as a math op, but the other opcodes should.
367 // This would make things consistent with Select/PHI (FP value type
368 // determines whether they are math ops and, therefore, capable of
369 // having fast-math-flags).
370 case Instruction::FCmp:
371 return true;
372 case Instruction::PHI:
373 case Instruction::Select:
374 case Instruction::Call: {
375 return isSupportedFloatingPointType(V->getType());
376 }
377 default:
378 return false;
379 }
380 }
381};
382
383/// A helper template for defining operators for individual opcodes.
384template<typename SuperClass, unsigned Opc>
386public:
387 static bool classof(const Instruction *I) {
388 return I->getOpcode() == Opc;
389 }
390 static bool classof(const ConstantExpr *CE) {
391 return CE->getOpcode() == Opc;
392 }
393 static bool classof(const Value *V) {
394 return (isa<Instruction>(V) && classof(cast<Instruction>(V))) ||
395 (isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V)));
396 }
397};
398
400 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Add> {
401};
403 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Sub> {
404};
406 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Mul> {
407};
409 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Shl> {
410};
411
413 : public ConcreteOperator<PossiblyExactOperator, Instruction::AShr> {
414};
416 : public ConcreteOperator<PossiblyExactOperator, Instruction::LShr> {
417};
418
420 : public ConcreteOperator<Operator, Instruction::GetElementPtr> {
421public:
422 /// Transparently provide more efficient getOperand methods.
424
427 }
428
429 /// Test whether this is an inbounds GEP, as defined by LangRef.html.
430 bool isInBounds() const { return getNoWrapFlags().isInBounds(); }
431
434 }
435
436 bool hasNoUnsignedWrap() const {
438 }
439
440 /// Returns the offset of the index with an inrange attachment, or
441 /// std::nullopt if none.
442 LLVM_ABI std::optional<ConstantRange> getInRange() const;
443
444 inline op_iterator idx_begin() { return op_begin()+1; }
445 inline const_op_iterator idx_begin() const { return op_begin()+1; }
446 inline op_iterator idx_end() { return op_end(); }
447 inline const_op_iterator idx_end() const { return op_end(); }
448
450 return make_range(idx_begin(), idx_end());
451 }
452
454 return make_range(idx_begin(), idx_end());
455 }
456
458 return getOperand(0);
459 }
460 const Value *getPointerOperand() const {
461 return getOperand(0);
462 }
463 static unsigned getPointerOperandIndex() {
464 return 0U; // get index for modifying correct operand
465 }
466
467 /// Method to return the pointer operand as a PointerType.
469 return getPointerOperand()->getType();
470 }
471
474
475 /// Method to return the address space of the pointer operand.
476 unsigned getPointerAddressSpace() const {
478 }
479
480 unsigned getNumIndices() const { // Note: always non-negative
481 return getNumOperands() - 1;
482 }
483
484 bool hasIndices() const {
485 return getNumOperands() > 1;
486 }
487
488 /// Return true if all of the indices of this GEP are zeros.
489 /// If so, the result pointer and the first operand have the same
490 /// value, just potentially different types.
491 bool hasAllZeroIndices() const {
492 for (const_op_iterator I = idx_begin(), E = idx_end(); I != E; ++I) {
493 if (ConstantInt *C = dyn_cast<ConstantInt>(I))
494 if (C->isZero())
495 continue;
496 return false;
497 }
498 return true;
499 }
500
501 /// Return true if all of the indices of this GEP are constant integers.
502 /// If so, the result pointer and the first operand have
503 /// a constant offset between them.
505 for (const_op_iterator I = idx_begin(), E = idx_end(); I != E; ++I) {
506 if (!isa<ConstantInt>(I))
507 return false;
508 }
509 return true;
510 }
511
512 unsigned countNonConstantIndices() const {
513 return count_if(indices(), [](const Use& use) {
514 return !isa<ConstantInt>(*use);
515 });
516 }
517
518 /// Compute the maximum alignment that this GEP is garranteed to preserve.
520
521 /// Accumulate the constant address offset of this GEP if possible.
522 ///
523 /// This routine accepts an APInt into which it will try to accumulate the
524 /// constant offset of this GEP.
525 ///
526 /// If \p ExternalAnalysis is provided it will be used to calculate a offset
527 /// when a operand of GEP is not constant.
528 /// For example, for a value \p ExternalAnalysis might try to calculate a
529 /// lower bound. If \p ExternalAnalysis is successful, it should return true.
530 ///
531 /// If the \p ExternalAnalysis returns false or the value returned by \p
532 /// ExternalAnalysis results in a overflow/underflow, this routine returns
533 /// false and the value of the offset APInt is undefined (it is *not*
534 /// preserved!).
535 ///
536 /// The APInt passed into this routine must be at exactly as wide as the
537 /// IntPtr type for the address space of the base GEP pointer.
539 const DataLayout &DL, APInt &Offset,
540 function_ref<bool(Value &, APInt &)> ExternalAnalysis = nullptr) const;
541
543 Type *SourceType, ArrayRef<const Value *> Index, const DataLayout &DL,
544 APInt &Offset,
545 function_ref<bool(Value &, APInt &)> ExternalAnalysis = nullptr);
546
547 /// Collect the offset of this GEP as a map of Values to their associated
548 /// APInt multipliers, as well as a total Constant Offset.
549 LLVM_ABI bool
550 collectOffset(const DataLayout &DL, unsigned BitWidth,
551 SmallMapVector<Value *, APInt, 4> &VariableOffsets,
552 APInt &ConstantOffset) const;
553};
554
555template <>
556struct OperandTraits<GEPOperator> : public VariadicOperandTraits<GEPOperator> {
557};
558
560
562 : public ConcreteOperator<Operator, Instruction::PtrToInt> {
563 friend class PtrToInt;
564 friend class ConstantExpr;
565
566public:
567 /// Transparently provide more efficient getOperand methods.
569
571 return getOperand(0);
572 }
573 const Value *getPointerOperand() const {
574 return getOperand(0);
575 }
576
577 static unsigned getPointerOperandIndex() {
578 return 0U; // get index for modifying correct operand
579 }
580
581 /// Method to return the pointer operand as a PointerType.
583 return getPointerOperand()->getType();
584 }
585
586 /// Method to return the address space of the pointer operand.
587 unsigned getPointerAddressSpace() const {
588 return cast<PointerType>(getPointerOperandType())->getAddressSpace();
589 }
590};
591
592template <>
594 : public FixedNumOperandTraits<PtrToIntOperator, 1> {};
595
597
599 : public ConcreteOperator<Operator, Instruction::PtrToAddr> {
600 friend class PtrToAddr;
601 friend class ConstantExpr;
602
603public:
604 /// Transparently provide more efficient getOperand methods.
606
607 Value *getPointerOperand() { return getOperand(0); }
608 const Value *getPointerOperand() const { return getOperand(0); }
609
610 static unsigned getPointerOperandIndex() {
611 return 0U; // get index for modifying correct operand
612 }
613
614 /// Method to return the pointer operand as a PointerType.
616
617 /// Method to return the address space of the pointer operand.
618 unsigned getPointerAddressSpace() const {
619 return cast<PointerType>(getPointerOperandType())->getAddressSpace();
620 }
621};
622
623template <>
625 : public FixedNumOperandTraits<PtrToAddrOperator, 1> {};
626
628
630 : public ConcreteOperator<Operator, Instruction::BitCast> {
631 friend class BitCastInst;
632 friend class ConstantExpr;
633
634public:
635 /// Transparently provide more efficient getOperand methods.
637
638 Type *getSrcTy() const {
639 return getOperand(0)->getType();
640 }
641
642 Type *getDestTy() const {
643 return getType();
644 }
645};
646
647template <>
649 : public FixedNumOperandTraits<BitCastOperator, 1> {};
650
652
654 : public ConcreteOperator<Operator, Instruction::AddrSpaceCast> {
655 friend class AddrSpaceCastInst;
656 friend class ConstantExpr;
657
658public:
659 /// Transparently provide more efficient getOperand methods.
661
662 Value *getPointerOperand() { return getOperand(0); }
663
664 const Value *getPointerOperand() const { return getOperand(0); }
665
666 unsigned getSrcAddressSpace() const {
668 }
669
670 unsigned getDestAddressSpace() const {
671 return getType()->getPointerAddressSpace();
672 }
673};
674
675template <>
677 : public FixedNumOperandTraits<AddrSpaceCastOperator, 1> {};
678
680
681} // end namespace llvm
682
683#endif // LLVM_IR_OPERATOR_H
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")
RelocType Type
Definition: COFFYAML.cpp:410
#define LLVM_ABI
Definition: Compiler.h:213
This file contains the declarations for the subclasses of Constant, which represent the different fla...
uint32_t Index
Move duplicate certain instructions close to their use
Definition: Localizer.cpp:33
#define I(x, y, z)
Definition: MD5.cpp:58
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)
Definition: TapiFile.cpp:39
Class for arbitrary precision integers.
Definition: APInt.h:78
This class represents a conversion between pointers from one address space to another.
const Value * getPointerOperand() const
Definition: Operator.h:664
unsigned getDestAddressSpace() const
Definition: Operator.h:670
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
unsigned getSrcAddressSpace() const
Definition: Operator.h:666
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
This class represents a no-op cast from one type to another.
Type * getDestTy() const
Definition: Operator.h:642
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Type * getSrcTy() const
Definition: Operator.h:638
A helper template for defining operators for individual opcodes.
Definition: Operator.h:385
static bool classof(const Value *V)
Definition: Operator.h:393
static bool classof(const ConstantExpr *CE)
Definition: Operator.h:390
static bool classof(const Instruction *I)
Definition: Operator.h:387
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:1120
This is the shared class of boolean and integer constants.
Definition: Constants.h:87
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
Utility class for floating point operations which can have information about relaxed accuracy require...
Definition: Operator.h:200
bool hasAllowReassoc() const
Test if this operation may be simplified with reassociative transforms.
Definition: Operator.h:297
bool isFast() const
Test if this operation allows all non-strict floating-point transforms.
Definition: Operator.h:286
static bool classof(const Value *V)
Definition: Operator.h:349
bool hasNoNaNs() const
Test if this operation's arguments and results are assumed not-NaN.
Definition: Operator.h:302
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags.
Definition: Operator.h:333
bool hasAllowReciprocal() const
Test if this operation can use reciprocal multiply instead of division.
Definition: Operator.h:317
bool hasNoSignedZeros() const
Test if this operation can ignore the sign of zero.
Definition: Operator.h:312
static bool isSupportedFloatingPointType(Type *Ty)
Returns true if Ty is a supported floating-point type for phi, select, or call FPMathOperators.
Definition: Operator.h:344
bool hasAllowContract() const
Test if this operation can be floating-point contracted (FMA).
Definition: Operator.h:322
bool hasNoInfs() const
Test if this operation's arguments and results are assumed not-infinite.
Definition: Operator.h:307
bool hasApproxFunc() const
Test if this operation allows approximations of math library functions or intrinsics.
Definition: Operator.h:328
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:22
Represents flags for the getelementptr instruction/expression.
static GEPNoWrapFlags fromRaw(unsigned Flags)
bool hasNoUnsignedSignedWrap() const
bool hasNoUnsignedWrap() const
bool isInBounds() const
bool hasNoUnsignedSignedWrap() const
Definition: Operator.h:432
const_op_iterator idx_end() const
Definition: Operator.h:447
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:208
const Value * getPointerOperand() const
Definition: Operator.h:460
const_op_iterator idx_begin() const
Definition: Operator.h:445
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
Definition: Operator.h:430
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
Definition: Operator.h:468
unsigned getNumIndices() const
Definition: Operator.h:480
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:82
unsigned countNonConstantIndices() const
Definition: Operator.h:512
LLVM_ABI Type * getSourceElementType() const
Definition: Operator.cpp:70
LLVM_ABI Type * getResultElementType() const
Definition: Operator.cpp:76
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:113
bool hasNoUnsignedWrap() const
Definition: Operator.h:436
bool hasAllZeroIndices() const
Return true if all of the indices of this GEP are zeros.
Definition: Operator.h:491
op_iterator idx_end()
Definition: Operator.h:446
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
op_iterator idx_begin()
Definition: Operator.h:444
Value * getPointerOperand()
Definition: Operator.h:457
GEPNoWrapFlags getNoWrapFlags() const
Definition: Operator.h:425
bool hasAllConstantIndices() const
Return true if all of the indices of this GEP are constant integers.
Definition: Operator.h:504
iterator_range< op_iterator > indices()
Definition: Operator.h:449
bool hasIndices() const
Definition: Operator.h:484
iterator_range< const_op_iterator > indices() const
Definition: Operator.h:453
LLVM_ABI Align getMaxPreservedAlignment(const DataLayout &DL) const
Compute the maximum alignment that this GEP is garranteed to preserve.
Definition: Operator.cpp:88
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
Definition: Operator.h:476
static unsigned getPointerOperandIndex()
Definition: Operator.h:463
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...
Definition: Operator.h:33
static bool classof(const ConstantExpr *)
Definition: Operator.h:60
LLVM_ABI bool hasPoisonGeneratingAnnotations() const
Return true if this operator has poison-generating flags, return attributes or metadata.
Definition: Operator.cpp:62
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:21
static bool classof(const Instruction *)
Definition: Operator.h:59
Operator()=delete
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
Definition: Operator.h:43
~Operator()=delete
static bool classof(const Value *V)
Definition: Operator.h:61
static unsigned getOpcode(const Value *V)
If V is an Instruction or ConstantExpr, return its opcode.
Definition: Operator.h:51
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl.
Definition: Operator.h:78
static bool classof(const Value *V)
Definition: Operator.h:140
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.
Definition: Operator.h:111
unsigned getNoWrapKind() const
Returns the no-wrap kind of the operation.
Definition: Operator.h:116
bool hasNoUnsignedWrap() const
Test whether this operation is known to never undergo unsigned overflow, aka the nuw property.
Definition: Operator.h:105
bool isCommutative() const
Return true if the instruction is commutative.
Definition: Operator.h:128
static bool classof(const ConstantExpr *CE)
Definition: Operator.h:136
static bool classof(const Instruction *I)
Definition: Operator.h:130
A udiv, sdiv, lshr, or ashr instruction, which can be marked as "exact", indicating that no bits are ...
Definition: Operator.h:154
bool isExact() const
Test whether this division is known to be exact, with zero remainder.
Definition: Operator.h:173
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static bool isPossiblyExactOpcode(unsigned OpC)
Definition: Operator.h:177
static bool classof(const Value *V)
Definition: Operator.h:187
static bool classof(const Instruction *I)
Definition: Operator.h:184
static unsigned getPointerOperandIndex()
Definition: Operator.h:610
Value * getPointerOperand()
Definition: Operator.h:607
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
Definition: Operator.h:615
const Value * getPointerOperand() const
Definition: Operator.h:608
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
Definition: Operator.h:618
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
Definition: Operator.h:582
static unsigned getPointerOperandIndex()
Definition: Operator.h:577
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
Definition: Operator.h:587
const Value * getPointerOperand() const
Definition: Operator.h:573
Value * getPointerOperand()
Definition: Operator.h:570
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
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.
Definition: Type.h:225
A Use represents the edge between a Value definition and its users.
Definition: Use.h:35
op_iterator op_begin()
Definition: User.h:284
Value * getOperand(unsigned i) const
Definition: User.h:232
unsigned getNumOperands() const
Definition: User.h:254
op_iterator op_end()
Definition: User.h:286
LLVM Value Representation.
Definition: Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
Definition: Value.h:85
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.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
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
Definition: BitmaskEnum.h:223
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...
Definition: STLExtras.h:1980
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:30
Compile-time customization of User operands.
Definition: User.h:42
A MapVector that performs no allocations if smaller than a certain size.
Definition: MapVector.h:249
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:67