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"
34 //===----------------------------------------------------------------------===//
35 // AllocationInst Class
36 //===----------------------------------------------------------------------===//
38 /// AllocationInst - This class is the common base class of MallocInst and
41 class AllocationInst : public UnaryInstruction {
44 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
45 const std::string &Name = "", Instruction *InsertBefore = 0);
46 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
47 const std::string &Name, BasicBlock *InsertAtEnd);
49 // Out of line virtual method, so the vtable, etc has a home.
50 virtual ~AllocationInst();
52 /// isArrayAllocation - Return true if there is an allocation size parameter
53 /// to the allocation instruction that is not 1.
55 bool isArrayAllocation() const;
57 /// getArraySize - Get the number of element allocated, for a simple
58 /// allocation of a single element, this will return a constant 1 value.
60 inline const Value *getArraySize() const { return getOperand(0); }
61 inline Value *getArraySize() { return getOperand(0); }
63 /// getType - Overload to return most specific pointer type
65 inline const PointerType *getType() const {
66 return reinterpret_cast<const PointerType*>(Instruction::getType());
69 /// getAllocatedType - Return the type that is being allocated by the
72 const Type *getAllocatedType() const;
74 /// getAlignment - Return the alignment of the memory that is being allocated
75 /// by the instruction.
77 unsigned getAlignment() const { return Alignment; }
78 void setAlignment(unsigned Align) {
79 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
83 virtual Instruction *clone() const = 0;
85 // Methods for support type inquiry through isa, cast, and dyn_cast:
86 static inline bool classof(const AllocationInst *) { return true; }
87 static inline bool classof(const Instruction *I) {
88 return I->getOpcode() == Instruction::Alloca ||
89 I->getOpcode() == Instruction::Malloc;
91 static inline bool classof(const Value *V) {
92 return isa<Instruction>(V) && classof(cast<Instruction>(V));
97 //===----------------------------------------------------------------------===//
99 //===----------------------------------------------------------------------===//
101 /// MallocInst - an instruction to allocated memory on the heap
103 class MallocInst : public AllocationInst {
104 MallocInst(const MallocInst &MI);
106 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
107 const std::string &Name = "",
108 Instruction *InsertBefore = 0)
109 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
110 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
111 BasicBlock *InsertAtEnd)
112 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
114 MallocInst(const Type *Ty, const std::string &Name,
115 Instruction *InsertBefore = 0)
116 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
117 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
118 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
120 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
121 const std::string &Name, BasicBlock *InsertAtEnd)
122 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
123 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
124 const std::string &Name = "",
125 Instruction *InsertBefore = 0)
126 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
128 virtual MallocInst *clone() const;
130 // Methods for support type inquiry through isa, cast, and dyn_cast:
131 static inline bool classof(const MallocInst *) { return true; }
132 static inline bool classof(const Instruction *I) {
133 return (I->getOpcode() == Instruction::Malloc);
135 static inline bool classof(const Value *V) {
136 return isa<Instruction>(V) && classof(cast<Instruction>(V));
141 //===----------------------------------------------------------------------===//
143 //===----------------------------------------------------------------------===//
145 /// AllocaInst - an instruction to allocate memory on the stack
147 class AllocaInst : public AllocationInst {
148 AllocaInst(const AllocaInst &);
150 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
151 const std::string &Name = "",
152 Instruction *InsertBefore = 0)
153 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
154 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
155 BasicBlock *InsertAtEnd)
156 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
158 AllocaInst(const Type *Ty, const std::string &Name,
159 Instruction *InsertBefore = 0)
160 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
161 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
162 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
164 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
165 const std::string &Name = "", Instruction *InsertBefore = 0)
166 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
167 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
168 const std::string &Name, BasicBlock *InsertAtEnd)
169 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
171 virtual AllocaInst *clone() const;
173 // Methods for support type inquiry through isa, cast, and dyn_cast:
174 static inline bool classof(const AllocaInst *) { return true; }
175 static inline bool classof(const Instruction *I) {
176 return (I->getOpcode() == Instruction::Alloca);
178 static inline bool classof(const Value *V) {
179 return isa<Instruction>(V) && classof(cast<Instruction>(V));
184 //===----------------------------------------------------------------------===//
186 //===----------------------------------------------------------------------===//
188 /// FreeInst - an instruction to deallocate memory
190 class FreeInst : public UnaryInstruction {
193 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
194 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
196 virtual FreeInst *clone() const;
198 // Accessor methods for consistency with other memory operations
199 Value *getPointerOperand() { return getOperand(0); }
200 const Value *getPointerOperand() const { return getOperand(0); }
202 // Methods for support type inquiry through isa, cast, and dyn_cast:
203 static inline bool classof(const FreeInst *) { return true; }
204 static inline bool classof(const Instruction *I) {
205 return (I->getOpcode() == Instruction::Free);
207 static inline bool classof(const Value *V) {
208 return isa<Instruction>(V) && classof(cast<Instruction>(V));
213 //===----------------------------------------------------------------------===//
215 //===----------------------------------------------------------------------===//
217 /// LoadInst - an instruction for reading from memory. This uses the
218 /// SubclassData field in Value to store whether or not the load is volatile.
220 class LoadInst : public UnaryInstruction {
222 LoadInst(const LoadInst &LI)
223 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
224 setVolatile(LI.isVolatile());
225 setAlignment(LI.getAlignment());
233 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
234 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
235 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false,
236 Instruction *InsertBefore = 0);
237 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
238 Instruction *InsertBefore = 0);
239 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
240 BasicBlock *InsertAtEnd);
241 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
242 BasicBlock *InsertAtEnd);
244 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
245 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
246 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
247 Instruction *InsertBefore = 0);
248 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
249 BasicBlock *InsertAtEnd);
251 /// isVolatile - Return true if this is a load from a volatile memory
254 bool isVolatile() const { return SubclassData & 1; }
256 /// setVolatile - Specify whether this is a volatile load or not.
258 void setVolatile(bool V) {
259 SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
262 virtual LoadInst *clone() const;
264 /// getAlignment - Return the alignment of the access that is being performed
266 unsigned getAlignment() const {
267 return (1 << (SubclassData>>1)) >> 1;
270 void setAlignment(unsigned Align);
272 Value *getPointerOperand() { return getOperand(0); }
273 const Value *getPointerOperand() const { return getOperand(0); }
274 static unsigned getPointerOperandIndex() { return 0U; }
276 // Methods for support type inquiry through isa, cast, and dyn_cast:
277 static inline bool classof(const LoadInst *) { return true; }
278 static inline bool classof(const Instruction *I) {
279 return I->getOpcode() == Instruction::Load;
281 static inline bool classof(const Value *V) {
282 return isa<Instruction>(V) && classof(cast<Instruction>(V));
287 //===----------------------------------------------------------------------===//
289 //===----------------------------------------------------------------------===//
291 /// StoreInst - an instruction for storing to memory
293 class StoreInst : public Instruction {
296 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
297 Ops[0].init(SI.Ops[0], this);
298 Ops[1].init(SI.Ops[1], this);
299 setVolatile(SI.isVolatile());
300 setAlignment(SI.getAlignment());
308 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
309 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
310 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
311 Instruction *InsertBefore = 0);
312 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
313 unsigned Align, Instruction *InsertBefore = 0);
314 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
315 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
316 unsigned Align, BasicBlock *InsertAtEnd);
319 /// isVolatile - Return true if this is a load from a volatile memory
322 bool isVolatile() const { return SubclassData & 1; }
324 /// setVolatile - Specify whether this is a volatile load or not.
326 void setVolatile(bool V) {
327 SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
330 /// Transparently provide more efficient getOperand methods.
331 Value *getOperand(unsigned i) const {
332 assert(i < 2 && "getOperand() out of range!");
335 void setOperand(unsigned i, Value *Val) {
336 assert(i < 2 && "setOperand() out of range!");
339 unsigned getNumOperands() const { return 2; }
341 /// getAlignment - Return the alignment of the access that is being performed
343 unsigned getAlignment() const {
344 return (1 << (SubclassData>>1)) >> 1;
347 void setAlignment(unsigned Align);
349 virtual StoreInst *clone() const;
351 Value *getPointerOperand() { return getOperand(1); }
352 const Value *getPointerOperand() const { return getOperand(1); }
353 static unsigned getPointerOperandIndex() { return 1U; }
355 // Methods for support type inquiry through isa, cast, and dyn_cast:
356 static inline bool classof(const StoreInst *) { return true; }
357 static inline bool classof(const Instruction *I) {
358 return I->getOpcode() == Instruction::Store;
360 static inline bool classof(const Value *V) {
361 return isa<Instruction>(V) && classof(cast<Instruction>(V));
366 //===----------------------------------------------------------------------===//
367 // GetElementPtrInst Class
368 //===----------------------------------------------------------------------===//
370 // checkType - Simple wrapper function to give a better assertion failure
371 // message on bad indexes for a gep instruction.
373 static inline const Type *checkType(const Type *Ty) {
374 assert(Ty && "Invalid GetElementPtrInst indices for type!");
378 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
379 /// access elements of arrays and structs
381 class GetElementPtrInst : public Instruction {
382 GetElementPtrInst(const GetElementPtrInst &GEPI)
383 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
384 0, GEPI.getNumOperands()) {
385 Use *OL = OperandList = new Use[NumOperands];
386 Use *GEPIOL = GEPI.OperandList;
387 for (unsigned i = 0, E = NumOperands; i != E; ++i)
388 OL[i].init(GEPIOL[i], this);
390 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
391 void init(Value *Ptr, Value *Idx);
393 template<typename InputIterator>
394 void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
395 const std::string &Name,
396 // This argument ensures that we have an iterator we can
397 // do arithmetic on in constant time
398 std::random_access_iterator_tag) {
399 typename std::iterator_traits<InputIterator>::difference_type NumIdx =
400 std::distance(IdxBegin, IdxEnd);
403 // This requires that the itoerator points to contiguous memory.
404 init(Ptr, &*IdxBegin, NumIdx);
407 init(Ptr, 0, NumIdx);
413 /// getIndexedType - Returns the type of the element that would be loaded with
414 /// a load instruction with the specified parameters.
416 /// A null type is returned if the indices are invalid for the specified
419 static const Type *getIndexedType(const Type *Ptr,
420 Value* const *Idx, unsigned NumIdx,
421 bool AllowStructLeaf = false);
423 template<typename InputIterator>
424 static const Type *getIndexedType(const Type *Ptr,
425 InputIterator IdxBegin,
426 InputIterator IdxEnd,
427 bool AllowStructLeaf,
428 // This argument ensures that we
429 // have an iterator we can do
430 // arithmetic on in constant time
431 std::random_access_iterator_tag) {
432 typename std::iterator_traits<InputIterator>::difference_type NumIdx =
433 std::distance(IdxBegin, IdxEnd);
436 // This requires that the iterator points to contiguous memory.
437 return(getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx,
441 return(getIndexedType(Ptr, (Value *const*)0, NumIdx, AllowStructLeaf));
446 /// Constructors - Create a getelementptr instruction with a base pointer an
447 /// list of indices. The first ctor can optionally insert before an existing
448 /// instruction, the second appends the new instruction to the specified
450 template<typename InputIterator>
451 GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
452 InputIterator IdxEnd,
453 const std::string &Name = "",
454 Instruction *InsertBefore =0)
455 : Instruction(PointerType::get(
456 checkType(getIndexedType(Ptr->getType(),
457 IdxBegin, IdxEnd, true))),
458 GetElementPtr, 0, 0, InsertBefore) {
459 init(Ptr, IdxBegin, IdxEnd, Name,
460 typename std::iterator_traits<InputIterator>::iterator_category());
462 template<typename InputIterator>
463 GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
464 const std::string &Name, BasicBlock *InsertAtEnd)
465 : Instruction(PointerType::get(
466 checkType(getIndexedType(Ptr->getType(),
467 IdxBegin, IdxEnd, true))),
468 GetElementPtr, 0, 0, InsertAtEnd) {
469 init(Ptr, IdxBegin, IdxEnd, Name,
470 typename std::iterator_traits<InputIterator>::iterator_category());
473 /// Constructors - These two constructors are convenience methods because one
474 /// and two index getelementptr instructions are so common.
475 GetElementPtrInst(Value *Ptr, Value *Idx,
476 const std::string &Name = "", Instruction *InsertBefore =0);
477 GetElementPtrInst(Value *Ptr, Value *Idx,
478 const std::string &Name, BasicBlock *InsertAtEnd);
479 ~GetElementPtrInst();
481 virtual GetElementPtrInst *clone() const;
483 // getType - Overload to return most specific pointer type...
484 inline const PointerType *getType() const {
485 return reinterpret_cast<const PointerType*>(Instruction::getType());
488 /// getIndexedType - Returns the type of the element that would be loaded with
489 /// a load instruction with the specified parameters.
491 /// A null type is returned if the indices are invalid for the specified
494 template<typename InputIterator>
495 static const Type *getIndexedType(const Type *Ptr,
496 InputIterator IdxBegin,
497 InputIterator IdxEnd,
498 bool AllowStructLeaf = false) {
499 return(getIndexedType(Ptr, IdxBegin, IdxEnd, AllowStructLeaf,
500 typename std::iterator_traits<InputIterator>::
501 iterator_category()));
503 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
505 inline op_iterator idx_begin() { return op_begin()+1; }
506 inline const_op_iterator idx_begin() const { return op_begin()+1; }
507 inline op_iterator idx_end() { return op_end(); }
508 inline const_op_iterator idx_end() const { return op_end(); }
510 Value *getPointerOperand() {
511 return getOperand(0);
513 const Value *getPointerOperand() const {
514 return getOperand(0);
516 static unsigned getPointerOperandIndex() {
517 return 0U; // get index for modifying correct operand
520 inline unsigned getNumIndices() const { // Note: always non-negative
521 return getNumOperands() - 1;
524 inline bool hasIndices() const {
525 return getNumOperands() > 1;
528 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
529 /// zeros. If so, the result pointer and the first operand have the same
530 /// value, just potentially different types.
531 bool hasAllZeroIndices() const;
533 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
534 /// constant integers. If so, the result pointer and the first operand have
535 /// a constant offset between them.
536 bool hasAllConstantIndices() const;
539 // Methods for support type inquiry through isa, cast, and dyn_cast:
540 static inline bool classof(const GetElementPtrInst *) { return true; }
541 static inline bool classof(const Instruction *I) {
542 return (I->getOpcode() == Instruction::GetElementPtr);
544 static inline bool classof(const Value *V) {
545 return isa<Instruction>(V) && classof(cast<Instruction>(V));
549 //===----------------------------------------------------------------------===//
551 //===----------------------------------------------------------------------===//
553 /// This instruction compares its operands according to the predicate given
554 /// to the constructor. It only operates on integers, pointers, or packed
555 /// vectors of integrals. The two operands must be the same type.
556 /// @brief Represent an integer comparison operator.
557 class ICmpInst: public CmpInst {
559 /// This enumeration lists the possible predicates for the ICmpInst. The
560 /// values in the range 0-31 are reserved for FCmpInst while values in the
561 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
562 /// predicate values are not overlapping between the classes.
564 ICMP_EQ = 32, ///< equal
565 ICMP_NE = 33, ///< not equal
566 ICMP_UGT = 34, ///< unsigned greater than
567 ICMP_UGE = 35, ///< unsigned greater or equal
568 ICMP_ULT = 36, ///< unsigned less than
569 ICMP_ULE = 37, ///< unsigned less or equal
570 ICMP_SGT = 38, ///< signed greater than
571 ICMP_SGE = 39, ///< signed greater or equal
572 ICMP_SLT = 40, ///< signed less than
573 ICMP_SLE = 41, ///< signed less or equal
574 FIRST_ICMP_PREDICATE = ICMP_EQ,
575 LAST_ICMP_PREDICATE = ICMP_SLE,
576 BAD_ICMP_PREDICATE = ICMP_SLE + 1
579 /// @brief Constructor with insert-before-instruction semantics.
581 Predicate pred, ///< The predicate to use for the comparison
582 Value *LHS, ///< The left-hand-side of the expression
583 Value *RHS, ///< The right-hand-side of the expression
584 const std::string &Name = "", ///< Name of the instruction
585 Instruction *InsertBefore = 0 ///< Where to insert
586 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
589 /// @brief Constructor with insert-at-block-end semantics.
591 Predicate pred, ///< The predicate to use for the comparison
592 Value *LHS, ///< The left-hand-side of the expression
593 Value *RHS, ///< The right-hand-side of the expression
594 const std::string &Name, ///< Name of the instruction
595 BasicBlock *InsertAtEnd ///< Block to insert into.
596 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
599 /// @brief Return the predicate for this instruction.
600 Predicate getPredicate() const { return Predicate(SubclassData); }
602 /// @brief Set the predicate for this instruction to the specified value.
603 void setPredicate(Predicate P) { SubclassData = P; }
605 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
606 /// @returns the inverse predicate for the instruction's current predicate.
607 /// @brief Return the inverse of the instruction's predicate.
608 Predicate getInversePredicate() const {
609 return getInversePredicate(getPredicate());
612 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
613 /// @returns the inverse predicate for predicate provided in \p pred.
614 /// @brief Return the inverse of a given predicate
615 static Predicate getInversePredicate(Predicate pred);
617 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
618 /// @returns the predicate that would be the result of exchanging the two
619 /// operands of the ICmpInst instruction without changing the result
621 /// @brief Return the predicate as if the operands were swapped
622 Predicate getSwappedPredicate() const {
623 return getSwappedPredicate(getPredicate());
626 /// This is a static version that you can use without an instruction
628 /// @brief Return the predicate as if the operands were swapped.
629 static Predicate getSwappedPredicate(Predicate pred);
631 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
632 /// @returns the predicate that would be the result if the operand were
633 /// regarded as signed.
634 /// @brief Return the signed version of the predicate
635 Predicate getSignedPredicate() const {
636 return getSignedPredicate(getPredicate());
639 /// This is a static version that you can use without an instruction.
640 /// @brief Return the signed version of the predicate.
641 static Predicate getSignedPredicate(Predicate pred);
643 /// isEquality - Return true if this predicate is either EQ or NE. This also
644 /// tests for commutativity.
645 static bool isEquality(Predicate P) {
646 return P == ICMP_EQ || P == ICMP_NE;
649 /// isEquality - Return true if this predicate is either EQ or NE. This also
650 /// tests for commutativity.
651 bool isEquality() const {
652 return isEquality(getPredicate());
655 /// @returns true if the predicate of this ICmpInst is commutative
656 /// @brief Determine if this relation is commutative.
657 bool isCommutative() const { return isEquality(); }
659 /// isRelational - Return true if the predicate is relational (not EQ or NE).
661 bool isRelational() const {
662 return !isEquality();
665 /// isRelational - Return true if the predicate is relational (not EQ or NE).
667 static bool isRelational(Predicate P) {
668 return !isEquality(P);
671 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
672 /// @brief Determine if this instruction's predicate is signed.
673 bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); }
675 /// @returns true if the predicate provided is signed, false otherwise
676 /// @brief Determine if the predicate is signed.
677 static bool isSignedPredicate(Predicate pred);
679 /// Initialize a set of values that all satisfy the predicate with C.
680 /// @brief Make a ConstantRange for a relation with a constant value.
681 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
683 /// Exchange the two operands to this instruction in such a way that it does
684 /// not modify the semantics of the instruction. The predicate value may be
685 /// changed to retain the same result if the predicate is order dependent
687 /// @brief Swap operands and adjust predicate.
688 void swapOperands() {
689 SubclassData = getSwappedPredicate();
690 std::swap(Ops[0], Ops[1]);
693 virtual ICmpInst *clone() const;
695 // Methods for support type inquiry through isa, cast, and dyn_cast:
696 static inline bool classof(const ICmpInst *) { return true; }
697 static inline bool classof(const Instruction *I) {
698 return I->getOpcode() == Instruction::ICmp;
700 static inline bool classof(const Value *V) {
701 return isa<Instruction>(V) && classof(cast<Instruction>(V));
705 //===----------------------------------------------------------------------===//
707 //===----------------------------------------------------------------------===//
709 /// This instruction compares its operands according to the predicate given
710 /// to the constructor. It only operates on floating point values or packed
711 /// vectors of floating point values. The operands must be identical types.
712 /// @brief Represents a floating point comparison operator.
713 class FCmpInst: public CmpInst {
715 /// This enumeration lists the possible predicates for the FCmpInst. Values
716 /// in the range 0-31 are reserved for FCmpInst.
718 // Opcode U L G E Intuitive operation
719 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
720 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
721 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
722 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
723 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
724 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
725 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
726 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
727 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
728 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
729 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
730 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
731 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
732 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
733 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
734 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
735 FIRST_FCMP_PREDICATE = FCMP_FALSE,
736 LAST_FCMP_PREDICATE = FCMP_TRUE,
737 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
740 /// @brief Constructor with insert-before-instruction semantics.
742 Predicate pred, ///< The predicate to use for the comparison
743 Value *LHS, ///< The left-hand-side of the expression
744 Value *RHS, ///< The right-hand-side of the expression
745 const std::string &Name = "", ///< Name of the instruction
746 Instruction *InsertBefore = 0 ///< Where to insert
747 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
750 /// @brief Constructor with insert-at-block-end semantics.
752 Predicate pred, ///< The predicate to use for the comparison
753 Value *LHS, ///< The left-hand-side of the expression
754 Value *RHS, ///< The right-hand-side of the expression
755 const std::string &Name, ///< Name of the instruction
756 BasicBlock *InsertAtEnd ///< Block to insert into.
757 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
760 /// @brief Return the predicate for this instruction.
761 Predicate getPredicate() const { return Predicate(SubclassData); }
763 /// @brief Set the predicate for this instruction to the specified value.
764 void setPredicate(Predicate P) { SubclassData = P; }
766 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
767 /// @returns the inverse predicate for the instructions current predicate.
768 /// @brief Return the inverse of the predicate
769 Predicate getInversePredicate() const {
770 return getInversePredicate(getPredicate());
773 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
774 /// @returns the inverse predicate for \p pred.
775 /// @brief Return the inverse of a given predicate
776 static Predicate getInversePredicate(Predicate pred);
778 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
779 /// @returns the predicate that would be the result of exchanging the two
780 /// operands of the ICmpInst instruction without changing the result
782 /// @brief Return the predicate as if the operands were swapped
783 Predicate getSwappedPredicate() const {
784 return getSwappedPredicate(getPredicate());
787 /// This is a static version that you can use without an instruction
789 /// @brief Return the predicate as if the operands were swapped.
790 static Predicate getSwappedPredicate(Predicate Opcode);
792 /// This also tests for commutativity. If isEquality() returns true then
793 /// the predicate is also commutative. Only the equality predicates are
795 /// @returns true if the predicate of this instruction is EQ or NE.
796 /// @brief Determine if this is an equality predicate.
797 bool isEquality() const {
798 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
799 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
801 bool isCommutative() const { return isEquality(); }
803 /// @returns true if the predicate is relational (not EQ or NE).
804 /// @brief Determine if this a relational predicate.
805 bool isRelational() const { return !isEquality(); }
807 /// Exchange the two operands to this instruction in such a way that it does
808 /// not modify the semantics of the instruction. The predicate value may be
809 /// changed to retain the same result if the predicate is order dependent
811 /// @brief Swap operands and adjust predicate.
812 void swapOperands() {
813 SubclassData = getSwappedPredicate();
814 std::swap(Ops[0], Ops[1]);
817 virtual FCmpInst *clone() const;
819 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
820 static inline bool classof(const FCmpInst *) { return true; }
821 static inline bool classof(const Instruction *I) {
822 return I->getOpcode() == Instruction::FCmp;
824 static inline bool classof(const Value *V) {
825 return isa<Instruction>(V) && classof(cast<Instruction>(V));
829 //===----------------------------------------------------------------------===//
831 //===----------------------------------------------------------------------===//
832 /// CallInst - This class represents a function call, abstracting a target
833 /// machine's calling convention. This class uses low bit of the SubClassData
834 /// field to indicate whether or not this is a tail call. The rest of the bits
835 /// hold the calling convention of the call.
838 class CallInst : public Instruction {
839 ParamAttrsList *ParamAttrs; ///< parameter attributes for call
840 CallInst(const CallInst &CI);
841 void init(Value *Func, Value* const *Params, unsigned NumParams);
842 void init(Value *Func, Value *Actual1, Value *Actual2);
843 void init(Value *Func, Value *Actual);
844 void init(Value *Func);
846 template<typename InputIterator>
847 void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
848 const std::string &Name,
849 // This argument ensures that we have an iterator we can
850 // do arithmetic on in constant time
851 std::random_access_iterator_tag) {
852 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
854 // This requires that the iterator points to contiguous memory.
855 init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
860 /// Construct a CallInst given a range of arguments. InputIterator
861 /// must be a random-access iterator pointing to contiguous storage
862 /// (e.g. a std::vector<>::iterator). Checks are made for
863 /// random-accessness but not for contiguous storage as that would
864 /// incur runtime overhead.
865 /// @brief Construct a CallInst from a range of arguments
866 template<typename InputIterator>
867 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
868 const std::string &Name = "", Instruction *InsertBefore = 0)
869 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
870 ->getElementType())->getReturnType(),
871 Instruction::Call, 0, 0, InsertBefore) {
872 init(Func, ArgBegin, ArgEnd, Name,
873 typename std::iterator_traits<InputIterator>::iterator_category());
876 /// Construct a CallInst given a range of arguments. InputIterator
877 /// must be a random-access iterator pointing to contiguous storage
878 /// (e.g. a std::vector<>::iterator). Checks are made for
879 /// random-accessness but not for contiguous storage as that would
880 /// incur runtime overhead.
881 /// @brief Construct a CallInst from a range of arguments
882 template<typename InputIterator>
883 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
884 const std::string &Name, BasicBlock *InsertAtEnd)
885 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
886 ->getElementType())->getReturnType(),
887 Instruction::Call, 0, 0, InsertAtEnd) {
888 init(Func, ArgBegin, ArgEnd, Name,
889 typename std::iterator_traits<InputIterator>::iterator_category());
892 CallInst(Value *F, Value *Actual, const std::string& Name = "",
893 Instruction *InsertBefore = 0);
894 CallInst(Value *F, Value *Actual, const std::string& Name,
895 BasicBlock *InsertAtEnd);
896 explicit CallInst(Value *F, const std::string &Name = "",
897 Instruction *InsertBefore = 0);
898 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
901 virtual CallInst *clone() const;
903 bool isTailCall() const { return SubclassData & 1; }
904 void setTailCall(bool isTailCall = true) {
905 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
908 /// getCallingConv/setCallingConv - Get or set the calling convention of this
910 unsigned getCallingConv() const { return SubclassData >> 1; }
911 void setCallingConv(unsigned CC) {
912 SubclassData = (SubclassData & 1) | (CC << 1);
915 /// Obtains a pointer to the ParamAttrsList object which holds the
916 /// parameter attributes information, if any.
917 /// @returns 0 if no attributes have been set.
918 /// @brief Get the parameter attributes.
919 ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
921 /// Sets the parameter attributes for this CallInst. To construct a
922 /// ParamAttrsList, see ParameterAttributes.h
923 /// @brief Set the parameter attributes.
924 void setParamAttrs(ParamAttrsList *attrs);
926 /// getCalledFunction - Return the function being called by this instruction
927 /// if it is a direct call. If it is a call through a function pointer,
929 Function *getCalledFunction() const {
930 return dyn_cast<Function>(getOperand(0));
933 /// getCalledValue - Get a pointer to the function that is invoked by this
935 inline const Value *getCalledValue() const { return getOperand(0); }
936 inline Value *getCalledValue() { return getOperand(0); }
938 // Methods for support type inquiry through isa, cast, and dyn_cast:
939 static inline bool classof(const CallInst *) { return true; }
940 static inline bool classof(const Instruction *I) {
941 return I->getOpcode() == Instruction::Call;
943 static inline bool classof(const Value *V) {
944 return isa<Instruction>(V) && classof(cast<Instruction>(V));
948 //===----------------------------------------------------------------------===//
950 //===----------------------------------------------------------------------===//
952 /// SelectInst - This class represents the LLVM 'select' instruction.
954 class SelectInst : public Instruction {
957 void init(Value *C, Value *S1, Value *S2) {
958 Ops[0].init(C, this);
959 Ops[1].init(S1, this);
960 Ops[2].init(S2, this);
963 SelectInst(const SelectInst &SI)
964 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
965 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
968 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
969 Instruction *InsertBefore = 0)
970 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
974 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
975 BasicBlock *InsertAtEnd)
976 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
981 Value *getCondition() const { return Ops[0]; }
982 Value *getTrueValue() const { return Ops[1]; }
983 Value *getFalseValue() const { return Ops[2]; }
985 /// Transparently provide more efficient getOperand methods.
986 Value *getOperand(unsigned i) const {
987 assert(i < 3 && "getOperand() out of range!");
990 void setOperand(unsigned i, Value *Val) {
991 assert(i < 3 && "setOperand() out of range!");
994 unsigned getNumOperands() const { return 3; }
996 OtherOps getOpcode() const {
997 return static_cast<OtherOps>(Instruction::getOpcode());
1000 virtual SelectInst *clone() const;
1002 // Methods for support type inquiry through isa, cast, and dyn_cast:
1003 static inline bool classof(const SelectInst *) { return true; }
1004 static inline bool classof(const Instruction *I) {
1005 return I->getOpcode() == Instruction::Select;
1007 static inline bool classof(const Value *V) {
1008 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1012 //===----------------------------------------------------------------------===//
1014 //===----------------------------------------------------------------------===//
1016 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1017 /// an argument of the specified type given a va_list and increments that list
1019 class VAArgInst : public UnaryInstruction {
1020 VAArgInst(const VAArgInst &VAA)
1021 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
1023 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
1024 Instruction *InsertBefore = 0)
1025 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1028 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
1029 BasicBlock *InsertAtEnd)
1030 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1034 virtual VAArgInst *clone() const;
1036 // Methods for support type inquiry through isa, cast, and dyn_cast:
1037 static inline bool classof(const VAArgInst *) { return true; }
1038 static inline bool classof(const Instruction *I) {
1039 return I->getOpcode() == VAArg;
1041 static inline bool classof(const Value *V) {
1042 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1046 //===----------------------------------------------------------------------===//
1047 // ExtractElementInst Class
1048 //===----------------------------------------------------------------------===//
1050 /// ExtractElementInst - This instruction extracts a single (scalar)
1051 /// element from a VectorType value
1053 class ExtractElementInst : public Instruction {
1055 ExtractElementInst(const ExtractElementInst &EE) :
1056 Instruction(EE.getType(), ExtractElement, Ops, 2) {
1057 Ops[0].init(EE.Ops[0], this);
1058 Ops[1].init(EE.Ops[1], this);
1062 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
1063 Instruction *InsertBefore = 0);
1064 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
1065 Instruction *InsertBefore = 0);
1066 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
1067 BasicBlock *InsertAtEnd);
1068 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
1069 BasicBlock *InsertAtEnd);
1071 /// isValidOperands - Return true if an extractelement instruction can be
1072 /// formed with the specified operands.
1073 static bool isValidOperands(const Value *Vec, const Value *Idx);
1075 virtual ExtractElementInst *clone() const;
1077 /// Transparently provide more efficient getOperand methods.
1078 Value *getOperand(unsigned i) const {
1079 assert(i < 2 && "getOperand() out of range!");
1082 void setOperand(unsigned i, Value *Val) {
1083 assert(i < 2 && "setOperand() out of range!");
1086 unsigned getNumOperands() const { return 2; }
1088 // Methods for support type inquiry through isa, cast, and dyn_cast:
1089 static inline bool classof(const ExtractElementInst *) { return true; }
1090 static inline bool classof(const Instruction *I) {
1091 return I->getOpcode() == Instruction::ExtractElement;
1093 static inline bool classof(const Value *V) {
1094 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1098 //===----------------------------------------------------------------------===//
1099 // InsertElementInst Class
1100 //===----------------------------------------------------------------------===//
1102 /// InsertElementInst - This instruction inserts a single (scalar)
1103 /// element into a VectorType value
1105 class InsertElementInst : public Instruction {
1107 InsertElementInst(const InsertElementInst &IE);
1109 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1110 const std::string &Name = "",Instruction *InsertBefore = 0);
1111 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1112 const std::string &Name = "",Instruction *InsertBefore = 0);
1113 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1114 const std::string &Name, BasicBlock *InsertAtEnd);
1115 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1116 const std::string &Name, BasicBlock *InsertAtEnd);
1118 /// isValidOperands - Return true if an insertelement instruction can be
1119 /// formed with the specified operands.
1120 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1123 virtual InsertElementInst *clone() const;
1125 /// getType - Overload to return most specific vector type.
1127 inline const VectorType *getType() const {
1128 return reinterpret_cast<const VectorType*>(Instruction::getType());
1131 /// Transparently provide more efficient getOperand methods.
1132 Value *getOperand(unsigned i) const {
1133 assert(i < 3 && "getOperand() out of range!");
1136 void setOperand(unsigned i, Value *Val) {
1137 assert(i < 3 && "setOperand() out of range!");
1140 unsigned getNumOperands() const { return 3; }
1142 // Methods for support type inquiry through isa, cast, and dyn_cast:
1143 static inline bool classof(const InsertElementInst *) { return true; }
1144 static inline bool classof(const Instruction *I) {
1145 return I->getOpcode() == Instruction::InsertElement;
1147 static inline bool classof(const Value *V) {
1148 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1152 //===----------------------------------------------------------------------===//
1153 // ShuffleVectorInst Class
1154 //===----------------------------------------------------------------------===//
1156 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1159 class ShuffleVectorInst : public Instruction {
1161 ShuffleVectorInst(const ShuffleVectorInst &IE);
1163 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1164 const std::string &Name = "", Instruction *InsertBefor = 0);
1165 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1166 const std::string &Name, BasicBlock *InsertAtEnd);
1168 /// isValidOperands - Return true if a shufflevector instruction can be
1169 /// formed with the specified operands.
1170 static bool isValidOperands(const Value *V1, const Value *V2,
1173 virtual ShuffleVectorInst *clone() const;
1175 /// getType - Overload to return most specific vector type.
1177 inline const VectorType *getType() const {
1178 return reinterpret_cast<const VectorType*>(Instruction::getType());
1181 /// Transparently provide more efficient getOperand methods.
1182 Value *getOperand(unsigned i) const {
1183 assert(i < 3 && "getOperand() out of range!");
1186 void setOperand(unsigned i, Value *Val) {
1187 assert(i < 3 && "setOperand() out of range!");
1190 unsigned getNumOperands() const { return 3; }
1192 // Methods for support type inquiry through isa, cast, and dyn_cast:
1193 static inline bool classof(const ShuffleVectorInst *) { return true; }
1194 static inline bool classof(const Instruction *I) {
1195 return I->getOpcode() == Instruction::ShuffleVector;
1197 static inline bool classof(const Value *V) {
1198 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1203 //===----------------------------------------------------------------------===//
1205 //===----------------------------------------------------------------------===//
1207 // PHINode - The PHINode class is used to represent the magical mystical PHI
1208 // node, that can not exist in nature, but can be synthesized in a computer
1209 // scientist's overactive imagination.
1211 class PHINode : public Instruction {
1212 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1213 /// the number actually in use.
1214 unsigned ReservedSpace;
1215 PHINode(const PHINode &PN);
1217 explicit PHINode(const Type *Ty, const std::string &Name = "",
1218 Instruction *InsertBefore = 0)
1219 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1224 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1225 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1232 /// reserveOperandSpace - This method can be used to avoid repeated
1233 /// reallocation of PHI operand lists by reserving space for the correct
1234 /// number of operands before adding them. Unlike normal vector reserves,
1235 /// this method can also be used to trim the operand space.
1236 void reserveOperandSpace(unsigned NumValues) {
1237 resizeOperands(NumValues*2);
1240 virtual PHINode *clone() const;
1242 /// getNumIncomingValues - Return the number of incoming edges
1244 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1246 /// getIncomingValue - Return incoming value number x
1248 Value *getIncomingValue(unsigned i) const {
1249 assert(i*2 < getNumOperands() && "Invalid value number!");
1250 return getOperand(i*2);
1252 void setIncomingValue(unsigned i, Value *V) {
1253 assert(i*2 < getNumOperands() && "Invalid value number!");
1256 unsigned getOperandNumForIncomingValue(unsigned i) {
1260 /// getIncomingBlock - Return incoming basic block number x
1262 BasicBlock *getIncomingBlock(unsigned i) const {
1263 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1265 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1266 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1268 unsigned getOperandNumForIncomingBlock(unsigned i) {
1272 /// addIncoming - Add an incoming value to the end of the PHI list
1274 void addIncoming(Value *V, BasicBlock *BB) {
1275 assert(getType() == V->getType() &&
1276 "All operands to PHI node must be the same type as the PHI node!");
1277 unsigned OpNo = NumOperands;
1278 if (OpNo+2 > ReservedSpace)
1279 resizeOperands(0); // Get more space!
1280 // Initialize some new operands.
1281 NumOperands = OpNo+2;
1282 OperandList[OpNo].init(V, this);
1283 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1286 /// removeIncomingValue - Remove an incoming value. This is useful if a
1287 /// predecessor basic block is deleted. The value removed is returned.
1289 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1290 /// is true), the PHI node is destroyed and any uses of it are replaced with
1291 /// dummy values. The only time there should be zero incoming values to a PHI
1292 /// node is when the block is dead, so this strategy is sound.
1294 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1296 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1297 int Idx = getBasicBlockIndex(BB);
1298 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1299 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1302 /// getBasicBlockIndex - Return the first index of the specified basic
1303 /// block in the value list for this PHI. Returns -1 if no instance.
1305 int getBasicBlockIndex(const BasicBlock *BB) const {
1306 Use *OL = OperandList;
1307 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1308 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1312 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1313 return getIncomingValue(getBasicBlockIndex(BB));
1316 /// hasConstantValue - If the specified PHI node always merges together the
1317 /// same value, return the value, otherwise return null.
1319 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1321 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1322 static inline bool classof(const PHINode *) { return true; }
1323 static inline bool classof(const Instruction *I) {
1324 return I->getOpcode() == Instruction::PHI;
1326 static inline bool classof(const Value *V) {
1327 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1330 void resizeOperands(unsigned NumOperands);
1333 //===----------------------------------------------------------------------===//
1335 //===----------------------------------------------------------------------===//
1337 //===---------------------------------------------------------------------------
1338 /// ReturnInst - Return a value (possibly void), from a function. Execution
1339 /// does not continue in this function any longer.
1341 class ReturnInst : public TerminatorInst {
1342 Use RetVal; // Return Value: null if 'void'.
1343 ReturnInst(const ReturnInst &RI);
1344 void init(Value *RetVal);
1347 // ReturnInst constructors:
1348 // ReturnInst() - 'ret void' instruction
1349 // ReturnInst( null) - 'ret void' instruction
1350 // ReturnInst(Value* X) - 'ret X' instruction
1351 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1352 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1353 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1354 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1356 // NOTE: If the Value* passed is of type void then the constructor behaves as
1357 // if it was passed NULL.
1358 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1359 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1360 explicit ReturnInst(BasicBlock *InsertAtEnd);
1362 virtual ReturnInst *clone() const;
1364 // Transparently provide more efficient getOperand methods.
1365 Value *getOperand(unsigned i) const {
1366 assert(i < getNumOperands() && "getOperand() out of range!");
1369 void setOperand(unsigned i, Value *Val) {
1370 assert(i < getNumOperands() && "setOperand() out of range!");
1374 Value *getReturnValue() const { return RetVal; }
1376 unsigned getNumSuccessors() const { return 0; }
1378 // Methods for support type inquiry through isa, cast, and dyn_cast:
1379 static inline bool classof(const ReturnInst *) { return true; }
1380 static inline bool classof(const Instruction *I) {
1381 return (I->getOpcode() == Instruction::Ret);
1383 static inline bool classof(const Value *V) {
1384 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1387 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1388 virtual unsigned getNumSuccessorsV() const;
1389 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1392 //===----------------------------------------------------------------------===//
1394 //===----------------------------------------------------------------------===//
1396 //===---------------------------------------------------------------------------
1397 /// BranchInst - Conditional or Unconditional Branch instruction.
1399 class BranchInst : public TerminatorInst {
1400 /// Ops list - Branches are strange. The operands are ordered:
1401 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1402 /// they don't have to check for cond/uncond branchness.
1404 BranchInst(const BranchInst &BI);
1407 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1408 // BranchInst(BB *B) - 'br B'
1409 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1410 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1411 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1412 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1413 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1414 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1415 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1416 Instruction *InsertBefore = 0);
1417 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1418 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1419 BasicBlock *InsertAtEnd);
1421 /// Transparently provide more efficient getOperand methods.
1422 Value *getOperand(unsigned i) const {
1423 assert(i < getNumOperands() && "getOperand() out of range!");
1426 void setOperand(unsigned i, Value *Val) {
1427 assert(i < getNumOperands() && "setOperand() out of range!");
1431 virtual BranchInst *clone() const;
1433 inline bool isUnconditional() const { return getNumOperands() == 1; }
1434 inline bool isConditional() const { return getNumOperands() == 3; }
1436 inline Value *getCondition() const {
1437 assert(isConditional() && "Cannot get condition of an uncond branch!");
1438 return getOperand(2);
1441 void setCondition(Value *V) {
1442 assert(isConditional() && "Cannot set condition of unconditional branch!");
1446 // setUnconditionalDest - Change the current branch to an unconditional branch
1447 // targeting the specified block.
1448 // FIXME: Eliminate this ugly method.
1449 void setUnconditionalDest(BasicBlock *Dest) {
1450 if (isConditional()) { // Convert this to an uncond branch.
1455 setOperand(0, reinterpret_cast<Value*>(Dest));
1458 unsigned getNumSuccessors() const { return 1+isConditional(); }
1460 BasicBlock *getSuccessor(unsigned i) const {
1461 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1462 return cast<BasicBlock>(getOperand(i));
1465 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1466 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1467 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1470 // Methods for support type inquiry through isa, cast, and dyn_cast:
1471 static inline bool classof(const BranchInst *) { return true; }
1472 static inline bool classof(const Instruction *I) {
1473 return (I->getOpcode() == Instruction::Br);
1475 static inline bool classof(const Value *V) {
1476 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1479 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1480 virtual unsigned getNumSuccessorsV() const;
1481 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1484 //===----------------------------------------------------------------------===//
1486 //===----------------------------------------------------------------------===//
1488 //===---------------------------------------------------------------------------
1489 /// SwitchInst - Multiway switch
1491 class SwitchInst : public TerminatorInst {
1492 unsigned ReservedSpace;
1493 // Operand[0] = Value to switch on
1494 // Operand[1] = Default basic block destination
1495 // Operand[2n ] = Value to match
1496 // Operand[2n+1] = BasicBlock to go to on match
1497 SwitchInst(const SwitchInst &RI);
1498 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1499 void resizeOperands(unsigned No);
1501 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1502 /// switch on and a default destination. The number of additional cases can
1503 /// be specified here to make memory allocation more efficient. This
1504 /// constructor can also autoinsert before another instruction.
1505 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1506 Instruction *InsertBefore = 0);
1508 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1509 /// switch on and a default destination. The number of additional cases can
1510 /// be specified here to make memory allocation more efficient. This
1511 /// constructor also autoinserts at the end of the specified BasicBlock.
1512 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1513 BasicBlock *InsertAtEnd);
1517 // Accessor Methods for Switch stmt
1518 inline Value *getCondition() const { return getOperand(0); }
1519 void setCondition(Value *V) { setOperand(0, V); }
1521 inline BasicBlock *getDefaultDest() const {
1522 return cast<BasicBlock>(getOperand(1));
1525 /// getNumCases - return the number of 'cases' in this switch instruction.
1526 /// Note that case #0 is always the default case.
1527 unsigned getNumCases() const {
1528 return getNumOperands()/2;
1531 /// getCaseValue - Return the specified case value. Note that case #0, the
1532 /// default destination, does not have a case value.
1533 ConstantInt *getCaseValue(unsigned i) {
1534 assert(i && i < getNumCases() && "Illegal case value to get!");
1535 return getSuccessorValue(i);
1538 /// getCaseValue - Return the specified case value. Note that case #0, the
1539 /// default destination, does not have a case value.
1540 const ConstantInt *getCaseValue(unsigned i) const {
1541 assert(i && i < getNumCases() && "Illegal case value to get!");
1542 return getSuccessorValue(i);
1545 /// findCaseValue - Search all of the case values for the specified constant.
1546 /// If it is explicitly handled, return the case number of it, otherwise
1547 /// return 0 to indicate that it is handled by the default handler.
1548 unsigned findCaseValue(const ConstantInt *C) const {
1549 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1550 if (getCaseValue(i) == C)
1555 /// findCaseDest - Finds the unique case value for a given successor. Returns
1556 /// null if the successor is not found, not unique, or is the default case.
1557 ConstantInt *findCaseDest(BasicBlock *BB) {
1558 if (BB == getDefaultDest()) return NULL;
1560 ConstantInt *CI = NULL;
1561 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1562 if (getSuccessor(i) == BB) {
1563 if (CI) return NULL; // Multiple cases lead to BB.
1564 else CI = getCaseValue(i);
1570 /// addCase - Add an entry to the switch instruction...
1572 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1574 /// removeCase - This method removes the specified successor from the switch
1575 /// instruction. Note that this cannot be used to remove the default
1576 /// destination (successor #0).
1578 void removeCase(unsigned idx);
1580 virtual SwitchInst *clone() const;
1582 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1583 BasicBlock *getSuccessor(unsigned idx) const {
1584 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1585 return cast<BasicBlock>(getOperand(idx*2+1));
1587 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1588 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1589 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1592 // getSuccessorValue - Return the value associated with the specified
1594 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1595 assert(idx < getNumSuccessors() && "Successor # out of range!");
1596 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1599 // Methods for support type inquiry through isa, cast, and dyn_cast:
1600 static inline bool classof(const SwitchInst *) { return true; }
1601 static inline bool classof(const Instruction *I) {
1602 return I->getOpcode() == Instruction::Switch;
1604 static inline bool classof(const Value *V) {
1605 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1608 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1609 virtual unsigned getNumSuccessorsV() const;
1610 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1613 //===----------------------------------------------------------------------===//
1615 //===----------------------------------------------------------------------===//
1617 //===---------------------------------------------------------------------------
1619 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1620 /// calling convention of the call.
1622 class InvokeInst : public TerminatorInst {
1623 ParamAttrsList *ParamAttrs;
1624 InvokeInst(const InvokeInst &BI);
1625 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1626 Value* const *Args, unsigned NumArgs);
1628 template<typename InputIterator>
1629 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1630 InputIterator ArgBegin, InputIterator ArgEnd,
1631 const std::string &Name,
1632 // This argument ensures that we have an iterator we can
1633 // do arithmetic on in constant time
1634 std::random_access_iterator_tag) {
1635 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
1637 // This requires that the iterator points to contiguous memory.
1638 init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
1643 /// Construct an InvokeInst given a range of arguments.
1644 /// InputIterator must be a random-access iterator pointing to
1645 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
1646 /// made for random-accessness but not for contiguous storage as
1647 /// that would incur runtime overhead.
1649 /// @brief Construct an InvokeInst from a range of arguments
1650 template<typename InputIterator>
1651 InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1652 InputIterator ArgBegin, InputIterator ArgEnd,
1653 const std::string &Name = "", Instruction *InsertBefore = 0)
1654 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
1655 ->getElementType())->getReturnType(),
1656 Instruction::Invoke, 0, 0, InsertBefore) {
1657 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
1658 typename std::iterator_traits<InputIterator>::iterator_category());
1661 /// Construct an InvokeInst given a range of arguments.
1662 /// InputIterator must be a random-access iterator pointing to
1663 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
1664 /// made for random-accessness but not for contiguous storage as
1665 /// that would incur runtime overhead.
1667 /// @brief Construct an InvokeInst from a range of arguments
1668 template<typename InputIterator>
1669 InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1670 InputIterator ArgBegin, InputIterator ArgEnd,
1671 const std::string &Name, BasicBlock *InsertAtEnd)
1672 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
1673 ->getElementType())->getReturnType(),
1674 Instruction::Invoke, 0, 0, InsertAtEnd) {
1675 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
1676 typename std::iterator_traits<InputIterator>::iterator_category());
1681 virtual InvokeInst *clone() const;
1683 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1685 unsigned getCallingConv() const { return SubclassData; }
1686 void setCallingConv(unsigned CC) {
1690 /// Obtains a pointer to the ParamAttrsList object which holds the
1691 /// parameter attributes information, if any.
1692 /// @returns 0 if no attributes have been set.
1693 /// @brief Get the parameter attributes.
1694 ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
1696 /// Sets the parameter attributes for this InvokeInst. To construct a
1697 /// ParamAttrsList, see ParameterAttributes.h
1698 /// @brief Set the parameter attributes.
1699 void setParamAttrs(ParamAttrsList *attrs);
1701 /// getCalledFunction - Return the function called, or null if this is an
1702 /// indirect function invocation.
1704 Function *getCalledFunction() const {
1705 return dyn_cast<Function>(getOperand(0));
1708 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1709 inline Value *getCalledValue() const { return getOperand(0); }
1711 // get*Dest - Return the destination basic blocks...
1712 BasicBlock *getNormalDest() const {
1713 return cast<BasicBlock>(getOperand(1));
1715 BasicBlock *getUnwindDest() const {
1716 return cast<BasicBlock>(getOperand(2));
1718 void setNormalDest(BasicBlock *B) {
1719 setOperand(1, reinterpret_cast<Value*>(B));
1722 void setUnwindDest(BasicBlock *B) {
1723 setOperand(2, reinterpret_cast<Value*>(B));
1726 inline BasicBlock *getSuccessor(unsigned i) const {
1727 assert(i < 2 && "Successor # out of range for invoke!");
1728 return i == 0 ? getNormalDest() : getUnwindDest();
1731 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1732 assert(idx < 2 && "Successor # out of range for invoke!");
1733 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1736 unsigned getNumSuccessors() const { return 2; }
1738 // Methods for support type inquiry through isa, cast, and dyn_cast:
1739 static inline bool classof(const InvokeInst *) { return true; }
1740 static inline bool classof(const Instruction *I) {
1741 return (I->getOpcode() == Instruction::Invoke);
1743 static inline bool classof(const Value *V) {
1744 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1747 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1748 virtual unsigned getNumSuccessorsV() const;
1749 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1753 //===----------------------------------------------------------------------===//
1755 //===----------------------------------------------------------------------===//
1757 //===---------------------------------------------------------------------------
1758 /// UnwindInst - Immediately exit the current function, unwinding the stack
1759 /// until an invoke instruction is found.
1761 class UnwindInst : public TerminatorInst {
1763 explicit UnwindInst(Instruction *InsertBefore = 0);
1764 explicit UnwindInst(BasicBlock *InsertAtEnd);
1766 virtual UnwindInst *clone() const;
1768 unsigned getNumSuccessors() const { return 0; }
1770 // Methods for support type inquiry through isa, cast, and dyn_cast:
1771 static inline bool classof(const UnwindInst *) { return true; }
1772 static inline bool classof(const Instruction *I) {
1773 return I->getOpcode() == Instruction::Unwind;
1775 static inline bool classof(const Value *V) {
1776 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1779 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1780 virtual unsigned getNumSuccessorsV() const;
1781 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1784 //===----------------------------------------------------------------------===//
1785 // UnreachableInst Class
1786 //===----------------------------------------------------------------------===//
1788 //===---------------------------------------------------------------------------
1789 /// UnreachableInst - This function has undefined behavior. In particular, the
1790 /// presence of this instruction indicates some higher level knowledge that the
1791 /// end of the block cannot be reached.
1793 class UnreachableInst : public TerminatorInst {
1795 explicit UnreachableInst(Instruction *InsertBefore = 0);
1796 explicit UnreachableInst(BasicBlock *InsertAtEnd);
1798 virtual UnreachableInst *clone() const;
1800 unsigned getNumSuccessors() const { return 0; }
1802 // Methods for support type inquiry through isa, cast, and dyn_cast:
1803 static inline bool classof(const UnreachableInst *) { return true; }
1804 static inline bool classof(const Instruction *I) {
1805 return I->getOpcode() == Instruction::Unreachable;
1807 static inline bool classof(const Value *V) {
1808 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1811 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1812 virtual unsigned getNumSuccessorsV() const;
1813 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1816 //===----------------------------------------------------------------------===//
1818 //===----------------------------------------------------------------------===//
1820 /// @brief This class represents a truncation of integer types.
1821 class TruncInst : public CastInst {
1822 /// Private copy constructor
1823 TruncInst(const TruncInst &CI)
1824 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1827 /// @brief Constructor with insert-before-instruction semantics
1829 Value *S, ///< The value to be truncated
1830 const Type *Ty, ///< The (smaller) type to truncate to
1831 const std::string &Name = "", ///< A name for the new instruction
1832 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1835 /// @brief Constructor with insert-at-end-of-block semantics
1837 Value *S, ///< The value to be truncated
1838 const Type *Ty, ///< The (smaller) type to truncate to
1839 const std::string &Name, ///< A name for the new instruction
1840 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1843 /// @brief Clone an identical TruncInst
1844 virtual CastInst *clone() const;
1846 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1847 static inline bool classof(const TruncInst *) { return true; }
1848 static inline bool classof(const Instruction *I) {
1849 return I->getOpcode() == Trunc;
1851 static inline bool classof(const Value *V) {
1852 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1856 //===----------------------------------------------------------------------===//
1858 //===----------------------------------------------------------------------===//
1860 /// @brief This class represents zero extension of integer types.
1861 class ZExtInst : public CastInst {
1862 /// @brief Private copy constructor
1863 ZExtInst(const ZExtInst &CI)
1864 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1867 /// @brief Constructor with insert-before-instruction semantics
1869 Value *S, ///< The value to be zero extended
1870 const Type *Ty, ///< The type to zero extend to
1871 const std::string &Name = "", ///< A name for the new instruction
1872 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1875 /// @brief Constructor with insert-at-end semantics.
1877 Value *S, ///< The value to be zero extended
1878 const Type *Ty, ///< The type to zero extend to
1879 const std::string &Name, ///< A name for the new instruction
1880 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1883 /// @brief Clone an identical ZExtInst
1884 virtual CastInst *clone() const;
1886 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1887 static inline bool classof(const ZExtInst *) { return true; }
1888 static inline bool classof(const Instruction *I) {
1889 return I->getOpcode() == ZExt;
1891 static inline bool classof(const Value *V) {
1892 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1896 //===----------------------------------------------------------------------===//
1898 //===----------------------------------------------------------------------===//
1900 /// @brief This class represents a sign extension of integer types.
1901 class SExtInst : public CastInst {
1902 /// @brief Private copy constructor
1903 SExtInst(const SExtInst &CI)
1904 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1907 /// @brief Constructor with insert-before-instruction semantics
1909 Value *S, ///< The value to be sign extended
1910 const Type *Ty, ///< The type to sign extend to
1911 const std::string &Name = "", ///< A name for the new instruction
1912 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1915 /// @brief Constructor with insert-at-end-of-block semantics
1917 Value *S, ///< The value to be sign extended
1918 const Type *Ty, ///< The type to sign extend to
1919 const std::string &Name, ///< A name for the new instruction
1920 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1923 /// @brief Clone an identical SExtInst
1924 virtual CastInst *clone() const;
1926 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1927 static inline bool classof(const SExtInst *) { return true; }
1928 static inline bool classof(const Instruction *I) {
1929 return I->getOpcode() == SExt;
1931 static inline bool classof(const Value *V) {
1932 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1936 //===----------------------------------------------------------------------===//
1937 // FPTruncInst Class
1938 //===----------------------------------------------------------------------===//
1940 /// @brief This class represents a truncation of floating point types.
1941 class FPTruncInst : public CastInst {
1942 FPTruncInst(const FPTruncInst &CI)
1943 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1946 /// @brief Constructor with insert-before-instruction semantics
1948 Value *S, ///< The value to be truncated
1949 const Type *Ty, ///< The type to truncate to
1950 const std::string &Name = "", ///< A name for the new instruction
1951 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1954 /// @brief Constructor with insert-before-instruction semantics
1956 Value *S, ///< The value to be truncated
1957 const Type *Ty, ///< The type to truncate to
1958 const std::string &Name, ///< A name for the new instruction
1959 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1962 /// @brief Clone an identical FPTruncInst
1963 virtual CastInst *clone() const;
1965 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1966 static inline bool classof(const FPTruncInst *) { return true; }
1967 static inline bool classof(const Instruction *I) {
1968 return I->getOpcode() == FPTrunc;
1970 static inline bool classof(const Value *V) {
1971 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1975 //===----------------------------------------------------------------------===//
1977 //===----------------------------------------------------------------------===//
1979 /// @brief This class represents an extension of floating point types.
1980 class FPExtInst : public CastInst {
1981 FPExtInst(const FPExtInst &CI)
1982 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1985 /// @brief Constructor with insert-before-instruction semantics
1987 Value *S, ///< The value to be extended
1988 const Type *Ty, ///< The type to extend to
1989 const std::string &Name = "", ///< A name for the new instruction
1990 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1993 /// @brief Constructor with insert-at-end-of-block semantics
1995 Value *S, ///< The value to be extended
1996 const Type *Ty, ///< The type to extend to
1997 const std::string &Name, ///< A name for the new instruction
1998 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2001 /// @brief Clone an identical FPExtInst
2002 virtual CastInst *clone() const;
2004 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2005 static inline bool classof(const FPExtInst *) { return true; }
2006 static inline bool classof(const Instruction *I) {
2007 return I->getOpcode() == FPExt;
2009 static inline bool classof(const Value *V) {
2010 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2014 //===----------------------------------------------------------------------===//
2016 //===----------------------------------------------------------------------===//
2018 /// @brief This class represents a cast unsigned integer to floating point.
2019 class UIToFPInst : public CastInst {
2020 UIToFPInst(const UIToFPInst &CI)
2021 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
2024 /// @brief Constructor with insert-before-instruction semantics
2026 Value *S, ///< The value to be converted
2027 const Type *Ty, ///< The type to convert to
2028 const std::string &Name = "", ///< A name for the new instruction
2029 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2032 /// @brief Constructor with insert-at-end-of-block semantics
2034 Value *S, ///< The value to be converted
2035 const Type *Ty, ///< The type to convert to
2036 const std::string &Name, ///< A name for the new instruction
2037 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2040 /// @brief Clone an identical UIToFPInst
2041 virtual CastInst *clone() const;
2043 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2044 static inline bool classof(const UIToFPInst *) { return true; }
2045 static inline bool classof(const Instruction *I) {
2046 return I->getOpcode() == UIToFP;
2048 static inline bool classof(const Value *V) {
2049 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2053 //===----------------------------------------------------------------------===//
2055 //===----------------------------------------------------------------------===//
2057 /// @brief This class represents a cast from signed integer to floating point.
2058 class SIToFPInst : public CastInst {
2059 SIToFPInst(const SIToFPInst &CI)
2060 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
2063 /// @brief Constructor with insert-before-instruction semantics
2065 Value *S, ///< The value to be converted
2066 const Type *Ty, ///< The type to convert to
2067 const std::string &Name = "", ///< A name for the new instruction
2068 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2071 /// @brief Constructor with insert-at-end-of-block semantics
2073 Value *S, ///< The value to be converted
2074 const Type *Ty, ///< The type to convert to
2075 const std::string &Name, ///< A name for the new instruction
2076 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2079 /// @brief Clone an identical SIToFPInst
2080 virtual CastInst *clone() const;
2082 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2083 static inline bool classof(const SIToFPInst *) { return true; }
2084 static inline bool classof(const Instruction *I) {
2085 return I->getOpcode() == SIToFP;
2087 static inline bool classof(const Value *V) {
2088 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2092 //===----------------------------------------------------------------------===//
2094 //===----------------------------------------------------------------------===//
2096 /// @brief This class represents a cast from floating point to unsigned integer
2097 class FPToUIInst : public CastInst {
2098 FPToUIInst(const FPToUIInst &CI)
2099 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
2102 /// @brief Constructor with insert-before-instruction semantics
2104 Value *S, ///< The value to be converted
2105 const Type *Ty, ///< The type to convert to
2106 const std::string &Name = "", ///< A name for the new instruction
2107 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2110 /// @brief Constructor with insert-at-end-of-block semantics
2112 Value *S, ///< The value to be converted
2113 const Type *Ty, ///< The type to convert to
2114 const std::string &Name, ///< A name for the new instruction
2115 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
2118 /// @brief Clone an identical FPToUIInst
2119 virtual CastInst *clone() const;
2121 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2122 static inline bool classof(const FPToUIInst *) { return true; }
2123 static inline bool classof(const Instruction *I) {
2124 return I->getOpcode() == FPToUI;
2126 static inline bool classof(const Value *V) {
2127 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2131 //===----------------------------------------------------------------------===//
2133 //===----------------------------------------------------------------------===//
2135 /// @brief This class represents a cast from floating point to signed integer.
2136 class FPToSIInst : public CastInst {
2137 FPToSIInst(const FPToSIInst &CI)
2138 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2141 /// @brief Constructor with insert-before-instruction semantics
2143 Value *S, ///< The value to be converted
2144 const Type *Ty, ///< The type to convert to
2145 const std::string &Name = "", ///< A name for the new instruction
2146 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2149 /// @brief Constructor with insert-at-end-of-block semantics
2151 Value *S, ///< The value to be converted
2152 const Type *Ty, ///< The type to convert to
2153 const std::string &Name, ///< A name for the new instruction
2154 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2157 /// @brief Clone an identical FPToSIInst
2158 virtual CastInst *clone() const;
2160 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2161 static inline bool classof(const FPToSIInst *) { return true; }
2162 static inline bool classof(const Instruction *I) {
2163 return I->getOpcode() == FPToSI;
2165 static inline bool classof(const Value *V) {
2166 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2170 //===----------------------------------------------------------------------===//
2171 // IntToPtrInst Class
2172 //===----------------------------------------------------------------------===//
2174 /// @brief This class represents a cast from an integer to a pointer.
2175 class IntToPtrInst : public CastInst {
2176 IntToPtrInst(const IntToPtrInst &CI)
2177 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2180 /// @brief Constructor with insert-before-instruction semantics
2182 Value *S, ///< The value to be converted
2183 const Type *Ty, ///< The type to convert to
2184 const std::string &Name = "", ///< A name for the new instruction
2185 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2188 /// @brief Constructor with insert-at-end-of-block semantics
2190 Value *S, ///< The value to be converted
2191 const Type *Ty, ///< The type to convert to
2192 const std::string &Name, ///< A name for the new instruction
2193 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2196 /// @brief Clone an identical IntToPtrInst
2197 virtual CastInst *clone() const;
2199 // Methods for support type inquiry through isa, cast, and dyn_cast:
2200 static inline bool classof(const IntToPtrInst *) { return true; }
2201 static inline bool classof(const Instruction *I) {
2202 return I->getOpcode() == IntToPtr;
2204 static inline bool classof(const Value *V) {
2205 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2209 //===----------------------------------------------------------------------===//
2210 // PtrToIntInst Class
2211 //===----------------------------------------------------------------------===//
2213 /// @brief This class represents a cast from a pointer to an integer
2214 class PtrToIntInst : public CastInst {
2215 PtrToIntInst(const PtrToIntInst &CI)
2216 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2219 /// @brief Constructor with insert-before-instruction semantics
2221 Value *S, ///< The value to be converted
2222 const Type *Ty, ///< The type to convert to
2223 const std::string &Name = "", ///< A name for the new instruction
2224 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2227 /// @brief Constructor with insert-at-end-of-block semantics
2229 Value *S, ///< The value to be converted
2230 const Type *Ty, ///< The type to convert to
2231 const std::string &Name, ///< A name for the new instruction
2232 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2235 /// @brief Clone an identical PtrToIntInst
2236 virtual CastInst *clone() const;
2238 // Methods for support type inquiry through isa, cast, and dyn_cast:
2239 static inline bool classof(const PtrToIntInst *) { return true; }
2240 static inline bool classof(const Instruction *I) {
2241 return I->getOpcode() == PtrToInt;
2243 static inline bool classof(const Value *V) {
2244 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2248 //===----------------------------------------------------------------------===//
2249 // BitCastInst Class
2250 //===----------------------------------------------------------------------===//
2252 /// @brief This class represents a no-op cast from one type to another.
2253 class BitCastInst : public CastInst {
2254 BitCastInst(const BitCastInst &CI)
2255 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2258 /// @brief Constructor with insert-before-instruction semantics
2260 Value *S, ///< The value to be casted
2261 const Type *Ty, ///< The type to casted to
2262 const std::string &Name = "", ///< A name for the new instruction
2263 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2266 /// @brief Constructor with insert-at-end-of-block semantics
2268 Value *S, ///< The value to be casted
2269 const Type *Ty, ///< The type to casted to
2270 const std::string &Name, ///< A name for the new instruction
2271 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2274 /// @brief Clone an identical BitCastInst
2275 virtual CastInst *clone() const;
2277 // Methods for support type inquiry through isa, cast, and dyn_cast:
2278 static inline bool classof(const BitCastInst *) { return true; }
2279 static inline bool classof(const Instruction *I) {
2280 return I->getOpcode() == BitCast;
2282 static inline bool classof(const Value *V) {
2283 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2287 } // End llvm namespace