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"
28 //===----------------------------------------------------------------------===//
29 // AllocationInst Class
30 //===----------------------------------------------------------------------===//
32 /// AllocationInst - This class is the common base class of MallocInst and
35 class AllocationInst : public UnaryInstruction {
38 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
39 const std::string &Name = "", Instruction *InsertBefore = 0);
40 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
41 const std::string &Name, BasicBlock *InsertAtEnd);
43 // Out of line virtual method, so the vtable, etc has a home.
44 virtual ~AllocationInst();
46 /// isArrayAllocation - Return true if there is an allocation size parameter
47 /// to the allocation instruction that is not 1.
49 bool isArrayAllocation() const;
51 /// getArraySize - Get the number of element allocated, for a simple
52 /// allocation of a single element, this will return a constant 1 value.
54 inline const Value *getArraySize() const { return getOperand(0); }
55 inline Value *getArraySize() { return getOperand(0); }
57 /// getType - Overload to return most specific pointer type
59 inline const PointerType *getType() const {
60 return reinterpret_cast<const PointerType*>(Instruction::getType());
63 /// getAllocatedType - Return the type that is being allocated by the
66 const Type *getAllocatedType() const;
68 /// getAlignment - Return the alignment of the memory that is being allocated
69 /// by the instruction.
71 unsigned getAlignment() const { return Alignment; }
72 void setAlignment(unsigned Align) {
73 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
77 virtual Instruction *clone() const = 0;
79 // Methods for support type inquiry through isa, cast, and dyn_cast:
80 static inline bool classof(const AllocationInst *) { return true; }
81 static inline bool classof(const Instruction *I) {
82 return I->getOpcode() == Instruction::Alloca ||
83 I->getOpcode() == Instruction::Malloc;
85 static inline bool classof(const Value *V) {
86 return isa<Instruction>(V) && classof(cast<Instruction>(V));
91 //===----------------------------------------------------------------------===//
93 //===----------------------------------------------------------------------===//
95 /// MallocInst - an instruction to allocated memory on the heap
97 class MallocInst : public AllocationInst {
98 MallocInst(const MallocInst &MI);
100 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
101 const std::string &Name = "",
102 Instruction *InsertBefore = 0)
103 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
104 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
105 BasicBlock *InsertAtEnd)
106 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
108 MallocInst(const Type *Ty, const std::string &Name,
109 Instruction *InsertBefore = 0)
110 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
111 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
112 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
114 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
115 const std::string &Name, BasicBlock *InsertAtEnd)
116 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
117 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
118 const std::string &Name = "",
119 Instruction *InsertBefore = 0)
120 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
122 virtual MallocInst *clone() const;
124 // Methods for support type inquiry through isa, cast, and dyn_cast:
125 static inline bool classof(const MallocInst *) { return true; }
126 static inline bool classof(const Instruction *I) {
127 return (I->getOpcode() == Instruction::Malloc);
129 static inline bool classof(const Value *V) {
130 return isa<Instruction>(V) && classof(cast<Instruction>(V));
135 //===----------------------------------------------------------------------===//
137 //===----------------------------------------------------------------------===//
139 /// AllocaInst - an instruction to allocate memory on the stack
141 class AllocaInst : public AllocationInst {
142 AllocaInst(const AllocaInst &);
144 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
145 const std::string &Name = "",
146 Instruction *InsertBefore = 0)
147 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
148 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
149 BasicBlock *InsertAtEnd)
150 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
152 AllocaInst(const Type *Ty, const std::string &Name,
153 Instruction *InsertBefore = 0)
154 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
155 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
156 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
158 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
159 const std::string &Name = "", Instruction *InsertBefore = 0)
160 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
161 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
162 const std::string &Name, BasicBlock *InsertAtEnd)
163 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
165 virtual AllocaInst *clone() const;
167 // Methods for support type inquiry through isa, cast, and dyn_cast:
168 static inline bool classof(const AllocaInst *) { return true; }
169 static inline bool classof(const Instruction *I) {
170 return (I->getOpcode() == Instruction::Alloca);
172 static inline bool classof(const Value *V) {
173 return isa<Instruction>(V) && classof(cast<Instruction>(V));
178 //===----------------------------------------------------------------------===//
180 //===----------------------------------------------------------------------===//
182 /// FreeInst - an instruction to deallocate memory
184 class FreeInst : public UnaryInstruction {
187 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
188 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
190 virtual FreeInst *clone() const;
192 virtual bool mayWriteToMemory() const { return true; }
194 // Methods for support type inquiry through isa, cast, and dyn_cast:
195 static inline bool classof(const FreeInst *) { return true; }
196 static inline bool classof(const Instruction *I) {
197 return (I->getOpcode() == Instruction::Free);
199 static inline bool classof(const Value *V) {
200 return isa<Instruction>(V) && classof(cast<Instruction>(V));
205 //===----------------------------------------------------------------------===//
207 //===----------------------------------------------------------------------===//
209 /// LoadInst - an instruction for reading from memory. This uses the
210 /// SubclassData field in Value to store whether or not the load is volatile.
212 class LoadInst : public UnaryInstruction {
213 LoadInst(const LoadInst &LI)
214 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
215 setVolatile(LI.isVolatile());
223 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
224 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
225 explicit LoadInst(Value *Ptr, const std::string &Name = "",
226 bool isVolatile = false, Instruction *InsertBefore = 0);
227 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
228 BasicBlock *InsertAtEnd);
230 /// isVolatile - Return true if this is a load from a volatile memory
233 bool isVolatile() const { return SubclassData; }
235 /// setVolatile - Specify whether this is a volatile load or not.
237 void setVolatile(bool V) { SubclassData = V; }
239 virtual LoadInst *clone() const;
241 virtual bool mayWriteToMemory() const { return isVolatile(); }
243 Value *getPointerOperand() { return getOperand(0); }
244 const Value *getPointerOperand() const { return getOperand(0); }
245 static unsigned getPointerOperandIndex() { return 0U; }
247 // Methods for support type inquiry through isa, cast, and dyn_cast:
248 static inline bool classof(const LoadInst *) { return true; }
249 static inline bool classof(const Instruction *I) {
250 return I->getOpcode() == Instruction::Load;
252 static inline bool classof(const Value *V) {
253 return isa<Instruction>(V) && classof(cast<Instruction>(V));
258 //===----------------------------------------------------------------------===//
260 //===----------------------------------------------------------------------===//
262 /// StoreInst - an instruction for storing to memory
264 class StoreInst : public Instruction {
266 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
267 Ops[0].init(SI.Ops[0], this);
268 Ops[1].init(SI.Ops[1], this);
269 setVolatile(SI.isVolatile());
276 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
277 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
278 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
279 Instruction *InsertBefore = 0);
280 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
283 /// isVolatile - Return true if this is a load from a volatile memory
286 bool isVolatile() const { return SubclassData; }
288 /// setVolatile - Specify whether this is a volatile load or not.
290 void setVolatile(bool V) { SubclassData = V; }
292 /// Transparently provide more efficient getOperand methods.
293 Value *getOperand(unsigned i) const {
294 assert(i < 2 && "getOperand() out of range!");
297 void setOperand(unsigned i, Value *Val) {
298 assert(i < 2 && "setOperand() out of range!");
301 unsigned getNumOperands() const { return 2; }
304 virtual StoreInst *clone() const;
306 virtual bool mayWriteToMemory() const { return true; }
308 Value *getPointerOperand() { return getOperand(1); }
309 const Value *getPointerOperand() const { return getOperand(1); }
310 static unsigned getPointerOperandIndex() { return 1U; }
312 // Methods for support type inquiry through isa, cast, and dyn_cast:
313 static inline bool classof(const StoreInst *) { return true; }
314 static inline bool classof(const Instruction *I) {
315 return I->getOpcode() == Instruction::Store;
317 static inline bool classof(const Value *V) {
318 return isa<Instruction>(V) && classof(cast<Instruction>(V));
323 //===----------------------------------------------------------------------===//
324 // GetElementPtrInst Class
325 //===----------------------------------------------------------------------===//
327 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
328 /// access elements of arrays and structs
330 class GetElementPtrInst : public Instruction {
331 GetElementPtrInst(const GetElementPtrInst &GEPI)
332 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
333 0, GEPI.getNumOperands()) {
334 Use *OL = OperandList = new Use[NumOperands];
335 Use *GEPIOL = GEPI.OperandList;
336 for (unsigned i = 0, E = NumOperands; i != E; ++i)
337 OL[i].init(GEPIOL[i], this);
339 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
340 void init(Value *Ptr, Value *Idx0, Value *Idx1);
341 void init(Value *Ptr, Value *Idx);
343 /// Constructors - Create a getelementptr instruction with a base pointer an
344 /// list of indices. The first ctor can optionally insert before an existing
345 /// instruction, the second appends the new instruction to the specified
347 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
348 const std::string &Name = "", Instruction *InsertBefore =0);
349 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
350 const std::string &Name, BasicBlock *InsertAtEnd);
352 /// Constructors - These two constructors are convenience methods because one
353 /// and two index getelementptr instructions are so common.
354 GetElementPtrInst(Value *Ptr, Value *Idx,
355 const std::string &Name = "", Instruction *InsertBefore =0);
356 GetElementPtrInst(Value *Ptr, Value *Idx,
357 const std::string &Name, BasicBlock *InsertAtEnd);
358 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
359 const std::string &Name = "", Instruction *InsertBefore =0);
360 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
361 const std::string &Name, BasicBlock *InsertAtEnd);
362 ~GetElementPtrInst();
364 virtual GetElementPtrInst *clone() const;
366 // getType - Overload to return most specific pointer type...
367 inline const PointerType *getType() const {
368 return reinterpret_cast<const PointerType*>(Instruction::getType());
371 /// getIndexedType - Returns the type of the element that would be loaded with
372 /// a load instruction with the specified parameters.
374 /// A null type is returned if the indices are invalid for the specified
377 static const Type *getIndexedType(const Type *Ptr,
378 Value* const *Idx, unsigned NumIdx,
379 bool AllowStructLeaf = false);
381 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
382 bool AllowStructLeaf = false);
383 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
385 inline op_iterator idx_begin() { return op_begin()+1; }
386 inline const_op_iterator idx_begin() const { return op_begin()+1; }
387 inline op_iterator idx_end() { return op_end(); }
388 inline const_op_iterator idx_end() const { return op_end(); }
390 Value *getPointerOperand() {
391 return getOperand(0);
393 const Value *getPointerOperand() const {
394 return getOperand(0);
396 static unsigned getPointerOperandIndex() {
397 return 0U; // get index for modifying correct operand
400 inline unsigned getNumIndices() const { // Note: always non-negative
401 return getNumOperands() - 1;
404 inline bool hasIndices() const {
405 return getNumOperands() > 1;
408 // Methods for support type inquiry through isa, cast, and dyn_cast:
409 static inline bool classof(const GetElementPtrInst *) { return true; }
410 static inline bool classof(const Instruction *I) {
411 return (I->getOpcode() == Instruction::GetElementPtr);
413 static inline bool classof(const Value *V) {
414 return isa<Instruction>(V) && classof(cast<Instruction>(V));
418 //===----------------------------------------------------------------------===//
420 //===----------------------------------------------------------------------===//
422 /// This instruction compares its operands according to the predicate given
423 /// to the constructor. It only operates on integers, pointers, or packed
424 /// vectors of integrals. The two operands must be the same type.
425 /// @brief Represent an integer comparison operator.
426 class ICmpInst: public CmpInst {
428 /// This enumeration lists the possible predicates for the ICmpInst. The
429 /// values in the range 0-31 are reserved for FCmpInst while values in the
430 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
431 /// predicate values are not overlapping between the classes.
433 ICMP_EQ = 32, ///< equal
434 ICMP_NE = 33, ///< not equal
435 ICMP_UGT = 34, ///< unsigned greater than
436 ICMP_UGE = 35, ///< unsigned greater or equal
437 ICMP_ULT = 36, ///< unsigned less than
438 ICMP_ULE = 37, ///< unsigned less or equal
439 ICMP_SGT = 38, ///< signed greater than
440 ICMP_SGE = 39, ///< signed greater or equal
441 ICMP_SLT = 40, ///< signed less than
442 ICMP_SLE = 41, ///< signed less or equal
443 FIRST_ICMP_PREDICATE = ICMP_EQ,
444 LAST_ICMP_PREDICATE = ICMP_SLE,
445 BAD_ICMP_PREDICATE = ICMP_SLE + 1
448 /// @brief Constructor with insert-before-instruction semantics.
450 Predicate pred, ///< The predicate to use for the comparison
451 Value *LHS, ///< The left-hand-side of the expression
452 Value *RHS, ///< The right-hand-side of the expression
453 const std::string &Name = "", ///< Name of the instruction
454 Instruction *InsertBefore = 0 ///< Where to insert
455 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
458 /// @brief Constructor with insert-at-block-end semantics.
460 Predicate pred, ///< The predicate to use for the comparison
461 Value *LHS, ///< The left-hand-side of the expression
462 Value *RHS, ///< The right-hand-side of the expression
463 const std::string &Name, ///< Name of the instruction
464 BasicBlock *InsertAtEnd ///< Block to insert into.
465 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
468 /// @brief Return the predicate for this instruction.
469 Predicate getPredicate() const { return Predicate(SubclassData); }
471 /// @brief Set the predicate for this instruction to the specified value.
472 void setPredicate(Predicate P) { SubclassData = P; }
474 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
475 /// @returns the inverse predicate for the instruction's current predicate.
476 /// @brief Return the inverse of the instruction's predicate.
477 Predicate getInversePredicate() const {
478 return getInversePredicate(getPredicate());
481 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
482 /// @returns the inverse predicate for predicate provided in \p pred.
483 /// @brief Return the inverse of a given predicate
484 static Predicate getInversePredicate(Predicate pred);
486 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
487 /// @returns the predicate that would be the result of exchanging the two
488 /// operands of the ICmpInst instruction without changing the result
490 /// @brief Return the predicate as if the operands were swapped
491 Predicate getSwappedPredicate() const {
492 return getSwappedPredicate(getPredicate());
495 /// This is a static version that you can use without an instruction
497 /// @brief Return the predicate as if the operands were swapped.
498 static Predicate getSwappedPredicate(Predicate pred);
500 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
501 /// @returns the predicate that would be the result if the operand were
502 /// regarded as signed.
503 /// @brief Return the signed version of the predicate
504 Predicate getSignedPredicate() const {
505 return getSignedPredicate(getPredicate());
508 /// This is a static version that you can use without an instruction.
509 /// @brief Return the signed version of the predicate.
510 static Predicate getSignedPredicate(Predicate pred);
512 /// This also tests for commutativity. If isEquality() returns true then
513 /// the predicate is also commutative.
514 /// @returns true if the predicate of this instruction is EQ or NE.
515 /// @brief Determine if this is an equality predicate.
516 bool isEquality() const {
517 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
520 /// @returns true if the predicate of this ICmpInst is commutative
521 /// @brief Determine if this relation is commutative.
522 bool isCommutative() const { return isEquality(); }
524 /// @returns true if the predicate is relational (not EQ or NE).
525 /// @brief Determine if this a relational predicate.
526 bool isRelational() const {
527 return !isEquality();
530 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
531 /// @brief Determine if this instruction's predicate is signed.
532 bool isSignedPredicate() { return isSignedPredicate(getPredicate()); }
534 /// @returns true if the predicate provided is signed, false otherwise
535 /// @brief Determine if the predicate is signed.
536 static bool isSignedPredicate(Predicate pred);
538 /// Exchange the two operands to this instruction in such a way that it does
539 /// not modify the semantics of the instruction. The predicate value may be
540 /// changed to retain the same result if the predicate is order dependent
542 /// @brief Swap operands and adjust predicate.
543 void swapOperands() {
544 SubclassData = getSwappedPredicate();
545 std::swap(Ops[0], Ops[1]);
548 // Methods for support type inquiry through isa, cast, and dyn_cast:
549 static inline bool classof(const ICmpInst *) { return true; }
550 static inline bool classof(const Instruction *I) {
551 return I->getOpcode() == Instruction::ICmp;
553 static inline bool classof(const Value *V) {
554 return isa<Instruction>(V) && classof(cast<Instruction>(V));
558 //===----------------------------------------------------------------------===//
560 //===----------------------------------------------------------------------===//
562 /// This instruction compares its operands according to the predicate given
563 /// to the constructor. It only operates on floating point values or packed
564 /// vectors of floating point values. The operands must be identical types.
565 /// @brief Represents a floating point comparison operator.
566 class FCmpInst: public CmpInst {
568 /// This enumeration lists the possible predicates for the FCmpInst. Values
569 /// in the range 0-31 are reserved for FCmpInst.
571 // Opcode U L G E Intuitive operation
572 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
573 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
574 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
575 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
576 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
577 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
578 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
579 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
580 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
581 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
582 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
583 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
584 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
585 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
586 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
587 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
588 FIRST_FCMP_PREDICATE = FCMP_FALSE,
589 LAST_FCMP_PREDICATE = FCMP_TRUE,
590 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
593 /// @brief Constructor with insert-before-instruction semantics.
595 Predicate pred, ///< The predicate to use for the comparison
596 Value *LHS, ///< The left-hand-side of the expression
597 Value *RHS, ///< The right-hand-side of the expression
598 const std::string &Name = "", ///< Name of the instruction
599 Instruction *InsertBefore = 0 ///< Where to insert
600 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
603 /// @brief Constructor with insert-at-block-end semantics.
605 Predicate pred, ///< The predicate to use for the comparison
606 Value *LHS, ///< The left-hand-side of the expression
607 Value *RHS, ///< The right-hand-side of the expression
608 const std::string &Name, ///< Name of the instruction
609 BasicBlock *InsertAtEnd ///< Block to insert into.
610 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
613 /// @brief Return the predicate for this instruction.
614 Predicate getPredicate() const { return Predicate(SubclassData); }
616 /// @brief Set the predicate for this instruction to the specified value.
617 void setPredicate(Predicate P) { SubclassData = P; }
619 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
620 /// @returns the inverse predicate for the instructions current predicate.
621 /// @brief Return the inverse of the predicate
622 Predicate getInversePredicate() const {
623 return getInversePredicate(getPredicate());
626 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
627 /// @returns the inverse predicate for \p pred.
628 /// @brief Return the inverse of a given predicate
629 static Predicate getInversePredicate(Predicate pred);
631 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
632 /// @returns the predicate that would be the result of exchanging the two
633 /// operands of the ICmpInst instruction without changing the result
635 /// @brief Return the predicate as if the operands were swapped
636 Predicate getSwappedPredicate() const {
637 return getSwappedPredicate(getPredicate());
640 /// This is a static version that you can use without an instruction
642 /// @brief Return the predicate as if the operands were swapped.
643 static Predicate getSwappedPredicate(Predicate Opcode);
645 /// This also tests for commutativity. If isEquality() returns true then
646 /// the predicate is also commutative. Only the equality predicates are
648 /// @returns true if the predicate of this instruction is EQ or NE.
649 /// @brief Determine if this is an equality predicate.
650 bool isEquality() const {
651 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
652 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
654 bool isCommutative() const { return isEquality(); }
656 /// @returns true if the predicate is relational (not EQ or NE).
657 /// @brief Determine if this a relational predicate.
658 bool isRelational() const { return !isEquality(); }
660 /// Exchange the two operands to this instruction in such a way that it does
661 /// not modify the semantics of the instruction. The predicate value may be
662 /// changed to retain the same result if the predicate is order dependent
664 /// @brief Swap operands and adjust predicate.
665 void swapOperands() {
666 SubclassData = getSwappedPredicate();
667 std::swap(Ops[0], Ops[1]);
670 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
671 static inline bool classof(const FCmpInst *) { return true; }
672 static inline bool classof(const Instruction *I) {
673 return I->getOpcode() == Instruction::FCmp;
675 static inline bool classof(const Value *V) {
676 return isa<Instruction>(V) && classof(cast<Instruction>(V));
680 //===----------------------------------------------------------------------===//
682 //===----------------------------------------------------------------------===//
684 /// CallInst - This class represents a function call, abstracting a target
685 /// machine's calling convention. This class uses low bit of the SubClassData
686 /// field to indicate whether or not this is a tail call. The rest of the bits
687 /// hold the calling convention of the call.
689 class CallInst : public Instruction {
690 CallInst(const CallInst &CI);
691 void init(Value *Func, Value* const *Params, unsigned NumParams);
692 void init(Value *Func, Value *Actual1, Value *Actual2);
693 void init(Value *Func, Value *Actual);
694 void init(Value *Func);
697 CallInst(Value *F, Value* const *Args, unsigned NumArgs,
698 const std::string &Name = "", Instruction *InsertBefore = 0);
699 CallInst(Value *F, Value *const *Args, unsigned NumArgs,
700 const std::string &Name, BasicBlock *InsertAtEnd);
702 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
703 // actuals, respectively.
704 CallInst(Value *F, Value *Actual1, Value *Actual2,
705 const std::string& Name = "", Instruction *InsertBefore = 0);
706 CallInst(Value *F, Value *Actual1, Value *Actual2,
707 const std::string& Name, BasicBlock *InsertAtEnd);
708 CallInst(Value *F, Value *Actual, const std::string& Name = "",
709 Instruction *InsertBefore = 0);
710 CallInst(Value *F, Value *Actual, const std::string& Name,
711 BasicBlock *InsertAtEnd);
712 explicit CallInst(Value *F, const std::string &Name = "",
713 Instruction *InsertBefore = 0);
714 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
717 virtual CallInst *clone() const;
718 bool mayWriteToMemory() const { return true; }
720 bool isTailCall() const { return SubclassData & 1; }
721 void setTailCall(bool isTailCall = true) {
722 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
725 /// getCallingConv/setCallingConv - Get or set the calling convention of this
727 unsigned getCallingConv() const { return SubclassData >> 1; }
728 void setCallingConv(unsigned CC) {
729 SubclassData = (SubclassData & 1) | (CC << 1);
732 /// getCalledFunction - Return the function being called by this instruction
733 /// if it is a direct call. If it is a call through a function pointer,
735 Function *getCalledFunction() const {
736 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
739 /// getCalledValue - Get a pointer to the function that is invoked by this
741 inline const Value *getCalledValue() const { return getOperand(0); }
742 inline Value *getCalledValue() { return getOperand(0); }
744 // Methods for support type inquiry through isa, cast, and dyn_cast:
745 static inline bool classof(const CallInst *) { return true; }
746 static inline bool classof(const Instruction *I) {
747 return I->getOpcode() == Instruction::Call;
749 static inline bool classof(const Value *V) {
750 return isa<Instruction>(V) && classof(cast<Instruction>(V));
754 //===----------------------------------------------------------------------===//
756 //===----------------------------------------------------------------------===//
758 /// SelectInst - This class represents the LLVM 'select' instruction.
760 class SelectInst : public Instruction {
763 void init(Value *C, Value *S1, Value *S2) {
764 Ops[0].init(C, this);
765 Ops[1].init(S1, this);
766 Ops[2].init(S2, this);
769 SelectInst(const SelectInst &SI)
770 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
771 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
774 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
775 Instruction *InsertBefore = 0)
776 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
777 Name, InsertBefore) {
780 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
781 BasicBlock *InsertAtEnd)
782 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
787 Value *getCondition() const { return Ops[0]; }
788 Value *getTrueValue() const { return Ops[1]; }
789 Value *getFalseValue() const { return Ops[2]; }
791 /// Transparently provide more efficient getOperand methods.
792 Value *getOperand(unsigned i) const {
793 assert(i < 3 && "getOperand() out of range!");
796 void setOperand(unsigned i, Value *Val) {
797 assert(i < 3 && "setOperand() out of range!");
800 unsigned getNumOperands() const { return 3; }
802 OtherOps getOpcode() const {
803 return static_cast<OtherOps>(Instruction::getOpcode());
806 virtual SelectInst *clone() const;
808 // Methods for support type inquiry through isa, cast, and dyn_cast:
809 static inline bool classof(const SelectInst *) { return true; }
810 static inline bool classof(const Instruction *I) {
811 return I->getOpcode() == Instruction::Select;
813 static inline bool classof(const Value *V) {
814 return isa<Instruction>(V) && classof(cast<Instruction>(V));
818 //===----------------------------------------------------------------------===//
820 //===----------------------------------------------------------------------===//
822 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
823 /// an argument of the specified type given a va_list and increments that list
825 class VAArgInst : public UnaryInstruction {
826 VAArgInst(const VAArgInst &VAA)
827 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
829 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
830 Instruction *InsertBefore = 0)
831 : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) {
833 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
834 BasicBlock *InsertAtEnd)
835 : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) {
838 virtual VAArgInst *clone() const;
839 bool mayWriteToMemory() const { return true; }
841 // Methods for support type inquiry through isa, cast, and dyn_cast:
842 static inline bool classof(const VAArgInst *) { return true; }
843 static inline bool classof(const Instruction *I) {
844 return I->getOpcode() == VAArg;
846 static inline bool classof(const Value *V) {
847 return isa<Instruction>(V) && classof(cast<Instruction>(V));
851 //===----------------------------------------------------------------------===//
852 // ExtractElementInst Class
853 //===----------------------------------------------------------------------===//
855 /// ExtractElementInst - This instruction extracts a single (scalar)
856 /// element from a PackedType value
858 class ExtractElementInst : public Instruction {
860 ExtractElementInst(const ExtractElementInst &EE) :
861 Instruction(EE.getType(), ExtractElement, Ops, 2) {
862 Ops[0].init(EE.Ops[0], this);
863 Ops[1].init(EE.Ops[1], this);
867 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
868 Instruction *InsertBefore = 0);
869 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
870 Instruction *InsertBefore = 0);
871 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
872 BasicBlock *InsertAtEnd);
873 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
874 BasicBlock *InsertAtEnd);
876 /// isValidOperands - Return true if an extractelement instruction can be
877 /// formed with the specified operands.
878 static bool isValidOperands(const Value *Vec, const Value *Idx);
880 virtual ExtractElementInst *clone() const;
882 virtual bool mayWriteToMemory() const { return false; }
884 /// Transparently provide more efficient getOperand methods.
885 Value *getOperand(unsigned i) const {
886 assert(i < 2 && "getOperand() out of range!");
889 void setOperand(unsigned i, Value *Val) {
890 assert(i < 2 && "setOperand() out of range!");
893 unsigned getNumOperands() const { return 2; }
895 // Methods for support type inquiry through isa, cast, and dyn_cast:
896 static inline bool classof(const ExtractElementInst *) { return true; }
897 static inline bool classof(const Instruction *I) {
898 return I->getOpcode() == Instruction::ExtractElement;
900 static inline bool classof(const Value *V) {
901 return isa<Instruction>(V) && classof(cast<Instruction>(V));
905 //===----------------------------------------------------------------------===//
906 // InsertElementInst Class
907 //===----------------------------------------------------------------------===//
909 /// InsertElementInst - This instruction inserts a single (scalar)
910 /// element into a PackedType value
912 class InsertElementInst : public Instruction {
914 InsertElementInst(const InsertElementInst &IE);
916 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
917 const std::string &Name = "",Instruction *InsertBefore = 0);
918 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
919 const std::string &Name = "",Instruction *InsertBefore = 0);
920 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
921 const std::string &Name, BasicBlock *InsertAtEnd);
922 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
923 const std::string &Name, BasicBlock *InsertAtEnd);
925 /// isValidOperands - Return true if an insertelement instruction can be
926 /// formed with the specified operands.
927 static bool isValidOperands(const Value *Vec, const Value *NewElt,
930 virtual InsertElementInst *clone() const;
932 virtual bool mayWriteToMemory() const { return false; }
934 /// getType - Overload to return most specific packed type.
936 inline const PackedType *getType() const {
937 return reinterpret_cast<const PackedType*>(Instruction::getType());
940 /// Transparently provide more efficient getOperand methods.
941 Value *getOperand(unsigned i) const {
942 assert(i < 3 && "getOperand() out of range!");
945 void setOperand(unsigned i, Value *Val) {
946 assert(i < 3 && "setOperand() out of range!");
949 unsigned getNumOperands() const { return 3; }
951 // Methods for support type inquiry through isa, cast, and dyn_cast:
952 static inline bool classof(const InsertElementInst *) { return true; }
953 static inline bool classof(const Instruction *I) {
954 return I->getOpcode() == Instruction::InsertElement;
956 static inline bool classof(const Value *V) {
957 return isa<Instruction>(V) && classof(cast<Instruction>(V));
961 //===----------------------------------------------------------------------===//
962 // ShuffleVectorInst Class
963 //===----------------------------------------------------------------------===//
965 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
968 class ShuffleVectorInst : public Instruction {
970 ShuffleVectorInst(const ShuffleVectorInst &IE);
972 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
973 const std::string &Name = "", Instruction *InsertBefor = 0);
974 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
975 const std::string &Name, BasicBlock *InsertAtEnd);
977 /// isValidOperands - Return true if a shufflevector instruction can be
978 /// formed with the specified operands.
979 static bool isValidOperands(const Value *V1, const Value *V2,
982 virtual ShuffleVectorInst *clone() const;
984 virtual bool mayWriteToMemory() const { return false; }
986 /// getType - Overload to return most specific packed type.
988 inline const PackedType *getType() const {
989 return reinterpret_cast<const PackedType*>(Instruction::getType());
992 /// Transparently provide more efficient getOperand methods.
993 Value *getOperand(unsigned i) const {
994 assert(i < 3 && "getOperand() out of range!");
997 void setOperand(unsigned i, Value *Val) {
998 assert(i < 3 && "setOperand() out of range!");
1001 unsigned getNumOperands() const { return 3; }
1003 // Methods for support type inquiry through isa, cast, and dyn_cast:
1004 static inline bool classof(const ShuffleVectorInst *) { return true; }
1005 static inline bool classof(const Instruction *I) {
1006 return I->getOpcode() == Instruction::ShuffleVector;
1008 static inline bool classof(const Value *V) {
1009 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1014 //===----------------------------------------------------------------------===//
1016 //===----------------------------------------------------------------------===//
1018 // PHINode - The PHINode class is used to represent the magical mystical PHI
1019 // node, that can not exist in nature, but can be synthesized in a computer
1020 // scientist's overactive imagination.
1022 class PHINode : public Instruction {
1023 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1024 /// the number actually in use.
1025 unsigned ReservedSpace;
1026 PHINode(const PHINode &PN);
1028 explicit PHINode(const Type *Ty, const std::string &Name = "",
1029 Instruction *InsertBefore = 0)
1030 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore),
1034 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1035 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
1041 /// reserveOperandSpace - This method can be used to avoid repeated
1042 /// reallocation of PHI operand lists by reserving space for the correct
1043 /// number of operands before adding them. Unlike normal vector reserves,
1044 /// this method can also be used to trim the operand space.
1045 void reserveOperandSpace(unsigned NumValues) {
1046 resizeOperands(NumValues*2);
1049 virtual PHINode *clone() const;
1051 /// getNumIncomingValues - Return the number of incoming edges
1053 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1055 /// getIncomingValue - Return incoming value number x
1057 Value *getIncomingValue(unsigned i) const {
1058 assert(i*2 < getNumOperands() && "Invalid value number!");
1059 return getOperand(i*2);
1061 void setIncomingValue(unsigned i, Value *V) {
1062 assert(i*2 < getNumOperands() && "Invalid value number!");
1065 unsigned getOperandNumForIncomingValue(unsigned i) {
1069 /// getIncomingBlock - Return incoming basic block number x
1071 BasicBlock *getIncomingBlock(unsigned i) const {
1072 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1074 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1075 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1077 unsigned getOperandNumForIncomingBlock(unsigned i) {
1081 /// addIncoming - Add an incoming value to the end of the PHI list
1083 void addIncoming(Value *V, BasicBlock *BB) {
1084 assert(getType() == V->getType() &&
1085 "All operands to PHI node must be the same type as the PHI node!");
1086 unsigned OpNo = NumOperands;
1087 if (OpNo+2 > ReservedSpace)
1088 resizeOperands(0); // Get more space!
1089 // Initialize some new operands.
1090 NumOperands = OpNo+2;
1091 OperandList[OpNo].init(V, this);
1092 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1095 /// removeIncomingValue - Remove an incoming value. This is useful if a
1096 /// predecessor basic block is deleted. The value removed is returned.
1098 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1099 /// is true), the PHI node is destroyed and any uses of it are replaced with
1100 /// dummy values. The only time there should be zero incoming values to a PHI
1101 /// node is when the block is dead, so this strategy is sound.
1103 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1105 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1106 int Idx = getBasicBlockIndex(BB);
1107 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1108 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1111 /// getBasicBlockIndex - Return the first index of the specified basic
1112 /// block in the value list for this PHI. Returns -1 if no instance.
1114 int getBasicBlockIndex(const BasicBlock *BB) const {
1115 Use *OL = OperandList;
1116 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1117 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1121 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1122 return getIncomingValue(getBasicBlockIndex(BB));
1125 /// hasConstantValue - If the specified PHI node always merges together the
1126 /// same value, return the value, otherwise return null.
1128 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1130 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1131 static inline bool classof(const PHINode *) { return true; }
1132 static inline bool classof(const Instruction *I) {
1133 return I->getOpcode() == Instruction::PHI;
1135 static inline bool classof(const Value *V) {
1136 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1139 void resizeOperands(unsigned NumOperands);
1142 //===----------------------------------------------------------------------===//
1144 //===----------------------------------------------------------------------===//
1146 //===---------------------------------------------------------------------------
1147 /// ReturnInst - Return a value (possibly void), from a function. Execution
1148 /// does not continue in this function any longer.
1150 class ReturnInst : public TerminatorInst {
1151 Use RetVal; // Possibly null retval.
1152 ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
1153 RI.getNumOperands()) {
1154 if (RI.getNumOperands())
1155 RetVal.init(RI.RetVal, this);
1158 void init(Value *RetVal);
1161 // ReturnInst constructors:
1162 // ReturnInst() - 'ret void' instruction
1163 // ReturnInst( null) - 'ret void' instruction
1164 // ReturnInst(Value* X) - 'ret X' instruction
1165 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1166 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1167 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1168 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1170 // NOTE: If the Value* passed is of type void then the constructor behaves as
1171 // if it was passed NULL.
1172 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
1173 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
1176 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
1177 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1180 explicit ReturnInst(BasicBlock *InsertAtEnd)
1181 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1184 virtual ReturnInst *clone() const;
1186 // Transparently provide more efficient getOperand methods.
1187 Value *getOperand(unsigned i) const {
1188 assert(i < getNumOperands() && "getOperand() out of range!");
1191 void setOperand(unsigned i, Value *Val) {
1192 assert(i < getNumOperands() && "setOperand() out of range!");
1196 Value *getReturnValue() const { return RetVal; }
1198 unsigned getNumSuccessors() const { return 0; }
1200 // Methods for support type inquiry through isa, cast, and dyn_cast:
1201 static inline bool classof(const ReturnInst *) { return true; }
1202 static inline bool classof(const Instruction *I) {
1203 return (I->getOpcode() == Instruction::Ret);
1205 static inline bool classof(const Value *V) {
1206 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1209 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1210 virtual unsigned getNumSuccessorsV() const;
1211 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1214 //===----------------------------------------------------------------------===//
1216 //===----------------------------------------------------------------------===//
1218 //===---------------------------------------------------------------------------
1219 /// BranchInst - Conditional or Unconditional Branch instruction.
1221 class BranchInst : public TerminatorInst {
1222 /// Ops list - Branches are strange. The operands are ordered:
1223 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1224 /// they don't have to check for cond/uncond branchness.
1226 BranchInst(const BranchInst &BI);
1229 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1230 // BranchInst(BB *B) - 'br B'
1231 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1232 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1233 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1234 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1235 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1236 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
1237 : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
1238 assert(IfTrue != 0 && "Branch destination may not be null!");
1239 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1241 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1242 Instruction *InsertBefore = 0)
1243 : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
1244 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1245 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1246 Ops[2].init(Cond, this);
1252 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
1253 : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
1254 assert(IfTrue != 0 && "Branch destination may not be null!");
1255 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1258 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1259 BasicBlock *InsertAtEnd)
1260 : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
1261 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1262 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1263 Ops[2].init(Cond, this);
1270 /// Transparently provide more efficient getOperand methods.
1271 Value *getOperand(unsigned i) const {
1272 assert(i < getNumOperands() && "getOperand() out of range!");
1275 void setOperand(unsigned i, Value *Val) {
1276 assert(i < getNumOperands() && "setOperand() out of range!");
1280 virtual BranchInst *clone() const;
1282 inline bool isUnconditional() const { return getNumOperands() == 1; }
1283 inline bool isConditional() const { return getNumOperands() == 3; }
1285 inline Value *getCondition() const {
1286 assert(isConditional() && "Cannot get condition of an uncond branch!");
1287 return getOperand(2);
1290 void setCondition(Value *V) {
1291 assert(isConditional() && "Cannot set condition of unconditional branch!");
1295 // setUnconditionalDest - Change the current branch to an unconditional branch
1296 // targeting the specified block.
1297 // FIXME: Eliminate this ugly method.
1298 void setUnconditionalDest(BasicBlock *Dest) {
1299 if (isConditional()) { // Convert this to an uncond branch.
1304 setOperand(0, reinterpret_cast<Value*>(Dest));
1307 unsigned getNumSuccessors() const { return 1+isConditional(); }
1309 BasicBlock *getSuccessor(unsigned i) const {
1310 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1311 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1312 cast<BasicBlock>(getOperand(1));
1315 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1316 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1317 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1320 // Methods for support type inquiry through isa, cast, and dyn_cast:
1321 static inline bool classof(const BranchInst *) { return true; }
1322 static inline bool classof(const Instruction *I) {
1323 return (I->getOpcode() == Instruction::Br);
1325 static inline bool classof(const Value *V) {
1326 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1329 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1330 virtual unsigned getNumSuccessorsV() const;
1331 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1334 //===----------------------------------------------------------------------===//
1336 //===----------------------------------------------------------------------===//
1338 //===---------------------------------------------------------------------------
1339 /// SwitchInst - Multiway switch
1341 class SwitchInst : public TerminatorInst {
1342 unsigned ReservedSpace;
1343 // Operand[0] = Value to switch on
1344 // Operand[1] = Default basic block destination
1345 // Operand[2n ] = Value to match
1346 // Operand[2n+1] = BasicBlock to go to on match
1347 SwitchInst(const SwitchInst &RI);
1348 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1349 void resizeOperands(unsigned No);
1351 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1352 /// switch on and a default destination. The number of additional cases can
1353 /// be specified here to make memory allocation more efficient. This
1354 /// constructor can also autoinsert before another instruction.
1355 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1356 Instruction *InsertBefore = 0)
1357 : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1358 init(Value, Default, NumCases);
1361 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1362 /// switch on and a default destination. The number of additional cases can
1363 /// be specified here to make memory allocation more efficient. This
1364 /// constructor also autoinserts at the end of the specified BasicBlock.
1365 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1366 BasicBlock *InsertAtEnd)
1367 : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1368 init(Value, Default, NumCases);
1373 // Accessor Methods for Switch stmt
1374 inline Value *getCondition() const { return getOperand(0); }
1375 void setCondition(Value *V) { setOperand(0, V); }
1377 inline BasicBlock *getDefaultDest() const {
1378 return cast<BasicBlock>(getOperand(1));
1381 /// getNumCases - return the number of 'cases' in this switch instruction.
1382 /// Note that case #0 is always the default case.
1383 unsigned getNumCases() const {
1384 return getNumOperands()/2;
1387 /// getCaseValue - Return the specified case value. Note that case #0, the
1388 /// default destination, does not have a case value.
1389 ConstantInt *getCaseValue(unsigned i) {
1390 assert(i && i < getNumCases() && "Illegal case value to get!");
1391 return getSuccessorValue(i);
1394 /// getCaseValue - Return the specified case value. Note that case #0, the
1395 /// default destination, does not have a case value.
1396 const ConstantInt *getCaseValue(unsigned i) const {
1397 assert(i && i < getNumCases() && "Illegal case value to get!");
1398 return getSuccessorValue(i);
1401 /// findCaseValue - Search all of the case values for the specified constant.
1402 /// If it is explicitly handled, return the case number of it, otherwise
1403 /// return 0 to indicate that it is handled by the default handler.
1404 unsigned findCaseValue(const ConstantInt *C) const {
1405 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1406 if (getCaseValue(i) == C)
1411 /// findCaseDest - Finds the unique case value for a given successor. Returns
1412 /// null if the successor is not found, not unique, or is the default case.
1413 ConstantInt *findCaseDest(BasicBlock *BB) {
1414 if (BB == getDefaultDest()) return NULL;
1416 ConstantInt *CI = NULL;
1417 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1418 if (getSuccessor(i) == BB) {
1419 if (CI) return NULL; // Multiple cases lead to BB.
1420 else CI = getCaseValue(i);
1426 /// addCase - Add an entry to the switch instruction...
1428 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1430 /// removeCase - This method removes the specified successor from the switch
1431 /// instruction. Note that this cannot be used to remove the default
1432 /// destination (successor #0).
1434 void removeCase(unsigned idx);
1436 virtual SwitchInst *clone() const;
1438 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1439 BasicBlock *getSuccessor(unsigned idx) const {
1440 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1441 return cast<BasicBlock>(getOperand(idx*2+1));
1443 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1444 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1445 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1448 // getSuccessorValue - Return the value associated with the specified
1450 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1451 assert(idx < getNumSuccessors() && "Successor # out of range!");
1452 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1455 // Methods for support type inquiry through isa, cast, and dyn_cast:
1456 static inline bool classof(const SwitchInst *) { return true; }
1457 static inline bool classof(const Instruction *I) {
1458 return I->getOpcode() == Instruction::Switch;
1460 static inline bool classof(const Value *V) {
1461 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1464 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1465 virtual unsigned getNumSuccessorsV() const;
1466 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1469 //===----------------------------------------------------------------------===//
1471 //===----------------------------------------------------------------------===//
1473 //===---------------------------------------------------------------------------
1475 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1476 /// calling convention of the call.
1478 class InvokeInst : public TerminatorInst {
1479 InvokeInst(const InvokeInst &BI);
1480 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1481 Value* const *Args, unsigned NumArgs);
1483 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1484 Value* const* Args, unsigned NumArgs, const std::string &Name = "",
1485 Instruction *InsertBefore = 0);
1486 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1487 Value* const* Args, unsigned NumArgs, const std::string &Name,
1488 BasicBlock *InsertAtEnd);
1491 virtual InvokeInst *clone() const;
1493 bool mayWriteToMemory() const { return true; }
1495 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1497 unsigned getCallingConv() const { return SubclassData; }
1498 void setCallingConv(unsigned CC) {
1502 /// getCalledFunction - Return the function called, or null if this is an
1503 /// indirect function invocation.
1505 Function *getCalledFunction() const {
1506 return dyn_cast<Function>(getOperand(0));
1509 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1510 inline Value *getCalledValue() const { return getOperand(0); }
1512 // get*Dest - Return the destination basic blocks...
1513 BasicBlock *getNormalDest() const {
1514 return cast<BasicBlock>(getOperand(1));
1516 BasicBlock *getUnwindDest() const {
1517 return cast<BasicBlock>(getOperand(2));
1519 void setNormalDest(BasicBlock *B) {
1520 setOperand(1, reinterpret_cast<Value*>(B));
1523 void setUnwindDest(BasicBlock *B) {
1524 setOperand(2, reinterpret_cast<Value*>(B));
1527 inline BasicBlock *getSuccessor(unsigned i) const {
1528 assert(i < 2 && "Successor # out of range for invoke!");
1529 return i == 0 ? getNormalDest() : getUnwindDest();
1532 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1533 assert(idx < 2 && "Successor # out of range for invoke!");
1534 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1537 unsigned getNumSuccessors() const { return 2; }
1539 // Methods for support type inquiry through isa, cast, and dyn_cast:
1540 static inline bool classof(const InvokeInst *) { return true; }
1541 static inline bool classof(const Instruction *I) {
1542 return (I->getOpcode() == Instruction::Invoke);
1544 static inline bool classof(const Value *V) {
1545 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1548 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1549 virtual unsigned getNumSuccessorsV() const;
1550 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1554 //===----------------------------------------------------------------------===//
1556 //===----------------------------------------------------------------------===//
1558 //===---------------------------------------------------------------------------
1559 /// UnwindInst - Immediately exit the current function, unwinding the stack
1560 /// until an invoke instruction is found.
1562 class UnwindInst : public TerminatorInst {
1564 explicit UnwindInst(Instruction *InsertBefore = 0)
1565 : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
1567 explicit UnwindInst(BasicBlock *InsertAtEnd)
1568 : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
1571 virtual UnwindInst *clone() const;
1573 unsigned getNumSuccessors() const { return 0; }
1575 // Methods for support type inquiry through isa, cast, and dyn_cast:
1576 static inline bool classof(const UnwindInst *) { return true; }
1577 static inline bool classof(const Instruction *I) {
1578 return I->getOpcode() == Instruction::Unwind;
1580 static inline bool classof(const Value *V) {
1581 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1584 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1585 virtual unsigned getNumSuccessorsV() const;
1586 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1589 //===----------------------------------------------------------------------===//
1590 // UnreachableInst Class
1591 //===----------------------------------------------------------------------===//
1593 //===---------------------------------------------------------------------------
1594 /// UnreachableInst - This function has undefined behavior. In particular, the
1595 /// presence of this instruction indicates some higher level knowledge that the
1596 /// end of the block cannot be reached.
1598 class UnreachableInst : public TerminatorInst {
1600 explicit UnreachableInst(Instruction *InsertBefore = 0)
1601 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
1603 explicit UnreachableInst(BasicBlock *InsertAtEnd)
1604 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
1607 virtual UnreachableInst *clone() const;
1609 unsigned getNumSuccessors() const { return 0; }
1611 // Methods for support type inquiry through isa, cast, and dyn_cast:
1612 static inline bool classof(const UnreachableInst *) { return true; }
1613 static inline bool classof(const Instruction *I) {
1614 return I->getOpcode() == Instruction::Unreachable;
1616 static inline bool classof(const Value *V) {
1617 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1620 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1621 virtual unsigned getNumSuccessorsV() const;
1622 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1625 //===----------------------------------------------------------------------===//
1627 //===----------------------------------------------------------------------===//
1629 /// @brief This class represents a truncation of integer types.
1630 class TruncInst : public CastInst {
1631 /// Private copy constructor
1632 TruncInst(const TruncInst &CI)
1633 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1636 /// @brief Constructor with insert-before-instruction semantics
1638 Value *S, ///< The value to be truncated
1639 const Type *Ty, ///< The (smaller) type to truncate to
1640 const std::string &Name = "", ///< A name for the new instruction
1641 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1644 /// @brief Constructor with insert-at-end-of-block semantics
1646 Value *S, ///< The value to be truncated
1647 const Type *Ty, ///< The (smaller) type to truncate to
1648 const std::string &Name, ///< A name for the new instruction
1649 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1652 /// @brief Clone an identical TruncInst
1653 virtual CastInst *clone() const;
1655 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1656 static inline bool classof(const TruncInst *) { return true; }
1657 static inline bool classof(const Instruction *I) {
1658 return I->getOpcode() == Trunc;
1660 static inline bool classof(const Value *V) {
1661 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1665 //===----------------------------------------------------------------------===//
1667 //===----------------------------------------------------------------------===//
1669 /// @brief This class represents zero extension of integer types.
1670 class ZExtInst : public CastInst {
1671 /// @brief Private copy constructor
1672 ZExtInst(const ZExtInst &CI)
1673 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1676 /// @brief Constructor with insert-before-instruction semantics
1678 Value *S, ///< The value to be zero extended
1679 const Type *Ty, ///< The type to zero extend to
1680 const std::string &Name = "", ///< A name for the new instruction
1681 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1684 /// @brief Constructor with insert-at-end semantics.
1686 Value *S, ///< The value to be zero extended
1687 const Type *Ty, ///< The type to zero extend to
1688 const std::string &Name, ///< A name for the new instruction
1689 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1692 /// @brief Clone an identical ZExtInst
1693 virtual CastInst *clone() const;
1695 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1696 static inline bool classof(const ZExtInst *) { return true; }
1697 static inline bool classof(const Instruction *I) {
1698 return I->getOpcode() == ZExt;
1700 static inline bool classof(const Value *V) {
1701 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1705 //===----------------------------------------------------------------------===//
1707 //===----------------------------------------------------------------------===//
1709 /// @brief This class represents a sign extension of integer types.
1710 class SExtInst : public CastInst {
1711 /// @brief Private copy constructor
1712 SExtInst(const SExtInst &CI)
1713 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1716 /// @brief Constructor with insert-before-instruction semantics
1718 Value *S, ///< The value to be sign extended
1719 const Type *Ty, ///< The type to sign extend to
1720 const std::string &Name = "", ///< A name for the new instruction
1721 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1724 /// @brief Constructor with insert-at-end-of-block semantics
1726 Value *S, ///< The value to be sign extended
1727 const Type *Ty, ///< The type to sign extend to
1728 const std::string &Name, ///< A name for the new instruction
1729 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1732 /// @brief Clone an identical SExtInst
1733 virtual CastInst *clone() const;
1735 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1736 static inline bool classof(const SExtInst *) { return true; }
1737 static inline bool classof(const Instruction *I) {
1738 return I->getOpcode() == SExt;
1740 static inline bool classof(const Value *V) {
1741 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1745 //===----------------------------------------------------------------------===//
1746 // FPTruncInst Class
1747 //===----------------------------------------------------------------------===//
1749 /// @brief This class represents a truncation of floating point types.
1750 class FPTruncInst : public CastInst {
1751 FPTruncInst(const FPTruncInst &CI)
1752 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1755 /// @brief Constructor with insert-before-instruction semantics
1757 Value *S, ///< The value to be truncated
1758 const Type *Ty, ///< The type to truncate to
1759 const std::string &Name = "", ///< A name for the new instruction
1760 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1763 /// @brief Constructor with insert-before-instruction semantics
1765 Value *S, ///< The value to be truncated
1766 const Type *Ty, ///< The type to truncate to
1767 const std::string &Name, ///< A name for the new instruction
1768 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1771 /// @brief Clone an identical FPTruncInst
1772 virtual CastInst *clone() const;
1774 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1775 static inline bool classof(const FPTruncInst *) { return true; }
1776 static inline bool classof(const Instruction *I) {
1777 return I->getOpcode() == FPTrunc;
1779 static inline bool classof(const Value *V) {
1780 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1784 //===----------------------------------------------------------------------===//
1786 //===----------------------------------------------------------------------===//
1788 /// @brief This class represents an extension of floating point types.
1789 class FPExtInst : public CastInst {
1790 FPExtInst(const FPExtInst &CI)
1791 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1794 /// @brief Constructor with insert-before-instruction semantics
1796 Value *S, ///< The value to be extended
1797 const Type *Ty, ///< The type to extend to
1798 const std::string &Name = "", ///< A name for the new instruction
1799 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1802 /// @brief Constructor with insert-at-end-of-block semantics
1804 Value *S, ///< The value to be extended
1805 const Type *Ty, ///< The type to extend to
1806 const std::string &Name, ///< A name for the new instruction
1807 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1810 /// @brief Clone an identical FPExtInst
1811 virtual CastInst *clone() const;
1813 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1814 static inline bool classof(const FPExtInst *) { return true; }
1815 static inline bool classof(const Instruction *I) {
1816 return I->getOpcode() == FPExt;
1818 static inline bool classof(const Value *V) {
1819 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1823 //===----------------------------------------------------------------------===//
1825 //===----------------------------------------------------------------------===//
1827 /// @brief This class represents a cast unsigned integer to floating point.
1828 class UIToFPInst : public CastInst {
1829 UIToFPInst(const UIToFPInst &CI)
1830 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1833 /// @brief Constructor with insert-before-instruction semantics
1835 Value *S, ///< The value to be converted
1836 const Type *Ty, ///< The type to convert to
1837 const std::string &Name = "", ///< A name for the new instruction
1838 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1841 /// @brief Constructor with insert-at-end-of-block semantics
1843 Value *S, ///< The value to be converted
1844 const Type *Ty, ///< The type to convert to
1845 const std::string &Name, ///< A name for the new instruction
1846 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1849 /// @brief Clone an identical UIToFPInst
1850 virtual CastInst *clone() const;
1852 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1853 static inline bool classof(const UIToFPInst *) { return true; }
1854 static inline bool classof(const Instruction *I) {
1855 return I->getOpcode() == UIToFP;
1857 static inline bool classof(const Value *V) {
1858 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1862 //===----------------------------------------------------------------------===//
1864 //===----------------------------------------------------------------------===//
1866 /// @brief This class represents a cast from signed integer to floating point.
1867 class SIToFPInst : public CastInst {
1868 SIToFPInst(const SIToFPInst &CI)
1869 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1872 /// @brief Constructor with insert-before-instruction semantics
1874 Value *S, ///< The value to be converted
1875 const Type *Ty, ///< The type to convert to
1876 const std::string &Name = "", ///< A name for the new instruction
1877 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1880 /// @brief Constructor with insert-at-end-of-block semantics
1882 Value *S, ///< The value to be converted
1883 const Type *Ty, ///< The type to convert to
1884 const std::string &Name, ///< A name for the new instruction
1885 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1888 /// @brief Clone an identical SIToFPInst
1889 virtual CastInst *clone() const;
1891 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1892 static inline bool classof(const SIToFPInst *) { return true; }
1893 static inline bool classof(const Instruction *I) {
1894 return I->getOpcode() == SIToFP;
1896 static inline bool classof(const Value *V) {
1897 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1901 //===----------------------------------------------------------------------===//
1903 //===----------------------------------------------------------------------===//
1905 /// @brief This class represents a cast from floating point to unsigned integer
1906 class FPToUIInst : public CastInst {
1907 FPToUIInst(const FPToUIInst &CI)
1908 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1911 /// @brief Constructor with insert-before-instruction semantics
1913 Value *S, ///< The value to be converted
1914 const Type *Ty, ///< The type to convert to
1915 const std::string &Name = "", ///< A name for the new instruction
1916 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1919 /// @brief Constructor with insert-at-end-of-block semantics
1921 Value *S, ///< The value to be converted
1922 const Type *Ty, ///< The type to convert to
1923 const std::string &Name, ///< A name for the new instruction
1924 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
1927 /// @brief Clone an identical FPToUIInst
1928 virtual CastInst *clone() const;
1930 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1931 static inline bool classof(const FPToUIInst *) { return true; }
1932 static inline bool classof(const Instruction *I) {
1933 return I->getOpcode() == FPToUI;
1935 static inline bool classof(const Value *V) {
1936 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1940 //===----------------------------------------------------------------------===//
1942 //===----------------------------------------------------------------------===//
1944 /// @brief This class represents a cast from floating point to signed integer.
1945 class FPToSIInst : public CastInst {
1946 FPToSIInst(const FPToSIInst &CI)
1947 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
1950 /// @brief Constructor with insert-before-instruction semantics
1952 Value *S, ///< The value to be converted
1953 const Type *Ty, ///< The type to convert to
1954 const std::string &Name = "", ///< A name for the new instruction
1955 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1958 /// @brief Constructor with insert-at-end-of-block semantics
1960 Value *S, ///< The value to be converted
1961 const Type *Ty, ///< The type to convert to
1962 const std::string &Name, ///< A name for the new instruction
1963 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1966 /// @brief Clone an identical FPToSIInst
1967 virtual CastInst *clone() const;
1969 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1970 static inline bool classof(const FPToSIInst *) { return true; }
1971 static inline bool classof(const Instruction *I) {
1972 return I->getOpcode() == FPToSI;
1974 static inline bool classof(const Value *V) {
1975 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1979 //===----------------------------------------------------------------------===//
1980 // IntToPtrInst Class
1981 //===----------------------------------------------------------------------===//
1983 /// @brief This class represents a cast from an integer to a pointer.
1984 class IntToPtrInst : public CastInst {
1985 IntToPtrInst(const IntToPtrInst &CI)
1986 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
1989 /// @brief Constructor with insert-before-instruction semantics
1991 Value *S, ///< The value to be converted
1992 const Type *Ty, ///< The type to convert to
1993 const std::string &Name = "", ///< A name for the new instruction
1994 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1997 /// @brief Constructor with insert-at-end-of-block semantics
1999 Value *S, ///< The value to be converted
2000 const Type *Ty, ///< The type to convert to
2001 const std::string &Name, ///< A name for the new instruction
2002 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2005 /// @brief Clone an identical IntToPtrInst
2006 virtual CastInst *clone() const;
2008 // Methods for support type inquiry through isa, cast, and dyn_cast:
2009 static inline bool classof(const IntToPtrInst *) { return true; }
2010 static inline bool classof(const Instruction *I) {
2011 return I->getOpcode() == IntToPtr;
2013 static inline bool classof(const Value *V) {
2014 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2018 //===----------------------------------------------------------------------===//
2019 // PtrToIntInst Class
2020 //===----------------------------------------------------------------------===//
2022 /// @brief This class represents a cast from a pointer to an integer
2023 class PtrToIntInst : public CastInst {
2024 PtrToIntInst(const PtrToIntInst &CI)
2025 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2028 /// @brief Constructor with insert-before-instruction semantics
2030 Value *S, ///< The value to be converted
2031 const Type *Ty, ///< The type to convert to
2032 const std::string &Name = "", ///< A name for the new instruction
2033 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2036 /// @brief Constructor with insert-at-end-of-block semantics
2038 Value *S, ///< The value to be converted
2039 const Type *Ty, ///< The type to convert to
2040 const std::string &Name, ///< A name for the new instruction
2041 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2044 /// @brief Clone an identical PtrToIntInst
2045 virtual CastInst *clone() const;
2047 // Methods for support type inquiry through isa, cast, and dyn_cast:
2048 static inline bool classof(const PtrToIntInst *) { return true; }
2049 static inline bool classof(const Instruction *I) {
2050 return I->getOpcode() == PtrToInt;
2052 static inline bool classof(const Value *V) {
2053 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2057 //===----------------------------------------------------------------------===//
2058 // BitCastInst Class
2059 //===----------------------------------------------------------------------===//
2061 /// @brief This class represents a no-op cast from one type to another.
2062 class BitCastInst : public CastInst {
2063 BitCastInst(const BitCastInst &CI)
2064 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2067 /// @brief Constructor with insert-before-instruction semantics
2069 Value *S, ///< The value to be casted
2070 const Type *Ty, ///< The type to casted to
2071 const std::string &Name = "", ///< A name for the new instruction
2072 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2075 /// @brief Constructor with insert-at-end-of-block semantics
2077 Value *S, ///< The value to be casted
2078 const Type *Ty, ///< The type to casted to
2079 const std::string &Name, ///< A name for the new instruction
2080 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2083 /// @brief Clone an identical BitCastInst
2084 virtual CastInst *clone() const;
2086 // Methods for support type inquiry through isa, cast, and dyn_cast:
2087 static inline bool classof(const BitCastInst *) { return true; }
2088 static inline bool classof(const Instruction *I) {
2089 return I->getOpcode() == BitCast;
2091 static inline bool classof(const Value *V) {
2092 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2096 } // End llvm namespace