LLVM 23.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) {
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))) ||
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) {
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 {
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 LLVM_ABI LLVM_READONLY FastMathFlags &getFastMathFlagsImpl();
205
206 /// 'Fast' means all bits are set.
207 void setFast(bool B) {
208 setHasAllowReassoc(B);
209 setHasNoNaNs(B);
210 setHasNoInfs(B);
211 setHasNoSignedZeros(B);
212 setHasAllowReciprocal(B);
213 setHasAllowContract(B);
214 setHasApproxFunc(B);
215 }
216
217 void setHasAllowReassoc(bool B) { getFastMathFlagsImpl().setAllowReassoc(B); }
218
219 void setHasNoNaNs(bool B) { getFastMathFlagsImpl().setNoNaNs(B); }
220
221 void setHasNoInfs(bool B) { getFastMathFlagsImpl().setNoInfs(B); }
222
223 void setHasNoSignedZeros(bool B) {
224 getFastMathFlagsImpl().setNoSignedZeros(B);
225 }
226
227 void setHasAllowReciprocal(bool B) {
228 getFastMathFlagsImpl().setAllowReciprocal(B);
229 }
230
231 void setHasAllowContract(bool B) {
232 getFastMathFlagsImpl().setAllowContract(B);
233 }
234
235 void setHasApproxFunc(bool B) { getFastMathFlagsImpl().setApproxFunc(B); }
236
237 /// Convenience function for setting multiple fast-math flags.
238 /// FMF is a mask of the bits to set.
239 void setFastMathFlags(FastMathFlags FMF) { getFastMathFlagsImpl() |= FMF; }
240
241 /// Convenience function for copying all fast-math flags.
242 /// All values in FMF are transferred to this operator.
243 void copyFastMathFlags(FastMathFlags FMF) { getFastMathFlagsImpl() = FMF; }
244
245 /// Returns true if `Ty` is composed of a single kind of float-poing type
246 /// (possibly repeated within an aggregate).
247 static bool isComposedOfHomogeneousFloatingPointTypes(Type *Ty) {
248 if (auto *StructTy = dyn_cast<StructType>(Ty)) {
249 if (!StructTy->isLiteral() || !StructTy->containsHomogeneousTypes())
250 return false;
251 Ty = StructTy->elements().front();
252 } else if (auto *ArrayTy = dyn_cast<ArrayType>(Ty)) {
253 do {
254 Ty = ArrayTy->getElementType();
255 } while ((ArrayTy = dyn_cast<ArrayType>(Ty)) != nullptr);
256 }
257 return Ty->isFPOrFPVectorTy();
258 };
259
260public:
261 /// Test if this operation allows all non-strict floating-point transforms.
262 bool isFast() const { return getFastMathFlags().isFast(); }
263
264 /// Test if this operation may be simplified with reassociative transforms.
265 bool hasAllowReassoc() const { return getFastMathFlags().allowReassoc(); }
266
267 /// Test if this operation's arguments and results are assumed not-NaN.
268 bool hasNoNaNs() const { return getFastMathFlags().noNaNs(); }
269
270 /// Test if this operation's arguments and results are assumed not-infinite.
271 bool hasNoInfs() const { return getFastMathFlags().noInfs(); }
272
273 /// Test if this operation can ignore the sign of zero.
274 bool hasNoSignedZeros() const { return getFastMathFlags().noSignedZeros(); }
275
276 /// Test if this operation can use reciprocal multiply instead of division.
277 bool hasAllowReciprocal() const {
278 return getFastMathFlags().allowReciprocal();
279 }
280
281 /// Test if this operation can be floating-point contracted (FMA).
282 bool hasAllowContract() const { return getFastMathFlags().allowContract(); }
283
284 /// Test if this operation allows approximations of math library functions or
285 /// intrinsics.
286 bool hasApproxFunc() const { return getFastMathFlags().approxFunc(); }
287
288 /// Convenience function for getting all the fast-math flags
290 return const_cast<FPMathOperator *>(this)->getFastMathFlagsImpl();
291 }
292
293 /// Get the maximum error permitted by this operation in ULPs. An accuracy of
294 /// 0.0 means that the operation should be performed with the default
295 /// precision.
296 LLVM_ABI float getFPAccuracy() const;
297
298 /// Returns true if `Ty` is a supported floating-point type for phi, select,
299 /// or call FPMathOperators.
301 return Ty->isFPOrFPVectorTy() ||
302 isComposedOfHomogeneousFloatingPointTypes(Ty);
303 }
304
305 static bool classof(const Value *V) {
306 unsigned Opcode;
307 if (auto *I = dyn_cast<Instruction>(V))
308 Opcode = I->getOpcode();
309 else
310 return false;
311
312 switch (Opcode) {
313 case Instruction::FNeg:
314 case Instruction::FAdd:
315 case Instruction::FSub:
316 case Instruction::FMul:
317 case Instruction::FDiv:
318 case Instruction::FRem:
319 case Instruction::FPTrunc:
320 case Instruction::FPExt:
321 // FIXME: To clean up and correct the semantics of fast-math-flags, FCmp
322 // should not be treated as a math op, but the other opcodes should.
323 // This would make things consistent with Select/PHI (FP value type
324 // determines whether they are math ops and, therefore, capable of
325 // having fast-math-flags).
326 case Instruction::FCmp:
327 return true;
328 case Instruction::PHI:
329 case Instruction::Select:
330 case Instruction::Call: {
331 return isSupportedFloatingPointType(V->getType());
332 }
333 default:
334 return false;
335 }
336 }
337};
338
339/// A helper template for defining operators for individual opcodes.
340template<typename SuperClass, unsigned Opc>
342public:
343 static bool classof(const Instruction *I) {
344 return I->getOpcode() == Opc;
345 }
346 static bool classof(const ConstantExpr *CE) {
347 return CE->getOpcode() == Opc;
348 }
349 static bool classof(const Value *V) {
350 return (isa<Instruction>(V) && classof(cast<Instruction>(V))) ||
352 }
353};
354
356 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Add> {
357};
359 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Sub> {
360};
362 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Mul> {
363};
365 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Shl> {
366};
367
369 : public ConcreteOperator<PossiblyExactOperator, Instruction::AShr> {
370};
372 : public ConcreteOperator<PossiblyExactOperator, Instruction::LShr> {
373};
374
376 : public ConcreteOperator<Operator, Instruction::GetElementPtr> {
377public:
378 /// Transparently provide more efficient getOperand methods.
380
384
385 /// Test whether this is an inbounds GEP, as defined by LangRef.html.
386 bool isInBounds() const { return getNoWrapFlags().isInBounds(); }
387
391
392 bool hasNoUnsignedWrap() const {
394 }
395
396 /// Returns the offset of the index with an inrange attachment, or
397 /// std::nullopt if none.
398 LLVM_ABI std::optional<ConstantRange> getInRange() const;
399
400 inline op_iterator idx_begin() { return op_begin()+1; }
401 inline const_op_iterator idx_begin() const { return op_begin()+1; }
402 inline op_iterator idx_end() { return op_end(); }
403 inline const_op_iterator idx_end() const { return op_end(); }
404
408
410 return make_range(idx_begin(), idx_end());
411 }
412
414 return getOperand(0);
415 }
416 const Value *getPointerOperand() const {
417 return getOperand(0);
418 }
419 static unsigned getPointerOperandIndex() {
420 return 0U; // get index for modifying correct operand
421 }
422
423 /// Method to return the pointer operand as a PointerType.
425 return getPointerOperand()->getType();
426 }
427
430
431 /// Method to return the address space of the pointer operand.
432 unsigned getPointerAddressSpace() const {
434 }
435
436 unsigned getNumIndices() const { // Note: always non-negative
437 return getNumOperands() - 1;
438 }
439
440 bool hasIndices() const {
441 return getNumOperands() > 1;
442 }
443
444 /// Return true if all of the indices of this GEP are zeros.
445 /// If so, the result pointer and the first operand have the same
446 /// value, just potentially different types.
447 bool hasAllZeroIndices() const {
448 for (const_op_iterator I = idx_begin(), E = idx_end(); I != E; ++I) {
450 if (C->isZero())
451 continue;
452 return false;
453 }
454 return true;
455 }
456
457 /// Return true if all of the indices of this GEP are constant integers.
458 /// If so, the result pointer and the first operand have
459 /// a constant offset between them.
461 for (const_op_iterator I = idx_begin(), E = idx_end(); I != E; ++I) {
462 if (!isa<ConstantInt>(I))
463 return false;
464 }
465 return true;
466 }
467
468 unsigned countNonConstantIndices() const {
469 return count_if(indices(), [](const Use& use) {
470 return !isa<ConstantInt>(*use);
471 });
472 }
473
474 /// Compute the maximum alignment that this GEP is garranteed to preserve.
476
477 /// Accumulate the constant address offset of this GEP if possible.
478 ///
479 /// This routine accepts an APInt into which it will try to accumulate the
480 /// constant offset of this GEP.
481 ///
482 /// If \p ExternalAnalysis is provided it will be used to calculate a offset
483 /// when a operand of GEP is not constant.
484 /// For example, for a value \p ExternalAnalysis might try to calculate a
485 /// lower bound. If \p ExternalAnalysis is successful, it should return true.
486 ///
487 /// If the \p ExternalAnalysis returns false or the value returned by \p
488 /// ExternalAnalysis results in a overflow/underflow, this routine returns
489 /// false and the value of the offset APInt is undefined (it is *not*
490 /// preserved!).
491 ///
492 /// The APInt passed into this routine must be at exactly as wide as the
493 /// IntPtr type for the address space of the base GEP pointer.
495 const DataLayout &DL, APInt &Offset,
496 function_ref<bool(Value &, APInt &)> ExternalAnalysis = nullptr) const;
497
499 Type *SourceType, ArrayRef<const Value *> Index, const DataLayout &DL,
500 APInt &Offset,
501 function_ref<bool(Value &, APInt &)> ExternalAnalysis = nullptr);
502
503 /// Collect the offset of this GEP as a map of Values to their associated
504 /// APInt multipliers, as well as a total Constant Offset.
505 LLVM_ABI bool
506 collectOffset(const DataLayout &DL, unsigned BitWidth,
507 SmallMapVector<Value *, APInt, 4> &VariableOffsets,
508 APInt &ConstantOffset) const;
509};
510
511template <>
512struct OperandTraits<GEPOperator> : public VariadicOperandTraits<GEPOperator> {
513};
514
516
519 friend class PtrToInt;
520 friend class ConstantExpr;
521
522public:
523 /// Transparently provide more efficient getOperand methods.
525
527 return getOperand(0);
528 }
529 const Value *getPointerOperand() const {
530 return getOperand(0);
531 }
532
533 static unsigned getPointerOperandIndex() {
534 return 0U; // get index for modifying correct operand
535 }
536
537 /// Method to return the pointer operand as a PointerType.
539 return getPointerOperand()->getType();
540 }
541
542 /// Method to return the address space of the pointer operand.
543 unsigned getPointerAddressSpace() const {
544 return cast<PointerType>(getPointerOperandType())->getAddressSpace();
545 }
546};
547
548template <>
550 : public FixedNumOperandTraits<PtrToIntOperator, 1> {};
551
553
556 friend class PtrToAddr;
557 friend class ConstantExpr;
558
559public:
560 /// Transparently provide more efficient getOperand methods.
562
564 const Value *getPointerOperand() const { return getOperand(0); }
565
566 static unsigned getPointerOperandIndex() {
567 return 0U; // get index for modifying correct operand
568 }
569
570 /// Method to return the pointer operand as a PointerType.
572
573 /// Method to return the address space of the pointer operand.
574 unsigned getPointerAddressSpace() const {
575 return cast<PointerType>(getPointerOperandType())->getAddressSpace();
576 }
577};
578
579template <>
581 : public FixedNumOperandTraits<PtrToAddrOperator, 1> {};
582
584
586 : public ConcreteOperator<Operator, Instruction::BitCast> {
587 friend class BitCastInst;
588 friend class ConstantExpr;
589
590public:
591 /// Transparently provide more efficient getOperand methods.
593
594 Type *getSrcTy() const {
595 return getOperand(0)->getType();
596 }
597
598 Type *getDestTy() const {
599 return getType();
600 }
601};
602
603template <>
605 : public FixedNumOperandTraits<BitCastOperator, 1> {};
606
608
610 : public ConcreteOperator<Operator, Instruction::AddrSpaceCast> {
611 friend class AddrSpaceCastInst;
612 friend class ConstantExpr;
613
614public:
615 /// Transparently provide more efficient getOperand methods.
617
619
620 const Value *getPointerOperand() const { return getOperand(0); }
621
622 unsigned getSrcAddressSpace() const {
624 }
625
626 unsigned getDestAddressSpace() const {
627 return getType()->getPointerAddressSpace();
628 }
629};
630
631template <>
633 : public FixedNumOperandTraits<AddrSpaceCastOperator, 1> {};
634
636
637} // end namespace llvm
638
639#endif // LLVM_IR_OPERATOR_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_READONLY
Definition Compiler.h:322
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Move duplicate certain instructions close to their use
Definition Localizer.cpp:33
#define I(x, y, z)
Definition MD5.cpp:57
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
const Value * getPointerOperand() const
Definition Operator.h:620
friend class AddrSpaceCastInst
Definition Operator.h:611
unsigned getDestAddressSpace() const
Definition Operator.h:626
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
unsigned getSrcAddressSpace() const
Definition Operator.h:622
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Type * getDestTy() const
Definition Operator.h:598
friend class ConstantExpr
Definition Operator.h:588
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Type * getSrcTy() const
Definition Operator.h:594
friend class BitCastInst
Definition Operator.h:587
A helper template for defining operators for individual opcodes.
Definition Operator.h:341
static bool classof(const Value *V)
Definition Operator.h:349
static bool classof(const ConstantExpr *CE)
Definition Operator.h:346
static bool classof(const Instruction *I)
Definition Operator.h:343
A constant value that is initialized with an expression using other constant values.
Definition Constants.h:1300
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:64
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:265
bool isFast() const
Test if this operation allows all non-strict floating-point transforms.
Definition Operator.h:262
static bool classof(const Value *V)
Definition Operator.h:305
bool hasNoNaNs() const
Test if this operation's arguments and results are assumed not-NaN.
Definition Operator.h:268
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition Operator.h:202
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags.
Definition Operator.h:289
bool hasAllowReciprocal() const
Test if this operation can use reciprocal multiply instead of division.
Definition Operator.h:277
bool hasNoSignedZeros() const
Test if this operation can ignore the sign of zero.
Definition Operator.h:274
static bool isSupportedFloatingPointType(Type *Ty)
Returns true if Ty is a supported floating-point type for phi, select, or call FPMathOperators.
Definition Operator.h:300
bool hasAllowContract() const
Test if this operation can be floating-point contracted (FMA).
Definition Operator.h:282
bool hasNoInfs() const
Test if this operation's arguments and results are assumed not-infinite.
Definition Operator.h:271
bool hasApproxFunc() const
Test if this operation allows approximations of math library functions or intrinsics.
Definition Operator.h:286
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
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:388
const_op_iterator idx_end() const
Definition Operator.h:403
const Value * getPointerOperand() const
Definition Operator.h:416
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:94
const_op_iterator idx_begin() const
Definition Operator.h:401
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:220
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
Definition Operator.h:386
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
Definition Operator.h:424
unsigned getNumIndices() const
Definition Operator.h:436
unsigned countNonConstantIndices() const
Definition Operator.h:468
bool hasNoUnsignedWrap() const
Definition Operator.h:392
bool hasAllZeroIndices() const
Return true if all of the indices of this GEP are zeros.
Definition Operator.h:447
op_iterator idx_end()
Definition Operator.h:402
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
LLVM_ABI Type * getResultElementType() const
Definition Operator.cpp:88
LLVM_ABI Type * getSourceElementType() const
Definition Operator.cpp:82
op_iterator idx_begin()
Definition Operator.h:400
Value * getPointerOperand()
Definition Operator.h:413
GEPNoWrapFlags getNoWrapFlags() const
Definition Operator.h:381
bool hasAllConstantIndices() const
Return true if all of the indices of this GEP are constant integers.
Definition Operator.h:460
LLVM_ABI Align getMaxPreservedAlignment(const DataLayout &DL) const
Compute the maximum alignment that this GEP is garranteed to preserve.
Definition Operator.cpp:100
iterator_range< op_iterator > indices()
Definition Operator.h:405
bool hasIndices() const
Definition Operator.h:440
iterator_range< const_op_iterator > indices() const
Definition Operator.h:409
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:125
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
Definition Operator.h:432
static unsigned getPointerOperandIndex()
Definition Operator.h:419
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
static bool classof(const Instruction *)
Definition Operator.h:59
Operator()=delete
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:23
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
LLVM_ABI bool hasPoisonGeneratingAnnotations() const
Return true if this operator has poison-generating flags, return attributes or metadata.
Definition Operator.cpp:74
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
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition Operator.h:87
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
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition Operator.h:161
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:566
Value * getPointerOperand()
Definition Operator.h:563
friend class PtrToAddr
Definition Operator.h:556
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
friend class ConstantExpr
Definition Operator.h:557
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
Definition Operator.h:571
const Value * getPointerOperand() const
Definition Operator.h:564
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
Definition Operator.h:574
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
friend class ConstantExpr
Definition Operator.h:520
friend class PtrToInt
Definition Operator.h:519
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
Definition Operator.h:538
static unsigned getPointerOperandIndex()
Definition Operator.h:533
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
Definition Operator.h:543
const Value * getPointerOperand() const
Definition Operator.h:529
Value * getPointerOperand()
Definition Operator.h:526
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
Use * op_iterator
Definition User.h:254
User(Type *ty, unsigned vty, AllocInfo AllocInfo)
Definition User.h:119
op_iterator op_begin()
Definition User.h:259
const Use * const_op_iterator
Definition User.h:255
Value * getOperand(unsigned i) const
Definition User.h:207
unsigned getNumOperands() const
Definition User.h:229
op_iterator op_end()
Definition User.h:261
LLVM Value Representation.
Definition Value.h:75
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: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.
@ Offset
Definition DWP.cpp:558
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
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.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
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...
Definition STLExtras.h:2018
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
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...
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:334
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...