1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the class definitions of all of the subclasses of the
11 // Instruction class. This is meant to be an easy way to get access to all
12 // instruction subclasses.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_INSTRUCTIONS_H
17 #define LLVM_INSTRUCTIONS_H
21 #include "llvm/InstrTypes.h"
22 #include "llvm/DerivedTypes.h"
23 #include "llvm/ParameterAttributes.h"
35 //===----------------------------------------------------------------------===//
36 // AllocationInst Class
37 //===----------------------------------------------------------------------===//
39 /// AllocationInst - This class is the common base class of MallocInst and
42 class AllocationInst : public UnaryInstruction {
45 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
46 const std::string &Name = "", Instruction *InsertBefore = 0);
47 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
48 const std::string &Name, BasicBlock *InsertAtEnd);
50 // Out of line virtual method, so the vtable, etc has a home.
51 virtual ~AllocationInst();
53 /// isArrayAllocation - Return true if there is an allocation size parameter
54 /// to the allocation instruction that is not 1.
56 bool isArrayAllocation() const;
58 /// getArraySize - Get the number of element allocated, for a simple
59 /// allocation of a single element, this will return a constant 1 value.
61 inline const Value *getArraySize() const { return getOperand(0); }
62 inline Value *getArraySize() { return getOperand(0); }
64 /// getType - Overload to return most specific pointer type
66 inline const PointerType *getType() const {
67 return reinterpret_cast<const PointerType*>(Instruction::getType());
70 /// getAllocatedType - Return the type that is being allocated by the
73 const Type *getAllocatedType() const;
75 /// getAlignment - Return the alignment of the memory that is being allocated
76 /// by the instruction.
78 unsigned getAlignment() const { return Alignment; }
79 void setAlignment(unsigned Align) {
80 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
84 virtual Instruction *clone() const = 0;
86 // Methods for support type inquiry through isa, cast, and dyn_cast:
87 static inline bool classof(const AllocationInst *) { return true; }
88 static inline bool classof(const Instruction *I) {
89 return I->getOpcode() == Instruction::Alloca ||
90 I->getOpcode() == Instruction::Malloc;
92 static inline bool classof(const Value *V) {
93 return isa<Instruction>(V) && classof(cast<Instruction>(V));
98 //===----------------------------------------------------------------------===//
100 //===----------------------------------------------------------------------===//
102 /// MallocInst - an instruction to allocated memory on the heap
104 class MallocInst : public AllocationInst {
105 MallocInst(const MallocInst &MI);
107 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
108 const std::string &Name = "",
109 Instruction *InsertBefore = 0)
110 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
111 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
112 BasicBlock *InsertAtEnd)
113 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
115 MallocInst(const Type *Ty, const std::string &Name,
116 Instruction *InsertBefore = 0)
117 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
118 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
119 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
121 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
122 const std::string &Name, BasicBlock *InsertAtEnd)
123 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
124 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
125 const std::string &Name = "",
126 Instruction *InsertBefore = 0)
127 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
129 virtual MallocInst *clone() const;
131 // Methods for support type inquiry through isa, cast, and dyn_cast:
132 static inline bool classof(const MallocInst *) { return true; }
133 static inline bool classof(const Instruction *I) {
134 return (I->getOpcode() == Instruction::Malloc);
136 static inline bool classof(const Value *V) {
137 return isa<Instruction>(V) && classof(cast<Instruction>(V));
142 //===----------------------------------------------------------------------===//
144 //===----------------------------------------------------------------------===//
146 /// AllocaInst - an instruction to allocate memory on the stack
148 class AllocaInst : public AllocationInst {
149 AllocaInst(const AllocaInst &);
151 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
152 const std::string &Name = "",
153 Instruction *InsertBefore = 0)
154 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
155 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
156 BasicBlock *InsertAtEnd)
157 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
159 AllocaInst(const Type *Ty, const std::string &Name,
160 Instruction *InsertBefore = 0)
161 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
162 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
163 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
165 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
166 const std::string &Name = "", Instruction *InsertBefore = 0)
167 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
168 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
169 const std::string &Name, BasicBlock *InsertAtEnd)
170 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
172 virtual AllocaInst *clone() const;
174 // Methods for support type inquiry through isa, cast, and dyn_cast:
175 static inline bool classof(const AllocaInst *) { return true; }
176 static inline bool classof(const Instruction *I) {
177 return (I->getOpcode() == Instruction::Alloca);
179 static inline bool classof(const Value *V) {
180 return isa<Instruction>(V) && classof(cast<Instruction>(V));
185 //===----------------------------------------------------------------------===//
187 //===----------------------------------------------------------------------===//
189 /// FreeInst - an instruction to deallocate memory
191 class FreeInst : public UnaryInstruction {
194 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
195 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
197 virtual FreeInst *clone() const;
199 // Accessor methods for consistency with other memory operations
200 Value *getPointerOperand() { return getOperand(0); }
201 const Value *getPointerOperand() const { return getOperand(0); }
203 // Methods for support type inquiry through isa, cast, and dyn_cast:
204 static inline bool classof(const FreeInst *) { return true; }
205 static inline bool classof(const Instruction *I) {
206 return (I->getOpcode() == Instruction::Free);
208 static inline bool classof(const Value *V) {
209 return isa<Instruction>(V) && classof(cast<Instruction>(V));
214 //===----------------------------------------------------------------------===//
216 //===----------------------------------------------------------------------===//
218 /// LoadInst - an instruction for reading from memory. This uses the
219 /// SubclassData field in Value to store whether or not the load is volatile.
221 class LoadInst : public UnaryInstruction {
223 LoadInst(const LoadInst &LI)
224 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
225 setVolatile(LI.isVolatile());
226 setAlignment(LI.getAlignment());
234 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
235 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
236 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false,
237 Instruction *InsertBefore = 0);
238 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
239 Instruction *InsertBefore = 0);
240 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
241 BasicBlock *InsertAtEnd);
242 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
243 BasicBlock *InsertAtEnd);
245 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
246 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
247 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
248 Instruction *InsertBefore = 0);
249 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
250 BasicBlock *InsertAtEnd);
252 /// isVolatile - Return true if this is a load from a volatile memory
255 bool isVolatile() const { return SubclassData & 1; }
257 /// setVolatile - Specify whether this is a volatile load or not.
259 void setVolatile(bool V) {
260 SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
263 virtual LoadInst *clone() const;
265 /// getAlignment - Return the alignment of the access that is being performed
267 unsigned getAlignment() const {
268 return (1 << (SubclassData>>1)) >> 1;
271 void setAlignment(unsigned Align);
273 Value *getPointerOperand() { return getOperand(0); }
274 const Value *getPointerOperand() const { return getOperand(0); }
275 static unsigned getPointerOperandIndex() { return 0U; }
277 // Methods for support type inquiry through isa, cast, and dyn_cast:
278 static inline bool classof(const LoadInst *) { return true; }
279 static inline bool classof(const Instruction *I) {
280 return I->getOpcode() == Instruction::Load;
282 static inline bool classof(const Value *V) {
283 return isa<Instruction>(V) && classof(cast<Instruction>(V));
288 //===----------------------------------------------------------------------===//
290 //===----------------------------------------------------------------------===//
292 /// StoreInst - an instruction for storing to memory
294 class StoreInst : public Instruction {
297 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
298 Ops[0].init(SI.Ops[0], this);
299 Ops[1].init(SI.Ops[1], this);
300 setVolatile(SI.isVolatile());
301 setAlignment(SI.getAlignment());
309 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
310 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
311 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
312 Instruction *InsertBefore = 0);
313 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
314 unsigned Align, Instruction *InsertBefore = 0);
315 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
316 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
317 unsigned Align, BasicBlock *InsertAtEnd);
320 /// isVolatile - Return true if this is a load from a volatile memory
323 bool isVolatile() const { return SubclassData & 1; }
325 /// setVolatile - Specify whether this is a volatile load or not.
327 void setVolatile(bool V) {
328 SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
331 /// Transparently provide more efficient getOperand methods.
332 Value *getOperand(unsigned i) const {
333 assert(i < 2 && "getOperand() out of range!");
336 void setOperand(unsigned i, Value *Val) {
337 assert(i < 2 && "setOperand() out of range!");
340 unsigned getNumOperands() const { return 2; }
342 /// getAlignment - Return the alignment of the access that is being performed
344 unsigned getAlignment() const {
345 return (1 << (SubclassData>>1)) >> 1;
348 void setAlignment(unsigned Align);
350 virtual StoreInst *clone() const;
352 Value *getPointerOperand() { return getOperand(1); }
353 const Value *getPointerOperand() const { return getOperand(1); }
354 static unsigned getPointerOperandIndex() { return 1U; }
356 // Methods for support type inquiry through isa, cast, and dyn_cast:
357 static inline bool classof(const StoreInst *) { return true; }
358 static inline bool classof(const Instruction *I) {
359 return I->getOpcode() == Instruction::Store;
361 static inline bool classof(const Value *V) {
362 return isa<Instruction>(V) && classof(cast<Instruction>(V));
367 //===----------------------------------------------------------------------===//
368 // GetElementPtrInst Class
369 //===----------------------------------------------------------------------===//
371 // checkType - Simple wrapper function to give a better assertion failure
372 // message on bad indexes for a gep instruction.
374 static inline const Type *checkType(const Type *Ty) {
375 assert(Ty && "Invalid GetElementPtrInst indices for type!");
379 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
380 /// access elements of arrays and structs
382 class GetElementPtrInst : public Instruction {
383 GetElementPtrInst(const GetElementPtrInst &GEPI)
384 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
385 0, GEPI.getNumOperands()) {
386 Use *OL = OperandList = new Use[NumOperands];
387 Use *GEPIOL = GEPI.OperandList;
388 for (unsigned i = 0, E = NumOperands; i != E; ++i)
389 OL[i].init(GEPIOL[i], this);
391 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
392 void init(Value *Ptr, Value *Idx);
394 template<typename InputIterator>
395 void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
396 const std::string &Name,
397 // This argument ensures that we have an iterator we can
398 // do arithmetic on in constant time
399 std::random_access_iterator_tag) {
400 typename std::iterator_traits<InputIterator>::difference_type NumIdx =
401 std::distance(IdxBegin, IdxEnd);
404 // This requires that the itoerator points to contiguous memory.
405 init(Ptr, &*IdxBegin, NumIdx);
408 init(Ptr, 0, NumIdx);
414 /// getIndexedType - Returns the type of the element that would be loaded with
415 /// a load instruction with the specified parameters.
417 /// A null type is returned if the indices are invalid for the specified
420 static const Type *getIndexedType(const Type *Ptr,
421 Value* const *Idx, unsigned NumIdx,
422 bool AllowStructLeaf = false);
424 template<typename InputIterator>
425 static const Type *getIndexedType(const Type *Ptr,
426 InputIterator IdxBegin,
427 InputIterator IdxEnd,
428 bool AllowStructLeaf,
429 // This argument ensures that we
430 // have an iterator we can do
431 // arithmetic on in constant time
432 std::random_access_iterator_tag) {
433 typename std::iterator_traits<InputIterator>::difference_type NumIdx =
434 std::distance(IdxBegin, IdxEnd);
437 // This requires that the iterator points to contiguous memory.
438 return(getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx,
442 return(getIndexedType(Ptr, (Value *const*)0, NumIdx, AllowStructLeaf));
447 /// Constructors - Create a getelementptr instruction with a base pointer an
448 /// list of indices. The first ctor can optionally insert before an existing
449 /// instruction, the second appends the new instruction to the specified
451 template<typename InputIterator>
452 GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
453 InputIterator IdxEnd,
454 const std::string &Name = "",
455 Instruction *InsertBefore =0)
456 : Instruction(PointerType::get(
457 checkType(getIndexedType(Ptr->getType(),
458 IdxBegin, IdxEnd, true))),
459 GetElementPtr, 0, 0, InsertBefore) {
460 init(Ptr, IdxBegin, IdxEnd, Name,
461 typename std::iterator_traits<InputIterator>::iterator_category());
463 template<typename InputIterator>
464 GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
465 const std::string &Name, BasicBlock *InsertAtEnd)
466 : Instruction(PointerType::get(
467 checkType(getIndexedType(Ptr->getType(),
468 IdxBegin, IdxEnd, true))),
469 GetElementPtr, 0, 0, InsertAtEnd) {
470 init(Ptr, IdxBegin, IdxEnd, Name,
471 typename std::iterator_traits<InputIterator>::iterator_category());
474 /// Constructors - These two constructors are convenience methods because one
475 /// and two index getelementptr instructions are so common.
476 GetElementPtrInst(Value *Ptr, Value *Idx,
477 const std::string &Name = "", Instruction *InsertBefore =0);
478 GetElementPtrInst(Value *Ptr, Value *Idx,
479 const std::string &Name, BasicBlock *InsertAtEnd);
480 ~GetElementPtrInst();
482 virtual GetElementPtrInst *clone() const;
484 // getType - Overload to return most specific pointer type...
485 inline const PointerType *getType() const {
486 return reinterpret_cast<const PointerType*>(Instruction::getType());
489 /// getIndexedType - Returns the type of the element that would be loaded with
490 /// a load instruction with the specified parameters.
492 /// A null type is returned if the indices are invalid for the specified
495 template<typename InputIterator>
496 static const Type *getIndexedType(const Type *Ptr,
497 InputIterator IdxBegin,
498 InputIterator IdxEnd,
499 bool AllowStructLeaf = false) {
500 return(getIndexedType(Ptr, IdxBegin, IdxEnd, AllowStructLeaf,
501 typename std::iterator_traits<InputIterator>::
502 iterator_category()));
504 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
506 inline op_iterator idx_begin() { return op_begin()+1; }
507 inline const_op_iterator idx_begin() const { return op_begin()+1; }
508 inline op_iterator idx_end() { return op_end(); }
509 inline const_op_iterator idx_end() const { return op_end(); }
511 Value *getPointerOperand() {
512 return getOperand(0);
514 const Value *getPointerOperand() const {
515 return getOperand(0);
517 static unsigned getPointerOperandIndex() {
518 return 0U; // get index for modifying correct operand
521 inline unsigned getNumIndices() const { // Note: always non-negative
522 return getNumOperands() - 1;
525 inline bool hasIndices() const {
526 return getNumOperands() > 1;
529 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
530 /// zeros. If so, the result pointer and the first operand have the same
531 /// value, just potentially different types.
532 bool hasAllZeroIndices() const;
534 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
535 /// constant integers. If so, the result pointer and the first operand have
536 /// a constant offset between them.
537 bool hasAllConstantIndices() const;
540 // Methods for support type inquiry through isa, cast, and dyn_cast:
541 static inline bool classof(const GetElementPtrInst *) { return true; }
542 static inline bool classof(const Instruction *I) {
543 return (I->getOpcode() == Instruction::GetElementPtr);
545 static inline bool classof(const Value *V) {
546 return isa<Instruction>(V) && classof(cast<Instruction>(V));
550 //===----------------------------------------------------------------------===//
552 //===----------------------------------------------------------------------===//
554 /// This instruction compares its operands according to the predicate given
555 /// to the constructor. It only operates on integers, pointers, or packed
556 /// vectors of integrals. The two operands must be the same type.
557 /// @brief Represent an integer comparison operator.
558 class ICmpInst: public CmpInst {
560 /// This enumeration lists the possible predicates for the ICmpInst. The
561 /// values in the range 0-31 are reserved for FCmpInst while values in the
562 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
563 /// predicate values are not overlapping between the classes.
565 ICMP_EQ = 32, ///< equal
566 ICMP_NE = 33, ///< not equal
567 ICMP_UGT = 34, ///< unsigned greater than
568 ICMP_UGE = 35, ///< unsigned greater or equal
569 ICMP_ULT = 36, ///< unsigned less than
570 ICMP_ULE = 37, ///< unsigned less or equal
571 ICMP_SGT = 38, ///< signed greater than
572 ICMP_SGE = 39, ///< signed greater or equal
573 ICMP_SLT = 40, ///< signed less than
574 ICMP_SLE = 41, ///< signed less or equal
575 FIRST_ICMP_PREDICATE = ICMP_EQ,
576 LAST_ICMP_PREDICATE = ICMP_SLE,
577 BAD_ICMP_PREDICATE = ICMP_SLE + 1
580 /// @brief Constructor with insert-before-instruction semantics.
582 Predicate pred, ///< The predicate to use for the comparison
583 Value *LHS, ///< The left-hand-side of the expression
584 Value *RHS, ///< The right-hand-side of the expression
585 const std::string &Name = "", ///< Name of the instruction
586 Instruction *InsertBefore = 0 ///< Where to insert
587 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
590 /// @brief Constructor with insert-at-block-end semantics.
592 Predicate pred, ///< The predicate to use for the comparison
593 Value *LHS, ///< The left-hand-side of the expression
594 Value *RHS, ///< The right-hand-side of the expression
595 const std::string &Name, ///< Name of the instruction
596 BasicBlock *InsertAtEnd ///< Block to insert into.
597 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
600 /// @brief Return the predicate for this instruction.
601 Predicate getPredicate() const { return Predicate(SubclassData); }
603 /// @brief Set the predicate for this instruction to the specified value.
604 void setPredicate(Predicate P) { SubclassData = P; }
606 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
607 /// @returns the inverse predicate for the instruction's current predicate.
608 /// @brief Return the inverse of the instruction's predicate.
609 Predicate getInversePredicate() const {
610 return getInversePredicate(getPredicate());
613 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
614 /// @returns the inverse predicate for predicate provided in \p pred.
615 /// @brief Return the inverse of a given predicate
616 static Predicate getInversePredicate(Predicate pred);
618 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
619 /// @returns the predicate that would be the result of exchanging the two
620 /// operands of the ICmpInst instruction without changing the result
622 /// @brief Return the predicate as if the operands were swapped
623 Predicate getSwappedPredicate() const {
624 return getSwappedPredicate(getPredicate());
627 /// This is a static version that you can use without an instruction
629 /// @brief Return the predicate as if the operands were swapped.
630 static Predicate getSwappedPredicate(Predicate pred);
632 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
633 /// @returns the predicate that would be the result if the operand were
634 /// regarded as signed.
635 /// @brief Return the signed version of the predicate
636 Predicate getSignedPredicate() const {
637 return getSignedPredicate(getPredicate());
640 /// This is a static version that you can use without an instruction.
641 /// @brief Return the signed version of the predicate.
642 static Predicate getSignedPredicate(Predicate pred);
644 /// isEquality - Return true if this predicate is either EQ or NE. This also
645 /// tests for commutativity.
646 static bool isEquality(Predicate P) {
647 return P == ICMP_EQ || P == ICMP_NE;
650 /// isEquality - Return true if this predicate is either EQ or NE. This also
651 /// tests for commutativity.
652 bool isEquality() const {
653 return isEquality(getPredicate());
656 /// @returns true if the predicate of this ICmpInst is commutative
657 /// @brief Determine if this relation is commutative.
658 bool isCommutative() const { return isEquality(); }
660 /// isRelational - Return true if the predicate is relational (not EQ or NE).
662 bool isRelational() const {
663 return !isEquality();
666 /// isRelational - Return true if the predicate is relational (not EQ or NE).
668 static bool isRelational(Predicate P) {
669 return !isEquality(P);
672 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
673 /// @brief Determine if this instruction's predicate is signed.
674 bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); }
676 /// @returns true if the predicate provided is signed, false otherwise
677 /// @brief Determine if the predicate is signed.
678 static bool isSignedPredicate(Predicate pred);
680 /// Initialize a set of values that all satisfy the predicate with C.
681 /// @brief Make a ConstantRange for a relation with a constant value.
682 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
684 /// Exchange the two operands to this instruction in such a way that it does
685 /// not modify the semantics of the instruction. The predicate value may be
686 /// changed to retain the same result if the predicate is order dependent
688 /// @brief Swap operands and adjust predicate.
689 void swapOperands() {
690 SubclassData = getSwappedPredicate();
691 std::swap(Ops[0], Ops[1]);
694 virtual ICmpInst *clone() const;
696 // Methods for support type inquiry through isa, cast, and dyn_cast:
697 static inline bool classof(const ICmpInst *) { return true; }
698 static inline bool classof(const Instruction *I) {
699 return I->getOpcode() == Instruction::ICmp;
701 static inline bool classof(const Value *V) {
702 return isa<Instruction>(V) && classof(cast<Instruction>(V));
706 //===----------------------------------------------------------------------===//
708 //===----------------------------------------------------------------------===//
710 /// This instruction compares its operands according to the predicate given
711 /// to the constructor. It only operates on floating point values or packed
712 /// vectors of floating point values. The operands must be identical types.
713 /// @brief Represents a floating point comparison operator.
714 class FCmpInst: public CmpInst {
716 /// This enumeration lists the possible predicates for the FCmpInst. Values
717 /// in the range 0-31 are reserved for FCmpInst.
719 // Opcode U L G E Intuitive operation
720 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
721 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
722 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
723 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
724 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
725 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
726 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
727 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
728 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
729 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
730 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
731 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
732 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
733 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
734 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
735 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
736 FIRST_FCMP_PREDICATE = FCMP_FALSE,
737 LAST_FCMP_PREDICATE = FCMP_TRUE,
738 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
741 /// @brief Constructor with insert-before-instruction semantics.
743 Predicate pred, ///< The predicate to use for the comparison
744 Value *LHS, ///< The left-hand-side of the expression
745 Value *RHS, ///< The right-hand-side of the expression
746 const std::string &Name = "", ///< Name of the instruction
747 Instruction *InsertBefore = 0 ///< Where to insert
748 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
751 /// @brief Constructor with insert-at-block-end semantics.
753 Predicate pred, ///< The predicate to use for the comparison
754 Value *LHS, ///< The left-hand-side of the expression
755 Value *RHS, ///< The right-hand-side of the expression
756 const std::string &Name, ///< Name of the instruction
757 BasicBlock *InsertAtEnd ///< Block to insert into.
758 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
761 /// @brief Return the predicate for this instruction.
762 Predicate getPredicate() const { return Predicate(SubclassData); }
764 /// @brief Set the predicate for this instruction to the specified value.
765 void setPredicate(Predicate P) { SubclassData = P; }
767 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
768 /// @returns the inverse predicate for the instructions current predicate.
769 /// @brief Return the inverse of the predicate
770 Predicate getInversePredicate() const {
771 return getInversePredicate(getPredicate());
774 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
775 /// @returns the inverse predicate for \p pred.
776 /// @brief Return the inverse of a given predicate
777 static Predicate getInversePredicate(Predicate pred);
779 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
780 /// @returns the predicate that would be the result of exchanging the two
781 /// operands of the ICmpInst instruction without changing the result
783 /// @brief Return the predicate as if the operands were swapped
784 Predicate getSwappedPredicate() const {
785 return getSwappedPredicate(getPredicate());
788 /// This is a static version that you can use without an instruction
790 /// @brief Return the predicate as if the operands were swapped.
791 static Predicate getSwappedPredicate(Predicate Opcode);
793 /// This also tests for commutativity. If isEquality() returns true then
794 /// the predicate is also commutative. Only the equality predicates are
796 /// @returns true if the predicate of this instruction is EQ or NE.
797 /// @brief Determine if this is an equality predicate.
798 bool isEquality() const {
799 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
800 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
802 bool isCommutative() const { return isEquality(); }
804 /// @returns true if the predicate is relational (not EQ or NE).
805 /// @brief Determine if this a relational predicate.
806 bool isRelational() const { return !isEquality(); }
808 /// Exchange the two operands to this instruction in such a way that it does
809 /// not modify the semantics of the instruction. The predicate value may be
810 /// changed to retain the same result if the predicate is order dependent
812 /// @brief Swap operands and adjust predicate.
813 void swapOperands() {
814 SubclassData = getSwappedPredicate();
815 std::swap(Ops[0], Ops[1]);
818 virtual FCmpInst *clone() const;
820 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
821 static inline bool classof(const FCmpInst *) { return true; }
822 static inline bool classof(const Instruction *I) {
823 return I->getOpcode() == Instruction::FCmp;
825 static inline bool classof(const Value *V) {
826 return isa<Instruction>(V) && classof(cast<Instruction>(V));
830 //===----------------------------------------------------------------------===//
832 //===----------------------------------------------------------------------===//
833 /// CallInst - This class represents a function call, abstracting a target
834 /// machine's calling convention. This class uses low bit of the SubClassData
835 /// field to indicate whether or not this is a tail call. The rest of the bits
836 /// hold the calling convention of the call.
839 class CallInst : public Instruction {
840 const ParamAttrsList *ParamAttrs; ///< parameter attributes for call
841 CallInst(const CallInst &CI);
842 void init(Value *Func, Value* const *Params, unsigned NumParams);
843 void init(Value *Func, Value *Actual1, Value *Actual2);
844 void init(Value *Func, Value *Actual);
845 void init(Value *Func);
847 template<typename InputIterator>
848 void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
849 const std::string &Name,
850 // This argument ensures that we have an iterator we can
851 // do arithmetic on in constant time
852 std::random_access_iterator_tag) {
853 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
855 // This requires that the iterator points to contiguous memory.
856 init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
861 /// Construct a CallInst given a range of arguments. InputIterator
862 /// must be a random-access iterator pointing to contiguous storage
863 /// (e.g. a std::vector<>::iterator). Checks are made for
864 /// random-accessness but not for contiguous storage as that would
865 /// incur runtime overhead.
866 /// @brief Construct a CallInst from a range of arguments
867 template<typename InputIterator>
868 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
869 const std::string &Name = "", Instruction *InsertBefore = 0)
870 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
871 ->getElementType())->getReturnType(),
872 Instruction::Call, 0, 0, InsertBefore) {
873 init(Func, ArgBegin, ArgEnd, Name,
874 typename std::iterator_traits<InputIterator>::iterator_category());
877 /// Construct a CallInst given a range of arguments. InputIterator
878 /// must be a random-access iterator pointing to contiguous storage
879 /// (e.g. a std::vector<>::iterator). Checks are made for
880 /// random-accessness but not for contiguous storage as that would
881 /// incur runtime overhead.
882 /// @brief Construct a CallInst from a range of arguments
883 template<typename InputIterator>
884 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
885 const std::string &Name, BasicBlock *InsertAtEnd)
886 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
887 ->getElementType())->getReturnType(),
888 Instruction::Call, 0, 0, InsertAtEnd) {
889 init(Func, ArgBegin, ArgEnd, Name,
890 typename std::iterator_traits<InputIterator>::iterator_category());
893 CallInst(Value *F, Value *Actual, const std::string& Name = "",
894 Instruction *InsertBefore = 0);
895 CallInst(Value *F, Value *Actual, const std::string& Name,
896 BasicBlock *InsertAtEnd);
897 explicit CallInst(Value *F, const std::string &Name = "",
898 Instruction *InsertBefore = 0);
899 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
902 virtual CallInst *clone() const;
904 bool isTailCall() const { return SubclassData & 1; }
905 void setTailCall(bool isTailCall = true) {
906 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
909 /// getCallingConv/setCallingConv - Get or set the calling convention of this
911 unsigned getCallingConv() const { return SubclassData >> 1; }
912 void setCallingConv(unsigned CC) {
913 SubclassData = (SubclassData & 1) | (CC << 1);
916 /// Obtains a pointer to the ParamAttrsList object which holds the
917 /// parameter attributes information, if any.
918 /// @returns 0 if no attributes have been set.
919 /// @brief Get the parameter attributes.
920 const ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
922 /// Sets the parameter attributes for this CallInst. To construct a
923 /// ParamAttrsList, see ParameterAttributes.h
924 /// @brief Set the parameter attributes.
925 void setParamAttrs(const ParamAttrsList *attrs);
927 /// @brief Determine whether the call or the callee has the given attribute.
928 bool paramHasAttr(uint16_t i, ParameterAttributes attr) const;
930 /// @brief Determine if the call does not access memory.
931 bool doesNotAccessMemory() const {
932 return paramHasAttr(0, ParamAttr::ReadNone);
935 /// @brief Determine if the call does not access or only reads memory.
936 bool onlyReadsMemory() const {
937 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
940 /// @brief Determine if the call cannot unwind.
941 bool isNoUnwind() const {
942 return paramHasAttr(0, ParamAttr::NoUnwind);
945 /// @brief Determine if the call returns a structure.
946 bool isStructReturn() const {
947 // Be friendly and also check the callee.
948 return paramHasAttr(1, ParamAttr::StructRet);
951 /// getCalledFunction - Return the function being called by this instruction
952 /// if it is a direct call. If it is a call through a function pointer,
954 Function *getCalledFunction() const {
955 return dyn_cast<Function>(getOperand(0));
958 /// getCalledValue - Get a pointer to the function that is invoked by this
960 inline const Value *getCalledValue() const { return getOperand(0); }
961 inline Value *getCalledValue() { return getOperand(0); }
963 // Methods for support type inquiry through isa, cast, and dyn_cast:
964 static inline bool classof(const CallInst *) { return true; }
965 static inline bool classof(const Instruction *I) {
966 return I->getOpcode() == Instruction::Call;
968 static inline bool classof(const Value *V) {
969 return isa<Instruction>(V) && classof(cast<Instruction>(V));
973 //===----------------------------------------------------------------------===//
975 //===----------------------------------------------------------------------===//
977 /// SelectInst - This class represents the LLVM 'select' instruction.
979 class SelectInst : public Instruction {
982 void init(Value *C, Value *S1, Value *S2) {
983 Ops[0].init(C, this);
984 Ops[1].init(S1, this);
985 Ops[2].init(S2, this);
988 SelectInst(const SelectInst &SI)
989 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
990 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
993 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
994 Instruction *InsertBefore = 0)
995 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
999 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
1000 BasicBlock *InsertAtEnd)
1001 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
1006 Value *getCondition() const { return Ops[0]; }
1007 Value *getTrueValue() const { return Ops[1]; }
1008 Value *getFalseValue() const { return Ops[2]; }
1010 /// Transparently provide more efficient getOperand methods.
1011 Value *getOperand(unsigned i) const {
1012 assert(i < 3 && "getOperand() out of range!");
1015 void setOperand(unsigned i, Value *Val) {
1016 assert(i < 3 && "setOperand() out of range!");
1019 unsigned getNumOperands() const { return 3; }
1021 OtherOps getOpcode() const {
1022 return static_cast<OtherOps>(Instruction::getOpcode());
1025 virtual SelectInst *clone() const;
1027 // Methods for support type inquiry through isa, cast, and dyn_cast:
1028 static inline bool classof(const SelectInst *) { return true; }
1029 static inline bool classof(const Instruction *I) {
1030 return I->getOpcode() == Instruction::Select;
1032 static inline bool classof(const Value *V) {
1033 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1037 //===----------------------------------------------------------------------===//
1039 //===----------------------------------------------------------------------===//
1041 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1042 /// an argument of the specified type given a va_list and increments that list
1044 class VAArgInst : public UnaryInstruction {
1045 VAArgInst(const VAArgInst &VAA)
1046 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
1048 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
1049 Instruction *InsertBefore = 0)
1050 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1053 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
1054 BasicBlock *InsertAtEnd)
1055 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1059 virtual VAArgInst *clone() const;
1061 // Methods for support type inquiry through isa, cast, and dyn_cast:
1062 static inline bool classof(const VAArgInst *) { return true; }
1063 static inline bool classof(const Instruction *I) {
1064 return I->getOpcode() == VAArg;
1066 static inline bool classof(const Value *V) {
1067 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1071 //===----------------------------------------------------------------------===//
1072 // ExtractElementInst Class
1073 //===----------------------------------------------------------------------===//
1075 /// ExtractElementInst - This instruction extracts a single (scalar)
1076 /// element from a VectorType value
1078 class ExtractElementInst : public Instruction {
1080 ExtractElementInst(const ExtractElementInst &EE) :
1081 Instruction(EE.getType(), ExtractElement, Ops, 2) {
1082 Ops[0].init(EE.Ops[0], this);
1083 Ops[1].init(EE.Ops[1], this);
1087 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
1088 Instruction *InsertBefore = 0);
1089 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
1090 Instruction *InsertBefore = 0);
1091 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
1092 BasicBlock *InsertAtEnd);
1093 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
1094 BasicBlock *InsertAtEnd);
1096 /// isValidOperands - Return true if an extractelement instruction can be
1097 /// formed with the specified operands.
1098 static bool isValidOperands(const Value *Vec, const Value *Idx);
1100 virtual ExtractElementInst *clone() const;
1102 /// Transparently provide more efficient getOperand methods.
1103 Value *getOperand(unsigned i) const {
1104 assert(i < 2 && "getOperand() out of range!");
1107 void setOperand(unsigned i, Value *Val) {
1108 assert(i < 2 && "setOperand() out of range!");
1111 unsigned getNumOperands() const { return 2; }
1113 // Methods for support type inquiry through isa, cast, and dyn_cast:
1114 static inline bool classof(const ExtractElementInst *) { return true; }
1115 static inline bool classof(const Instruction *I) {
1116 return I->getOpcode() == Instruction::ExtractElement;
1118 static inline bool classof(const Value *V) {
1119 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1123 //===----------------------------------------------------------------------===//
1124 // InsertElementInst Class
1125 //===----------------------------------------------------------------------===//
1127 /// InsertElementInst - This instruction inserts a single (scalar)
1128 /// element into a VectorType value
1130 class InsertElementInst : public Instruction {
1132 InsertElementInst(const InsertElementInst &IE);
1134 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1135 const std::string &Name = "",Instruction *InsertBefore = 0);
1136 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1137 const std::string &Name = "",Instruction *InsertBefore = 0);
1138 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1139 const std::string &Name, BasicBlock *InsertAtEnd);
1140 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1141 const std::string &Name, BasicBlock *InsertAtEnd);
1143 /// isValidOperands - Return true if an insertelement instruction can be
1144 /// formed with the specified operands.
1145 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1148 virtual InsertElementInst *clone() const;
1150 /// getType - Overload to return most specific vector type.
1152 inline const VectorType *getType() const {
1153 return reinterpret_cast<const VectorType*>(Instruction::getType());
1156 /// Transparently provide more efficient getOperand methods.
1157 Value *getOperand(unsigned i) const {
1158 assert(i < 3 && "getOperand() out of range!");
1161 void setOperand(unsigned i, Value *Val) {
1162 assert(i < 3 && "setOperand() out of range!");
1165 unsigned getNumOperands() const { return 3; }
1167 // Methods for support type inquiry through isa, cast, and dyn_cast:
1168 static inline bool classof(const InsertElementInst *) { return true; }
1169 static inline bool classof(const Instruction *I) {
1170 return I->getOpcode() == Instruction::InsertElement;
1172 static inline bool classof(const Value *V) {
1173 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1177 //===----------------------------------------------------------------------===//
1178 // ShuffleVectorInst Class
1179 //===----------------------------------------------------------------------===//
1181 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1184 class ShuffleVectorInst : public Instruction {
1186 ShuffleVectorInst(const ShuffleVectorInst &IE);
1188 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1189 const std::string &Name = "", Instruction *InsertBefor = 0);
1190 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1191 const std::string &Name, BasicBlock *InsertAtEnd);
1193 /// isValidOperands - Return true if a shufflevector instruction can be
1194 /// formed with the specified operands.
1195 static bool isValidOperands(const Value *V1, const Value *V2,
1198 virtual ShuffleVectorInst *clone() const;
1200 /// getType - Overload to return most specific vector type.
1202 inline const VectorType *getType() const {
1203 return reinterpret_cast<const VectorType*>(Instruction::getType());
1206 /// Transparently provide more efficient getOperand methods.
1207 Value *getOperand(unsigned i) const {
1208 assert(i < 3 && "getOperand() out of range!");
1211 void setOperand(unsigned i, Value *Val) {
1212 assert(i < 3 && "setOperand() out of range!");
1215 unsigned getNumOperands() const { return 3; }
1217 // Methods for support type inquiry through isa, cast, and dyn_cast:
1218 static inline bool classof(const ShuffleVectorInst *) { return true; }
1219 static inline bool classof(const Instruction *I) {
1220 return I->getOpcode() == Instruction::ShuffleVector;
1222 static inline bool classof(const Value *V) {
1223 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1228 //===----------------------------------------------------------------------===//
1230 //===----------------------------------------------------------------------===//
1232 // PHINode - The PHINode class is used to represent the magical mystical PHI
1233 // node, that can not exist in nature, but can be synthesized in a computer
1234 // scientist's overactive imagination.
1236 class PHINode : public Instruction {
1237 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1238 /// the number actually in use.
1239 unsigned ReservedSpace;
1240 PHINode(const PHINode &PN);
1242 explicit PHINode(const Type *Ty, const std::string &Name = "",
1243 Instruction *InsertBefore = 0)
1244 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1249 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1250 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1257 /// reserveOperandSpace - This method can be used to avoid repeated
1258 /// reallocation of PHI operand lists by reserving space for the correct
1259 /// number of operands before adding them. Unlike normal vector reserves,
1260 /// this method can also be used to trim the operand space.
1261 void reserveOperandSpace(unsigned NumValues) {
1262 resizeOperands(NumValues*2);
1265 virtual PHINode *clone() const;
1267 /// getNumIncomingValues - Return the number of incoming edges
1269 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1271 /// getIncomingValue - Return incoming value number x
1273 Value *getIncomingValue(unsigned i) const {
1274 assert(i*2 < getNumOperands() && "Invalid value number!");
1275 return getOperand(i*2);
1277 void setIncomingValue(unsigned i, Value *V) {
1278 assert(i*2 < getNumOperands() && "Invalid value number!");
1281 unsigned getOperandNumForIncomingValue(unsigned i) {
1285 /// getIncomingBlock - Return incoming basic block number x
1287 BasicBlock *getIncomingBlock(unsigned i) const {
1288 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1290 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1291 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1293 unsigned getOperandNumForIncomingBlock(unsigned i) {
1297 /// addIncoming - Add an incoming value to the end of the PHI list
1299 void addIncoming(Value *V, BasicBlock *BB) {
1300 assert(getType() == V->getType() &&
1301 "All operands to PHI node must be the same type as the PHI node!");
1302 unsigned OpNo = NumOperands;
1303 if (OpNo+2 > ReservedSpace)
1304 resizeOperands(0); // Get more space!
1305 // Initialize some new operands.
1306 NumOperands = OpNo+2;
1307 OperandList[OpNo].init(V, this);
1308 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1311 /// removeIncomingValue - Remove an incoming value. This is useful if a
1312 /// predecessor basic block is deleted. The value removed is returned.
1314 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1315 /// is true), the PHI node is destroyed and any uses of it are replaced with
1316 /// dummy values. The only time there should be zero incoming values to a PHI
1317 /// node is when the block is dead, so this strategy is sound.
1319 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1321 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1322 int Idx = getBasicBlockIndex(BB);
1323 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1324 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1327 /// getBasicBlockIndex - Return the first index of the specified basic
1328 /// block in the value list for this PHI. Returns -1 if no instance.
1330 int getBasicBlockIndex(const BasicBlock *BB) const {
1331 Use *OL = OperandList;
1332 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1333 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1337 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1338 return getIncomingValue(getBasicBlockIndex(BB));
1341 /// hasConstantValue - If the specified PHI node always merges together the
1342 /// same value, return the value, otherwise return null.
1344 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1346 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1347 static inline bool classof(const PHINode *) { return true; }
1348 static inline bool classof(const Instruction *I) {
1349 return I->getOpcode() == Instruction::PHI;
1351 static inline bool classof(const Value *V) {
1352 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1355 void resizeOperands(unsigned NumOperands);
1358 //===----------------------------------------------------------------------===//
1360 //===----------------------------------------------------------------------===//
1362 //===---------------------------------------------------------------------------
1363 /// ReturnInst - Return a value (possibly void), from a function. Execution
1364 /// does not continue in this function any longer.
1366 class ReturnInst : public TerminatorInst {
1367 Use RetVal; // Return Value: null if 'void'.
1368 ReturnInst(const ReturnInst &RI);
1369 void init(Value *RetVal);
1372 // ReturnInst constructors:
1373 // ReturnInst() - 'ret void' instruction
1374 // ReturnInst( null) - 'ret void' instruction
1375 // ReturnInst(Value* X) - 'ret X' instruction
1376 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1377 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1378 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1379 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1381 // NOTE: If the Value* passed is of type void then the constructor behaves as
1382 // if it was passed NULL.
1383 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1384 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1385 explicit ReturnInst(BasicBlock *InsertAtEnd);
1387 virtual ReturnInst *clone() const;
1389 // Transparently provide more efficient getOperand methods.
1390 Value *getOperand(unsigned i) const {
1391 assert(i < getNumOperands() && "getOperand() out of range!");
1394 void setOperand(unsigned i, Value *Val) {
1395 assert(i < getNumOperands() && "setOperand() out of range!");
1399 Value *getReturnValue() const { return RetVal; }
1401 unsigned getNumSuccessors() const { return 0; }
1403 // Methods for support type inquiry through isa, cast, and dyn_cast:
1404 static inline bool classof(const ReturnInst *) { return true; }
1405 static inline bool classof(const Instruction *I) {
1406 return (I->getOpcode() == Instruction::Ret);
1408 static inline bool classof(const Value *V) {
1409 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1412 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1413 virtual unsigned getNumSuccessorsV() const;
1414 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1417 //===----------------------------------------------------------------------===//
1419 //===----------------------------------------------------------------------===//
1421 //===---------------------------------------------------------------------------
1422 /// BranchInst - Conditional or Unconditional Branch instruction.
1424 class BranchInst : public TerminatorInst {
1425 /// Ops list - Branches are strange. The operands are ordered:
1426 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1427 /// they don't have to check for cond/uncond branchness.
1429 BranchInst(const BranchInst &BI);
1432 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1433 // BranchInst(BB *B) - 'br B'
1434 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1435 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1436 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1437 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1438 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1439 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1440 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1441 Instruction *InsertBefore = 0);
1442 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1443 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1444 BasicBlock *InsertAtEnd);
1446 /// Transparently provide more efficient getOperand methods.
1447 Value *getOperand(unsigned i) const {
1448 assert(i < getNumOperands() && "getOperand() out of range!");
1451 void setOperand(unsigned i, Value *Val) {
1452 assert(i < getNumOperands() && "setOperand() out of range!");
1456 virtual BranchInst *clone() const;
1458 inline bool isUnconditional() const { return getNumOperands() == 1; }
1459 inline bool isConditional() const { return getNumOperands() == 3; }
1461 inline Value *getCondition() const {
1462 assert(isConditional() && "Cannot get condition of an uncond branch!");
1463 return getOperand(2);
1466 void setCondition(Value *V) {
1467 assert(isConditional() && "Cannot set condition of unconditional branch!");
1471 // setUnconditionalDest - Change the current branch to an unconditional branch
1472 // targeting the specified block.
1473 // FIXME: Eliminate this ugly method.
1474 void setUnconditionalDest(BasicBlock *Dest) {
1475 if (isConditional()) { // Convert this to an uncond branch.
1480 setOperand(0, reinterpret_cast<Value*>(Dest));
1483 unsigned getNumSuccessors() const { return 1+isConditional(); }
1485 BasicBlock *getSuccessor(unsigned i) const {
1486 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1487 return cast<BasicBlock>(getOperand(i));
1490 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1491 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1492 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1495 // Methods for support type inquiry through isa, cast, and dyn_cast:
1496 static inline bool classof(const BranchInst *) { return true; }
1497 static inline bool classof(const Instruction *I) {
1498 return (I->getOpcode() == Instruction::Br);
1500 static inline bool classof(const Value *V) {
1501 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1504 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1505 virtual unsigned getNumSuccessorsV() const;
1506 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1509 //===----------------------------------------------------------------------===//
1511 //===----------------------------------------------------------------------===//
1513 //===---------------------------------------------------------------------------
1514 /// SwitchInst - Multiway switch
1516 class SwitchInst : public TerminatorInst {
1517 unsigned ReservedSpace;
1518 // Operand[0] = Value to switch on
1519 // Operand[1] = Default basic block destination
1520 // Operand[2n ] = Value to match
1521 // Operand[2n+1] = BasicBlock to go to on match
1522 SwitchInst(const SwitchInst &RI);
1523 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1524 void resizeOperands(unsigned No);
1526 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1527 /// switch on and a default destination. The number of additional cases can
1528 /// be specified here to make memory allocation more efficient. This
1529 /// constructor can also autoinsert before another instruction.
1530 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1531 Instruction *InsertBefore = 0);
1533 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1534 /// switch on and a default destination. The number of additional cases can
1535 /// be specified here to make memory allocation more efficient. This
1536 /// constructor also autoinserts at the end of the specified BasicBlock.
1537 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1538 BasicBlock *InsertAtEnd);
1542 // Accessor Methods for Switch stmt
1543 inline Value *getCondition() const { return getOperand(0); }
1544 void setCondition(Value *V) { setOperand(0, V); }
1546 inline BasicBlock *getDefaultDest() const {
1547 return cast<BasicBlock>(getOperand(1));
1550 /// getNumCases - return the number of 'cases' in this switch instruction.
1551 /// Note that case #0 is always the default case.
1552 unsigned getNumCases() const {
1553 return getNumOperands()/2;
1556 /// getCaseValue - Return the specified case value. Note that case #0, the
1557 /// default destination, does not have a case value.
1558 ConstantInt *getCaseValue(unsigned i) {
1559 assert(i && i < getNumCases() && "Illegal case value to get!");
1560 return getSuccessorValue(i);
1563 /// getCaseValue - Return the specified case value. Note that case #0, the
1564 /// default destination, does not have a case value.
1565 const ConstantInt *getCaseValue(unsigned i) const {
1566 assert(i && i < getNumCases() && "Illegal case value to get!");
1567 return getSuccessorValue(i);
1570 /// findCaseValue - Search all of the case values for the specified constant.
1571 /// If it is explicitly handled, return the case number of it, otherwise
1572 /// return 0 to indicate that it is handled by the default handler.
1573 unsigned findCaseValue(const ConstantInt *C) const {
1574 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1575 if (getCaseValue(i) == C)
1580 /// findCaseDest - Finds the unique case value for a given successor. Returns
1581 /// null if the successor is not found, not unique, or is the default case.
1582 ConstantInt *findCaseDest(BasicBlock *BB) {
1583 if (BB == getDefaultDest()) return NULL;
1585 ConstantInt *CI = NULL;
1586 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1587 if (getSuccessor(i) == BB) {
1588 if (CI) return NULL; // Multiple cases lead to BB.
1589 else CI = getCaseValue(i);
1595 /// addCase - Add an entry to the switch instruction...
1597 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1599 /// removeCase - This method removes the specified successor from the switch
1600 /// instruction. Note that this cannot be used to remove the default
1601 /// destination (successor #0).
1603 void removeCase(unsigned idx);
1605 virtual SwitchInst *clone() const;
1607 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1608 BasicBlock *getSuccessor(unsigned idx) const {
1609 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1610 return cast<BasicBlock>(getOperand(idx*2+1));
1612 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1613 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1614 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1617 // getSuccessorValue - Return the value associated with the specified
1619 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1620 assert(idx < getNumSuccessors() && "Successor # out of range!");
1621 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1624 // Methods for support type inquiry through isa, cast, and dyn_cast:
1625 static inline bool classof(const SwitchInst *) { return true; }
1626 static inline bool classof(const Instruction *I) {
1627 return I->getOpcode() == Instruction::Switch;
1629 static inline bool classof(const Value *V) {
1630 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1633 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1634 virtual unsigned getNumSuccessorsV() const;
1635 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1638 //===----------------------------------------------------------------------===//
1640 //===----------------------------------------------------------------------===//
1642 //===---------------------------------------------------------------------------
1644 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1645 /// calling convention of the call.
1647 class InvokeInst : public TerminatorInst {
1648 const ParamAttrsList *ParamAttrs;
1649 InvokeInst(const InvokeInst &BI);
1650 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1651 Value* const *Args, unsigned NumArgs);
1653 template<typename InputIterator>
1654 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1655 InputIterator ArgBegin, InputIterator ArgEnd,
1656 const std::string &Name,
1657 // This argument ensures that we have an iterator we can
1658 // do arithmetic on in constant time
1659 std::random_access_iterator_tag) {
1660 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
1662 // This requires that the iterator points to contiguous memory.
1663 init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
1668 /// Construct an InvokeInst given a range of arguments.
1669 /// InputIterator must be a random-access iterator pointing to
1670 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
1671 /// made for random-accessness but not for contiguous storage as
1672 /// that would incur runtime overhead.
1674 /// @brief Construct an InvokeInst from a range of arguments
1675 template<typename InputIterator>
1676 InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1677 InputIterator ArgBegin, InputIterator ArgEnd,
1678 const std::string &Name = "", Instruction *InsertBefore = 0)
1679 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
1680 ->getElementType())->getReturnType(),
1681 Instruction::Invoke, 0, 0, InsertBefore) {
1682 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
1683 typename std::iterator_traits<InputIterator>::iterator_category());
1686 /// Construct an InvokeInst given a range of arguments.
1687 /// InputIterator must be a random-access iterator pointing to
1688 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
1689 /// made for random-accessness but not for contiguous storage as
1690 /// that would incur runtime overhead.
1692 /// @brief Construct an InvokeInst from a range of arguments
1693 template<typename InputIterator>
1694 InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1695 InputIterator ArgBegin, InputIterator ArgEnd,
1696 const std::string &Name, BasicBlock *InsertAtEnd)
1697 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
1698 ->getElementType())->getReturnType(),
1699 Instruction::Invoke, 0, 0, InsertAtEnd) {
1700 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
1701 typename std::iterator_traits<InputIterator>::iterator_category());
1706 virtual InvokeInst *clone() const;
1708 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1710 unsigned getCallingConv() const { return SubclassData; }
1711 void setCallingConv(unsigned CC) {
1715 /// Obtains a pointer to the ParamAttrsList object which holds the
1716 /// parameter attributes information, if any.
1717 /// @returns 0 if no attributes have been set.
1718 /// @brief Get the parameter attributes.
1719 const ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
1721 /// Sets the parameter attributes for this InvokeInst. To construct a
1722 /// ParamAttrsList, see ParameterAttributes.h
1723 /// @brief Set the parameter attributes.
1724 void setParamAttrs(const ParamAttrsList *attrs);
1726 /// @brief Determine whether the call or the callee has the given attribute.
1727 bool paramHasAttr(uint16_t i, ParameterAttributes attr) const;
1729 /// @brief Determine if the call does not access memory.
1730 bool doesNotAccessMemory() const {
1731 return paramHasAttr(0, ParamAttr::ReadNone);
1734 /// @brief Determine if the call does not access or only reads memory.
1735 bool onlyReadsMemory() const {
1736 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
1739 /// @brief Determine if the call cannot unwind.
1740 bool isNoUnwind() const {
1741 return paramHasAttr(0, ParamAttr::NoUnwind);
1744 /// @brief Determine if the call returns a structure.
1745 bool isStructReturn() const {
1746 // Be friendly and also check the callee.
1747 return paramHasAttr(1, ParamAttr::StructRet);
1750 /// getCalledFunction - Return the function called, or null if this is an
1751 /// indirect function invocation.
1753 Function *getCalledFunction() const {
1754 return dyn_cast<Function>(getOperand(0));
1757 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1758 inline Value *getCalledValue() const { return getOperand(0); }
1760 // get*Dest - Return the destination basic blocks...
1761 BasicBlock *getNormalDest() const {
1762 return cast<BasicBlock>(getOperand(1));
1764 BasicBlock *getUnwindDest() const {
1765 return cast<BasicBlock>(getOperand(2));
1767 void setNormalDest(BasicBlock *B) {
1768 setOperand(1, reinterpret_cast<Value*>(B));
1771 void setUnwindDest(BasicBlock *B) {
1772 setOperand(2, reinterpret_cast<Value*>(B));
1775 inline BasicBlock *getSuccessor(unsigned i) const {
1776 assert(i < 2 && "Successor # out of range for invoke!");
1777 return i == 0 ? getNormalDest() : getUnwindDest();
1780 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1781 assert(idx < 2 && "Successor # out of range for invoke!");
1782 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1785 unsigned getNumSuccessors() const { return 2; }
1787 // Methods for support type inquiry through isa, cast, and dyn_cast:
1788 static inline bool classof(const InvokeInst *) { return true; }
1789 static inline bool classof(const Instruction *I) {
1790 return (I->getOpcode() == Instruction::Invoke);
1792 static inline bool classof(const Value *V) {
1793 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1796 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1797 virtual unsigned getNumSuccessorsV() const;
1798 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1802 //===----------------------------------------------------------------------===//
1804 //===----------------------------------------------------------------------===//
1806 //===---------------------------------------------------------------------------
1807 /// UnwindInst - Immediately exit the current function, unwinding the stack
1808 /// until an invoke instruction is found.
1810 class UnwindInst : public TerminatorInst {
1812 explicit UnwindInst(Instruction *InsertBefore = 0);
1813 explicit UnwindInst(BasicBlock *InsertAtEnd);
1815 virtual UnwindInst *clone() const;
1817 unsigned getNumSuccessors() const { return 0; }
1819 // Methods for support type inquiry through isa, cast, and dyn_cast:
1820 static inline bool classof(const UnwindInst *) { return true; }
1821 static inline bool classof(const Instruction *I) {
1822 return I->getOpcode() == Instruction::Unwind;
1824 static inline bool classof(const Value *V) {
1825 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1828 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1829 virtual unsigned getNumSuccessorsV() const;
1830 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1833 //===----------------------------------------------------------------------===//
1834 // UnreachableInst Class
1835 //===----------------------------------------------------------------------===//
1837 //===---------------------------------------------------------------------------
1838 /// UnreachableInst - This function has undefined behavior. In particular, the
1839 /// presence of this instruction indicates some higher level knowledge that the
1840 /// end of the block cannot be reached.
1842 class UnreachableInst : public TerminatorInst {
1844 explicit UnreachableInst(Instruction *InsertBefore = 0);
1845 explicit UnreachableInst(BasicBlock *InsertAtEnd);
1847 virtual UnreachableInst *clone() const;
1849 unsigned getNumSuccessors() const { return 0; }
1851 // Methods for support type inquiry through isa, cast, and dyn_cast:
1852 static inline bool classof(const UnreachableInst *) { return true; }
1853 static inline bool classof(const Instruction *I) {
1854 return I->getOpcode() == Instruction::Unreachable;
1856 static inline bool classof(const Value *V) {
1857 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1860 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1861 virtual unsigned getNumSuccessorsV() const;
1862 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1865 //===----------------------------------------------------------------------===//
1867 //===----------------------------------------------------------------------===//
1869 /// @brief This class represents a truncation of integer types.
1870 class TruncInst : public CastInst {
1871 /// Private copy constructor
1872 TruncInst(const TruncInst &CI)
1873 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1876 /// @brief Constructor with insert-before-instruction semantics
1878 Value *S, ///< The value to be truncated
1879 const Type *Ty, ///< The (smaller) type to truncate to
1880 const std::string &Name = "", ///< A name for the new instruction
1881 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1884 /// @brief Constructor with insert-at-end-of-block semantics
1886 Value *S, ///< The value to be truncated
1887 const Type *Ty, ///< The (smaller) type to truncate to
1888 const std::string &Name, ///< A name for the new instruction
1889 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1892 /// @brief Clone an identical TruncInst
1893 virtual CastInst *clone() const;
1895 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1896 static inline bool classof(const TruncInst *) { return true; }
1897 static inline bool classof(const Instruction *I) {
1898 return I->getOpcode() == Trunc;
1900 static inline bool classof(const Value *V) {
1901 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1905 //===----------------------------------------------------------------------===//
1907 //===----------------------------------------------------------------------===//
1909 /// @brief This class represents zero extension of integer types.
1910 class ZExtInst : public CastInst {
1911 /// @brief Private copy constructor
1912 ZExtInst(const ZExtInst &CI)
1913 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1916 /// @brief Constructor with insert-before-instruction semantics
1918 Value *S, ///< The value to be zero extended
1919 const Type *Ty, ///< The type to zero extend to
1920 const std::string &Name = "", ///< A name for the new instruction
1921 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1924 /// @brief Constructor with insert-at-end semantics.
1926 Value *S, ///< The value to be zero extended
1927 const Type *Ty, ///< The type to zero extend to
1928 const std::string &Name, ///< A name for the new instruction
1929 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1932 /// @brief Clone an identical ZExtInst
1933 virtual CastInst *clone() const;
1935 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1936 static inline bool classof(const ZExtInst *) { return true; }
1937 static inline bool classof(const Instruction *I) {
1938 return I->getOpcode() == ZExt;
1940 static inline bool classof(const Value *V) {
1941 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1945 //===----------------------------------------------------------------------===//
1947 //===----------------------------------------------------------------------===//
1949 /// @brief This class represents a sign extension of integer types.
1950 class SExtInst : public CastInst {
1951 /// @brief Private copy constructor
1952 SExtInst(const SExtInst &CI)
1953 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1956 /// @brief Constructor with insert-before-instruction semantics
1958 Value *S, ///< The value to be sign extended
1959 const Type *Ty, ///< The type to sign extend to
1960 const std::string &Name = "", ///< A name for the new instruction
1961 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1964 /// @brief Constructor with insert-at-end-of-block semantics
1966 Value *S, ///< The value to be sign extended
1967 const Type *Ty, ///< The type to sign extend to
1968 const std::string &Name, ///< A name for the new instruction
1969 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1972 /// @brief Clone an identical SExtInst
1973 virtual CastInst *clone() const;
1975 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1976 static inline bool classof(const SExtInst *) { return true; }
1977 static inline bool classof(const Instruction *I) {
1978 return I->getOpcode() == SExt;
1980 static inline bool classof(const Value *V) {
1981 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1985 //===----------------------------------------------------------------------===//
1986 // FPTruncInst Class
1987 //===----------------------------------------------------------------------===//
1989 /// @brief This class represents a truncation of floating point types.
1990 class FPTruncInst : public CastInst {
1991 FPTruncInst(const FPTruncInst &CI)
1992 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1995 /// @brief Constructor with insert-before-instruction semantics
1997 Value *S, ///< The value to be truncated
1998 const Type *Ty, ///< The type to truncate to
1999 const std::string &Name = "", ///< A name for the new instruction
2000 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2003 /// @brief Constructor with insert-before-instruction semantics
2005 Value *S, ///< The value to be truncated
2006 const Type *Ty, ///< The type to truncate to
2007 const std::string &Name, ///< A name for the new instruction
2008 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2011 /// @brief Clone an identical FPTruncInst
2012 virtual CastInst *clone() const;
2014 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2015 static inline bool classof(const FPTruncInst *) { return true; }
2016 static inline bool classof(const Instruction *I) {
2017 return I->getOpcode() == FPTrunc;
2019 static inline bool classof(const Value *V) {
2020 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2024 //===----------------------------------------------------------------------===//
2026 //===----------------------------------------------------------------------===//
2028 /// @brief This class represents an extension of floating point types.
2029 class FPExtInst : public CastInst {
2030 FPExtInst(const FPExtInst &CI)
2031 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
2034 /// @brief Constructor with insert-before-instruction semantics
2036 Value *S, ///< The value to be extended
2037 const Type *Ty, ///< The type to extend to
2038 const std::string &Name = "", ///< A name for the new instruction
2039 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2042 /// @brief Constructor with insert-at-end-of-block semantics
2044 Value *S, ///< The value to be extended
2045 const Type *Ty, ///< The type to extend to
2046 const std::string &Name, ///< A name for the new instruction
2047 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2050 /// @brief Clone an identical FPExtInst
2051 virtual CastInst *clone() const;
2053 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2054 static inline bool classof(const FPExtInst *) { return true; }
2055 static inline bool classof(const Instruction *I) {
2056 return I->getOpcode() == FPExt;
2058 static inline bool classof(const Value *V) {
2059 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2063 //===----------------------------------------------------------------------===//
2065 //===----------------------------------------------------------------------===//
2067 /// @brief This class represents a cast unsigned integer to floating point.
2068 class UIToFPInst : public CastInst {
2069 UIToFPInst(const UIToFPInst &CI)
2070 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
2073 /// @brief Constructor with insert-before-instruction semantics
2075 Value *S, ///< The value to be converted
2076 const Type *Ty, ///< The type to convert to
2077 const std::string &Name = "", ///< A name for the new instruction
2078 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2081 /// @brief Constructor with insert-at-end-of-block semantics
2083 Value *S, ///< The value to be converted
2084 const Type *Ty, ///< The type to convert to
2085 const std::string &Name, ///< A name for the new instruction
2086 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2089 /// @brief Clone an identical UIToFPInst
2090 virtual CastInst *clone() const;
2092 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2093 static inline bool classof(const UIToFPInst *) { return true; }
2094 static inline bool classof(const Instruction *I) {
2095 return I->getOpcode() == UIToFP;
2097 static inline bool classof(const Value *V) {
2098 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2102 //===----------------------------------------------------------------------===//
2104 //===----------------------------------------------------------------------===//
2106 /// @brief This class represents a cast from signed integer to floating point.
2107 class SIToFPInst : public CastInst {
2108 SIToFPInst(const SIToFPInst &CI)
2109 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
2112 /// @brief Constructor with insert-before-instruction semantics
2114 Value *S, ///< The value to be converted
2115 const Type *Ty, ///< The type to convert to
2116 const std::string &Name = "", ///< A name for the new instruction
2117 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2120 /// @brief Constructor with insert-at-end-of-block semantics
2122 Value *S, ///< The value to be converted
2123 const Type *Ty, ///< The type to convert to
2124 const std::string &Name, ///< A name for the new instruction
2125 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2128 /// @brief Clone an identical SIToFPInst
2129 virtual CastInst *clone() const;
2131 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2132 static inline bool classof(const SIToFPInst *) { return true; }
2133 static inline bool classof(const Instruction *I) {
2134 return I->getOpcode() == SIToFP;
2136 static inline bool classof(const Value *V) {
2137 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2141 //===----------------------------------------------------------------------===//
2143 //===----------------------------------------------------------------------===//
2145 /// @brief This class represents a cast from floating point to unsigned integer
2146 class FPToUIInst : public CastInst {
2147 FPToUIInst(const FPToUIInst &CI)
2148 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
2151 /// @brief Constructor with insert-before-instruction semantics
2153 Value *S, ///< The value to be converted
2154 const Type *Ty, ///< The type to convert to
2155 const std::string &Name = "", ///< A name for the new instruction
2156 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2159 /// @brief Constructor with insert-at-end-of-block semantics
2161 Value *S, ///< The value to be converted
2162 const Type *Ty, ///< The type to convert to
2163 const std::string &Name, ///< A name for the new instruction
2164 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
2167 /// @brief Clone an identical FPToUIInst
2168 virtual CastInst *clone() const;
2170 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2171 static inline bool classof(const FPToUIInst *) { return true; }
2172 static inline bool classof(const Instruction *I) {
2173 return I->getOpcode() == FPToUI;
2175 static inline bool classof(const Value *V) {
2176 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2180 //===----------------------------------------------------------------------===//
2182 //===----------------------------------------------------------------------===//
2184 /// @brief This class represents a cast from floating point to signed integer.
2185 class FPToSIInst : public CastInst {
2186 FPToSIInst(const FPToSIInst &CI)
2187 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2190 /// @brief Constructor with insert-before-instruction semantics
2192 Value *S, ///< The value to be converted
2193 const Type *Ty, ///< The type to convert to
2194 const std::string &Name = "", ///< A name for the new instruction
2195 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2198 /// @brief Constructor with insert-at-end-of-block semantics
2200 Value *S, ///< The value to be converted
2201 const Type *Ty, ///< The type to convert to
2202 const std::string &Name, ///< A name for the new instruction
2203 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2206 /// @brief Clone an identical FPToSIInst
2207 virtual CastInst *clone() const;
2209 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2210 static inline bool classof(const FPToSIInst *) { return true; }
2211 static inline bool classof(const Instruction *I) {
2212 return I->getOpcode() == FPToSI;
2214 static inline bool classof(const Value *V) {
2215 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2219 //===----------------------------------------------------------------------===//
2220 // IntToPtrInst Class
2221 //===----------------------------------------------------------------------===//
2223 /// @brief This class represents a cast from an integer to a pointer.
2224 class IntToPtrInst : public CastInst {
2225 IntToPtrInst(const IntToPtrInst &CI)
2226 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2229 /// @brief Constructor with insert-before-instruction semantics
2231 Value *S, ///< The value to be converted
2232 const Type *Ty, ///< The type to convert to
2233 const std::string &Name = "", ///< A name for the new instruction
2234 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2237 /// @brief Constructor with insert-at-end-of-block semantics
2239 Value *S, ///< The value to be converted
2240 const Type *Ty, ///< The type to convert to
2241 const std::string &Name, ///< A name for the new instruction
2242 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2245 /// @brief Clone an identical IntToPtrInst
2246 virtual CastInst *clone() const;
2248 // Methods for support type inquiry through isa, cast, and dyn_cast:
2249 static inline bool classof(const IntToPtrInst *) { return true; }
2250 static inline bool classof(const Instruction *I) {
2251 return I->getOpcode() == IntToPtr;
2253 static inline bool classof(const Value *V) {
2254 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2258 //===----------------------------------------------------------------------===//
2259 // PtrToIntInst Class
2260 //===----------------------------------------------------------------------===//
2262 /// @brief This class represents a cast from a pointer to an integer
2263 class PtrToIntInst : public CastInst {
2264 PtrToIntInst(const PtrToIntInst &CI)
2265 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2268 /// @brief Constructor with insert-before-instruction semantics
2270 Value *S, ///< The value to be converted
2271 const Type *Ty, ///< The type to convert to
2272 const std::string &Name = "", ///< A name for the new instruction
2273 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2276 /// @brief Constructor with insert-at-end-of-block semantics
2278 Value *S, ///< The value to be converted
2279 const Type *Ty, ///< The type to convert to
2280 const std::string &Name, ///< A name for the new instruction
2281 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2284 /// @brief Clone an identical PtrToIntInst
2285 virtual CastInst *clone() const;
2287 // Methods for support type inquiry through isa, cast, and dyn_cast:
2288 static inline bool classof(const PtrToIntInst *) { return true; }
2289 static inline bool classof(const Instruction *I) {
2290 return I->getOpcode() == PtrToInt;
2292 static inline bool classof(const Value *V) {
2293 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2297 //===----------------------------------------------------------------------===//
2298 // BitCastInst Class
2299 //===----------------------------------------------------------------------===//
2301 /// @brief This class represents a no-op cast from one type to another.
2302 class BitCastInst : public CastInst {
2303 BitCastInst(const BitCastInst &CI)
2304 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2307 /// @brief Constructor with insert-before-instruction semantics
2309 Value *S, ///< The value to be casted
2310 const Type *Ty, ///< The type to casted to
2311 const std::string &Name = "", ///< A name for the new instruction
2312 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2315 /// @brief Constructor with insert-at-end-of-block semantics
2317 Value *S, ///< The value to be casted
2318 const Type *Ty, ///< The type to casted to
2319 const std::string &Name, ///< A name for the new instruction
2320 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2323 /// @brief Clone an identical BitCastInst
2324 virtual CastInst *clone() const;
2326 // Methods for support type inquiry through isa, cast, and dyn_cast:
2327 static inline bool classof(const BitCastInst *) { return true; }
2328 static inline bool classof(const Instruction *I) {
2329 return I->getOpcode() == BitCast;
2331 static inline bool classof(const Value *V) {
2332 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2336 } // End llvm namespace