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) {
91 assert(isa<Instruction>(this) && "cannot modify ConstantExpr");
94 }
95 void setHasNoSignedWrap(bool B) {
96 assert(isa<Instruction>(this) && "cannot modify ConstantExpr");
98 (SubclassOptionalData & ~NoSignedWrap) | (B * NoSignedWrap);
99 }
100
101public:
102 /// Transparently provide more efficient getOperand methods.
104
105 /// Test whether this operation is known to never
106 /// undergo unsigned overflow, aka the nuw property.
107 bool hasNoUnsignedWrap() const {
109 }
110
111 /// Test whether this operation is known to never
112 /// undergo signed overflow, aka the nsw property.
113 bool hasNoSignedWrap() const {
114 return (SubclassOptionalData & NoSignedWrap) != 0;
115 }
116
117 /// Returns the no-wrap kind of the operation.
118 unsigned getNoWrapKind() const {
119 unsigned NoWrapKind = 0;
120 if (hasNoUnsignedWrap())
121 NoWrapKind |= NoUnsignedWrap;
122
123 if (hasNoSignedWrap())
124 NoWrapKind |= NoSignedWrap;
125
126 return NoWrapKind;
127 }
128
129 /// Return true if the instruction is commutative
131
132 static bool classof(const Instruction *I) {
133 return I->getOpcode() == Instruction::Add ||
134 I->getOpcode() == Instruction::Sub ||
135 I->getOpcode() == Instruction::Mul ||
136 I->getOpcode() == Instruction::Shl;
137 }
138 static bool classof(const ConstantExpr *CE) {
139 return CE->getOpcode() == Instruction::Add ||
140 CE->getOpcode() == Instruction::Sub;
141 }
142 static bool classof(const Value *V) {
143 return (isa<Instruction>(V) && classof(cast<Instruction>(V))) ||
145 }
146};
147
148template <>
150 : public FixedNumOperandTraits<OverflowingBinaryOperator, 2> {};
151
153
154/// A udiv, sdiv, lshr, or ashr instruction, which can be marked as "exact",
155/// indicating that no bits are destroyed.
157public:
158 enum {
159 IsExact = (1 << 0)
160 };
161
162private:
163 friend class Instruction;
164 friend class ConstantExpr;
165
166 void setIsExact(bool B) {
168 }
169
170public:
171 /// Transparently provide more efficient getOperand methods.
173
174 /// Test whether this division is known to be exact, with zero remainder.
175 bool isExact() const {
177 }
178
179 static bool isPossiblyExactOpcode(unsigned OpC) {
180 return OpC == Instruction::SDiv ||
181 OpC == Instruction::UDiv ||
182 OpC == Instruction::AShr ||
183 OpC == Instruction::LShr;
184 }
185
186 static bool classof(const Instruction *I) {
187 return isPossiblyExactOpcode(I->getOpcode());
188 }
189 static bool classof(const Value *V) {
190 return (isa<Instruction>(V) && classof(cast<Instruction>(V)));
191 }
192};
193
194template <>
196 : public FixedNumOperandTraits<PossiblyExactOperator, 2> {};
197
199
200/// Utility class for floating point operations which can have
201/// information about relaxed accuracy requirements attached to them.
202class FPMathOperator : public Operator {
203private:
204 friend class Instruction;
205
206 LLVM_ABI LLVM_READONLY FastMathFlags &getFastMathFlagsImpl();
207
208 /// 'Fast' means all bits are set.
209 void setFast(bool B) {
210 setHasAllowReassoc(B);
211 setHasNoNaNs(B);
212 setHasNoInfs(B);
213 setHasNoSignedZeros(B);
214 setHasAllowReciprocal(B);
215 setHasAllowContract(B);
216 setHasApproxFunc(B);
217 }
218
219 void setHasAllowReassoc(bool B) { getFastMathFlagsImpl().setAllowReassoc(B); }
220
221 void setHasNoNaNs(bool B) { getFastMathFlagsImpl().setNoNaNs(B); }
222
223 void setHasNoInfs(bool B) { getFastMathFlagsImpl().setNoInfs(B); }
224
225 void setHasNoSignedZeros(bool B) {
226 getFastMathFlagsImpl().setNoSignedZeros(B);
227 }
228
229 void setHasAllowReciprocal(bool B) {
230 getFastMathFlagsImpl().setAllowReciprocal(B);
231 }
232
233 void setHasAllowContract(bool B) {
234 getFastMathFlagsImpl().setAllowContract(B);
235 }
236
237 void setHasApproxFunc(bool B) { getFastMathFlagsImpl().setApproxFunc(B); }
238
239 /// Convenience function for setting multiple fast-math flags.
240 /// FMF is a mask of the bits to set.
241 void setFastMathFlags(FastMathFlags FMF) { getFastMathFlagsImpl() |= FMF; }
242
243 /// Convenience function for copying all fast-math flags.
244 /// All values in FMF are transferred to this operator.
245 void copyFastMathFlags(FastMathFlags FMF) { getFastMathFlagsImpl() = FMF; }
246
247 /// Returns true if `Ty` is composed of a single kind of float-poing type
248 /// (possibly repeated within an aggregate).
249 static bool isComposedOfHomogeneousFloatingPointTypes(Type *Ty) {
250 if (auto *StructTy = dyn_cast<StructType>(Ty)) {
251 if (!StructTy->isLiteral() || !StructTy->containsHomogeneousTypes())
252 return false;
253 Ty = StructTy->elements().front();
254 } else if (auto *ArrayTy = dyn_cast<ArrayType>(Ty)) {
255 do {
256 Ty = ArrayTy->getElementType();
257 } while ((ArrayTy = dyn_cast<ArrayType>(Ty)) != nullptr);
258 }
259 return Ty->isFPOrFPVectorTy();
260 };
261
262public:
263 /// Test if this operation allows all non-strict floating-point transforms.
264 bool isFast() const { return getFastMathFlags().isFast(); }
265
266 /// Test if this operation may be simplified with reassociative transforms.
267 bool hasAllowReassoc() const { return getFastMathFlags().allowReassoc(); }
268
269 /// Test if this operation's arguments and results are assumed not-NaN.
270 bool hasNoNaNs() const { return getFastMathFlags().noNaNs(); }
271
272 /// Test if this operation's arguments and results are assumed not-infinite.
273 bool hasNoInfs() const { return getFastMathFlags().noInfs(); }
274
275 /// Test if this operation can ignore the sign of zero.
276 bool hasNoSignedZeros() const { return getFastMathFlags().noSignedZeros(); }
277
278 /// Test if this operation can use reciprocal multiply instead of division.
279 bool hasAllowReciprocal() const {
280 return getFastMathFlags().allowReciprocal();
281 }
282
283 /// Test if this operation can be floating-point contracted (FMA).
284 bool hasAllowContract() const { return getFastMathFlags().allowContract(); }
285
286 /// Test if this operation allows approximations of math library functions or
287 /// intrinsics.
288 bool hasApproxFunc() const { return getFastMathFlags().approxFunc(); }
289
290 /// Convenience function for getting all the fast-math flags
292 return const_cast<FPMathOperator *>(this)->getFastMathFlagsImpl();
293 }
294
295 /// Get the maximum error permitted by this operation in ULPs. An accuracy of
296 /// 0.0 means that the operation should be performed with the default
297 /// precision.
298 LLVM_ABI float getFPAccuracy() const;
299
300 /// Returns true if `Ty` is a supported floating-point type for phi, select,
301 /// or call FPMathOperators.
303 return Ty->isFPOrFPVectorTy() ||
304 isComposedOfHomogeneousFloatingPointTypes(Ty);
305 }
306
307 static bool classof(const Value *V) {
308 unsigned Opcode;
309 if (auto *I = dyn_cast<Instruction>(V))
310 Opcode = I->getOpcode();
311 else
312 return false;
313
314 switch (Opcode) {
315 case Instruction::FNeg:
316 case Instruction::FAdd:
317 case Instruction::FSub:
318 case Instruction::FMul:
319 case Instruction::FDiv:
320 case Instruction::FRem:
321 case Instruction::FPTrunc:
322 case Instruction::FPExt:
323 // FIXME: To clean up and correct the semantics of fast-math-flags, FCmp
324 // should not be treated as a math op, but the other opcodes should.
325 // This would make things consistent with Select/PHI (FP value type
326 // determines whether they are math ops and, therefore, capable of
327 // having fast-math-flags).
328 case Instruction::FCmp:
329 return true;
330 case Instruction::PHI:
331 case Instruction::Select:
332 case Instruction::Call: {
333 return isSupportedFloatingPointType(V->getType());
334 }
335 default:
336 return false;
337 }
338 }
339};
340
341/// A helper template for defining operators for individual opcodes.
342template<typename SuperClass, unsigned Opc>
344public:
345 static bool classof(const Instruction *I) {
346 return I->getOpcode() == Opc;
347 }
348 static bool classof(const ConstantExpr *CE) {
349 return CE->getOpcode() == Opc;
350 }
351 static bool classof(const Value *V) {
352 return (isa<Instruction>(V) && classof(cast<Instruction>(V))) ||
354 }
355};
356
358 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Add> {
359};
361 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Sub> {
362};
364 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Mul> {
365};
367 : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Shl> {
368};
369
371 : public ConcreteOperator<PossiblyExactOperator, Instruction::AShr> {
372};
374 : public ConcreteOperator<PossiblyExactOperator, Instruction::LShr> {
375};
376
378 : public ConcreteOperator<Operator, Instruction::GetElementPtr> {
379public:
380 /// Transparently provide more efficient getOperand methods.
382
386
387 /// Test whether this is an inbounds GEP, as defined by LangRef.html.
388 bool isInBounds() const { return getNoWrapFlags().isInBounds(); }
389
393
394 bool hasNoUnsignedWrap() const {
396 }
397
398 /// Returns the offset of the index with an inrange attachment, or
399 /// std::nullopt if none.
400 LLVM_ABI std::optional<ConstantRange> getInRange() const;
401
402 inline op_iterator idx_begin() { return op_begin()+1; }
403 inline const_op_iterator idx_begin() const { return op_begin()+1; }
404 inline op_iterator idx_end() { return op_end(); }
405 inline const_op_iterator idx_end() const { return op_end(); }
406
410
412 return make_range(idx_begin(), idx_end());
413 }
414
416 return getOperand(0);
417 }
418 const Value *getPointerOperand() const {
419 return getOperand(0);
420 }
421 static unsigned getPointerOperandIndex() {
422 return 0U; // get index for modifying correct operand
423 }
424
425 /// Method to return the pointer operand as a PointerType.
427 return getPointerOperand()->getType();
428 }
429
432
433 /// Method to return the address space of the pointer operand.
434 unsigned getPointerAddressSpace() const {
436 }
437
438 unsigned getNumIndices() const { // Note: always non-negative
439 return getNumOperands() - 1;
440 }
441
442 bool hasIndices() const {
443 return getNumOperands() > 1;
444 }
445
446 /// Return true if all of the indices of this GEP are zeros.
447 /// If so, the result pointer and the first operand have the same
448 /// value, just potentially different types.
449 bool hasAllZeroIndices() const {
450 for (const_op_iterator I = idx_begin(), E = idx_end(); I != E; ++I) {
452 if (C->isZero())
453 continue;
454 return false;
455 }
456 return true;
457 }
458
459 /// Return true if all of the indices of this GEP are constant integers.
460 /// If so, the result pointer and the first operand have
461 /// a constant offset between them.
463 for (const_op_iterator I = idx_begin(), E = idx_end(); I != E; ++I) {
464 if (!isa<ConstantInt>(I))
465 return false;
466 }
467 return true;
468 }
469
470 unsigned countNonConstantIndices() const {
471 return count_if(indices(), [](const Use& use) {
472 return !isa<ConstantInt>(*use);
473 });
474 }
475
476 /// Compute the maximum alignment that this GEP is garranteed to preserve.
478
479 /// Accumulate the constant address offset of this GEP if possible.
480 ///
481 /// This routine accepts an APInt into which it will try to accumulate the
482 /// constant offset of this GEP.
483 ///
484 /// If \p ExternalAnalysis is provided it will be used to calculate a offset
485 /// when a operand of GEP is not constant.
486 /// For example, for a value \p ExternalAnalysis might try to calculate a
487 /// lower bound. If \p ExternalAnalysis is successful, it should return true.
488 ///
489 /// If the \p ExternalAnalysis returns false or the value returned by \p
490 /// ExternalAnalysis results in a overflow/underflow, this routine returns
491 /// false and the value of the offset APInt is undefined (it is *not*
492 /// preserved!).
493 ///
494 /// The APInt passed into this routine must be at exactly as wide as the
495 /// IntPtr type for the address space of the base GEP pointer.
497 const DataLayout &DL, APInt &Offset,
498 function_ref<bool(Value &, APInt &)> ExternalAnalysis = nullptr) const;
499
501 Type *SourceType, ArrayRef<const Value *> Index, const DataLayout &DL,
502 APInt &Offset,
503 function_ref<bool(Value &, APInt &)> ExternalAnalysis = nullptr);
504
505 /// Collect the offset of this GEP as a map of Values to their associated
506 /// APInt multipliers, as well as a total Constant Offset.
507 LLVM_ABI bool
508 collectOffset(const DataLayout &DL, unsigned BitWidth,
509 SmallMapVector<Value *, APInt, 4> &VariableOffsets,
510 APInt &ConstantOffset) const;
511};
512
513template <>
514struct OperandTraits<GEPOperator> : public VariadicOperandTraits<GEPOperator> {
515};
516
518
521 friend class PtrToInt;
522 friend class ConstantExpr;
523
524public:
525 /// Transparently provide more efficient getOperand methods.
527
529 return getOperand(0);
530 }
531 const Value *getPointerOperand() const {
532 return getOperand(0);
533 }
534
535 static unsigned getPointerOperandIndex() {
536 return 0U; // get index for modifying correct operand
537 }
538
539 /// Method to return the pointer operand as a PointerType.
541 return getPointerOperand()->getType();
542 }
543
544 /// Method to return the address space of the pointer operand.
545 unsigned getPointerAddressSpace() const {
546 return cast<PointerType>(getPointerOperandType())->getAddressSpace();
547 }
548};
549
550template <>
552 : public FixedNumOperandTraits<PtrToIntOperator, 1> {};
553
555
558 friend class PtrToAddr;
559 friend class ConstantExpr;
560
561public:
562 /// Transparently provide more efficient getOperand methods.
564
566 const Value *getPointerOperand() const { return getOperand(0); }
567
568 static unsigned getPointerOperandIndex() {
569 return 0U; // get index for modifying correct operand
570 }
571
572 /// Method to return the pointer operand as a PointerType.
574
575 /// Method to return the address space of the pointer operand.
576 unsigned getPointerAddressSpace() const {
577 return cast<PointerType>(getPointerOperandType())->getAddressSpace();
578 }
579};
580
581template <>
583 : public FixedNumOperandTraits<PtrToAddrOperator, 1> {};
584
586
588 : public ConcreteOperator<Operator, Instruction::BitCast> {
589 friend class BitCastInst;
590 friend class ConstantExpr;
591
592public:
593 /// Transparently provide more efficient getOperand methods.
595
596 Type *getSrcTy() const {
597 return getOperand(0)->getType();
598 }
599
600 Type *getDestTy() const {
601 return getType();
602 }
603};
604
605template <>
607 : public FixedNumOperandTraits<BitCastOperator, 1> {};
608
610
612 : public ConcreteOperator<Operator, Instruction::AddrSpaceCast> {
613 friend class AddrSpaceCastInst;
614 friend class ConstantExpr;
615
616public:
617 /// Transparently provide more efficient getOperand methods.
619
621
622 const Value *getPointerOperand() const { return getOperand(0); }
623
624 unsigned getSrcAddressSpace() const {
626 }
627
628 unsigned getDestAddressSpace() const {
629 return getType()->getPointerAddressSpace();
630 }
631};
632
633template <>
635 : public FixedNumOperandTraits<AddrSpaceCastOperator, 1> {};
636
638
639} // end namespace llvm
640
641#endif // LLVM_IR_OPERATOR_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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:622
friend class AddrSpaceCastInst
Definition Operator.h:613
unsigned getDestAddressSpace() const
Definition Operator.h:628
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
unsigned getSrcAddressSpace() const
Definition Operator.h:624
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Type * getDestTy() const
Definition Operator.h:600
friend class ConstantExpr
Definition Operator.h:590
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Type * getSrcTy() const
Definition Operator.h:596
friend class BitCastInst
Definition Operator.h:589
A helper template for defining operators for individual opcodes.
Definition Operator.h:343
static bool classof(const Value *V)
Definition Operator.h:351
static bool classof(const ConstantExpr *CE)
Definition Operator.h:348
static bool classof(const Instruction *I)
Definition Operator.h:345
A constant value that is initialized with an expression using other constant values.
Definition Constants.h:1308
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:202
bool hasAllowReassoc() const
Test if this operation may be simplified with reassociative transforms.
Definition Operator.h:267
bool isFast() const
Test if this operation allows all non-strict floating-point transforms.
Definition Operator.h:264
static bool classof(const Value *V)
Definition Operator.h:307
bool hasNoNaNs() const
Test if this operation's arguments and results are assumed not-NaN.
Definition Operator.h:270
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition Operator.h:204
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags.
Definition Operator.h:291
bool hasAllowReciprocal() const
Test if this operation can use reciprocal multiply instead of division.
Definition Operator.h:279
bool hasNoSignedZeros() const
Test if this operation can ignore the sign of zero.
Definition Operator.h:276
static bool isSupportedFloatingPointType(Type *Ty)
Returns true if Ty is a supported floating-point type for phi, select, or call FPMathOperators.
Definition Operator.h:302
bool hasAllowContract() const
Test if this operation can be floating-point contracted (FMA).
Definition Operator.h:284
bool hasNoInfs() const
Test if this operation's arguments and results are assumed not-infinite.
Definition Operator.h:273
bool hasApproxFunc() const
Test if this operation allows approximations of math library functions or intrinsics.
Definition Operator.h:288
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:390
const_op_iterator idx_end() const
Definition Operator.h:405
const Value * getPointerOperand() const
Definition Operator.h:418
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:403
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:388
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
Definition Operator.h:426
unsigned getNumIndices() const
Definition Operator.h:438
unsigned countNonConstantIndices() const
Definition Operator.h:470
bool hasNoUnsignedWrap() const
Definition Operator.h:394
bool hasAllZeroIndices() const
Return true if all of the indices of this GEP are zeros.
Definition Operator.h:449
op_iterator idx_end()
Definition Operator.h:404
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:402
Value * getPointerOperand()
Definition Operator.h:415
GEPNoWrapFlags getNoWrapFlags() const
Definition Operator.h:383
bool hasAllConstantIndices() const
Return true if all of the indices of this GEP are constant integers.
Definition Operator.h:462
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:407
bool hasIndices() const
Definition Operator.h:442
iterator_range< const_op_iterator > indices() const
Definition Operator.h:411
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:434
static unsigned getPointerOperandIndex()
Definition Operator.h:421
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:142
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:113
unsigned getNoWrapKind() const
Returns the no-wrap kind of the operation.
Definition Operator.h:118
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:107
bool isCommutative() const
Return true if the instruction is commutative.
Definition Operator.h:130
static bool classof(const ConstantExpr *CE)
Definition Operator.h:138
static bool classof(const Instruction *I)
Definition Operator.h:132
A udiv, sdiv, lshr, or ashr instruction, which can be marked as "exact", indicating that no bits are ...
Definition Operator.h:156
bool isExact() const
Test whether this division is known to be exact, with zero remainder.
Definition Operator.h:175
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static bool isPossiblyExactOpcode(unsigned OpC)
Definition Operator.h:179
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition Operator.h:163
static bool classof(const Value *V)
Definition Operator.h:189
static bool classof(const Instruction *I)
Definition Operator.h:186
static unsigned getPointerOperandIndex()
Definition Operator.h:568
Value * getPointerOperand()
Definition Operator.h:565
friend class PtrToAddr
Definition Operator.h:558
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
friend class ConstantExpr
Definition Operator.h:559
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
Definition Operator.h:573
const Value * getPointerOperand() const
Definition Operator.h:566
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
Definition Operator.h:576
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
friend class ConstantExpr
Definition Operator.h:522
friend class PtrToInt
Definition Operator.h:521
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
Definition Operator.h:540
static unsigned getPointerOperandIndex()
Definition Operator.h:535
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
Definition Operator.h:545
const Value * getPointerOperand() const
Definition Operator.h:531
Value * getPointerOperand()
Definition Operator.h:528
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 arbitary subclass data.
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...