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
19 #include "llvm/InstrTypes.h"
20 #include <vector> // fixme remove.
29 //===----------------------------------------------------------------------===//
30 // AllocationInst Class
31 //===----------------------------------------------------------------------===//
33 /// AllocationInst - This class is the common base class of MallocInst and
36 class AllocationInst : public UnaryInstruction {
39 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
40 const std::string &Name = "", Instruction *InsertBefore = 0);
41 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
42 const std::string &Name, BasicBlock *InsertAtEnd);
44 // Out of line virtual method, so the vtable, etc has a home.
45 virtual ~AllocationInst();
47 /// isArrayAllocation - Return true if there is an allocation size parameter
48 /// to the allocation instruction that is not 1.
50 bool isArrayAllocation() const;
52 /// getArraySize - Get the number of element allocated, for a simple
53 /// allocation of a single element, this will return a constant 1 value.
55 inline const Value *getArraySize() const { return getOperand(0); }
56 inline Value *getArraySize() { return getOperand(0); }
58 /// getType - Overload to return most specific pointer type
60 inline const PointerType *getType() const {
61 return reinterpret_cast<const PointerType*>(Instruction::getType());
64 /// getAllocatedType - Return the type that is being allocated by the
67 const Type *getAllocatedType() const;
69 /// getAlignment - Return the alignment of the memory that is being allocated
70 /// by the instruction.
72 unsigned getAlignment() const { return Alignment; }
73 void setAlignment(unsigned Align) {
74 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
78 virtual Instruction *clone() const = 0;
80 // Methods for support type inquiry through isa, cast, and dyn_cast:
81 static inline bool classof(const AllocationInst *) { return true; }
82 static inline bool classof(const Instruction *I) {
83 return I->getOpcode() == Instruction::Alloca ||
84 I->getOpcode() == Instruction::Malloc;
86 static inline bool classof(const Value *V) {
87 return isa<Instruction>(V) && classof(cast<Instruction>(V));
92 //===----------------------------------------------------------------------===//
94 //===----------------------------------------------------------------------===//
96 /// MallocInst - an instruction to allocated memory on the heap
98 class MallocInst : public AllocationInst {
99 MallocInst(const MallocInst &MI);
101 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
102 const std::string &Name = "",
103 Instruction *InsertBefore = 0)
104 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
105 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
106 BasicBlock *InsertAtEnd)
107 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
109 MallocInst(const Type *Ty, const std::string &Name,
110 Instruction *InsertBefore = 0)
111 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
112 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
113 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
115 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
116 const std::string &Name, BasicBlock *InsertAtEnd)
117 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
118 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
119 const std::string &Name = "",
120 Instruction *InsertBefore = 0)
121 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
123 virtual MallocInst *clone() const;
125 // Methods for support type inquiry through isa, cast, and dyn_cast:
126 static inline bool classof(const MallocInst *) { return true; }
127 static inline bool classof(const Instruction *I) {
128 return (I->getOpcode() == Instruction::Malloc);
130 static inline bool classof(const Value *V) {
131 return isa<Instruction>(V) && classof(cast<Instruction>(V));
136 //===----------------------------------------------------------------------===//
138 //===----------------------------------------------------------------------===//
140 /// AllocaInst - an instruction to allocate memory on the stack
142 class AllocaInst : public AllocationInst {
143 AllocaInst(const AllocaInst &);
145 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
146 const std::string &Name = "",
147 Instruction *InsertBefore = 0)
148 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
149 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
150 BasicBlock *InsertAtEnd)
151 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
153 AllocaInst(const Type *Ty, const std::string &Name,
154 Instruction *InsertBefore = 0)
155 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
156 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
157 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
159 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
160 const std::string &Name = "", Instruction *InsertBefore = 0)
161 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
162 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
163 const std::string &Name, BasicBlock *InsertAtEnd)
164 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
166 virtual AllocaInst *clone() const;
168 // Methods for support type inquiry through isa, cast, and dyn_cast:
169 static inline bool classof(const AllocaInst *) { return true; }
170 static inline bool classof(const Instruction *I) {
171 return (I->getOpcode() == Instruction::Alloca);
173 static inline bool classof(const Value *V) {
174 return isa<Instruction>(V) && classof(cast<Instruction>(V));
179 //===----------------------------------------------------------------------===//
181 //===----------------------------------------------------------------------===//
183 /// FreeInst - an instruction to deallocate memory
185 class FreeInst : public UnaryInstruction {
188 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
189 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
191 virtual FreeInst *clone() const;
193 virtual bool mayWriteToMemory() const { return true; }
195 // Methods for support type inquiry through isa, cast, and dyn_cast:
196 static inline bool classof(const FreeInst *) { return true; }
197 static inline bool classof(const Instruction *I) {
198 return (I->getOpcode() == Instruction::Free);
200 static inline bool classof(const Value *V) {
201 return isa<Instruction>(V) && classof(cast<Instruction>(V));
206 //===----------------------------------------------------------------------===//
208 //===----------------------------------------------------------------------===//
210 /// LoadInst - an instruction for reading from memory. This uses the
211 /// SubclassData field in Value to store whether or not the load is volatile.
213 class LoadInst : public UnaryInstruction {
214 LoadInst(const LoadInst &LI)
215 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
216 setVolatile(LI.isVolatile());
224 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
225 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
226 explicit LoadInst(Value *Ptr, const std::string &Name = "",
227 bool isVolatile = false, Instruction *InsertBefore = 0);
228 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
229 BasicBlock *InsertAtEnd);
231 /// isVolatile - Return true if this is a load from a volatile memory
234 bool isVolatile() const { return SubclassData; }
236 /// setVolatile - Specify whether this is a volatile load or not.
238 void setVolatile(bool V) { SubclassData = V; }
240 virtual LoadInst *clone() const;
242 virtual bool mayWriteToMemory() const { return isVolatile(); }
244 Value *getPointerOperand() { return getOperand(0); }
245 const Value *getPointerOperand() const { return getOperand(0); }
246 static unsigned getPointerOperandIndex() { return 0U; }
248 // Methods for support type inquiry through isa, cast, and dyn_cast:
249 static inline bool classof(const LoadInst *) { return true; }
250 static inline bool classof(const Instruction *I) {
251 return I->getOpcode() == Instruction::Load;
253 static inline bool classof(const Value *V) {
254 return isa<Instruction>(V) && classof(cast<Instruction>(V));
259 //===----------------------------------------------------------------------===//
261 //===----------------------------------------------------------------------===//
263 /// StoreInst - an instruction for storing to memory
265 class StoreInst : public Instruction {
267 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
268 Ops[0].init(SI.Ops[0], this);
269 Ops[1].init(SI.Ops[1], this);
270 setVolatile(SI.isVolatile());
277 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
278 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
279 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
280 Instruction *InsertBefore = 0);
281 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
284 /// isVolatile - Return true if this is a load from a volatile memory
287 bool isVolatile() const { return SubclassData; }
289 /// setVolatile - Specify whether this is a volatile load or not.
291 void setVolatile(bool V) { SubclassData = V; }
293 /// Transparently provide more efficient getOperand methods.
294 Value *getOperand(unsigned i) const {
295 assert(i < 2 && "getOperand() out of range!");
298 void setOperand(unsigned i, Value *Val) {
299 assert(i < 2 && "setOperand() out of range!");
302 unsigned getNumOperands() const { return 2; }
305 virtual StoreInst *clone() const;
307 virtual bool mayWriteToMemory() const { return true; }
309 Value *getPointerOperand() { return getOperand(1); }
310 const Value *getPointerOperand() const { return getOperand(1); }
311 static unsigned getPointerOperandIndex() { return 1U; }
313 // Methods for support type inquiry through isa, cast, and dyn_cast:
314 static inline bool classof(const StoreInst *) { return true; }
315 static inline bool classof(const Instruction *I) {
316 return I->getOpcode() == Instruction::Store;
318 static inline bool classof(const Value *V) {
319 return isa<Instruction>(V) && classof(cast<Instruction>(V));
324 //===----------------------------------------------------------------------===//
325 // GetElementPtrInst Class
326 //===----------------------------------------------------------------------===//
328 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
329 /// access elements of arrays and structs
331 class GetElementPtrInst : public Instruction {
332 GetElementPtrInst(const GetElementPtrInst &GEPI)
333 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
334 0, GEPI.getNumOperands()) {
335 Use *OL = OperandList = new Use[NumOperands];
336 Use *GEPIOL = GEPI.OperandList;
337 for (unsigned i = 0, E = NumOperands; i != E; ++i)
338 OL[i].init(GEPIOL[i], this);
340 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
341 void init(Value *Ptr, Value *Idx0, Value *Idx1);
342 void init(Value *Ptr, Value *Idx);
344 /// Constructors - Create a getelementptr instruction with a base pointer an
345 /// list of indices. The first ctor can optionally insert before an existing
346 /// instruction, the second appends the new instruction to the specified
348 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
349 const std::string &Name = "", Instruction *InsertBefore =0);
350 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
351 const std::string &Name, BasicBlock *InsertAtEnd);
353 /// Constructors - These two constructors are convenience methods because one
354 /// and two index getelementptr instructions are so common.
355 GetElementPtrInst(Value *Ptr, Value *Idx,
356 const std::string &Name = "", Instruction *InsertBefore =0);
357 GetElementPtrInst(Value *Ptr, Value *Idx,
358 const std::string &Name, BasicBlock *InsertAtEnd);
359 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
360 const std::string &Name = "", Instruction *InsertBefore =0);
361 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
362 const std::string &Name, BasicBlock *InsertAtEnd);
363 ~GetElementPtrInst();
365 virtual GetElementPtrInst *clone() const;
367 // getType - Overload to return most specific pointer type...
368 inline const PointerType *getType() const {
369 return reinterpret_cast<const PointerType*>(Instruction::getType());
372 /// getIndexedType - Returns the type of the element that would be loaded with
373 /// a load instruction with the specified parameters.
375 /// A null type is returned if the indices are invalid for the specified
378 static const Type *getIndexedType(const Type *Ptr,
379 Value* const *Idx, unsigned NumIdx,
380 bool AllowStructLeaf = false);
382 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
383 bool AllowStructLeaf = false);
384 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
386 inline op_iterator idx_begin() { return op_begin()+1; }
387 inline const_op_iterator idx_begin() const { return op_begin()+1; }
388 inline op_iterator idx_end() { return op_end(); }
389 inline const_op_iterator idx_end() const { return op_end(); }
391 Value *getPointerOperand() {
392 return getOperand(0);
394 const Value *getPointerOperand() const {
395 return getOperand(0);
397 static unsigned getPointerOperandIndex() {
398 return 0U; // get index for modifying correct operand
401 inline unsigned getNumIndices() const { // Note: always non-negative
402 return getNumOperands() - 1;
405 inline bool hasIndices() const {
406 return getNumOperands() > 1;
409 // Methods for support type inquiry through isa, cast, and dyn_cast:
410 static inline bool classof(const GetElementPtrInst *) { return true; }
411 static inline bool classof(const Instruction *I) {
412 return (I->getOpcode() == Instruction::GetElementPtr);
414 static inline bool classof(const Value *V) {
415 return isa<Instruction>(V) && classof(cast<Instruction>(V));
419 //===----------------------------------------------------------------------===//
421 //===----------------------------------------------------------------------===//
423 /// This instruction compares its operands according to the predicate given
424 /// to the constructor. It only operates on integers, pointers, or packed
425 /// vectors of integrals. The two operands must be the same type.
426 /// @brief Represent an integer comparison operator.
427 class ICmpInst: public CmpInst {
429 /// This enumeration lists the possible predicates for the ICmpInst. The
430 /// values in the range 0-31 are reserved for FCmpInst while values in the
431 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
432 /// predicate values are not overlapping between the classes.
434 ICMP_EQ = 32, ///< equal
435 ICMP_NE = 33, ///< not equal
436 ICMP_UGT = 34, ///< unsigned greater than
437 ICMP_UGE = 35, ///< unsigned greater or equal
438 ICMP_ULT = 36, ///< unsigned less than
439 ICMP_ULE = 37, ///< unsigned less or equal
440 ICMP_SGT = 38, ///< signed greater than
441 ICMP_SGE = 39, ///< signed greater or equal
442 ICMP_SLT = 40, ///< signed less than
443 ICMP_SLE = 41, ///< signed less or equal
444 FIRST_ICMP_PREDICATE = ICMP_EQ,
445 LAST_ICMP_PREDICATE = ICMP_SLE,
446 BAD_ICMP_PREDICATE = ICMP_SLE + 1
449 /// @brief Constructor with insert-before-instruction semantics.
451 Predicate pred, ///< The predicate to use for the comparison
452 Value *LHS, ///< The left-hand-side of the expression
453 Value *RHS, ///< The right-hand-side of the expression
454 const std::string &Name = "", ///< Name of the instruction
455 Instruction *InsertBefore = 0 ///< Where to insert
456 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
459 /// @brief Constructor with insert-at-block-end semantics.
461 Predicate pred, ///< The predicate to use for the comparison
462 Value *LHS, ///< The left-hand-side of the expression
463 Value *RHS, ///< The right-hand-side of the expression
464 const std::string &Name, ///< Name of the instruction
465 BasicBlock *InsertAtEnd ///< Block to insert into.
466 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
469 /// @brief Return the predicate for this instruction.
470 Predicate getPredicate() const { return Predicate(SubclassData); }
472 /// @brief Set the predicate for this instruction to the specified value.
473 void setPredicate(Predicate P) { SubclassData = P; }
475 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
476 /// @returns the inverse predicate for the instruction's current predicate.
477 /// @brief Return the inverse of the instruction's predicate.
478 Predicate getInversePredicate() const {
479 return getInversePredicate(getPredicate());
482 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
483 /// @returns the inverse predicate for predicate provided in \p pred.
484 /// @brief Return the inverse of a given predicate
485 static Predicate getInversePredicate(Predicate pred);
487 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
488 /// @returns the predicate that would be the result of exchanging the two
489 /// operands of the ICmpInst instruction without changing the result
491 /// @brief Return the predicate as if the operands were swapped
492 Predicate getSwappedPredicate() const {
493 return getSwappedPredicate(getPredicate());
496 /// This is a static version that you can use without an instruction
498 /// @brief Return the predicate as if the operands were swapped.
499 static Predicate getSwappedPredicate(Predicate pred);
501 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
502 /// @returns the predicate that would be the result if the operand were
503 /// regarded as signed.
504 /// @brief Return the signed version of the predicate
505 Predicate getSignedPredicate() const {
506 return getSignedPredicate(getPredicate());
509 /// This is a static version that you can use without an instruction.
510 /// @brief Return the signed version of the predicate.
511 static Predicate getSignedPredicate(Predicate pred);
513 /// This also tests for commutativity. If isEquality() returns true then
514 /// the predicate is also commutative.
515 /// @returns true if the predicate of this instruction is EQ or NE.
516 /// @brief Determine if this is an equality predicate.
517 bool isEquality() const {
518 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
521 /// @returns true if the predicate of this ICmpInst is commutative
522 /// @brief Determine if this relation is commutative.
523 bool isCommutative() const { return isEquality(); }
525 /// @returns true if the predicate is relational (not EQ or NE).
526 /// @brief Determine if this a relational predicate.
527 bool isRelational() const {
528 return !isEquality();
531 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
532 /// @brief Determine if this instruction's predicate is signed.
533 bool isSignedPredicate() { return isSignedPredicate(getPredicate()); }
535 /// @returns true if the predicate provided is signed, false otherwise
536 /// @brief Determine if the predicate is signed.
537 static bool isSignedPredicate(Predicate pred);
539 /// Exchange the two operands to this instruction in such a way that it does
540 /// not modify the semantics of the instruction. The predicate value may be
541 /// changed to retain the same result if the predicate is order dependent
543 /// @brief Swap operands and adjust predicate.
544 void swapOperands() {
545 SubclassData = getSwappedPredicate();
546 std::swap(Ops[0], Ops[1]);
549 // Methods for support type inquiry through isa, cast, and dyn_cast:
550 static inline bool classof(const ICmpInst *) { return true; }
551 static inline bool classof(const Instruction *I) {
552 return I->getOpcode() == Instruction::ICmp;
554 static inline bool classof(const Value *V) {
555 return isa<Instruction>(V) && classof(cast<Instruction>(V));
559 //===----------------------------------------------------------------------===//
561 //===----------------------------------------------------------------------===//
563 /// This instruction compares its operands according to the predicate given
564 /// to the constructor. It only operates on floating point values or packed
565 /// vectors of floating point values. The operands must be identical types.
566 /// @brief Represents a floating point comparison operator.
567 class FCmpInst: public CmpInst {
569 /// This enumeration lists the possible predicates for the FCmpInst. Values
570 /// in the range 0-31 are reserved for FCmpInst.
572 // Opcode U L G E Intuitive operation
573 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
574 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
575 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
576 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
577 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
578 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
579 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
580 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
581 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
582 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
583 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
584 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
585 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
586 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
587 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
588 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
589 FIRST_FCMP_PREDICATE = FCMP_FALSE,
590 LAST_FCMP_PREDICATE = FCMP_TRUE,
591 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
594 /// @brief Constructor with insert-before-instruction semantics.
596 Predicate pred, ///< The predicate to use for the comparison
597 Value *LHS, ///< The left-hand-side of the expression
598 Value *RHS, ///< The right-hand-side of the expression
599 const std::string &Name = "", ///< Name of the instruction
600 Instruction *InsertBefore = 0 ///< Where to insert
601 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
604 /// @brief Constructor with insert-at-block-end semantics.
606 Predicate pred, ///< The predicate to use for the comparison
607 Value *LHS, ///< The left-hand-side of the expression
608 Value *RHS, ///< The right-hand-side of the expression
609 const std::string &Name, ///< Name of the instruction
610 BasicBlock *InsertAtEnd ///< Block to insert into.
611 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
614 /// @brief Return the predicate for this instruction.
615 Predicate getPredicate() const { return Predicate(SubclassData); }
617 /// @brief Set the predicate for this instruction to the specified value.
618 void setPredicate(Predicate P) { SubclassData = P; }
620 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
621 /// @returns the inverse predicate for the instructions current predicate.
622 /// @brief Return the inverse of the predicate
623 Predicate getInversePredicate() const {
624 return getInversePredicate(getPredicate());
627 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
628 /// @returns the inverse predicate for \p pred.
629 /// @brief Return the inverse of a given predicate
630 static Predicate getInversePredicate(Predicate pred);
632 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
633 /// @returns the predicate that would be the result of exchanging the two
634 /// operands of the ICmpInst instruction without changing the result
636 /// @brief Return the predicate as if the operands were swapped
637 Predicate getSwappedPredicate() const {
638 return getSwappedPredicate(getPredicate());
641 /// This is a static version that you can use without an instruction
643 /// @brief Return the predicate as if the operands were swapped.
644 static Predicate getSwappedPredicate(Predicate Opcode);
646 /// This also tests for commutativity. If isEquality() returns true then
647 /// the predicate is also commutative. Only the equality predicates are
649 /// @returns true if the predicate of this instruction is EQ or NE.
650 /// @brief Determine if this is an equality predicate.
651 bool isEquality() const {
652 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
653 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
655 bool isCommutative() const { return isEquality(); }
657 /// @returns true if the predicate is relational (not EQ or NE).
658 /// @brief Determine if this a relational predicate.
659 bool isRelational() const { return !isEquality(); }
661 /// Exchange the two operands to this instruction in such a way that it does
662 /// not modify the semantics of the instruction. The predicate value may be
663 /// changed to retain the same result if the predicate is order dependent
665 /// @brief Swap operands and adjust predicate.
666 void swapOperands() {
667 SubclassData = getSwappedPredicate();
668 std::swap(Ops[0], Ops[1]);
671 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
672 static inline bool classof(const FCmpInst *) { return true; }
673 static inline bool classof(const Instruction *I) {
674 return I->getOpcode() == Instruction::FCmp;
676 static inline bool classof(const Value *V) {
677 return isa<Instruction>(V) && classof(cast<Instruction>(V));
681 //===----------------------------------------------------------------------===//
683 //===----------------------------------------------------------------------===//
685 /// CallInst - This class represents a function call, abstracting a target
686 /// machine's calling convention. This class uses low bit of the SubClassData
687 /// field to indicate whether or not this is a tail call. The rest of the bits
688 /// hold the calling convention of the call.
690 class CallInst : public Instruction {
691 CallInst(const CallInst &CI);
692 void init(Value *Func, Value* const *Params, unsigned NumParams);
693 void init(Value *Func, Value *Actual1, Value *Actual2);
694 void init(Value *Func, Value *Actual);
695 void init(Value *Func);
698 CallInst(Value *F, const std::vector<Value*> &Par,
699 const std::string &Name = "", Instruction *InsertBefore = 0);
700 CallInst(Value *F, const std::vector<Value*> &Par,
701 const std::string &Name, BasicBlock *InsertAtEnd);
703 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
704 // actuals, respectively.
705 CallInst(Value *F, Value *Actual1, Value *Actual2,
706 const std::string& Name = "", Instruction *InsertBefore = 0);
707 CallInst(Value *F, Value *Actual1, Value *Actual2,
708 const std::string& Name, BasicBlock *InsertAtEnd);
709 CallInst(Value *F, Value *Actual, const std::string& Name = "",
710 Instruction *InsertBefore = 0);
711 CallInst(Value *F, Value *Actual, const std::string& Name,
712 BasicBlock *InsertAtEnd);
713 explicit CallInst(Value *F, const std::string &Name = "",
714 Instruction *InsertBefore = 0);
715 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
718 virtual CallInst *clone() const;
719 bool mayWriteToMemory() const { return true; }
721 bool isTailCall() const { return SubclassData & 1; }
722 void setTailCall(bool isTailCall = true) {
723 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
726 /// getCallingConv/setCallingConv - Get or set the calling convention of this
728 unsigned getCallingConv() const { return SubclassData >> 1; }
729 void setCallingConv(unsigned CC) {
730 SubclassData = (SubclassData & 1) | (CC << 1);
733 /// getCalledFunction - Return the function being called by this instruction
734 /// if it is a direct call. If it is a call through a function pointer,
736 Function *getCalledFunction() const {
737 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
740 /// getCalledValue - Get a pointer to the function that is invoked by this
742 inline const Value *getCalledValue() const { return getOperand(0); }
743 inline Value *getCalledValue() { return getOperand(0); }
745 // Methods for support type inquiry through isa, cast, and dyn_cast:
746 static inline bool classof(const CallInst *) { return true; }
747 static inline bool classof(const Instruction *I) {
748 return I->getOpcode() == Instruction::Call;
750 static inline bool classof(const Value *V) {
751 return isa<Instruction>(V) && classof(cast<Instruction>(V));
755 //===----------------------------------------------------------------------===//
757 //===----------------------------------------------------------------------===//
759 /// SelectInst - This class represents the LLVM 'select' instruction.
761 class SelectInst : public Instruction {
764 void init(Value *C, Value *S1, Value *S2) {
765 Ops[0].init(C, this);
766 Ops[1].init(S1, this);
767 Ops[2].init(S2, this);
770 SelectInst(const SelectInst &SI)
771 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
772 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
775 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
776 Instruction *InsertBefore = 0)
777 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
778 Name, InsertBefore) {
781 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
782 BasicBlock *InsertAtEnd)
783 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
788 Value *getCondition() const { return Ops[0]; }
789 Value *getTrueValue() const { return Ops[1]; }
790 Value *getFalseValue() const { return Ops[2]; }
792 /// Transparently provide more efficient getOperand methods.
793 Value *getOperand(unsigned i) const {
794 assert(i < 3 && "getOperand() out of range!");
797 void setOperand(unsigned i, Value *Val) {
798 assert(i < 3 && "setOperand() out of range!");
801 unsigned getNumOperands() const { return 3; }
803 OtherOps getOpcode() const {
804 return static_cast<OtherOps>(Instruction::getOpcode());
807 virtual SelectInst *clone() const;
809 // Methods for support type inquiry through isa, cast, and dyn_cast:
810 static inline bool classof(const SelectInst *) { return true; }
811 static inline bool classof(const Instruction *I) {
812 return I->getOpcode() == Instruction::Select;
814 static inline bool classof(const Value *V) {
815 return isa<Instruction>(V) && classof(cast<Instruction>(V));
819 //===----------------------------------------------------------------------===//
821 //===----------------------------------------------------------------------===//
823 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
824 /// an argument of the specified type given a va_list and increments that list
826 class VAArgInst : public UnaryInstruction {
827 VAArgInst(const VAArgInst &VAA)
828 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
830 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
831 Instruction *InsertBefore = 0)
832 : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) {
834 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
835 BasicBlock *InsertAtEnd)
836 : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) {
839 virtual VAArgInst *clone() const;
840 bool mayWriteToMemory() const { return true; }
842 // Methods for support type inquiry through isa, cast, and dyn_cast:
843 static inline bool classof(const VAArgInst *) { return true; }
844 static inline bool classof(const Instruction *I) {
845 return I->getOpcode() == VAArg;
847 static inline bool classof(const Value *V) {
848 return isa<Instruction>(V) && classof(cast<Instruction>(V));
852 //===----------------------------------------------------------------------===//
853 // ExtractElementInst Class
854 //===----------------------------------------------------------------------===//
856 /// ExtractElementInst - This instruction extracts a single (scalar)
857 /// element from a PackedType value
859 class ExtractElementInst : public Instruction {
861 ExtractElementInst(const ExtractElementInst &EE) :
862 Instruction(EE.getType(), ExtractElement, Ops, 2) {
863 Ops[0].init(EE.Ops[0], this);
864 Ops[1].init(EE.Ops[1], this);
868 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
869 Instruction *InsertBefore = 0);
870 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
871 Instruction *InsertBefore = 0);
872 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
873 BasicBlock *InsertAtEnd);
874 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
875 BasicBlock *InsertAtEnd);
877 /// isValidOperands - Return true if an extractelement instruction can be
878 /// formed with the specified operands.
879 static bool isValidOperands(const Value *Vec, const Value *Idx);
881 virtual ExtractElementInst *clone() const;
883 virtual bool mayWriteToMemory() const { return false; }
885 /// Transparently provide more efficient getOperand methods.
886 Value *getOperand(unsigned i) const {
887 assert(i < 2 && "getOperand() out of range!");
890 void setOperand(unsigned i, Value *Val) {
891 assert(i < 2 && "setOperand() out of range!");
894 unsigned getNumOperands() const { return 2; }
896 // Methods for support type inquiry through isa, cast, and dyn_cast:
897 static inline bool classof(const ExtractElementInst *) { return true; }
898 static inline bool classof(const Instruction *I) {
899 return I->getOpcode() == Instruction::ExtractElement;
901 static inline bool classof(const Value *V) {
902 return isa<Instruction>(V) && classof(cast<Instruction>(V));
906 //===----------------------------------------------------------------------===//
907 // InsertElementInst Class
908 //===----------------------------------------------------------------------===//
910 /// InsertElementInst - This instruction inserts a single (scalar)
911 /// element into a PackedType value
913 class InsertElementInst : public Instruction {
915 InsertElementInst(const InsertElementInst &IE);
917 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
918 const std::string &Name = "",Instruction *InsertBefore = 0);
919 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
920 const std::string &Name = "",Instruction *InsertBefore = 0);
921 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
922 const std::string &Name, BasicBlock *InsertAtEnd);
923 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
924 const std::string &Name, BasicBlock *InsertAtEnd);
926 /// isValidOperands - Return true if an insertelement instruction can be
927 /// formed with the specified operands.
928 static bool isValidOperands(const Value *Vec, const Value *NewElt,
931 virtual InsertElementInst *clone() const;
933 virtual bool mayWriteToMemory() const { return false; }
935 /// getType - Overload to return most specific packed type.
937 inline const PackedType *getType() const {
938 return reinterpret_cast<const PackedType*>(Instruction::getType());
941 /// Transparently provide more efficient getOperand methods.
942 Value *getOperand(unsigned i) const {
943 assert(i < 3 && "getOperand() out of range!");
946 void setOperand(unsigned i, Value *Val) {
947 assert(i < 3 && "setOperand() out of range!");
950 unsigned getNumOperands() const { return 3; }
952 // Methods for support type inquiry through isa, cast, and dyn_cast:
953 static inline bool classof(const InsertElementInst *) { return true; }
954 static inline bool classof(const Instruction *I) {
955 return I->getOpcode() == Instruction::InsertElement;
957 static inline bool classof(const Value *V) {
958 return isa<Instruction>(V) && classof(cast<Instruction>(V));
962 //===----------------------------------------------------------------------===//
963 // ShuffleVectorInst Class
964 //===----------------------------------------------------------------------===//
966 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
969 class ShuffleVectorInst : public Instruction {
971 ShuffleVectorInst(const ShuffleVectorInst &IE);
973 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
974 const std::string &Name = "", Instruction *InsertBefor = 0);
975 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
976 const std::string &Name, BasicBlock *InsertAtEnd);
978 /// isValidOperands - Return true if a shufflevector instruction can be
979 /// formed with the specified operands.
980 static bool isValidOperands(const Value *V1, const Value *V2,
983 virtual ShuffleVectorInst *clone() const;
985 virtual bool mayWriteToMemory() const { return false; }
987 /// getType - Overload to return most specific packed type.
989 inline const PackedType *getType() const {
990 return reinterpret_cast<const PackedType*>(Instruction::getType());
993 /// Transparently provide more efficient getOperand methods.
994 Value *getOperand(unsigned i) const {
995 assert(i < 3 && "getOperand() out of range!");
998 void setOperand(unsigned i, Value *Val) {
999 assert(i < 3 && "setOperand() out of range!");
1002 unsigned getNumOperands() const { return 3; }
1004 // Methods for support type inquiry through isa, cast, and dyn_cast:
1005 static inline bool classof(const ShuffleVectorInst *) { return true; }
1006 static inline bool classof(const Instruction *I) {
1007 return I->getOpcode() == Instruction::ShuffleVector;
1009 static inline bool classof(const Value *V) {
1010 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1015 //===----------------------------------------------------------------------===//
1017 //===----------------------------------------------------------------------===//
1019 // PHINode - The PHINode class is used to represent the magical mystical PHI
1020 // node, that can not exist in nature, but can be synthesized in a computer
1021 // scientist's overactive imagination.
1023 class PHINode : public Instruction {
1024 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1025 /// the number actually in use.
1026 unsigned ReservedSpace;
1027 PHINode(const PHINode &PN);
1029 explicit PHINode(const Type *Ty, const std::string &Name = "",
1030 Instruction *InsertBefore = 0)
1031 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore),
1035 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1036 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
1042 /// reserveOperandSpace - This method can be used to avoid repeated
1043 /// reallocation of PHI operand lists by reserving space for the correct
1044 /// number of operands before adding them. Unlike normal vector reserves,
1045 /// this method can also be used to trim the operand space.
1046 void reserveOperandSpace(unsigned NumValues) {
1047 resizeOperands(NumValues*2);
1050 virtual PHINode *clone() const;
1052 /// getNumIncomingValues - Return the number of incoming edges
1054 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1056 /// getIncomingValue - Return incoming value number x
1058 Value *getIncomingValue(unsigned i) const {
1059 assert(i*2 < getNumOperands() && "Invalid value number!");
1060 return getOperand(i*2);
1062 void setIncomingValue(unsigned i, Value *V) {
1063 assert(i*2 < getNumOperands() && "Invalid value number!");
1066 unsigned getOperandNumForIncomingValue(unsigned i) {
1070 /// getIncomingBlock - Return incoming basic block number x
1072 BasicBlock *getIncomingBlock(unsigned i) const {
1073 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1075 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1076 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1078 unsigned getOperandNumForIncomingBlock(unsigned i) {
1082 /// addIncoming - Add an incoming value to the end of the PHI list
1084 void addIncoming(Value *V, BasicBlock *BB) {
1085 assert(getType() == V->getType() &&
1086 "All operands to PHI node must be the same type as the PHI node!");
1087 unsigned OpNo = NumOperands;
1088 if (OpNo+2 > ReservedSpace)
1089 resizeOperands(0); // Get more space!
1090 // Initialize some new operands.
1091 NumOperands = OpNo+2;
1092 OperandList[OpNo].init(V, this);
1093 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1096 /// removeIncomingValue - Remove an incoming value. This is useful if a
1097 /// predecessor basic block is deleted. The value removed is returned.
1099 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1100 /// is true), the PHI node is destroyed and any uses of it are replaced with
1101 /// dummy values. The only time there should be zero incoming values to a PHI
1102 /// node is when the block is dead, so this strategy is sound.
1104 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1106 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1107 int Idx = getBasicBlockIndex(BB);
1108 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1109 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1112 /// getBasicBlockIndex - Return the first index of the specified basic
1113 /// block in the value list for this PHI. Returns -1 if no instance.
1115 int getBasicBlockIndex(const BasicBlock *BB) const {
1116 Use *OL = OperandList;
1117 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1118 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1122 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1123 return getIncomingValue(getBasicBlockIndex(BB));
1126 /// hasConstantValue - If the specified PHI node always merges together the
1127 /// same value, return the value, otherwise return null.
1129 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1131 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1132 static inline bool classof(const PHINode *) { return true; }
1133 static inline bool classof(const Instruction *I) {
1134 return I->getOpcode() == Instruction::PHI;
1136 static inline bool classof(const Value *V) {
1137 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1140 void resizeOperands(unsigned NumOperands);
1143 //===----------------------------------------------------------------------===//
1145 //===----------------------------------------------------------------------===//
1147 //===---------------------------------------------------------------------------
1148 /// ReturnInst - Return a value (possibly void), from a function. Execution
1149 /// does not continue in this function any longer.
1151 class ReturnInst : public TerminatorInst {
1152 Use RetVal; // Possibly null retval.
1153 ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
1154 RI.getNumOperands()) {
1155 if (RI.getNumOperands())
1156 RetVal.init(RI.RetVal, this);
1159 void init(Value *RetVal);
1162 // ReturnInst constructors:
1163 // ReturnInst() - 'ret void' instruction
1164 // ReturnInst( null) - 'ret void' instruction
1165 // ReturnInst(Value* X) - 'ret X' instruction
1166 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1167 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1168 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1169 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1171 // NOTE: If the Value* passed is of type void then the constructor behaves as
1172 // if it was passed NULL.
1173 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
1174 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
1177 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
1178 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1181 explicit ReturnInst(BasicBlock *InsertAtEnd)
1182 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1185 virtual ReturnInst *clone() const;
1187 // Transparently provide more efficient getOperand methods.
1188 Value *getOperand(unsigned i) const {
1189 assert(i < getNumOperands() && "getOperand() out of range!");
1192 void setOperand(unsigned i, Value *Val) {
1193 assert(i < getNumOperands() && "setOperand() out of range!");
1197 Value *getReturnValue() const { return RetVal; }
1199 unsigned getNumSuccessors() const { return 0; }
1201 // Methods for support type inquiry through isa, cast, and dyn_cast:
1202 static inline bool classof(const ReturnInst *) { return true; }
1203 static inline bool classof(const Instruction *I) {
1204 return (I->getOpcode() == Instruction::Ret);
1206 static inline bool classof(const Value *V) {
1207 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1210 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1211 virtual unsigned getNumSuccessorsV() const;
1212 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1215 //===----------------------------------------------------------------------===//
1217 //===----------------------------------------------------------------------===//
1219 //===---------------------------------------------------------------------------
1220 /// BranchInst - Conditional or Unconditional Branch instruction.
1222 class BranchInst : public TerminatorInst {
1223 /// Ops list - Branches are strange. The operands are ordered:
1224 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1225 /// they don't have to check for cond/uncond branchness.
1227 BranchInst(const BranchInst &BI);
1230 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1231 // BranchInst(BB *B) - 'br B'
1232 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1233 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1234 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1235 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1236 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1237 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
1238 : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
1239 assert(IfTrue != 0 && "Branch destination may not be null!");
1240 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1242 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1243 Instruction *InsertBefore = 0)
1244 : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
1245 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1246 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1247 Ops[2].init(Cond, this);
1253 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
1254 : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
1255 assert(IfTrue != 0 && "Branch destination may not be null!");
1256 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1259 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1260 BasicBlock *InsertAtEnd)
1261 : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
1262 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1263 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1264 Ops[2].init(Cond, this);
1271 /// Transparently provide more efficient getOperand methods.
1272 Value *getOperand(unsigned i) const {
1273 assert(i < getNumOperands() && "getOperand() out of range!");
1276 void setOperand(unsigned i, Value *Val) {
1277 assert(i < getNumOperands() && "setOperand() out of range!");
1281 virtual BranchInst *clone() const;
1283 inline bool isUnconditional() const { return getNumOperands() == 1; }
1284 inline bool isConditional() const { return getNumOperands() == 3; }
1286 inline Value *getCondition() const {
1287 assert(isConditional() && "Cannot get condition of an uncond branch!");
1288 return getOperand(2);
1291 void setCondition(Value *V) {
1292 assert(isConditional() && "Cannot set condition of unconditional branch!");
1296 // setUnconditionalDest - Change the current branch to an unconditional branch
1297 // targeting the specified block.
1298 // FIXME: Eliminate this ugly method.
1299 void setUnconditionalDest(BasicBlock *Dest) {
1300 if (isConditional()) { // Convert this to an uncond branch.
1305 setOperand(0, reinterpret_cast<Value*>(Dest));
1308 unsigned getNumSuccessors() const { return 1+isConditional(); }
1310 BasicBlock *getSuccessor(unsigned i) const {
1311 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1312 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1313 cast<BasicBlock>(getOperand(1));
1316 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1317 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1318 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1321 // Methods for support type inquiry through isa, cast, and dyn_cast:
1322 static inline bool classof(const BranchInst *) { return true; }
1323 static inline bool classof(const Instruction *I) {
1324 return (I->getOpcode() == Instruction::Br);
1326 static inline bool classof(const Value *V) {
1327 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1330 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1331 virtual unsigned getNumSuccessorsV() const;
1332 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1335 //===----------------------------------------------------------------------===//
1337 //===----------------------------------------------------------------------===//
1339 //===---------------------------------------------------------------------------
1340 /// SwitchInst - Multiway switch
1342 class SwitchInst : public TerminatorInst {
1343 unsigned ReservedSpace;
1344 // Operand[0] = Value to switch on
1345 // Operand[1] = Default basic block destination
1346 // Operand[2n ] = Value to match
1347 // Operand[2n+1] = BasicBlock to go to on match
1348 SwitchInst(const SwitchInst &RI);
1349 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1350 void resizeOperands(unsigned No);
1352 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1353 /// switch on and a default destination. The number of additional cases can
1354 /// be specified here to make memory allocation more efficient. This
1355 /// constructor can also autoinsert before another instruction.
1356 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1357 Instruction *InsertBefore = 0)
1358 : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1359 init(Value, Default, NumCases);
1362 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1363 /// switch on and a default destination. The number of additional cases can
1364 /// be specified here to make memory allocation more efficient. This
1365 /// constructor also autoinserts at the end of the specified BasicBlock.
1366 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1367 BasicBlock *InsertAtEnd)
1368 : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1369 init(Value, Default, NumCases);
1374 // Accessor Methods for Switch stmt
1375 inline Value *getCondition() const { return getOperand(0); }
1376 void setCondition(Value *V) { setOperand(0, V); }
1378 inline BasicBlock *getDefaultDest() const {
1379 return cast<BasicBlock>(getOperand(1));
1382 /// getNumCases - return the number of 'cases' in this switch instruction.
1383 /// Note that case #0 is always the default case.
1384 unsigned getNumCases() const {
1385 return getNumOperands()/2;
1388 /// getCaseValue - Return the specified case value. Note that case #0, the
1389 /// default destination, does not have a case value.
1390 ConstantInt *getCaseValue(unsigned i) {
1391 assert(i && i < getNumCases() && "Illegal case value to get!");
1392 return getSuccessorValue(i);
1395 /// getCaseValue - Return the specified case value. Note that case #0, the
1396 /// default destination, does not have a case value.
1397 const ConstantInt *getCaseValue(unsigned i) const {
1398 assert(i && i < getNumCases() && "Illegal case value to get!");
1399 return getSuccessorValue(i);
1402 /// findCaseValue - Search all of the case values for the specified constant.
1403 /// If it is explicitly handled, return the case number of it, otherwise
1404 /// return 0 to indicate that it is handled by the default handler.
1405 unsigned findCaseValue(const ConstantInt *C) const {
1406 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1407 if (getCaseValue(i) == C)
1412 /// findCaseDest - Finds the unique case value for a given successor. Returns
1413 /// null if the successor is not found, not unique, or is the default case.
1414 ConstantInt *findCaseDest(BasicBlock *BB) {
1415 if (BB == getDefaultDest()) return NULL;
1417 ConstantInt *CI = NULL;
1418 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1419 if (getSuccessor(i) == BB) {
1420 if (CI) return NULL; // Multiple cases lead to BB.
1421 else CI = getCaseValue(i);
1427 /// addCase - Add an entry to the switch instruction...
1429 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1431 /// removeCase - This method removes the specified successor from the switch
1432 /// instruction. Note that this cannot be used to remove the default
1433 /// destination (successor #0).
1435 void removeCase(unsigned idx);
1437 virtual SwitchInst *clone() const;
1439 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1440 BasicBlock *getSuccessor(unsigned idx) const {
1441 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1442 return cast<BasicBlock>(getOperand(idx*2+1));
1444 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1445 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1446 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1449 // getSuccessorValue - Return the value associated with the specified
1451 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1452 assert(idx < getNumSuccessors() && "Successor # out of range!");
1453 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1456 // Methods for support type inquiry through isa, cast, and dyn_cast:
1457 static inline bool classof(const SwitchInst *) { return true; }
1458 static inline bool classof(const Instruction *I) {
1459 return I->getOpcode() == Instruction::Switch;
1461 static inline bool classof(const Value *V) {
1462 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1465 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1466 virtual unsigned getNumSuccessorsV() const;
1467 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1470 //===----------------------------------------------------------------------===//
1472 //===----------------------------------------------------------------------===//
1474 //===---------------------------------------------------------------------------
1476 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1477 /// calling convention of the call.
1479 class InvokeInst : public TerminatorInst {
1480 InvokeInst(const InvokeInst &BI);
1481 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1482 const std::vector<Value*> &Params);
1484 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1485 const std::vector<Value*> &Params, const std::string &Name = "",
1486 Instruction *InsertBefore = 0);
1487 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1488 const std::vector<Value*> &Params, const std::string &Name,
1489 BasicBlock *InsertAtEnd);
1492 virtual InvokeInst *clone() const;
1494 bool mayWriteToMemory() const { return true; }
1496 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1498 unsigned getCallingConv() const { return SubclassData; }
1499 void setCallingConv(unsigned CC) {
1503 /// getCalledFunction - Return the function called, or null if this is an
1504 /// indirect function invocation.
1506 Function *getCalledFunction() const {
1507 return dyn_cast<Function>(getOperand(0));
1510 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1511 inline Value *getCalledValue() const { return getOperand(0); }
1513 // get*Dest - Return the destination basic blocks...
1514 BasicBlock *getNormalDest() const {
1515 return cast<BasicBlock>(getOperand(1));
1517 BasicBlock *getUnwindDest() const {
1518 return cast<BasicBlock>(getOperand(2));
1520 void setNormalDest(BasicBlock *B) {
1521 setOperand(1, reinterpret_cast<Value*>(B));
1524 void setUnwindDest(BasicBlock *B) {
1525 setOperand(2, reinterpret_cast<Value*>(B));
1528 inline BasicBlock *getSuccessor(unsigned i) const {
1529 assert(i < 2 && "Successor # out of range for invoke!");
1530 return i == 0 ? getNormalDest() : getUnwindDest();
1533 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1534 assert(idx < 2 && "Successor # out of range for invoke!");
1535 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1538 unsigned getNumSuccessors() const { return 2; }
1540 // Methods for support type inquiry through isa, cast, and dyn_cast:
1541 static inline bool classof(const InvokeInst *) { return true; }
1542 static inline bool classof(const Instruction *I) {
1543 return (I->getOpcode() == Instruction::Invoke);
1545 static inline bool classof(const Value *V) {
1546 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1549 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1550 virtual unsigned getNumSuccessorsV() const;
1551 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1555 //===----------------------------------------------------------------------===//
1557 //===----------------------------------------------------------------------===//
1559 //===---------------------------------------------------------------------------
1560 /// UnwindInst - Immediately exit the current function, unwinding the stack
1561 /// until an invoke instruction is found.
1563 class UnwindInst : public TerminatorInst {
1565 explicit UnwindInst(Instruction *InsertBefore = 0)
1566 : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
1568 explicit UnwindInst(BasicBlock *InsertAtEnd)
1569 : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
1572 virtual UnwindInst *clone() const;
1574 unsigned getNumSuccessors() const { return 0; }
1576 // Methods for support type inquiry through isa, cast, and dyn_cast:
1577 static inline bool classof(const UnwindInst *) { return true; }
1578 static inline bool classof(const Instruction *I) {
1579 return I->getOpcode() == Instruction::Unwind;
1581 static inline bool classof(const Value *V) {
1582 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1585 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1586 virtual unsigned getNumSuccessorsV() const;
1587 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1590 //===----------------------------------------------------------------------===//
1591 // UnreachableInst Class
1592 //===----------------------------------------------------------------------===//
1594 //===---------------------------------------------------------------------------
1595 /// UnreachableInst - This function has undefined behavior. In particular, the
1596 /// presence of this instruction indicates some higher level knowledge that the
1597 /// end of the block cannot be reached.
1599 class UnreachableInst : public TerminatorInst {
1601 explicit UnreachableInst(Instruction *InsertBefore = 0)
1602 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
1604 explicit UnreachableInst(BasicBlock *InsertAtEnd)
1605 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
1608 virtual UnreachableInst *clone() const;
1610 unsigned getNumSuccessors() const { return 0; }
1612 // Methods for support type inquiry through isa, cast, and dyn_cast:
1613 static inline bool classof(const UnreachableInst *) { return true; }
1614 static inline bool classof(const Instruction *I) {
1615 return I->getOpcode() == Instruction::Unreachable;
1617 static inline bool classof(const Value *V) {
1618 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1621 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1622 virtual unsigned getNumSuccessorsV() const;
1623 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1626 //===----------------------------------------------------------------------===//
1628 //===----------------------------------------------------------------------===//
1630 /// @brief This class represents a truncation of integer types.
1631 class TruncInst : public CastInst {
1632 /// Private copy constructor
1633 TruncInst(const TruncInst &CI)
1634 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1637 /// @brief Constructor with insert-before-instruction semantics
1639 Value *S, ///< The value to be truncated
1640 const Type *Ty, ///< The (smaller) type to truncate to
1641 const std::string &Name = "", ///< A name for the new instruction
1642 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1645 /// @brief Constructor with insert-at-end-of-block semantics
1647 Value *S, ///< The value to be truncated
1648 const Type *Ty, ///< The (smaller) type to truncate to
1649 const std::string &Name, ///< A name for the new instruction
1650 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1653 /// @brief Clone an identical TruncInst
1654 virtual CastInst *clone() const;
1656 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1657 static inline bool classof(const TruncInst *) { return true; }
1658 static inline bool classof(const Instruction *I) {
1659 return I->getOpcode() == Trunc;
1661 static inline bool classof(const Value *V) {
1662 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1666 //===----------------------------------------------------------------------===//
1668 //===----------------------------------------------------------------------===//
1670 /// @brief This class represents zero extension of integer types.
1671 class ZExtInst : public CastInst {
1672 /// @brief Private copy constructor
1673 ZExtInst(const ZExtInst &CI)
1674 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1677 /// @brief Constructor with insert-before-instruction semantics
1679 Value *S, ///< The value to be zero extended
1680 const Type *Ty, ///< The type to zero extend to
1681 const std::string &Name = "", ///< A name for the new instruction
1682 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1685 /// @brief Constructor with insert-at-end semantics.
1687 Value *S, ///< The value to be zero extended
1688 const Type *Ty, ///< The type to zero extend to
1689 const std::string &Name, ///< A name for the new instruction
1690 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1693 /// @brief Clone an identical ZExtInst
1694 virtual CastInst *clone() const;
1696 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1697 static inline bool classof(const ZExtInst *) { return true; }
1698 static inline bool classof(const Instruction *I) {
1699 return I->getOpcode() == ZExt;
1701 static inline bool classof(const Value *V) {
1702 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1706 //===----------------------------------------------------------------------===//
1708 //===----------------------------------------------------------------------===//
1710 /// @brief This class represents a sign extension of integer types.
1711 class SExtInst : public CastInst {
1712 /// @brief Private copy constructor
1713 SExtInst(const SExtInst &CI)
1714 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1717 /// @brief Constructor with insert-before-instruction semantics
1719 Value *S, ///< The value to be sign extended
1720 const Type *Ty, ///< The type to sign extend to
1721 const std::string &Name = "", ///< A name for the new instruction
1722 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1725 /// @brief Constructor with insert-at-end-of-block semantics
1727 Value *S, ///< The value to be sign extended
1728 const Type *Ty, ///< The type to sign extend to
1729 const std::string &Name, ///< A name for the new instruction
1730 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1733 /// @brief Clone an identical SExtInst
1734 virtual CastInst *clone() const;
1736 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1737 static inline bool classof(const SExtInst *) { return true; }
1738 static inline bool classof(const Instruction *I) {
1739 return I->getOpcode() == SExt;
1741 static inline bool classof(const Value *V) {
1742 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1746 //===----------------------------------------------------------------------===//
1747 // FPTruncInst Class
1748 //===----------------------------------------------------------------------===//
1750 /// @brief This class represents a truncation of floating point types.
1751 class FPTruncInst : public CastInst {
1752 FPTruncInst(const FPTruncInst &CI)
1753 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1756 /// @brief Constructor with insert-before-instruction semantics
1758 Value *S, ///< The value to be truncated
1759 const Type *Ty, ///< The type to truncate to
1760 const std::string &Name = "", ///< A name for the new instruction
1761 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1764 /// @brief Constructor with insert-before-instruction semantics
1766 Value *S, ///< The value to be truncated
1767 const Type *Ty, ///< The type to truncate to
1768 const std::string &Name, ///< A name for the new instruction
1769 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1772 /// @brief Clone an identical FPTruncInst
1773 virtual CastInst *clone() const;
1775 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1776 static inline bool classof(const FPTruncInst *) { return true; }
1777 static inline bool classof(const Instruction *I) {
1778 return I->getOpcode() == FPTrunc;
1780 static inline bool classof(const Value *V) {
1781 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1785 //===----------------------------------------------------------------------===//
1787 //===----------------------------------------------------------------------===//
1789 /// @brief This class represents an extension of floating point types.
1790 class FPExtInst : public CastInst {
1791 FPExtInst(const FPExtInst &CI)
1792 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1795 /// @brief Constructor with insert-before-instruction semantics
1797 Value *S, ///< The value to be extended
1798 const Type *Ty, ///< The type to extend to
1799 const std::string &Name = "", ///< A name for the new instruction
1800 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1803 /// @brief Constructor with insert-at-end-of-block semantics
1805 Value *S, ///< The value to be extended
1806 const Type *Ty, ///< The type to extend to
1807 const std::string &Name, ///< A name for the new instruction
1808 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1811 /// @brief Clone an identical FPExtInst
1812 virtual CastInst *clone() const;
1814 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1815 static inline bool classof(const FPExtInst *) { return true; }
1816 static inline bool classof(const Instruction *I) {
1817 return I->getOpcode() == FPExt;
1819 static inline bool classof(const Value *V) {
1820 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1824 //===----------------------------------------------------------------------===//
1826 //===----------------------------------------------------------------------===//
1828 /// @brief This class represents a cast unsigned integer to floating point.
1829 class UIToFPInst : public CastInst {
1830 UIToFPInst(const UIToFPInst &CI)
1831 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1834 /// @brief Constructor with insert-before-instruction semantics
1836 Value *S, ///< The value to be converted
1837 const Type *Ty, ///< The type to convert to
1838 const std::string &Name = "", ///< A name for the new instruction
1839 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1842 /// @brief Constructor with insert-at-end-of-block semantics
1844 Value *S, ///< The value to be converted
1845 const Type *Ty, ///< The type to convert to
1846 const std::string &Name, ///< A name for the new instruction
1847 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1850 /// @brief Clone an identical UIToFPInst
1851 virtual CastInst *clone() const;
1853 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1854 static inline bool classof(const UIToFPInst *) { return true; }
1855 static inline bool classof(const Instruction *I) {
1856 return I->getOpcode() == UIToFP;
1858 static inline bool classof(const Value *V) {
1859 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1863 //===----------------------------------------------------------------------===//
1865 //===----------------------------------------------------------------------===//
1867 /// @brief This class represents a cast from signed integer to floating point.
1868 class SIToFPInst : public CastInst {
1869 SIToFPInst(const SIToFPInst &CI)
1870 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1873 /// @brief Constructor with insert-before-instruction semantics
1875 Value *S, ///< The value to be converted
1876 const Type *Ty, ///< The type to convert to
1877 const std::string &Name = "", ///< A name for the new instruction
1878 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1881 /// @brief Constructor with insert-at-end-of-block semantics
1883 Value *S, ///< The value to be converted
1884 const Type *Ty, ///< The type to convert to
1885 const std::string &Name, ///< A name for the new instruction
1886 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1889 /// @brief Clone an identical SIToFPInst
1890 virtual CastInst *clone() const;
1892 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1893 static inline bool classof(const SIToFPInst *) { return true; }
1894 static inline bool classof(const Instruction *I) {
1895 return I->getOpcode() == SIToFP;
1897 static inline bool classof(const Value *V) {
1898 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1902 //===----------------------------------------------------------------------===//
1904 //===----------------------------------------------------------------------===//
1906 /// @brief This class represents a cast from floating point to unsigned integer
1907 class FPToUIInst : public CastInst {
1908 FPToUIInst(const FPToUIInst &CI)
1909 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1912 /// @brief Constructor with insert-before-instruction semantics
1914 Value *S, ///< The value to be converted
1915 const Type *Ty, ///< The type to convert to
1916 const std::string &Name = "", ///< A name for the new instruction
1917 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1920 /// @brief Constructor with insert-at-end-of-block semantics
1922 Value *S, ///< The value to be converted
1923 const Type *Ty, ///< The type to convert to
1924 const std::string &Name, ///< A name for the new instruction
1925 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
1928 /// @brief Clone an identical FPToUIInst
1929 virtual CastInst *clone() const;
1931 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1932 static inline bool classof(const FPToUIInst *) { return true; }
1933 static inline bool classof(const Instruction *I) {
1934 return I->getOpcode() == FPToUI;
1936 static inline bool classof(const Value *V) {
1937 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1941 //===----------------------------------------------------------------------===//
1943 //===----------------------------------------------------------------------===//
1945 /// @brief This class represents a cast from floating point to signed integer.
1946 class FPToSIInst : public CastInst {
1947 FPToSIInst(const FPToSIInst &CI)
1948 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
1951 /// @brief Constructor with insert-before-instruction semantics
1953 Value *S, ///< The value to be converted
1954 const Type *Ty, ///< The type to convert to
1955 const std::string &Name = "", ///< A name for the new instruction
1956 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1959 /// @brief Constructor with insert-at-end-of-block semantics
1961 Value *S, ///< The value to be converted
1962 const Type *Ty, ///< The type to convert to
1963 const std::string &Name, ///< A name for the new instruction
1964 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1967 /// @brief Clone an identical FPToSIInst
1968 virtual CastInst *clone() const;
1970 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1971 static inline bool classof(const FPToSIInst *) { return true; }
1972 static inline bool classof(const Instruction *I) {
1973 return I->getOpcode() == FPToSI;
1975 static inline bool classof(const Value *V) {
1976 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1980 //===----------------------------------------------------------------------===//
1981 // IntToPtrInst Class
1982 //===----------------------------------------------------------------------===//
1984 /// @brief This class represents a cast from an integer to a pointer.
1985 class IntToPtrInst : public CastInst {
1986 IntToPtrInst(const IntToPtrInst &CI)
1987 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
1990 /// @brief Constructor with insert-before-instruction semantics
1992 Value *S, ///< The value to be converted
1993 const Type *Ty, ///< The type to convert to
1994 const std::string &Name = "", ///< A name for the new instruction
1995 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1998 /// @brief Constructor with insert-at-end-of-block semantics
2000 Value *S, ///< The value to be converted
2001 const Type *Ty, ///< The type to convert to
2002 const std::string &Name, ///< A name for the new instruction
2003 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2006 /// @brief Clone an identical IntToPtrInst
2007 virtual CastInst *clone() const;
2009 // Methods for support type inquiry through isa, cast, and dyn_cast:
2010 static inline bool classof(const IntToPtrInst *) { return true; }
2011 static inline bool classof(const Instruction *I) {
2012 return I->getOpcode() == IntToPtr;
2014 static inline bool classof(const Value *V) {
2015 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2019 //===----------------------------------------------------------------------===//
2020 // PtrToIntInst Class
2021 //===----------------------------------------------------------------------===//
2023 /// @brief This class represents a cast from a pointer to an integer
2024 class PtrToIntInst : public CastInst {
2025 PtrToIntInst(const PtrToIntInst &CI)
2026 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2029 /// @brief Constructor with insert-before-instruction semantics
2031 Value *S, ///< The value to be converted
2032 const Type *Ty, ///< The type to convert to
2033 const std::string &Name = "", ///< A name for the new instruction
2034 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2037 /// @brief Constructor with insert-at-end-of-block semantics
2039 Value *S, ///< The value to be converted
2040 const Type *Ty, ///< The type to convert to
2041 const std::string &Name, ///< A name for the new instruction
2042 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2045 /// @brief Clone an identical PtrToIntInst
2046 virtual CastInst *clone() const;
2048 // Methods for support type inquiry through isa, cast, and dyn_cast:
2049 static inline bool classof(const PtrToIntInst *) { return true; }
2050 static inline bool classof(const Instruction *I) {
2051 return I->getOpcode() == PtrToInt;
2053 static inline bool classof(const Value *V) {
2054 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2058 //===----------------------------------------------------------------------===//
2059 // BitCastInst Class
2060 //===----------------------------------------------------------------------===//
2062 /// @brief This class represents a no-op cast from one type to another.
2063 class BitCastInst : public CastInst {
2064 BitCastInst(const BitCastInst &CI)
2065 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2068 /// @brief Constructor with insert-before-instruction semantics
2070 Value *S, ///< The value to be casted
2071 const Type *Ty, ///< The type to casted to
2072 const std::string &Name = "", ///< A name for the new instruction
2073 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2076 /// @brief Constructor with insert-at-end-of-block semantics
2078 Value *S, ///< The value to be casted
2079 const Type *Ty, ///< The type to casted to
2080 const std::string &Name, ///< A name for the new instruction
2081 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2084 /// @brief Clone an identical BitCastInst
2085 virtual CastInst *clone() const;
2087 // Methods for support type inquiry through isa, cast, and dyn_cast:
2088 static inline bool classof(const BitCastInst *) { return true; }
2089 static inline bool classof(const Instruction *I) {
2090 return I->getOpcode() == BitCast;
2092 static inline bool classof(const Value *V) {
2093 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2097 } // End llvm namespace