LLVM 20.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"
25#include <cstddef>
26#include <optional>
27
28namespace llvm {
29
30/// This is a utility class that provides an abstraction for the common
31/// functionality between Instructions and ConstantExprs.
32class Operator : public User {
33public:
34 // The Operator class is intended to be used as a utility, and is never itself
35 // instantiated.
36 Operator() = delete;
37 ~Operator() = delete;
38
39 void *operator new(size_t s) = delete;
40
41 /// Return the opcode for this Instruction or ConstantExpr.
42 unsigned getOpcode() const {
43 if (const Instruction *I = dyn_cast<Instruction>(this))
44 return I->getOpcode();
45 return cast<ConstantExpr>(this)->getOpcode();
46 }
47
48 /// If V is an Instruction or ConstantExpr, return its opcode.
49 /// Otherwise return UserOp1.
50 static unsigned getOpcode(const Value *V) {
51 if (const Instruction *I = dyn_cast<Instruction>(V))
52 return I->getOpcode();
53 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
54 return CE->getOpcode();
55 return Instruction::UserOp1;
56 }
57
58 static bool classof(const Instruction *) { return true; }
59 static bool classof(const ConstantExpr *) { return true; }
60 static bool classof(const Value *V) {
61 return isa<Instruction>(V) || isa<ConstantExpr>(V);
62 }
63
64 /// Return true if this operator has flags which may cause this operator
65 /// to evaluate to poison despite having non-poison inputs.
66 bool hasPoisonGeneratingFlags() const;
67
68 /// Return true if this operator has poison-generating flags,
69 /// return attributes or metadata. The latter two is only possible for
70 /// instructions.
72};
73
74/// Utility class for integer operators which may exhibit overflow - Add, Sub,
75/// Mul, and Shl. It does not include SDiv, despite that operator having the
76/// potential for overflow.
78public:
79 enum {
81 NoUnsignedWrap = (1 << 0),
82 NoSignedWrap = (1 << 1)
83 };
84
85private:
86 friend class Instruction;
87 friend class ConstantExpr;
88
89 void setHasNoUnsignedWrap(bool B) {
91 (SubclassOptionalData & ~NoUnsignedWrap) | (B * NoUnsignedWrap);
92 }
93 void setHasNoSignedWrap(bool B) {
95 (SubclassOptionalData & ~NoSignedWrap) | (B * NoSignedWrap);
96 }
97
98public:
99 /// Transparently provide more efficient getOperand methods.
101
102 /// Test whether this operation is known to never
103 /// undergo unsigned overflow, aka the nuw property.
104 bool hasNoUnsignedWrap() const {
106 }
107
108 /// Test whether this operation is known to never
109 /// undergo signed overflow, aka the nsw property.
110 bool hasNoSignedWrap() const {
111 return (SubclassOptionalData & NoSignedWrap) != 0;
112 }
113
114 /// Returns the no-wrap kind of the operation.
115 unsigned getNoWrapKind() const {
116 unsigned NoWrapKind = 0;
117 if (hasNoUnsignedWrap())
118 NoWrapKind |= NoUnsignedWrap;
119
120 if (hasNoSignedWrap())
121 NoWrapKind |= NoSignedWrap;
122
123 return NoWrapKind;
124 }
125
126 /// Return true if the instruction is commutative
128
129 static bool classof(const Instruction *I) {
130 return I->getOpcode() == Instruction::Add ||
131 I->getOpcode() == Instruction::Sub ||
132 I->getOpcode() == Instruction::Mul ||
133 I->getOpcode() == Instruction::Shl;
134 }
135 static bool classof(const ConstantExpr *CE) {
136 return CE->getOpcode() == Instruction::Add ||
137 CE->getOpcode() == Instruction::Sub ||
138 CE->getOpcode() == Instruction::Mul ||
139 CE->getOpcode() == Instruction::Shl;
140 }
141 static bool classof(const Value *V) {
142 return (isa<Instruction>(V) && classof(cast<Instruction>(V))) ||
143 (isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V)));
144 }
145};
146
147template <>
149 : public FixedNumOperandTraits<OverflowingBinaryOperator, 2> {};
150
152
153/// A udiv or sdiv instruction, which can be marked as "exact",
154/// indicating that no bits are destroyed.
156public:
157 enum {
158 IsExact = (1 << 0)
159 };
160
161private:
162 friend class Instruction;
163 friend class ConstantExpr;
164
165 void setIsExact(bool B) {
166 SubclassOptionalData = (SubclassOptionalData & ~IsExact) | (B * IsExact);
167 }
168
169public:
170 /// Transparently provide more efficient getOperand methods.
172
173 /// Test whether this division is known to be exact, with zero remainder.
174 bool isExact() const {
175 return SubclassOptionalData & IsExact;
176 }
177
178 static bool isPossiblyExactOpcode(unsigned OpC) {
179 return OpC == Instruction::SDiv ||
180 OpC == Instruction::UDiv ||
181 OpC == Instruction::AShr ||
182 OpC == Instruction::LShr;
183 }
184
185 static bool classof(const ConstantExpr *CE) {
186 return isPossiblyExactOpcode(CE->getOpcode());
187 }
188 static bool classof(const Instruction *I) {
189 return isPossiblyExactOpcode(I->getOpcode());
190 }
191 static bool classof(const Value *V) {
192 return (isa<Instruction>(V) && classof(cast<Instruction>(V))) ||
193 (isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V)));
194 }
195};
196
197template <>
199 : public FixedNumOperandTraits<PossiblyExactOperator, 2> {};
200
202
203/// Utility class for floating point operations which can have
204/// information about relaxed accuracy requirements attached to them.
205class FPMathOperator : public Operator {
206private:
207 friend class Instruction;
208
209 /// 'Fast' means all bits are set.
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 /// Convenience function for setting multiple fast-math flags.
263 /// FMF is a mask of the bits to set.
264 void setFastMathFlags(FastMathFlags FMF) {
265 SubclassOptionalData |= FMF.Flags;
266 }
267
268 /// Convenience function for copying all fast-math flags.
269 /// All values in FMF are transferred to this operator.
270 void copyFastMathFlags(FastMathFlags FMF) {
271 SubclassOptionalData = FMF.Flags;
272 }
273
274 /// Returns true if `Ty` is composed of a single kind of float-poing type
275 /// (possibly repeated within an aggregate).
276 static bool isComposedOfHomogeneousFloatingPointTypes(Type *Ty) {
277 if (auto *StructTy = dyn_cast<StructType>(Ty)) {
278 if (!StructTy->isLiteral() || !StructTy->containsHomogeneousTypes())
279 return false;
280 Ty = StructTy->elements().front();
281 } else if (auto *ArrayTy = dyn_cast<ArrayType>(Ty)) {
282 do {
283 Ty = ArrayTy->getElementType();
284 } while ((ArrayTy = dyn_cast<ArrayType>(Ty)));
285 }
286 return Ty->isFPOrFPVectorTy();
287 };
288
289public:
290 /// Test if this operation allows all non-strict floating-point transforms.
291 bool isFast() const {
292 return ((SubclassOptionalData & FastMathFlags::AllowReassoc) != 0 &&
293 (SubclassOptionalData & FastMathFlags::NoNaNs) != 0 &&
294 (SubclassOptionalData & FastMathFlags::NoInfs) != 0 &&
295 (SubclassOptionalData & FastMathFlags::NoSignedZeros) != 0 &&
296 (SubclassOptionalData & FastMathFlags::AllowReciprocal) != 0 &&
297 (SubclassOptionalData & FastMathFlags::AllowContract) != 0 &&
298 (SubclassOptionalData & FastMathFlags::ApproxFunc) != 0);
299 }
300
301 /// Test if this operation may be simplified with reassociative transforms.
302 bool hasAllowReassoc() const {
303 return (SubclassOptionalData & FastMathFlags::AllowReassoc) != 0;
304 }
305
306 /// Test if this operation's arguments and results are assumed not-NaN.
307 bool hasNoNaNs() const {
308 return (SubclassOptionalData & FastMathFlags::NoNaNs) != 0;
309 }
310
311 /// Test if this operation's arguments and results are assumed not-infinite.
312 bool hasNoInfs() const {
313 return (SubclassOptionalData & FastMathFlags::NoInfs) != 0;
314 }
315
316 /// Test if this operation can ignore the sign of zero.
317 bool hasNoSignedZeros() const {
318 return (SubclassOptionalData & FastMathFlags::NoSignedZeros) != 0;
319 }
320
321 /// Test if this operation can use reciprocal multiply instead of division.
322 bool hasAllowReciprocal() const {
323 return (SubclassOptionalData & FastMathFlags::AllowReciprocal) != 0;
324 }
325
326 /// Test if this operation can be floating-point contracted (FMA).
327 bool hasAllowContract() const {
328 return (SubclassOptionalData & FastMathFlags::AllowContract) != 0;
329 }
330
331 /// Test if this operation allows approximations of math library functions or
332 /// intrinsics.
333 bool hasApproxFunc() const {
334 return (SubclassOptionalData & FastMathFlags::ApproxFunc) != 0;
335 }
336
337 /// Convenience function for getting all the fast-math flags
339 return FastMathFlags(SubclassOptionalData);
340 }
341
342 /// Get the maximum error permitted by this operation in ULPs. An accuracy of
343 /// 0.0 means that the operation should be performed with the default
344 /// precision.
345 float getFPAccuracy() const;
346
347 /// Returns true if `Ty` is a supported floating-point type for phi, select,
348 /// or call FPMathOperators.
350 return Ty->isFPOrFPVectorTy() ||
351 isComposedOfHomogeneousFloatingPointTypes(Ty);
352 }
353
354 static bool classof(const Value *V) {
355 unsigned Opcode;
356 if (auto *I = dyn_cast<Instruction>(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 // FIXME: To clean up and correct the semantics of fast-math-flags, FCmp
371 // should not be treated as a math op, but the other opcodes should.
372 // This would make things consistent with Select/PHI (FP value type
373 // determines whether they are math ops and, therefore, capable of
374 // having fast-math-flags).
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/// A helper template for defining operators for individual opcodes.
389template<typename SuperClass, unsigned Opc>
391public:
392 static bool classof(const Instruction *I) {
393 return I->getOpcode() == Opc;
394 }
395 static bool classof(const ConstantExpr *CE) {
396 return CE->getOpcode() == Opc;
397 }
398 static bool classof(const Value *V) {
399 return (isa<Instruction>(V) && classof(cast<Instruction>(V))) ||
400 (isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(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 /// Transparently provide more efficient getOperand methods.
429
432 }
433
434 /// Test whether this is an inbounds GEP, as defined by LangRef.html.
435 bool isInBounds() const { return getNoWrapFlags().isInBounds(); }
436
439 }
440
441 bool hasNoUnsignedWrap() const {
443 }
444
445 /// Returns the offset of the index with an inrange attachment, or
446 /// std::nullopt if none.
447 std::optional<ConstantRange> getInRange() const;
448
449 inline op_iterator idx_begin() { return op_begin()+1; }
450 inline const_op_iterator idx_begin() const { return op_begin()+1; }
451 inline op_iterator idx_end() { return op_end(); }
452 inline const_op_iterator idx_end() const { return op_end(); }
453
455 return make_range(idx_begin(), idx_end());
456 }
457
459 return make_range(idx_begin(), idx_end());
460 }
461
463 return getOperand(0);
464 }
465 const Value *getPointerOperand() const {
466 return getOperand(0);
467 }
468 static unsigned getPointerOperandIndex() {
469 return 0U; // get index for modifying correct operand
470 }
471
472 /// Method to return the pointer operand as a PointerType.
474 return getPointerOperand()->getType();
475 }
476
477 Type *getSourceElementType() const;
478 Type *getResultElementType() const;
479
480 /// Method to return the address space of the pointer operand.
481 unsigned getPointerAddressSpace() const {
483 }
484
485 unsigned getNumIndices() const { // Note: always non-negative
486 return getNumOperands() - 1;
487 }
488
489 bool hasIndices() const {
490 return getNumOperands() > 1;
491 }
492
493 /// Return true if all of the indices of this GEP are zeros.
494 /// If so, the result pointer and the first operand have the same
495 /// value, just potentially different types.
496 bool hasAllZeroIndices() const {
497 for (const_op_iterator I = idx_begin(), E = idx_end(); I != E; ++I) {
498 if (ConstantInt *C = dyn_cast<ConstantInt>(I))
499 if (C->isZero())
500 continue;
501 return false;
502 }
503 return true;
504 }
505
506 /// Return true if all of the indices of this GEP are constant integers.
507 /// If so, the result pointer and the first operand have
508 /// a constant offset between them.
510 for (const_op_iterator I = idx_begin(), E = idx_end(); I != E; ++I) {
511 if (!isa<ConstantInt>(I))
512 return false;
513 }
514 return true;
515 }
516
517 unsigned countNonConstantIndices() const {
518 return count_if(indices(), [](const Use& use) {
519 return !isa<ConstantInt>(*use);
520 });
521 }
522
523 /// Compute the maximum alignment that this GEP is garranteed to preserve.
525
526 /// Accumulate the constant address offset of this GEP if possible.
527 ///
528 /// This routine accepts an APInt into which it will try to accumulate the
529 /// constant offset of this GEP.
530 ///
531 /// If \p ExternalAnalysis is provided it will be used to calculate a offset
532 /// when a operand of GEP is not constant.
533 /// For example, for a value \p ExternalAnalysis might try to calculate a
534 /// lower bound. If \p ExternalAnalysis is successful, it should return true.
535 ///
536 /// If the \p ExternalAnalysis returns false or the value returned by \p
537 /// ExternalAnalysis results in a overflow/underflow, this routine returns
538 /// false and the value of the offset APInt is undefined (it is *not*
539 /// preserved!).
540 ///
541 /// The APInt passed into this routine must be at exactly as wide as the
542 /// IntPtr type for the address space of the base GEP pointer.
544 const DataLayout &DL, APInt &Offset,
545 function_ref<bool(Value &, APInt &)> ExternalAnalysis = nullptr) const;
546
547 static bool accumulateConstantOffset(
548 Type *SourceType, ArrayRef<const Value *> Index, const DataLayout &DL,
549 APInt &Offset,
550 function_ref<bool(Value &, APInt &)> ExternalAnalysis = nullptr);
551
552 /// Collect the offset of this GEP as a map of Values to their associated
553 /// APInt multipliers, as well as a total Constant Offset.
554 bool collectOffset(const DataLayout &DL, unsigned BitWidth,
555 SmallMapVector<Value *, APInt, 4> &VariableOffsets,
556 APInt &ConstantOffset) const;
557};
558
559template <>
560struct OperandTraits<GEPOperator> : public VariadicOperandTraits<GEPOperator> {
561};
562
564
566 : public ConcreteOperator<Operator, Instruction::PtrToInt> {
567 friend class PtrToInt;
568 friend class ConstantExpr;
569
570public:
571 /// Transparently provide more efficient getOperand methods.
573
575 return getOperand(0);
576 }
577 const Value *getPointerOperand() const {
578 return getOperand(0);
579 }
580
581 static unsigned getPointerOperandIndex() {
582 return 0U; // get index for modifying correct operand
583 }
584
585 /// Method to return the pointer operand as a PointerType.
587 return getPointerOperand()->getType();
588 }
589
590 /// Method to return the address space of the pointer operand.
591 unsigned getPointerAddressSpace() const {
592 return cast<PointerType>(getPointerOperandType())->getAddressSpace();
593 }
594};
595
596template <>
598 : public FixedNumOperandTraits<PtrToIntOperator, 1> {};
599
601
603 : public ConcreteOperator<Operator, Instruction::BitCast> {
604 friend class BitCastInst;
605 friend class ConstantExpr;
606
607public:
608 /// Transparently provide more efficient getOperand methods.
610
611 Type *getSrcTy() const {
612 return getOperand(0)->getType();
613 }
614
615 Type *getDestTy() const {
616 return getType();
617 }
618};
619
620template <>
622 : public FixedNumOperandTraits<BitCastOperator, 1> {};
623
625
627 : public ConcreteOperator<Operator, Instruction::AddrSpaceCast> {
628 friend class AddrSpaceCastInst;
629 friend class ConstantExpr;
630
631public:
632 /// Transparently provide more efficient getOperand methods.
634
635 Value *getPointerOperand() { return getOperand(0); }
636
637 const Value *getPointerOperand() const { return getOperand(0); }
638
639 unsigned getSrcAddressSpace() const {
641 }
642
643 unsigned getDestAddressSpace() const {
644 return getType()->getPointerAddressSpace();
645 }
646};
647
648template <>
650 : public FixedNumOperandTraits<AddrSpaceCastOperator, 1> {};
651
653
654} // end namespace llvm
655
656#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
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:637
unsigned getDestAddressSpace() const
Definition: Operator.h:643
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
unsigned getSrcAddressSpace() const
Definition: Operator.h:639
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:615
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Type * getSrcTy() const
Definition: Operator.h:611
A helper template for defining operators for individual opcodes.
Definition: Operator.h:390
static bool classof(const Value *V)
Definition: Operator.h:398
static bool classof(const ConstantExpr *CE)
Definition: Operator.h:395
static bool classof(const Instruction *I)
Definition: Operator.h:392
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:1108
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
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:205
bool hasAllowReassoc() const
Test if this operation may be simplified with reassociative transforms.
Definition: Operator.h:302
bool isFast() const
Test if this operation allows all non-strict floating-point transforms.
Definition: Operator.h:291
static bool classof(const Value *V)
Definition: Operator.h:354
bool hasNoNaNs() const
Test if this operation's arguments and results are assumed not-NaN.
Definition: Operator.h:307
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags.
Definition: Operator.h:338
bool hasAllowReciprocal() const
Test if this operation can use reciprocal multiply instead of division.
Definition: Operator.h:322
bool hasNoSignedZeros() const
Test if this operation can ignore the sign of zero.
Definition: Operator.h:317
static bool isSupportedFloatingPointType(Type *Ty)
Returns true if Ty is a supported floating-point type for phi, select, or call FPMathOperators.
Definition: Operator.h:349
bool hasAllowContract() const
Test if this operation can be floating-point contracted (FMA).
Definition: Operator.h:327
bool hasNoInfs() const
Test if this operation's arguments and results are assumed not-infinite.
Definition: Operator.h:312
bool hasApproxFunc() const
Test if this operation allows approximations of math library functions or intrinsics.
Definition: Operator.h:333
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
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:437
const_op_iterator idx_end() const
Definition: Operator.h:452
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:465
const_op_iterator idx_begin() const
Definition: Operator.h:450
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
Definition: Operator.h:435
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
Definition: Operator.h:473
unsigned getNumIndices() const
Definition: Operator.h:485
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:517
Type * getSourceElementType() const
Definition: Operator.cpp:70
Type * getResultElementType() const
Definition: Operator.cpp:76
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:441
bool hasAllZeroIndices() const
Return true if all of the indices of this GEP are zeros.
Definition: Operator.h:496
op_iterator idx_end()
Definition: Operator.h:451
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
op_iterator idx_begin()
Definition: Operator.h:449
Value * getPointerOperand()
Definition: Operator.h:462
GEPNoWrapFlags getNoWrapFlags() const
Definition: Operator.h:430
bool hasAllConstantIndices() const
Return true if all of the indices of this GEP are constant integers.
Definition: Operator.h:509
iterator_range< op_iterator > indices()
Definition: Operator.h:454
bool hasIndices() const
Definition: Operator.h:489
iterator_range< const_op_iterator > indices() const
Definition: Operator.h:458
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:481
static unsigned getPointerOperandIndex()
Definition: Operator.h:468
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:32
static bool classof(const ConstantExpr *)
Definition: Operator.h:59
bool hasPoisonGeneratingAnnotations() const
Return true if this operator has poison-generating flags, return attributes or metadata.
Definition: Operator.cpp:62
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:58
Operator()=delete
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
Definition: Operator.h:42
~Operator()=delete
static bool classof(const Value *V)
Definition: Operator.h:60
static unsigned getOpcode(const Value *V)
If V is an Instruction or ConstantExpr, return its opcode.
Definition: Operator.h:50
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl.
Definition: Operator.h:77
static bool classof(const Value *V)
Definition: Operator.h:141
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:110
unsigned getNoWrapKind() const
Returns the no-wrap kind of the operation.
Definition: Operator.h:115
bool hasNoUnsignedWrap() const
Test whether this operation is known to never undergo unsigned overflow, aka the nuw property.
Definition: Operator.h:104
bool isCommutative() const
Return true if the instruction is commutative.
Definition: Operator.h:127
static bool classof(const ConstantExpr *CE)
Definition: Operator.h:135
static bool classof(const Instruction *I)
Definition: Operator.h:129
A udiv or sdiv instruction, which can be marked as "exact", indicating that no bits are destroyed.
Definition: Operator.h:155
static bool classof(const ConstantExpr *CE)
Definition: Operator.h:185
bool isExact() const
Test whether this division is known to be exact, with zero remainder.
Definition: Operator.h:174
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static bool isPossiblyExactOpcode(unsigned OpC)
Definition: Operator.h:178
static bool classof(const Value *V)
Definition: Operator.h:191
static bool classof(const Instruction *I)
Definition: Operator.h:188
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:586
static unsigned getPointerOperandIndex()
Definition: Operator.h:581
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
Definition: Operator.h:591
const Value * getPointerOperand() const
Definition: Operator.h:577
Value * getPointerOperand()
Definition: Operator.h:574
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
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:43
op_iterator op_begin()
Definition: User.h:280
Value * getOperand(unsigned i) const
Definition: User.h:228
unsigned getNumOperands() const
Definition: User.h:250
op_iterator op_end()
Definition: User.h:282
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
Definition: Value.h:84
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:480
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:217
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:1945
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:254
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:67