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, Value* const *Args, unsigned NumArgs,
699 const std::string &Name = "", Instruction *InsertBefore = 0);
700 CallInst(Value *F, Value *const *Args, unsigned NumArgs,
701 const std::string &Name, BasicBlock *InsertAtEnd);
703 CallInst(Value *F, const std::vector<Value*> &Par,
704 const std::string &Name = "", Instruction *InsertBefore = 0);
705 CallInst(Value *F, const std::vector<Value*> &Par,
706 const std::string &Name, BasicBlock *InsertAtEnd);
708 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
709 // actuals, respectively.
710 CallInst(Value *F, Value *Actual1, Value *Actual2,
711 const std::string& Name = "", Instruction *InsertBefore = 0);
712 CallInst(Value *F, Value *Actual1, Value *Actual2,
713 const std::string& Name, BasicBlock *InsertAtEnd);
714 CallInst(Value *F, Value *Actual, const std::string& Name = "",
715 Instruction *InsertBefore = 0);
716 CallInst(Value *F, Value *Actual, const std::string& Name,
717 BasicBlock *InsertAtEnd);
718 explicit CallInst(Value *F, const std::string &Name = "",
719 Instruction *InsertBefore = 0);
720 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
723 virtual CallInst *clone() const;
724 bool mayWriteToMemory() const { return true; }
726 bool isTailCall() const { return SubclassData & 1; }
727 void setTailCall(bool isTailCall = true) {
728 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
731 /// getCallingConv/setCallingConv - Get or set the calling convention of this
733 unsigned getCallingConv() const { return SubclassData >> 1; }
734 void setCallingConv(unsigned CC) {
735 SubclassData = (SubclassData & 1) | (CC << 1);
738 /// getCalledFunction - Return the function being called by this instruction
739 /// if it is a direct call. If it is a call through a function pointer,
741 Function *getCalledFunction() const {
742 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
745 /// getCalledValue - Get a pointer to the function that is invoked by this
747 inline const Value *getCalledValue() const { return getOperand(0); }
748 inline Value *getCalledValue() { return getOperand(0); }
750 // Methods for support type inquiry through isa, cast, and dyn_cast:
751 static inline bool classof(const CallInst *) { return true; }
752 static inline bool classof(const Instruction *I) {
753 return I->getOpcode() == Instruction::Call;
755 static inline bool classof(const Value *V) {
756 return isa<Instruction>(V) && classof(cast<Instruction>(V));
760 //===----------------------------------------------------------------------===//
762 //===----------------------------------------------------------------------===//
764 /// SelectInst - This class represents the LLVM 'select' instruction.
766 class SelectInst : public Instruction {
769 void init(Value *C, Value *S1, Value *S2) {
770 Ops[0].init(C, this);
771 Ops[1].init(S1, this);
772 Ops[2].init(S2, this);
775 SelectInst(const SelectInst &SI)
776 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
777 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
780 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
781 Instruction *InsertBefore = 0)
782 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
783 Name, InsertBefore) {
786 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
787 BasicBlock *InsertAtEnd)
788 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
793 Value *getCondition() const { return Ops[0]; }
794 Value *getTrueValue() const { return Ops[1]; }
795 Value *getFalseValue() const { return Ops[2]; }
797 /// Transparently provide more efficient getOperand methods.
798 Value *getOperand(unsigned i) const {
799 assert(i < 3 && "getOperand() out of range!");
802 void setOperand(unsigned i, Value *Val) {
803 assert(i < 3 && "setOperand() out of range!");
806 unsigned getNumOperands() const { return 3; }
808 OtherOps getOpcode() const {
809 return static_cast<OtherOps>(Instruction::getOpcode());
812 virtual SelectInst *clone() const;
814 // Methods for support type inquiry through isa, cast, and dyn_cast:
815 static inline bool classof(const SelectInst *) { return true; }
816 static inline bool classof(const Instruction *I) {
817 return I->getOpcode() == Instruction::Select;
819 static inline bool classof(const Value *V) {
820 return isa<Instruction>(V) && classof(cast<Instruction>(V));
824 //===----------------------------------------------------------------------===//
826 //===----------------------------------------------------------------------===//
828 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
829 /// an argument of the specified type given a va_list and increments that list
831 class VAArgInst : public UnaryInstruction {
832 VAArgInst(const VAArgInst &VAA)
833 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
835 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
836 Instruction *InsertBefore = 0)
837 : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) {
839 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
840 BasicBlock *InsertAtEnd)
841 : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) {
844 virtual VAArgInst *clone() const;
845 bool mayWriteToMemory() const { return true; }
847 // Methods for support type inquiry through isa, cast, and dyn_cast:
848 static inline bool classof(const VAArgInst *) { return true; }
849 static inline bool classof(const Instruction *I) {
850 return I->getOpcode() == VAArg;
852 static inline bool classof(const Value *V) {
853 return isa<Instruction>(V) && classof(cast<Instruction>(V));
857 //===----------------------------------------------------------------------===//
858 // ExtractElementInst Class
859 //===----------------------------------------------------------------------===//
861 /// ExtractElementInst - This instruction extracts a single (scalar)
862 /// element from a PackedType value
864 class ExtractElementInst : public Instruction {
866 ExtractElementInst(const ExtractElementInst &EE) :
867 Instruction(EE.getType(), ExtractElement, Ops, 2) {
868 Ops[0].init(EE.Ops[0], this);
869 Ops[1].init(EE.Ops[1], this);
873 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
874 Instruction *InsertBefore = 0);
875 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
876 Instruction *InsertBefore = 0);
877 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
878 BasicBlock *InsertAtEnd);
879 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
880 BasicBlock *InsertAtEnd);
882 /// isValidOperands - Return true if an extractelement instruction can be
883 /// formed with the specified operands.
884 static bool isValidOperands(const Value *Vec, const Value *Idx);
886 virtual ExtractElementInst *clone() const;
888 virtual bool mayWriteToMemory() const { return false; }
890 /// Transparently provide more efficient getOperand methods.
891 Value *getOperand(unsigned i) const {
892 assert(i < 2 && "getOperand() out of range!");
895 void setOperand(unsigned i, Value *Val) {
896 assert(i < 2 && "setOperand() out of range!");
899 unsigned getNumOperands() const { return 2; }
901 // Methods for support type inquiry through isa, cast, and dyn_cast:
902 static inline bool classof(const ExtractElementInst *) { return true; }
903 static inline bool classof(const Instruction *I) {
904 return I->getOpcode() == Instruction::ExtractElement;
906 static inline bool classof(const Value *V) {
907 return isa<Instruction>(V) && classof(cast<Instruction>(V));
911 //===----------------------------------------------------------------------===//
912 // InsertElementInst Class
913 //===----------------------------------------------------------------------===//
915 /// InsertElementInst - This instruction inserts a single (scalar)
916 /// element into a PackedType value
918 class InsertElementInst : public Instruction {
920 InsertElementInst(const InsertElementInst &IE);
922 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
923 const std::string &Name = "",Instruction *InsertBefore = 0);
924 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
925 const std::string &Name = "",Instruction *InsertBefore = 0);
926 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
927 const std::string &Name, BasicBlock *InsertAtEnd);
928 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
929 const std::string &Name, BasicBlock *InsertAtEnd);
931 /// isValidOperands - Return true if an insertelement instruction can be
932 /// formed with the specified operands.
933 static bool isValidOperands(const Value *Vec, const Value *NewElt,
936 virtual InsertElementInst *clone() const;
938 virtual bool mayWriteToMemory() const { return false; }
940 /// getType - Overload to return most specific packed type.
942 inline const PackedType *getType() const {
943 return reinterpret_cast<const PackedType*>(Instruction::getType());
946 /// Transparently provide more efficient getOperand methods.
947 Value *getOperand(unsigned i) const {
948 assert(i < 3 && "getOperand() out of range!");
951 void setOperand(unsigned i, Value *Val) {
952 assert(i < 3 && "setOperand() out of range!");
955 unsigned getNumOperands() const { return 3; }
957 // Methods for support type inquiry through isa, cast, and dyn_cast:
958 static inline bool classof(const InsertElementInst *) { return true; }
959 static inline bool classof(const Instruction *I) {
960 return I->getOpcode() == Instruction::InsertElement;
962 static inline bool classof(const Value *V) {
963 return isa<Instruction>(V) && classof(cast<Instruction>(V));
967 //===----------------------------------------------------------------------===//
968 // ShuffleVectorInst Class
969 //===----------------------------------------------------------------------===//
971 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
974 class ShuffleVectorInst : public Instruction {
976 ShuffleVectorInst(const ShuffleVectorInst &IE);
978 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
979 const std::string &Name = "", Instruction *InsertBefor = 0);
980 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
981 const std::string &Name, BasicBlock *InsertAtEnd);
983 /// isValidOperands - Return true if a shufflevector instruction can be
984 /// formed with the specified operands.
985 static bool isValidOperands(const Value *V1, const Value *V2,
988 virtual ShuffleVectorInst *clone() const;
990 virtual bool mayWriteToMemory() const { return false; }
992 /// getType - Overload to return most specific packed type.
994 inline const PackedType *getType() const {
995 return reinterpret_cast<const PackedType*>(Instruction::getType());
998 /// Transparently provide more efficient getOperand methods.
999 Value *getOperand(unsigned i) const {
1000 assert(i < 3 && "getOperand() out of range!");
1003 void setOperand(unsigned i, Value *Val) {
1004 assert(i < 3 && "setOperand() out of range!");
1007 unsigned getNumOperands() const { return 3; }
1009 // Methods for support type inquiry through isa, cast, and dyn_cast:
1010 static inline bool classof(const ShuffleVectorInst *) { return true; }
1011 static inline bool classof(const Instruction *I) {
1012 return I->getOpcode() == Instruction::ShuffleVector;
1014 static inline bool classof(const Value *V) {
1015 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1020 //===----------------------------------------------------------------------===//
1022 //===----------------------------------------------------------------------===//
1024 // PHINode - The PHINode class is used to represent the magical mystical PHI
1025 // node, that can not exist in nature, but can be synthesized in a computer
1026 // scientist's overactive imagination.
1028 class PHINode : public Instruction {
1029 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1030 /// the number actually in use.
1031 unsigned ReservedSpace;
1032 PHINode(const PHINode &PN);
1034 explicit PHINode(const Type *Ty, const std::string &Name = "",
1035 Instruction *InsertBefore = 0)
1036 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore),
1040 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1041 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
1047 /// reserveOperandSpace - This method can be used to avoid repeated
1048 /// reallocation of PHI operand lists by reserving space for the correct
1049 /// number of operands before adding them. Unlike normal vector reserves,
1050 /// this method can also be used to trim the operand space.
1051 void reserveOperandSpace(unsigned NumValues) {
1052 resizeOperands(NumValues*2);
1055 virtual PHINode *clone() const;
1057 /// getNumIncomingValues - Return the number of incoming edges
1059 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1061 /// getIncomingValue - Return incoming value number x
1063 Value *getIncomingValue(unsigned i) const {
1064 assert(i*2 < getNumOperands() && "Invalid value number!");
1065 return getOperand(i*2);
1067 void setIncomingValue(unsigned i, Value *V) {
1068 assert(i*2 < getNumOperands() && "Invalid value number!");
1071 unsigned getOperandNumForIncomingValue(unsigned i) {
1075 /// getIncomingBlock - Return incoming basic block number x
1077 BasicBlock *getIncomingBlock(unsigned i) const {
1078 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1080 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1081 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1083 unsigned getOperandNumForIncomingBlock(unsigned i) {
1087 /// addIncoming - Add an incoming value to the end of the PHI list
1089 void addIncoming(Value *V, BasicBlock *BB) {
1090 assert(getType() == V->getType() &&
1091 "All operands to PHI node must be the same type as the PHI node!");
1092 unsigned OpNo = NumOperands;
1093 if (OpNo+2 > ReservedSpace)
1094 resizeOperands(0); // Get more space!
1095 // Initialize some new operands.
1096 NumOperands = OpNo+2;
1097 OperandList[OpNo].init(V, this);
1098 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1101 /// removeIncomingValue - Remove an incoming value. This is useful if a
1102 /// predecessor basic block is deleted. The value removed is returned.
1104 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1105 /// is true), the PHI node is destroyed and any uses of it are replaced with
1106 /// dummy values. The only time there should be zero incoming values to a PHI
1107 /// node is when the block is dead, so this strategy is sound.
1109 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1111 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1112 int Idx = getBasicBlockIndex(BB);
1113 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1114 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1117 /// getBasicBlockIndex - Return the first index of the specified basic
1118 /// block in the value list for this PHI. Returns -1 if no instance.
1120 int getBasicBlockIndex(const BasicBlock *BB) const {
1121 Use *OL = OperandList;
1122 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1123 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1127 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1128 return getIncomingValue(getBasicBlockIndex(BB));
1131 /// hasConstantValue - If the specified PHI node always merges together the
1132 /// same value, return the value, otherwise return null.
1134 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1136 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1137 static inline bool classof(const PHINode *) { return true; }
1138 static inline bool classof(const Instruction *I) {
1139 return I->getOpcode() == Instruction::PHI;
1141 static inline bool classof(const Value *V) {
1142 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1145 void resizeOperands(unsigned NumOperands);
1148 //===----------------------------------------------------------------------===//
1150 //===----------------------------------------------------------------------===//
1152 //===---------------------------------------------------------------------------
1153 /// ReturnInst - Return a value (possibly void), from a function. Execution
1154 /// does not continue in this function any longer.
1156 class ReturnInst : public TerminatorInst {
1157 Use RetVal; // Possibly null retval.
1158 ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
1159 RI.getNumOperands()) {
1160 if (RI.getNumOperands())
1161 RetVal.init(RI.RetVal, this);
1164 void init(Value *RetVal);
1167 // ReturnInst constructors:
1168 // ReturnInst() - 'ret void' instruction
1169 // ReturnInst( null) - 'ret void' instruction
1170 // ReturnInst(Value* X) - 'ret X' instruction
1171 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1172 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1173 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1174 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1176 // NOTE: If the Value* passed is of type void then the constructor behaves as
1177 // if it was passed NULL.
1178 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
1179 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
1182 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
1183 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1186 explicit ReturnInst(BasicBlock *InsertAtEnd)
1187 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1190 virtual ReturnInst *clone() const;
1192 // Transparently provide more efficient getOperand methods.
1193 Value *getOperand(unsigned i) const {
1194 assert(i < getNumOperands() && "getOperand() out of range!");
1197 void setOperand(unsigned i, Value *Val) {
1198 assert(i < getNumOperands() && "setOperand() out of range!");
1202 Value *getReturnValue() const { return RetVal; }
1204 unsigned getNumSuccessors() const { return 0; }
1206 // Methods for support type inquiry through isa, cast, and dyn_cast:
1207 static inline bool classof(const ReturnInst *) { return true; }
1208 static inline bool classof(const Instruction *I) {
1209 return (I->getOpcode() == Instruction::Ret);
1211 static inline bool classof(const Value *V) {
1212 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1215 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1216 virtual unsigned getNumSuccessorsV() const;
1217 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1220 //===----------------------------------------------------------------------===//
1222 //===----------------------------------------------------------------------===//
1224 //===---------------------------------------------------------------------------
1225 /// BranchInst - Conditional or Unconditional Branch instruction.
1227 class BranchInst : public TerminatorInst {
1228 /// Ops list - Branches are strange. The operands are ordered:
1229 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1230 /// they don't have to check for cond/uncond branchness.
1232 BranchInst(const BranchInst &BI);
1235 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1236 // BranchInst(BB *B) - 'br B'
1237 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1238 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1239 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1240 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1241 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1242 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
1243 : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
1244 assert(IfTrue != 0 && "Branch destination may not be null!");
1245 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1247 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1248 Instruction *InsertBefore = 0)
1249 : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
1250 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1251 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1252 Ops[2].init(Cond, this);
1258 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
1259 : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
1260 assert(IfTrue != 0 && "Branch destination may not be null!");
1261 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1264 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1265 BasicBlock *InsertAtEnd)
1266 : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
1267 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1268 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1269 Ops[2].init(Cond, this);
1276 /// Transparently provide more efficient getOperand methods.
1277 Value *getOperand(unsigned i) const {
1278 assert(i < getNumOperands() && "getOperand() out of range!");
1281 void setOperand(unsigned i, Value *Val) {
1282 assert(i < getNumOperands() && "setOperand() out of range!");
1286 virtual BranchInst *clone() const;
1288 inline bool isUnconditional() const { return getNumOperands() == 1; }
1289 inline bool isConditional() const { return getNumOperands() == 3; }
1291 inline Value *getCondition() const {
1292 assert(isConditional() && "Cannot get condition of an uncond branch!");
1293 return getOperand(2);
1296 void setCondition(Value *V) {
1297 assert(isConditional() && "Cannot set condition of unconditional branch!");
1301 // setUnconditionalDest - Change the current branch to an unconditional branch
1302 // targeting the specified block.
1303 // FIXME: Eliminate this ugly method.
1304 void setUnconditionalDest(BasicBlock *Dest) {
1305 if (isConditional()) { // Convert this to an uncond branch.
1310 setOperand(0, reinterpret_cast<Value*>(Dest));
1313 unsigned getNumSuccessors() const { return 1+isConditional(); }
1315 BasicBlock *getSuccessor(unsigned i) const {
1316 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1317 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1318 cast<BasicBlock>(getOperand(1));
1321 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1322 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1323 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1326 // Methods for support type inquiry through isa, cast, and dyn_cast:
1327 static inline bool classof(const BranchInst *) { return true; }
1328 static inline bool classof(const Instruction *I) {
1329 return (I->getOpcode() == Instruction::Br);
1331 static inline bool classof(const Value *V) {
1332 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1335 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1336 virtual unsigned getNumSuccessorsV() const;
1337 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1340 //===----------------------------------------------------------------------===//
1342 //===----------------------------------------------------------------------===//
1344 //===---------------------------------------------------------------------------
1345 /// SwitchInst - Multiway switch
1347 class SwitchInst : public TerminatorInst {
1348 unsigned ReservedSpace;
1349 // Operand[0] = Value to switch on
1350 // Operand[1] = Default basic block destination
1351 // Operand[2n ] = Value to match
1352 // Operand[2n+1] = BasicBlock to go to on match
1353 SwitchInst(const SwitchInst &RI);
1354 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1355 void resizeOperands(unsigned No);
1357 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1358 /// switch on and a default destination. The number of additional cases can
1359 /// be specified here to make memory allocation more efficient. This
1360 /// constructor can also autoinsert before another instruction.
1361 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1362 Instruction *InsertBefore = 0)
1363 : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1364 init(Value, Default, NumCases);
1367 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1368 /// switch on and a default destination. The number of additional cases can
1369 /// be specified here to make memory allocation more efficient. This
1370 /// constructor also autoinserts at the end of the specified BasicBlock.
1371 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1372 BasicBlock *InsertAtEnd)
1373 : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1374 init(Value, Default, NumCases);
1379 // Accessor Methods for Switch stmt
1380 inline Value *getCondition() const { return getOperand(0); }
1381 void setCondition(Value *V) { setOperand(0, V); }
1383 inline BasicBlock *getDefaultDest() const {
1384 return cast<BasicBlock>(getOperand(1));
1387 /// getNumCases - return the number of 'cases' in this switch instruction.
1388 /// Note that case #0 is always the default case.
1389 unsigned getNumCases() const {
1390 return getNumOperands()/2;
1393 /// getCaseValue - Return the specified case value. Note that case #0, the
1394 /// default destination, does not have a case value.
1395 ConstantInt *getCaseValue(unsigned i) {
1396 assert(i && i < getNumCases() && "Illegal case value to get!");
1397 return getSuccessorValue(i);
1400 /// getCaseValue - Return the specified case value. Note that case #0, the
1401 /// default destination, does not have a case value.
1402 const ConstantInt *getCaseValue(unsigned i) const {
1403 assert(i && i < getNumCases() && "Illegal case value to get!");
1404 return getSuccessorValue(i);
1407 /// findCaseValue - Search all of the case values for the specified constant.
1408 /// If it is explicitly handled, return the case number of it, otherwise
1409 /// return 0 to indicate that it is handled by the default handler.
1410 unsigned findCaseValue(const ConstantInt *C) const {
1411 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1412 if (getCaseValue(i) == C)
1417 /// findCaseDest - Finds the unique case value for a given successor. Returns
1418 /// null if the successor is not found, not unique, or is the default case.
1419 ConstantInt *findCaseDest(BasicBlock *BB) {
1420 if (BB == getDefaultDest()) return NULL;
1422 ConstantInt *CI = NULL;
1423 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1424 if (getSuccessor(i) == BB) {
1425 if (CI) return NULL; // Multiple cases lead to BB.
1426 else CI = getCaseValue(i);
1432 /// addCase - Add an entry to the switch instruction...
1434 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1436 /// removeCase - This method removes the specified successor from the switch
1437 /// instruction. Note that this cannot be used to remove the default
1438 /// destination (successor #0).
1440 void removeCase(unsigned idx);
1442 virtual SwitchInst *clone() const;
1444 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1445 BasicBlock *getSuccessor(unsigned idx) const {
1446 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1447 return cast<BasicBlock>(getOperand(idx*2+1));
1449 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1450 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1451 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1454 // getSuccessorValue - Return the value associated with the specified
1456 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1457 assert(idx < getNumSuccessors() && "Successor # out of range!");
1458 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1461 // Methods for support type inquiry through isa, cast, and dyn_cast:
1462 static inline bool classof(const SwitchInst *) { return true; }
1463 static inline bool classof(const Instruction *I) {
1464 return I->getOpcode() == Instruction::Switch;
1466 static inline bool classof(const Value *V) {
1467 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1470 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1471 virtual unsigned getNumSuccessorsV() const;
1472 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1475 //===----------------------------------------------------------------------===//
1477 //===----------------------------------------------------------------------===//
1479 //===---------------------------------------------------------------------------
1481 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1482 /// calling convention of the call.
1484 class InvokeInst : public TerminatorInst {
1485 InvokeInst(const InvokeInst &BI);
1486 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1487 Value* const *Args, unsigned NumArgs);
1489 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1490 const std::vector<Value*> &Params, const std::string &Name = "",
1491 Instruction *InsertBefore = 0);
1492 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1493 const std::vector<Value*> &Params, const std::string &Name,
1494 BasicBlock *InsertAtEnd);
1495 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1496 Value* const* Args, unsigned NumArgs, const std::string &Name = "",
1497 Instruction *InsertBefore = 0);
1498 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1499 Value* const* Args, unsigned NumArgs, const std::string &Name,
1500 BasicBlock *InsertAtEnd);
1503 virtual InvokeInst *clone() const;
1505 bool mayWriteToMemory() const { return true; }
1507 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1509 unsigned getCallingConv() const { return SubclassData; }
1510 void setCallingConv(unsigned CC) {
1514 /// getCalledFunction - Return the function called, or null if this is an
1515 /// indirect function invocation.
1517 Function *getCalledFunction() const {
1518 return dyn_cast<Function>(getOperand(0));
1521 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1522 inline Value *getCalledValue() const { return getOperand(0); }
1524 // get*Dest - Return the destination basic blocks...
1525 BasicBlock *getNormalDest() const {
1526 return cast<BasicBlock>(getOperand(1));
1528 BasicBlock *getUnwindDest() const {
1529 return cast<BasicBlock>(getOperand(2));
1531 void setNormalDest(BasicBlock *B) {
1532 setOperand(1, reinterpret_cast<Value*>(B));
1535 void setUnwindDest(BasicBlock *B) {
1536 setOperand(2, reinterpret_cast<Value*>(B));
1539 inline BasicBlock *getSuccessor(unsigned i) const {
1540 assert(i < 2 && "Successor # out of range for invoke!");
1541 return i == 0 ? getNormalDest() : getUnwindDest();
1544 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1545 assert(idx < 2 && "Successor # out of range for invoke!");
1546 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1549 unsigned getNumSuccessors() const { return 2; }
1551 // Methods for support type inquiry through isa, cast, and dyn_cast:
1552 static inline bool classof(const InvokeInst *) { return true; }
1553 static inline bool classof(const Instruction *I) {
1554 return (I->getOpcode() == Instruction::Invoke);
1556 static inline bool classof(const Value *V) {
1557 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1560 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1561 virtual unsigned getNumSuccessorsV() const;
1562 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1566 //===----------------------------------------------------------------------===//
1568 //===----------------------------------------------------------------------===//
1570 //===---------------------------------------------------------------------------
1571 /// UnwindInst - Immediately exit the current function, unwinding the stack
1572 /// until an invoke instruction is found.
1574 class UnwindInst : public TerminatorInst {
1576 explicit UnwindInst(Instruction *InsertBefore = 0)
1577 : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
1579 explicit UnwindInst(BasicBlock *InsertAtEnd)
1580 : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
1583 virtual UnwindInst *clone() const;
1585 unsigned getNumSuccessors() const { return 0; }
1587 // Methods for support type inquiry through isa, cast, and dyn_cast:
1588 static inline bool classof(const UnwindInst *) { return true; }
1589 static inline bool classof(const Instruction *I) {
1590 return I->getOpcode() == Instruction::Unwind;
1592 static inline bool classof(const Value *V) {
1593 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1596 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1597 virtual unsigned getNumSuccessorsV() const;
1598 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1601 //===----------------------------------------------------------------------===//
1602 // UnreachableInst Class
1603 //===----------------------------------------------------------------------===//
1605 //===---------------------------------------------------------------------------
1606 /// UnreachableInst - This function has undefined behavior. In particular, the
1607 /// presence of this instruction indicates some higher level knowledge that the
1608 /// end of the block cannot be reached.
1610 class UnreachableInst : public TerminatorInst {
1612 explicit UnreachableInst(Instruction *InsertBefore = 0)
1613 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
1615 explicit UnreachableInst(BasicBlock *InsertAtEnd)
1616 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
1619 virtual UnreachableInst *clone() const;
1621 unsigned getNumSuccessors() const { return 0; }
1623 // Methods for support type inquiry through isa, cast, and dyn_cast:
1624 static inline bool classof(const UnreachableInst *) { return true; }
1625 static inline bool classof(const Instruction *I) {
1626 return I->getOpcode() == Instruction::Unreachable;
1628 static inline bool classof(const Value *V) {
1629 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1632 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1633 virtual unsigned getNumSuccessorsV() const;
1634 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1637 //===----------------------------------------------------------------------===//
1639 //===----------------------------------------------------------------------===//
1641 /// @brief This class represents a truncation of integer types.
1642 class TruncInst : public CastInst {
1643 /// Private copy constructor
1644 TruncInst(const TruncInst &CI)
1645 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1648 /// @brief Constructor with insert-before-instruction semantics
1650 Value *S, ///< The value to be truncated
1651 const Type *Ty, ///< The (smaller) type to truncate to
1652 const std::string &Name = "", ///< A name for the new instruction
1653 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1656 /// @brief Constructor with insert-at-end-of-block semantics
1658 Value *S, ///< The value to be truncated
1659 const Type *Ty, ///< The (smaller) type to truncate to
1660 const std::string &Name, ///< A name for the new instruction
1661 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1664 /// @brief Clone an identical TruncInst
1665 virtual CastInst *clone() const;
1667 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1668 static inline bool classof(const TruncInst *) { return true; }
1669 static inline bool classof(const Instruction *I) {
1670 return I->getOpcode() == Trunc;
1672 static inline bool classof(const Value *V) {
1673 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1677 //===----------------------------------------------------------------------===//
1679 //===----------------------------------------------------------------------===//
1681 /// @brief This class represents zero extension of integer types.
1682 class ZExtInst : public CastInst {
1683 /// @brief Private copy constructor
1684 ZExtInst(const ZExtInst &CI)
1685 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1688 /// @brief Constructor with insert-before-instruction semantics
1690 Value *S, ///< The value to be zero extended
1691 const Type *Ty, ///< The type to zero extend to
1692 const std::string &Name = "", ///< A name for the new instruction
1693 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1696 /// @brief Constructor with insert-at-end semantics.
1698 Value *S, ///< The value to be zero extended
1699 const Type *Ty, ///< The type to zero extend to
1700 const std::string &Name, ///< A name for the new instruction
1701 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1704 /// @brief Clone an identical ZExtInst
1705 virtual CastInst *clone() const;
1707 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1708 static inline bool classof(const ZExtInst *) { return true; }
1709 static inline bool classof(const Instruction *I) {
1710 return I->getOpcode() == ZExt;
1712 static inline bool classof(const Value *V) {
1713 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1717 //===----------------------------------------------------------------------===//
1719 //===----------------------------------------------------------------------===//
1721 /// @brief This class represents a sign extension of integer types.
1722 class SExtInst : public CastInst {
1723 /// @brief Private copy constructor
1724 SExtInst(const SExtInst &CI)
1725 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1728 /// @brief Constructor with insert-before-instruction semantics
1730 Value *S, ///< The value to be sign extended
1731 const Type *Ty, ///< The type to sign extend to
1732 const std::string &Name = "", ///< A name for the new instruction
1733 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1736 /// @brief Constructor with insert-at-end-of-block semantics
1738 Value *S, ///< The value to be sign extended
1739 const Type *Ty, ///< The type to sign extend to
1740 const std::string &Name, ///< A name for the new instruction
1741 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1744 /// @brief Clone an identical SExtInst
1745 virtual CastInst *clone() const;
1747 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1748 static inline bool classof(const SExtInst *) { return true; }
1749 static inline bool classof(const Instruction *I) {
1750 return I->getOpcode() == SExt;
1752 static inline bool classof(const Value *V) {
1753 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1757 //===----------------------------------------------------------------------===//
1758 // FPTruncInst Class
1759 //===----------------------------------------------------------------------===//
1761 /// @brief This class represents a truncation of floating point types.
1762 class FPTruncInst : public CastInst {
1763 FPTruncInst(const FPTruncInst &CI)
1764 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1767 /// @brief Constructor with insert-before-instruction semantics
1769 Value *S, ///< The value to be truncated
1770 const Type *Ty, ///< The type to truncate to
1771 const std::string &Name = "", ///< A name for the new instruction
1772 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1775 /// @brief Constructor with insert-before-instruction semantics
1777 Value *S, ///< The value to be truncated
1778 const Type *Ty, ///< The type to truncate to
1779 const std::string &Name, ///< A name for the new instruction
1780 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1783 /// @brief Clone an identical FPTruncInst
1784 virtual CastInst *clone() const;
1786 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1787 static inline bool classof(const FPTruncInst *) { return true; }
1788 static inline bool classof(const Instruction *I) {
1789 return I->getOpcode() == FPTrunc;
1791 static inline bool classof(const Value *V) {
1792 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1796 //===----------------------------------------------------------------------===//
1798 //===----------------------------------------------------------------------===//
1800 /// @brief This class represents an extension of floating point types.
1801 class FPExtInst : public CastInst {
1802 FPExtInst(const FPExtInst &CI)
1803 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1806 /// @brief Constructor with insert-before-instruction semantics
1808 Value *S, ///< The value to be extended
1809 const Type *Ty, ///< The type to extend to
1810 const std::string &Name = "", ///< A name for the new instruction
1811 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1814 /// @brief Constructor with insert-at-end-of-block semantics
1816 Value *S, ///< The value to be extended
1817 const Type *Ty, ///< The type to extend to
1818 const std::string &Name, ///< A name for the new instruction
1819 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1822 /// @brief Clone an identical FPExtInst
1823 virtual CastInst *clone() const;
1825 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1826 static inline bool classof(const FPExtInst *) { return true; }
1827 static inline bool classof(const Instruction *I) {
1828 return I->getOpcode() == FPExt;
1830 static inline bool classof(const Value *V) {
1831 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1835 //===----------------------------------------------------------------------===//
1837 //===----------------------------------------------------------------------===//
1839 /// @brief This class represents a cast unsigned integer to floating point.
1840 class UIToFPInst : public CastInst {
1841 UIToFPInst(const UIToFPInst &CI)
1842 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1845 /// @brief Constructor with insert-before-instruction semantics
1847 Value *S, ///< The value to be converted
1848 const Type *Ty, ///< The type to convert to
1849 const std::string &Name = "", ///< A name for the new instruction
1850 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1853 /// @brief Constructor with insert-at-end-of-block semantics
1855 Value *S, ///< The value to be converted
1856 const Type *Ty, ///< The type to convert to
1857 const std::string &Name, ///< A name for the new instruction
1858 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1861 /// @brief Clone an identical UIToFPInst
1862 virtual CastInst *clone() const;
1864 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1865 static inline bool classof(const UIToFPInst *) { return true; }
1866 static inline bool classof(const Instruction *I) {
1867 return I->getOpcode() == UIToFP;
1869 static inline bool classof(const Value *V) {
1870 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1874 //===----------------------------------------------------------------------===//
1876 //===----------------------------------------------------------------------===//
1878 /// @brief This class represents a cast from signed integer to floating point.
1879 class SIToFPInst : public CastInst {
1880 SIToFPInst(const SIToFPInst &CI)
1881 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1884 /// @brief Constructor with insert-before-instruction semantics
1886 Value *S, ///< The value to be converted
1887 const Type *Ty, ///< The type to convert to
1888 const std::string &Name = "", ///< A name for the new instruction
1889 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1892 /// @brief Constructor with insert-at-end-of-block semantics
1894 Value *S, ///< The value to be converted
1895 const Type *Ty, ///< The type to convert to
1896 const std::string &Name, ///< A name for the new instruction
1897 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1900 /// @brief Clone an identical SIToFPInst
1901 virtual CastInst *clone() const;
1903 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1904 static inline bool classof(const SIToFPInst *) { return true; }
1905 static inline bool classof(const Instruction *I) {
1906 return I->getOpcode() == SIToFP;
1908 static inline bool classof(const Value *V) {
1909 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1913 //===----------------------------------------------------------------------===//
1915 //===----------------------------------------------------------------------===//
1917 /// @brief This class represents a cast from floating point to unsigned integer
1918 class FPToUIInst : public CastInst {
1919 FPToUIInst(const FPToUIInst &CI)
1920 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1923 /// @brief Constructor with insert-before-instruction semantics
1925 Value *S, ///< The value to be converted
1926 const Type *Ty, ///< The type to convert to
1927 const std::string &Name = "", ///< A name for the new instruction
1928 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1931 /// @brief Constructor with insert-at-end-of-block semantics
1933 Value *S, ///< The value to be converted
1934 const Type *Ty, ///< The type to convert to
1935 const std::string &Name, ///< A name for the new instruction
1936 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
1939 /// @brief Clone an identical FPToUIInst
1940 virtual CastInst *clone() const;
1942 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1943 static inline bool classof(const FPToUIInst *) { return true; }
1944 static inline bool classof(const Instruction *I) {
1945 return I->getOpcode() == FPToUI;
1947 static inline bool classof(const Value *V) {
1948 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1952 //===----------------------------------------------------------------------===//
1954 //===----------------------------------------------------------------------===//
1956 /// @brief This class represents a cast from floating point to signed integer.
1957 class FPToSIInst : public CastInst {
1958 FPToSIInst(const FPToSIInst &CI)
1959 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
1962 /// @brief Constructor with insert-before-instruction semantics
1964 Value *S, ///< The value to be converted
1965 const Type *Ty, ///< The type to convert to
1966 const std::string &Name = "", ///< A name for the new instruction
1967 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1970 /// @brief Constructor with insert-at-end-of-block semantics
1972 Value *S, ///< The value to be converted
1973 const Type *Ty, ///< The type to convert to
1974 const std::string &Name, ///< A name for the new instruction
1975 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1978 /// @brief Clone an identical FPToSIInst
1979 virtual CastInst *clone() const;
1981 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1982 static inline bool classof(const FPToSIInst *) { return true; }
1983 static inline bool classof(const Instruction *I) {
1984 return I->getOpcode() == FPToSI;
1986 static inline bool classof(const Value *V) {
1987 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1991 //===----------------------------------------------------------------------===//
1992 // IntToPtrInst Class
1993 //===----------------------------------------------------------------------===//
1995 /// @brief This class represents a cast from an integer to a pointer.
1996 class IntToPtrInst : public CastInst {
1997 IntToPtrInst(const IntToPtrInst &CI)
1998 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2001 /// @brief Constructor with insert-before-instruction semantics
2003 Value *S, ///< The value to be converted
2004 const Type *Ty, ///< The type to convert to
2005 const std::string &Name = "", ///< A name for the new instruction
2006 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2009 /// @brief Constructor with insert-at-end-of-block semantics
2011 Value *S, ///< The value to be converted
2012 const Type *Ty, ///< The type to convert to
2013 const std::string &Name, ///< A name for the new instruction
2014 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2017 /// @brief Clone an identical IntToPtrInst
2018 virtual CastInst *clone() const;
2020 // Methods for support type inquiry through isa, cast, and dyn_cast:
2021 static inline bool classof(const IntToPtrInst *) { return true; }
2022 static inline bool classof(const Instruction *I) {
2023 return I->getOpcode() == IntToPtr;
2025 static inline bool classof(const Value *V) {
2026 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2030 //===----------------------------------------------------------------------===//
2031 // PtrToIntInst Class
2032 //===----------------------------------------------------------------------===//
2034 /// @brief This class represents a cast from a pointer to an integer
2035 class PtrToIntInst : public CastInst {
2036 PtrToIntInst(const PtrToIntInst &CI)
2037 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2040 /// @brief Constructor with insert-before-instruction semantics
2042 Value *S, ///< The value to be converted
2043 const Type *Ty, ///< The type to convert to
2044 const std::string &Name = "", ///< A name for the new instruction
2045 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2048 /// @brief Constructor with insert-at-end-of-block semantics
2050 Value *S, ///< The value to be converted
2051 const Type *Ty, ///< The type to convert to
2052 const std::string &Name, ///< A name for the new instruction
2053 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2056 /// @brief Clone an identical PtrToIntInst
2057 virtual CastInst *clone() const;
2059 // Methods for support type inquiry through isa, cast, and dyn_cast:
2060 static inline bool classof(const PtrToIntInst *) { return true; }
2061 static inline bool classof(const Instruction *I) {
2062 return I->getOpcode() == PtrToInt;
2064 static inline bool classof(const Value *V) {
2065 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2069 //===----------------------------------------------------------------------===//
2070 // BitCastInst Class
2071 //===----------------------------------------------------------------------===//
2073 /// @brief This class represents a no-op cast from one type to another.
2074 class BitCastInst : public CastInst {
2075 BitCastInst(const BitCastInst &CI)
2076 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2079 /// @brief Constructor with insert-before-instruction semantics
2081 Value *S, ///< The value to be casted
2082 const Type *Ty, ///< The type to casted to
2083 const std::string &Name = "", ///< A name for the new instruction
2084 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2087 /// @brief Constructor with insert-at-end-of-block semantics
2089 Value *S, ///< The value to be casted
2090 const Type *Ty, ///< The type to casted to
2091 const std::string &Name, ///< A name for the new instruction
2092 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2095 /// @brief Clone an identical BitCastInst
2096 virtual CastInst *clone() const;
2098 // Methods for support type inquiry through isa, cast, and dyn_cast:
2099 static inline bool classof(const BitCastInst *) { return true; }
2100 static inline bool classof(const Instruction *I) {
2101 return I->getOpcode() == BitCast;
2103 static inline bool classof(const Value *V) {
2104 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2108 } // End llvm namespace