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"
31 //===----------------------------------------------------------------------===//
32 // AllocationInst Class
33 //===----------------------------------------------------------------------===//
35 /// AllocationInst - This class is the common base class of MallocInst and
38 class AllocationInst : public UnaryInstruction {
41 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
42 const std::string &Name = "", Instruction *InsertBefore = 0);
43 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
44 const std::string &Name, BasicBlock *InsertAtEnd);
46 // Out of line virtual method, so the vtable, etc has a home.
47 virtual ~AllocationInst();
49 /// isArrayAllocation - Return true if there is an allocation size parameter
50 /// to the allocation instruction that is not 1.
52 bool isArrayAllocation() const;
54 /// getArraySize - Get the number of element allocated, for a simple
55 /// allocation of a single element, this will return a constant 1 value.
57 inline const Value *getArraySize() const { return getOperand(0); }
58 inline Value *getArraySize() { return getOperand(0); }
60 /// getType - Overload to return most specific pointer type
62 inline const PointerType *getType() const {
63 return reinterpret_cast<const PointerType*>(Instruction::getType());
66 /// getAllocatedType - Return the type that is being allocated by the
69 const Type *getAllocatedType() const;
71 /// getAlignment - Return the alignment of the memory that is being allocated
72 /// by the instruction.
74 unsigned getAlignment() const { return Alignment; }
75 void setAlignment(unsigned Align) {
76 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
80 virtual Instruction *clone() const = 0;
82 // Methods for support type inquiry through isa, cast, and dyn_cast:
83 static inline bool classof(const AllocationInst *) { return true; }
84 static inline bool classof(const Instruction *I) {
85 return I->getOpcode() == Instruction::Alloca ||
86 I->getOpcode() == Instruction::Malloc;
88 static inline bool classof(const Value *V) {
89 return isa<Instruction>(V) && classof(cast<Instruction>(V));
94 //===----------------------------------------------------------------------===//
96 //===----------------------------------------------------------------------===//
98 /// MallocInst - an instruction to allocated memory on the heap
100 class MallocInst : public AllocationInst {
101 MallocInst(const MallocInst &MI);
103 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
104 const std::string &Name = "",
105 Instruction *InsertBefore = 0)
106 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
107 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
108 BasicBlock *InsertAtEnd)
109 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
111 MallocInst(const Type *Ty, const std::string &Name,
112 Instruction *InsertBefore = 0)
113 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
114 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
115 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
117 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
118 const std::string &Name, BasicBlock *InsertAtEnd)
119 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
120 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
121 const std::string &Name = "",
122 Instruction *InsertBefore = 0)
123 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
125 virtual MallocInst *clone() const;
127 // Methods for support type inquiry through isa, cast, and dyn_cast:
128 static inline bool classof(const MallocInst *) { return true; }
129 static inline bool classof(const Instruction *I) {
130 return (I->getOpcode() == Instruction::Malloc);
132 static inline bool classof(const Value *V) {
133 return isa<Instruction>(V) && classof(cast<Instruction>(V));
138 //===----------------------------------------------------------------------===//
140 //===----------------------------------------------------------------------===//
142 /// AllocaInst - an instruction to allocate memory on the stack
144 class AllocaInst : public AllocationInst {
145 AllocaInst(const AllocaInst &);
147 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
148 const std::string &Name = "",
149 Instruction *InsertBefore = 0)
150 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
151 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
152 BasicBlock *InsertAtEnd)
153 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
155 AllocaInst(const Type *Ty, const std::string &Name,
156 Instruction *InsertBefore = 0)
157 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
158 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
159 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
161 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
162 const std::string &Name = "", Instruction *InsertBefore = 0)
163 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
164 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
165 const std::string &Name, BasicBlock *InsertAtEnd)
166 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
168 virtual AllocaInst *clone() const;
170 // Methods for support type inquiry through isa, cast, and dyn_cast:
171 static inline bool classof(const AllocaInst *) { return true; }
172 static inline bool classof(const Instruction *I) {
173 return (I->getOpcode() == Instruction::Alloca);
175 static inline bool classof(const Value *V) {
176 return isa<Instruction>(V) && classof(cast<Instruction>(V));
181 //===----------------------------------------------------------------------===//
183 //===----------------------------------------------------------------------===//
185 /// FreeInst - an instruction to deallocate memory
187 class FreeInst : public UnaryInstruction {
190 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
191 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
193 virtual FreeInst *clone() const;
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 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false,
227 Instruction *InsertBefore = 0);
228 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
229 BasicBlock *InsertAtEnd);
231 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
232 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
233 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
234 Instruction *InsertBefore = 0);
235 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
236 BasicBlock *InsertAtEnd);
238 /// isVolatile - Return true if this is a load from a volatile memory
241 bool isVolatile() const { return SubclassData; }
243 /// setVolatile - Specify whether this is a volatile load or not.
245 void setVolatile(bool V) { SubclassData = V; }
247 virtual LoadInst *clone() const;
249 Value *getPointerOperand() { return getOperand(0); }
250 const Value *getPointerOperand() const { return getOperand(0); }
251 static unsigned getPointerOperandIndex() { return 0U; }
253 // Methods for support type inquiry through isa, cast, and dyn_cast:
254 static inline bool classof(const LoadInst *) { return true; }
255 static inline bool classof(const Instruction *I) {
256 return I->getOpcode() == Instruction::Load;
258 static inline bool classof(const Value *V) {
259 return isa<Instruction>(V) && classof(cast<Instruction>(V));
264 //===----------------------------------------------------------------------===//
266 //===----------------------------------------------------------------------===//
268 /// StoreInst - an instruction for storing to memory
270 class StoreInst : public Instruction {
272 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
273 Ops[0].init(SI.Ops[0], this);
274 Ops[1].init(SI.Ops[1], this);
275 setVolatile(SI.isVolatile());
282 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
283 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
284 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
285 Instruction *InsertBefore = 0);
286 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
289 /// isVolatile - Return true if this is a load from a volatile memory
292 bool isVolatile() const { return SubclassData; }
294 /// setVolatile - Specify whether this is a volatile load or not.
296 void setVolatile(bool V) { SubclassData = V; }
298 /// Transparently provide more efficient getOperand methods.
299 Value *getOperand(unsigned i) const {
300 assert(i < 2 && "getOperand() out of range!");
303 void setOperand(unsigned i, Value *Val) {
304 assert(i < 2 && "setOperand() out of range!");
307 unsigned getNumOperands() const { return 2; }
310 virtual StoreInst *clone() const;
312 Value *getPointerOperand() { return getOperand(1); }
313 const Value *getPointerOperand() const { return getOperand(1); }
314 static unsigned getPointerOperandIndex() { return 1U; }
316 // Methods for support type inquiry through isa, cast, and dyn_cast:
317 static inline bool classof(const StoreInst *) { return true; }
318 static inline bool classof(const Instruction *I) {
319 return I->getOpcode() == Instruction::Store;
321 static inline bool classof(const Value *V) {
322 return isa<Instruction>(V) && classof(cast<Instruction>(V));
327 //===----------------------------------------------------------------------===//
328 // GetElementPtrInst Class
329 //===----------------------------------------------------------------------===//
331 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
332 /// access elements of arrays and structs
334 class GetElementPtrInst : public Instruction {
335 GetElementPtrInst(const GetElementPtrInst &GEPI)
336 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
337 0, GEPI.getNumOperands()) {
338 Use *OL = OperandList = new Use[NumOperands];
339 Use *GEPIOL = GEPI.OperandList;
340 for (unsigned i = 0, E = NumOperands; i != E; ++i)
341 OL[i].init(GEPIOL[i], this);
343 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
344 void init(Value *Ptr, Value *Idx0, Value *Idx1);
345 void init(Value *Ptr, Value *Idx);
347 /// Constructors - Create a getelementptr instruction with a base pointer an
348 /// list of indices. The first ctor can optionally insert before an existing
349 /// instruction, the second appends the new instruction to the specified
351 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
352 const std::string &Name = "", Instruction *InsertBefore =0);
353 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
354 const std::string &Name, BasicBlock *InsertAtEnd);
356 /// Constructors - These two constructors are convenience methods because one
357 /// and two index getelementptr instructions are so common.
358 GetElementPtrInst(Value *Ptr, Value *Idx,
359 const std::string &Name = "", Instruction *InsertBefore =0);
360 GetElementPtrInst(Value *Ptr, Value *Idx,
361 const std::string &Name, BasicBlock *InsertAtEnd);
362 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
363 const std::string &Name = "", Instruction *InsertBefore =0);
364 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
365 const std::string &Name, BasicBlock *InsertAtEnd);
366 ~GetElementPtrInst();
368 virtual GetElementPtrInst *clone() const;
370 // getType - Overload to return most specific pointer type...
371 inline const PointerType *getType() const {
372 return reinterpret_cast<const PointerType*>(Instruction::getType());
375 /// getIndexedType - Returns the type of the element that would be loaded with
376 /// a load instruction with the specified parameters.
378 /// A null type is returned if the indices are invalid for the specified
381 static const Type *getIndexedType(const Type *Ptr,
382 Value* const *Idx, unsigned NumIdx,
383 bool AllowStructLeaf = false);
385 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
386 bool AllowStructLeaf = false);
387 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
389 inline op_iterator idx_begin() { return op_begin()+1; }
390 inline const_op_iterator idx_begin() const { return op_begin()+1; }
391 inline op_iterator idx_end() { return op_end(); }
392 inline const_op_iterator idx_end() const { return op_end(); }
394 Value *getPointerOperand() {
395 return getOperand(0);
397 const Value *getPointerOperand() const {
398 return getOperand(0);
400 static unsigned getPointerOperandIndex() {
401 return 0U; // get index for modifying correct operand
404 inline unsigned getNumIndices() const { // Note: always non-negative
405 return getNumOperands() - 1;
408 inline bool hasIndices() const {
409 return getNumOperands() > 1;
412 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
413 /// zeros. If so, the result pointer and the first operand have the same
414 /// value, just potentially different types.
415 bool hasAllZeroIndices() const;
417 // Methods for support type inquiry through isa, cast, and dyn_cast:
418 static inline bool classof(const GetElementPtrInst *) { return true; }
419 static inline bool classof(const Instruction *I) {
420 return (I->getOpcode() == Instruction::GetElementPtr);
422 static inline bool classof(const Value *V) {
423 return isa<Instruction>(V) && classof(cast<Instruction>(V));
427 //===----------------------------------------------------------------------===//
429 //===----------------------------------------------------------------------===//
431 /// This instruction compares its operands according to the predicate given
432 /// to the constructor. It only operates on integers, pointers, or packed
433 /// vectors of integrals. The two operands must be the same type.
434 /// @brief Represent an integer comparison operator.
435 class ICmpInst: public CmpInst {
437 /// This enumeration lists the possible predicates for the ICmpInst. The
438 /// values in the range 0-31 are reserved for FCmpInst while values in the
439 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
440 /// predicate values are not overlapping between the classes.
442 ICMP_EQ = 32, ///< equal
443 ICMP_NE = 33, ///< not equal
444 ICMP_UGT = 34, ///< unsigned greater than
445 ICMP_UGE = 35, ///< unsigned greater or equal
446 ICMP_ULT = 36, ///< unsigned less than
447 ICMP_ULE = 37, ///< unsigned less or equal
448 ICMP_SGT = 38, ///< signed greater than
449 ICMP_SGE = 39, ///< signed greater or equal
450 ICMP_SLT = 40, ///< signed less than
451 ICMP_SLE = 41, ///< signed less or equal
452 FIRST_ICMP_PREDICATE = ICMP_EQ,
453 LAST_ICMP_PREDICATE = ICMP_SLE,
454 BAD_ICMP_PREDICATE = ICMP_SLE + 1
457 /// @brief Constructor with insert-before-instruction semantics.
459 Predicate pred, ///< The predicate to use for the comparison
460 Value *LHS, ///< The left-hand-side of the expression
461 Value *RHS, ///< The right-hand-side of the expression
462 const std::string &Name = "", ///< Name of the instruction
463 Instruction *InsertBefore = 0 ///< Where to insert
464 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
467 /// @brief Constructor with insert-at-block-end semantics.
469 Predicate pred, ///< The predicate to use for the comparison
470 Value *LHS, ///< The left-hand-side of the expression
471 Value *RHS, ///< The right-hand-side of the expression
472 const std::string &Name, ///< Name of the instruction
473 BasicBlock *InsertAtEnd ///< Block to insert into.
474 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
477 /// @brief Return the predicate for this instruction.
478 Predicate getPredicate() const { return Predicate(SubclassData); }
480 /// @brief Set the predicate for this instruction to the specified value.
481 void setPredicate(Predicate P) { SubclassData = P; }
483 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
484 /// @returns the inverse predicate for the instruction's current predicate.
485 /// @brief Return the inverse of the instruction's predicate.
486 Predicate getInversePredicate() const {
487 return getInversePredicate(getPredicate());
490 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
491 /// @returns the inverse predicate for predicate provided in \p pred.
492 /// @brief Return the inverse of a given predicate
493 static Predicate getInversePredicate(Predicate pred);
495 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
496 /// @returns the predicate that would be the result of exchanging the two
497 /// operands of the ICmpInst instruction without changing the result
499 /// @brief Return the predicate as if the operands were swapped
500 Predicate getSwappedPredicate() const {
501 return getSwappedPredicate(getPredicate());
504 /// This is a static version that you can use without an instruction
506 /// @brief Return the predicate as if the operands were swapped.
507 static Predicate getSwappedPredicate(Predicate pred);
509 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
510 /// @returns the predicate that would be the result if the operand were
511 /// regarded as signed.
512 /// @brief Return the signed version of the predicate
513 Predicate getSignedPredicate() const {
514 return getSignedPredicate(getPredicate());
517 /// This is a static version that you can use without an instruction.
518 /// @brief Return the signed version of the predicate.
519 static Predicate getSignedPredicate(Predicate pred);
521 /// This also tests for commutativity. If isEquality() returns true then
522 /// the predicate is also commutative.
523 /// @returns true if the predicate of this instruction is EQ or NE.
524 /// @brief Determine if this is an equality predicate.
525 bool isEquality() const {
526 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
529 /// @returns true if the predicate of this ICmpInst is commutative
530 /// @brief Determine if this relation is commutative.
531 bool isCommutative() const { return isEquality(); }
533 /// @returns true if the predicate is relational (not EQ or NE).
534 /// @brief Determine if this a relational predicate.
535 bool isRelational() const {
536 return !isEquality();
539 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
540 /// @brief Determine if this instruction's predicate is signed.
541 bool isSignedPredicate() { return isSignedPredicate(getPredicate()); }
543 /// @returns true if the predicate provided is signed, false otherwise
544 /// @brief Determine if the predicate is signed.
545 static bool isSignedPredicate(Predicate pred);
547 /// Initialize a set of values that all satisfy the predicate with C.
548 /// @brief Make a ConstantRange for a relation with a constant value.
549 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
551 /// Exchange the two operands to this instruction in such a way that it does
552 /// not modify the semantics of the instruction. The predicate value may be
553 /// changed to retain the same result if the predicate is order dependent
555 /// @brief Swap operands and adjust predicate.
556 void swapOperands() {
557 SubclassData = getSwappedPredicate();
558 std::swap(Ops[0], Ops[1]);
561 // Methods for support type inquiry through isa, cast, and dyn_cast:
562 static inline bool classof(const ICmpInst *) { return true; }
563 static inline bool classof(const Instruction *I) {
564 return I->getOpcode() == Instruction::ICmp;
566 static inline bool classof(const Value *V) {
567 return isa<Instruction>(V) && classof(cast<Instruction>(V));
571 //===----------------------------------------------------------------------===//
573 //===----------------------------------------------------------------------===//
575 /// This instruction compares its operands according to the predicate given
576 /// to the constructor. It only operates on floating point values or packed
577 /// vectors of floating point values. The operands must be identical types.
578 /// @brief Represents a floating point comparison operator.
579 class FCmpInst: public CmpInst {
581 /// This enumeration lists the possible predicates for the FCmpInst. Values
582 /// in the range 0-31 are reserved for FCmpInst.
584 // Opcode U L G E Intuitive operation
585 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
586 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
587 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
588 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
589 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
590 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
591 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
592 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
593 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
594 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
595 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
596 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
597 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
598 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
599 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
600 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
601 FIRST_FCMP_PREDICATE = FCMP_FALSE,
602 LAST_FCMP_PREDICATE = FCMP_TRUE,
603 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
606 /// @brief Constructor with insert-before-instruction semantics.
608 Predicate pred, ///< The predicate to use for the comparison
609 Value *LHS, ///< The left-hand-side of the expression
610 Value *RHS, ///< The right-hand-side of the expression
611 const std::string &Name = "", ///< Name of the instruction
612 Instruction *InsertBefore = 0 ///< Where to insert
613 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
616 /// @brief Constructor with insert-at-block-end semantics.
618 Predicate pred, ///< The predicate to use for the comparison
619 Value *LHS, ///< The left-hand-side of the expression
620 Value *RHS, ///< The right-hand-side of the expression
621 const std::string &Name, ///< Name of the instruction
622 BasicBlock *InsertAtEnd ///< Block to insert into.
623 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
626 /// @brief Return the predicate for this instruction.
627 Predicate getPredicate() const { return Predicate(SubclassData); }
629 /// @brief Set the predicate for this instruction to the specified value.
630 void setPredicate(Predicate P) { SubclassData = P; }
632 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
633 /// @returns the inverse predicate for the instructions current predicate.
634 /// @brief Return the inverse of the predicate
635 Predicate getInversePredicate() const {
636 return getInversePredicate(getPredicate());
639 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
640 /// @returns the inverse predicate for \p pred.
641 /// @brief Return the inverse of a given predicate
642 static Predicate getInversePredicate(Predicate pred);
644 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
645 /// @returns the predicate that would be the result of exchanging the two
646 /// operands of the ICmpInst instruction without changing the result
648 /// @brief Return the predicate as if the operands were swapped
649 Predicate getSwappedPredicate() const {
650 return getSwappedPredicate(getPredicate());
653 /// This is a static version that you can use without an instruction
655 /// @brief Return the predicate as if the operands were swapped.
656 static Predicate getSwappedPredicate(Predicate Opcode);
658 /// This also tests for commutativity. If isEquality() returns true then
659 /// the predicate is also commutative. Only the equality predicates are
661 /// @returns true if the predicate of this instruction is EQ or NE.
662 /// @brief Determine if this is an equality predicate.
663 bool isEquality() const {
664 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
665 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
667 bool isCommutative() const { return isEquality(); }
669 /// @returns true if the predicate is relational (not EQ or NE).
670 /// @brief Determine if this a relational predicate.
671 bool isRelational() const { return !isEquality(); }
673 /// Exchange the two operands to this instruction in such a way that it does
674 /// not modify the semantics of the instruction. The predicate value may be
675 /// changed to retain the same result if the predicate is order dependent
677 /// @brief Swap operands and adjust predicate.
678 void swapOperands() {
679 SubclassData = getSwappedPredicate();
680 std::swap(Ops[0], Ops[1]);
683 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
684 static inline bool classof(const FCmpInst *) { return true; }
685 static inline bool classof(const Instruction *I) {
686 return I->getOpcode() == Instruction::FCmp;
688 static inline bool classof(const Value *V) {
689 return isa<Instruction>(V) && classof(cast<Instruction>(V));
693 //===----------------------------------------------------------------------===//
695 //===----------------------------------------------------------------------===//
697 /// CallInst - This class represents a function call, abstracting a target
698 /// machine's calling convention. This class uses low bit of the SubClassData
699 /// field to indicate whether or not this is a tail call. The rest of the bits
700 /// hold the calling convention of the call.
702 class CallInst : public Instruction {
703 ParamAttrsList *ParamAttrs; ///< parameter attributes for call
704 CallInst(const CallInst &CI);
705 void init(Value *Func, Value* const *Params, unsigned NumParams);
706 void init(Value *Func, Value *Actual1, Value *Actual2);
707 void init(Value *Func, Value *Actual);
708 void init(Value *Func);
711 CallInst(Value *F, Value* const *Args, unsigned NumArgs,
712 const std::string &Name = "", Instruction *InsertBefore = 0);
713 CallInst(Value *F, Value *const *Args, unsigned NumArgs,
714 const std::string &Name, BasicBlock *InsertAtEnd);
716 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
717 // actuals, respectively.
718 CallInst(Value *F, Value *Actual1, Value *Actual2,
719 const std::string& Name = "", Instruction *InsertBefore = 0);
720 CallInst(Value *F, Value *Actual1, Value *Actual2,
721 const std::string& Name, BasicBlock *InsertAtEnd);
722 CallInst(Value *F, Value *Actual, const std::string& Name = "",
723 Instruction *InsertBefore = 0);
724 CallInst(Value *F, Value *Actual, const std::string& Name,
725 BasicBlock *InsertAtEnd);
726 explicit CallInst(Value *F, const std::string &Name = "",
727 Instruction *InsertBefore = 0);
728 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
731 virtual CallInst *clone() const;
733 bool isTailCall() const { return SubclassData & 1; }
734 void setTailCall(bool isTailCall = true) {
735 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
738 /// getCallingConv/setCallingConv - Get or set the calling convention of this
740 unsigned getCallingConv() const { return SubclassData >> 1; }
741 void setCallingConv(unsigned CC) {
742 SubclassData = (SubclassData & 1) | (CC << 1);
745 /// Obtains a pointer to the ParamAttrsList object which holds the
746 /// parameter attributes information, if any.
747 /// @returns 0 if no attributes have been set.
748 /// @brief Get the parameter attributes.
749 ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
751 /// Sets the parameter attributes for this CallInst. To construct a
752 /// ParamAttrsList, see ParameterAttributes.h
753 /// @brief Set the parameter attributes.
754 void setParamAttrs(ParamAttrsList *attrs) { ParamAttrs = attrs; }
756 /// getCalledFunction - Return the function being called by this instruction
757 /// if it is a direct call. If it is a call through a function pointer,
759 Function *getCalledFunction() const {
760 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
763 /// getCalledValue - Get a pointer to the function that is invoked by this
765 inline const Value *getCalledValue() const { return getOperand(0); }
766 inline Value *getCalledValue() { return getOperand(0); }
768 // Methods for support type inquiry through isa, cast, and dyn_cast:
769 static inline bool classof(const CallInst *) { return true; }
770 static inline bool classof(const Instruction *I) {
771 return I->getOpcode() == Instruction::Call;
773 static inline bool classof(const Value *V) {
774 return isa<Instruction>(V) && classof(cast<Instruction>(V));
778 //===----------------------------------------------------------------------===//
780 //===----------------------------------------------------------------------===//
782 /// SelectInst - This class represents the LLVM 'select' instruction.
784 class SelectInst : public Instruction {
787 void init(Value *C, Value *S1, Value *S2) {
788 Ops[0].init(C, this);
789 Ops[1].init(S1, this);
790 Ops[2].init(S2, this);
793 SelectInst(const SelectInst &SI)
794 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
795 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
798 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
799 Instruction *InsertBefore = 0)
800 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
804 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
805 BasicBlock *InsertAtEnd)
806 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
811 Value *getCondition() const { return Ops[0]; }
812 Value *getTrueValue() const { return Ops[1]; }
813 Value *getFalseValue() const { return Ops[2]; }
815 /// Transparently provide more efficient getOperand methods.
816 Value *getOperand(unsigned i) const {
817 assert(i < 3 && "getOperand() out of range!");
820 void setOperand(unsigned i, Value *Val) {
821 assert(i < 3 && "setOperand() out of range!");
824 unsigned getNumOperands() const { return 3; }
826 OtherOps getOpcode() const {
827 return static_cast<OtherOps>(Instruction::getOpcode());
830 virtual SelectInst *clone() const;
832 // Methods for support type inquiry through isa, cast, and dyn_cast:
833 static inline bool classof(const SelectInst *) { return true; }
834 static inline bool classof(const Instruction *I) {
835 return I->getOpcode() == Instruction::Select;
837 static inline bool classof(const Value *V) {
838 return isa<Instruction>(V) && classof(cast<Instruction>(V));
842 //===----------------------------------------------------------------------===//
844 //===----------------------------------------------------------------------===//
846 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
847 /// an argument of the specified type given a va_list and increments that list
849 class VAArgInst : public UnaryInstruction {
850 VAArgInst(const VAArgInst &VAA)
851 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
853 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
854 Instruction *InsertBefore = 0)
855 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
858 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
859 BasicBlock *InsertAtEnd)
860 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
864 virtual VAArgInst *clone() const;
866 // Methods for support type inquiry through isa, cast, and dyn_cast:
867 static inline bool classof(const VAArgInst *) { return true; }
868 static inline bool classof(const Instruction *I) {
869 return I->getOpcode() == VAArg;
871 static inline bool classof(const Value *V) {
872 return isa<Instruction>(V) && classof(cast<Instruction>(V));
876 //===----------------------------------------------------------------------===//
877 // ExtractElementInst Class
878 //===----------------------------------------------------------------------===//
880 /// ExtractElementInst - This instruction extracts a single (scalar)
881 /// element from a VectorType value
883 class ExtractElementInst : public Instruction {
885 ExtractElementInst(const ExtractElementInst &EE) :
886 Instruction(EE.getType(), ExtractElement, Ops, 2) {
887 Ops[0].init(EE.Ops[0], this);
888 Ops[1].init(EE.Ops[1], this);
892 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
893 Instruction *InsertBefore = 0);
894 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
895 Instruction *InsertBefore = 0);
896 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
897 BasicBlock *InsertAtEnd);
898 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
899 BasicBlock *InsertAtEnd);
901 /// isValidOperands - Return true if an extractelement instruction can be
902 /// formed with the specified operands.
903 static bool isValidOperands(const Value *Vec, const Value *Idx);
905 virtual ExtractElementInst *clone() const;
907 /// Transparently provide more efficient getOperand methods.
908 Value *getOperand(unsigned i) const {
909 assert(i < 2 && "getOperand() out of range!");
912 void setOperand(unsigned i, Value *Val) {
913 assert(i < 2 && "setOperand() out of range!");
916 unsigned getNumOperands() const { return 2; }
918 // Methods for support type inquiry through isa, cast, and dyn_cast:
919 static inline bool classof(const ExtractElementInst *) { return true; }
920 static inline bool classof(const Instruction *I) {
921 return I->getOpcode() == Instruction::ExtractElement;
923 static inline bool classof(const Value *V) {
924 return isa<Instruction>(V) && classof(cast<Instruction>(V));
928 //===----------------------------------------------------------------------===//
929 // InsertElementInst Class
930 //===----------------------------------------------------------------------===//
932 /// InsertElementInst - This instruction inserts a single (scalar)
933 /// element into a VectorType value
935 class InsertElementInst : public Instruction {
937 InsertElementInst(const InsertElementInst &IE);
939 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
940 const std::string &Name = "",Instruction *InsertBefore = 0);
941 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
942 const std::string &Name = "",Instruction *InsertBefore = 0);
943 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
944 const std::string &Name, BasicBlock *InsertAtEnd);
945 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
946 const std::string &Name, BasicBlock *InsertAtEnd);
948 /// isValidOperands - Return true if an insertelement instruction can be
949 /// formed with the specified operands.
950 static bool isValidOperands(const Value *Vec, const Value *NewElt,
953 virtual InsertElementInst *clone() const;
955 /// getType - Overload to return most specific vector type.
957 inline const VectorType *getType() const {
958 return reinterpret_cast<const VectorType*>(Instruction::getType());
961 /// Transparently provide more efficient getOperand methods.
962 Value *getOperand(unsigned i) const {
963 assert(i < 3 && "getOperand() out of range!");
966 void setOperand(unsigned i, Value *Val) {
967 assert(i < 3 && "setOperand() out of range!");
970 unsigned getNumOperands() const { return 3; }
972 // Methods for support type inquiry through isa, cast, and dyn_cast:
973 static inline bool classof(const InsertElementInst *) { return true; }
974 static inline bool classof(const Instruction *I) {
975 return I->getOpcode() == Instruction::InsertElement;
977 static inline bool classof(const Value *V) {
978 return isa<Instruction>(V) && classof(cast<Instruction>(V));
982 //===----------------------------------------------------------------------===//
983 // ShuffleVectorInst Class
984 //===----------------------------------------------------------------------===//
986 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
989 class ShuffleVectorInst : public Instruction {
991 ShuffleVectorInst(const ShuffleVectorInst &IE);
993 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
994 const std::string &Name = "", Instruction *InsertBefor = 0);
995 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
996 const std::string &Name, BasicBlock *InsertAtEnd);
998 /// isValidOperands - Return true if a shufflevector instruction can be
999 /// formed with the specified operands.
1000 static bool isValidOperands(const Value *V1, const Value *V2,
1003 virtual ShuffleVectorInst *clone() const;
1005 /// getType - Overload to return most specific vector type.
1007 inline const VectorType *getType() const {
1008 return reinterpret_cast<const VectorType*>(Instruction::getType());
1011 /// Transparently provide more efficient getOperand methods.
1012 Value *getOperand(unsigned i) const {
1013 assert(i < 3 && "getOperand() out of range!");
1016 void setOperand(unsigned i, Value *Val) {
1017 assert(i < 3 && "setOperand() out of range!");
1020 unsigned getNumOperands() const { return 3; }
1022 // Methods for support type inquiry through isa, cast, and dyn_cast:
1023 static inline bool classof(const ShuffleVectorInst *) { return true; }
1024 static inline bool classof(const Instruction *I) {
1025 return I->getOpcode() == Instruction::ShuffleVector;
1027 static inline bool classof(const Value *V) {
1028 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1033 //===----------------------------------------------------------------------===//
1035 //===----------------------------------------------------------------------===//
1037 // PHINode - The PHINode class is used to represent the magical mystical PHI
1038 // node, that can not exist in nature, but can be synthesized in a computer
1039 // scientist's overactive imagination.
1041 class PHINode : public Instruction {
1042 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1043 /// the number actually in use.
1044 unsigned ReservedSpace;
1045 PHINode(const PHINode &PN);
1047 explicit PHINode(const Type *Ty, const std::string &Name = "",
1048 Instruction *InsertBefore = 0)
1049 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1054 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1055 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1062 /// reserveOperandSpace - This method can be used to avoid repeated
1063 /// reallocation of PHI operand lists by reserving space for the correct
1064 /// number of operands before adding them. Unlike normal vector reserves,
1065 /// this method can also be used to trim the operand space.
1066 void reserveOperandSpace(unsigned NumValues) {
1067 resizeOperands(NumValues*2);
1070 virtual PHINode *clone() const;
1072 /// getNumIncomingValues - Return the number of incoming edges
1074 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1076 /// getIncomingValue - Return incoming value number x
1078 Value *getIncomingValue(unsigned i) const {
1079 assert(i*2 < getNumOperands() && "Invalid value number!");
1080 return getOperand(i*2);
1082 void setIncomingValue(unsigned i, Value *V) {
1083 assert(i*2 < getNumOperands() && "Invalid value number!");
1086 unsigned getOperandNumForIncomingValue(unsigned i) {
1090 /// getIncomingBlock - Return incoming basic block number x
1092 BasicBlock *getIncomingBlock(unsigned i) const {
1093 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1095 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1096 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1098 unsigned getOperandNumForIncomingBlock(unsigned i) {
1102 /// addIncoming - Add an incoming value to the end of the PHI list
1104 void addIncoming(Value *V, BasicBlock *BB) {
1105 assert(getType() == V->getType() &&
1106 "All operands to PHI node must be the same type as the PHI node!");
1107 unsigned OpNo = NumOperands;
1108 if (OpNo+2 > ReservedSpace)
1109 resizeOperands(0); // Get more space!
1110 // Initialize some new operands.
1111 NumOperands = OpNo+2;
1112 OperandList[OpNo].init(V, this);
1113 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1116 /// removeIncomingValue - Remove an incoming value. This is useful if a
1117 /// predecessor basic block is deleted. The value removed is returned.
1119 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1120 /// is true), the PHI node is destroyed and any uses of it are replaced with
1121 /// dummy values. The only time there should be zero incoming values to a PHI
1122 /// node is when the block is dead, so this strategy is sound.
1124 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1126 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1127 int Idx = getBasicBlockIndex(BB);
1128 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1129 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1132 /// getBasicBlockIndex - Return the first index of the specified basic
1133 /// block in the value list for this PHI. Returns -1 if no instance.
1135 int getBasicBlockIndex(const BasicBlock *BB) const {
1136 Use *OL = OperandList;
1137 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1138 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1142 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1143 return getIncomingValue(getBasicBlockIndex(BB));
1146 /// hasConstantValue - If the specified PHI node always merges together the
1147 /// same value, return the value, otherwise return null.
1149 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1151 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1152 static inline bool classof(const PHINode *) { return true; }
1153 static inline bool classof(const Instruction *I) {
1154 return I->getOpcode() == Instruction::PHI;
1156 static inline bool classof(const Value *V) {
1157 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1160 void resizeOperands(unsigned NumOperands);
1163 //===----------------------------------------------------------------------===//
1165 //===----------------------------------------------------------------------===//
1167 //===---------------------------------------------------------------------------
1168 /// ReturnInst - Return a value (possibly void), from a function. Execution
1169 /// does not continue in this function any longer.
1171 class ReturnInst : public TerminatorInst {
1172 Use RetVal; // Return Value: null if 'void'.
1173 ReturnInst(const ReturnInst &RI);
1174 void init(Value *RetVal);
1177 // ReturnInst constructors:
1178 // ReturnInst() - 'ret void' instruction
1179 // ReturnInst( null) - 'ret void' instruction
1180 // ReturnInst(Value* X) - 'ret X' instruction
1181 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1182 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1183 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1184 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1186 // NOTE: If the Value* passed is of type void then the constructor behaves as
1187 // if it was passed NULL.
1188 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1189 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1190 explicit ReturnInst(BasicBlock *InsertAtEnd);
1192 virtual ReturnInst *clone() const;
1194 // Transparently provide more efficient getOperand methods.
1195 Value *getOperand(unsigned i) const {
1196 assert(i < getNumOperands() && "getOperand() out of range!");
1199 void setOperand(unsigned i, Value *Val) {
1200 assert(i < getNumOperands() && "setOperand() out of range!");
1204 Value *getReturnValue() const { return RetVal; }
1206 unsigned getNumSuccessors() const { return 0; }
1208 // Methods for support type inquiry through isa, cast, and dyn_cast:
1209 static inline bool classof(const ReturnInst *) { return true; }
1210 static inline bool classof(const Instruction *I) {
1211 return (I->getOpcode() == Instruction::Ret);
1213 static inline bool classof(const Value *V) {
1214 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1217 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1218 virtual unsigned getNumSuccessorsV() const;
1219 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1222 //===----------------------------------------------------------------------===//
1224 //===----------------------------------------------------------------------===//
1226 //===---------------------------------------------------------------------------
1227 /// BranchInst - Conditional or Unconditional Branch instruction.
1229 class BranchInst : public TerminatorInst {
1230 /// Ops list - Branches are strange. The operands are ordered:
1231 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1232 /// they don't have to check for cond/uncond branchness.
1234 BranchInst(const BranchInst &BI);
1237 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1238 // BranchInst(BB *B) - 'br B'
1239 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1240 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1241 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1242 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1243 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1244 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1245 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1246 Instruction *InsertBefore = 0);
1247 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1248 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1249 BasicBlock *InsertAtEnd);
1251 /// Transparently provide more efficient getOperand methods.
1252 Value *getOperand(unsigned i) const {
1253 assert(i < getNumOperands() && "getOperand() out of range!");
1256 void setOperand(unsigned i, Value *Val) {
1257 assert(i < getNumOperands() && "setOperand() out of range!");
1261 virtual BranchInst *clone() const;
1263 inline bool isUnconditional() const { return getNumOperands() == 1; }
1264 inline bool isConditional() const { return getNumOperands() == 3; }
1266 inline Value *getCondition() const {
1267 assert(isConditional() && "Cannot get condition of an uncond branch!");
1268 return getOperand(2);
1271 void setCondition(Value *V) {
1272 assert(isConditional() && "Cannot set condition of unconditional branch!");
1276 // setUnconditionalDest - Change the current branch to an unconditional branch
1277 // targeting the specified block.
1278 // FIXME: Eliminate this ugly method.
1279 void setUnconditionalDest(BasicBlock *Dest) {
1280 if (isConditional()) { // Convert this to an uncond branch.
1285 setOperand(0, reinterpret_cast<Value*>(Dest));
1288 unsigned getNumSuccessors() const { return 1+isConditional(); }
1290 BasicBlock *getSuccessor(unsigned i) const {
1291 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1292 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1293 cast<BasicBlock>(getOperand(1));
1296 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1297 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1298 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1301 // Methods for support type inquiry through isa, cast, and dyn_cast:
1302 static inline bool classof(const BranchInst *) { return true; }
1303 static inline bool classof(const Instruction *I) {
1304 return (I->getOpcode() == Instruction::Br);
1306 static inline bool classof(const Value *V) {
1307 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1310 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1311 virtual unsigned getNumSuccessorsV() const;
1312 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1315 //===----------------------------------------------------------------------===//
1317 //===----------------------------------------------------------------------===//
1319 //===---------------------------------------------------------------------------
1320 /// SwitchInst - Multiway switch
1322 class SwitchInst : public TerminatorInst {
1323 unsigned ReservedSpace;
1324 // Operand[0] = Value to switch on
1325 // Operand[1] = Default basic block destination
1326 // Operand[2n ] = Value to match
1327 // Operand[2n+1] = BasicBlock to go to on match
1328 SwitchInst(const SwitchInst &RI);
1329 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1330 void resizeOperands(unsigned No);
1332 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1333 /// switch on and a default destination. The number of additional cases can
1334 /// be specified here to make memory allocation more efficient. This
1335 /// constructor can also autoinsert before another instruction.
1336 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1337 Instruction *InsertBefore = 0);
1339 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1340 /// switch on and a default destination. The number of additional cases can
1341 /// be specified here to make memory allocation more efficient. This
1342 /// constructor also autoinserts at the end of the specified BasicBlock.
1343 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1344 BasicBlock *InsertAtEnd);
1348 // Accessor Methods for Switch stmt
1349 inline Value *getCondition() const { return getOperand(0); }
1350 void setCondition(Value *V) { setOperand(0, V); }
1352 inline BasicBlock *getDefaultDest() const {
1353 return cast<BasicBlock>(getOperand(1));
1356 /// getNumCases - return the number of 'cases' in this switch instruction.
1357 /// Note that case #0 is always the default case.
1358 unsigned getNumCases() const {
1359 return getNumOperands()/2;
1362 /// getCaseValue - Return the specified case value. Note that case #0, the
1363 /// default destination, does not have a case value.
1364 ConstantInt *getCaseValue(unsigned i) {
1365 assert(i && i < getNumCases() && "Illegal case value to get!");
1366 return getSuccessorValue(i);
1369 /// getCaseValue - Return the specified case value. Note that case #0, the
1370 /// default destination, does not have a case value.
1371 const ConstantInt *getCaseValue(unsigned i) const {
1372 assert(i && i < getNumCases() && "Illegal case value to get!");
1373 return getSuccessorValue(i);
1376 /// findCaseValue - Search all of the case values for the specified constant.
1377 /// If it is explicitly handled, return the case number of it, otherwise
1378 /// return 0 to indicate that it is handled by the default handler.
1379 unsigned findCaseValue(const ConstantInt *C) const {
1380 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1381 if (getCaseValue(i) == C)
1386 /// findCaseDest - Finds the unique case value for a given successor. Returns
1387 /// null if the successor is not found, not unique, or is the default case.
1388 ConstantInt *findCaseDest(BasicBlock *BB) {
1389 if (BB == getDefaultDest()) return NULL;
1391 ConstantInt *CI = NULL;
1392 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1393 if (getSuccessor(i) == BB) {
1394 if (CI) return NULL; // Multiple cases lead to BB.
1395 else CI = getCaseValue(i);
1401 /// addCase - Add an entry to the switch instruction...
1403 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1405 /// removeCase - This method removes the specified successor from the switch
1406 /// instruction. Note that this cannot be used to remove the default
1407 /// destination (successor #0).
1409 void removeCase(unsigned idx);
1411 virtual SwitchInst *clone() const;
1413 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1414 BasicBlock *getSuccessor(unsigned idx) const {
1415 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1416 return cast<BasicBlock>(getOperand(idx*2+1));
1418 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1419 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1420 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1423 // getSuccessorValue - Return the value associated with the specified
1425 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1426 assert(idx < getNumSuccessors() && "Successor # out of range!");
1427 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1430 // Methods for support type inquiry through isa, cast, and dyn_cast:
1431 static inline bool classof(const SwitchInst *) { return true; }
1432 static inline bool classof(const Instruction *I) {
1433 return I->getOpcode() == Instruction::Switch;
1435 static inline bool classof(const Value *V) {
1436 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1439 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1440 virtual unsigned getNumSuccessorsV() const;
1441 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1444 //===----------------------------------------------------------------------===//
1446 //===----------------------------------------------------------------------===//
1448 //===---------------------------------------------------------------------------
1450 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1451 /// calling convention of the call.
1453 class InvokeInst : public TerminatorInst {
1454 ParamAttrsList *ParamAttrs;
1455 InvokeInst(const InvokeInst &BI);
1456 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1457 Value* const *Args, unsigned NumArgs);
1459 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1460 Value* const* Args, unsigned NumArgs, const std::string &Name = "",
1461 Instruction *InsertBefore = 0);
1462 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1463 Value* const* Args, unsigned NumArgs, const std::string &Name,
1464 BasicBlock *InsertAtEnd);
1467 virtual InvokeInst *clone() const;
1469 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1471 unsigned getCallingConv() const { return SubclassData; }
1472 void setCallingConv(unsigned CC) {
1476 /// Obtains a pointer to the ParamAttrsList object which holds the
1477 /// parameter attributes information, if any.
1478 /// @returns 0 if no attributes have been set.
1479 /// @brief Get the parameter attributes.
1480 ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
1482 /// Sets the parameter attributes for this InvokeInst. To construct a
1483 /// ParamAttrsList, see ParameterAttributes.h
1484 /// @brief Set the parameter attributes.
1485 void setParamAttrs(ParamAttrsList *attrs) { ParamAttrs = attrs; }
1487 /// getCalledFunction - Return the function called, or null if this is an
1488 /// indirect function invocation.
1490 Function *getCalledFunction() const {
1491 return dyn_cast<Function>(getOperand(0));
1494 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1495 inline Value *getCalledValue() const { return getOperand(0); }
1497 // get*Dest - Return the destination basic blocks...
1498 BasicBlock *getNormalDest() const {
1499 return cast<BasicBlock>(getOperand(1));
1501 BasicBlock *getUnwindDest() const {
1502 return cast<BasicBlock>(getOperand(2));
1504 void setNormalDest(BasicBlock *B) {
1505 setOperand(1, reinterpret_cast<Value*>(B));
1508 void setUnwindDest(BasicBlock *B) {
1509 setOperand(2, reinterpret_cast<Value*>(B));
1512 inline BasicBlock *getSuccessor(unsigned i) const {
1513 assert(i < 2 && "Successor # out of range for invoke!");
1514 return i == 0 ? getNormalDest() : getUnwindDest();
1517 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1518 assert(idx < 2 && "Successor # out of range for invoke!");
1519 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1522 unsigned getNumSuccessors() const { return 2; }
1524 // Methods for support type inquiry through isa, cast, and dyn_cast:
1525 static inline bool classof(const InvokeInst *) { return true; }
1526 static inline bool classof(const Instruction *I) {
1527 return (I->getOpcode() == Instruction::Invoke);
1529 static inline bool classof(const Value *V) {
1530 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1533 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1534 virtual unsigned getNumSuccessorsV() const;
1535 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1539 //===----------------------------------------------------------------------===//
1541 //===----------------------------------------------------------------------===//
1543 //===---------------------------------------------------------------------------
1544 /// UnwindInst - Immediately exit the current function, unwinding the stack
1545 /// until an invoke instruction is found.
1547 class UnwindInst : public TerminatorInst {
1549 explicit UnwindInst(Instruction *InsertBefore = 0);
1550 explicit UnwindInst(BasicBlock *InsertAtEnd);
1552 virtual UnwindInst *clone() const;
1554 unsigned getNumSuccessors() const { return 0; }
1556 // Methods for support type inquiry through isa, cast, and dyn_cast:
1557 static inline bool classof(const UnwindInst *) { return true; }
1558 static inline bool classof(const Instruction *I) {
1559 return I->getOpcode() == Instruction::Unwind;
1561 static inline bool classof(const Value *V) {
1562 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1565 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1566 virtual unsigned getNumSuccessorsV() const;
1567 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1570 //===----------------------------------------------------------------------===//
1571 // UnreachableInst Class
1572 //===----------------------------------------------------------------------===//
1574 //===---------------------------------------------------------------------------
1575 /// UnreachableInst - This function has undefined behavior. In particular, the
1576 /// presence of this instruction indicates some higher level knowledge that the
1577 /// end of the block cannot be reached.
1579 class UnreachableInst : public TerminatorInst {
1581 explicit UnreachableInst(Instruction *InsertBefore = 0);
1582 explicit UnreachableInst(BasicBlock *InsertAtEnd);
1584 virtual UnreachableInst *clone() const;
1586 unsigned getNumSuccessors() const { return 0; }
1588 // Methods for support type inquiry through isa, cast, and dyn_cast:
1589 static inline bool classof(const UnreachableInst *) { return true; }
1590 static inline bool classof(const Instruction *I) {
1591 return I->getOpcode() == Instruction::Unreachable;
1593 static inline bool classof(const Value *V) {
1594 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1597 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1598 virtual unsigned getNumSuccessorsV() const;
1599 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1602 //===----------------------------------------------------------------------===//
1604 //===----------------------------------------------------------------------===//
1606 /// @brief This class represents a truncation of integer types.
1607 class TruncInst : public CastInst {
1608 /// Private copy constructor
1609 TruncInst(const TruncInst &CI)
1610 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1613 /// @brief Constructor with insert-before-instruction semantics
1615 Value *S, ///< The value to be truncated
1616 const Type *Ty, ///< The (smaller) type to truncate to
1617 const std::string &Name = "", ///< A name for the new instruction
1618 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1621 /// @brief Constructor with insert-at-end-of-block semantics
1623 Value *S, ///< The value to be truncated
1624 const Type *Ty, ///< The (smaller) type to truncate to
1625 const std::string &Name, ///< A name for the new instruction
1626 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1629 /// @brief Clone an identical TruncInst
1630 virtual CastInst *clone() const;
1632 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1633 static inline bool classof(const TruncInst *) { return true; }
1634 static inline bool classof(const Instruction *I) {
1635 return I->getOpcode() == Trunc;
1637 static inline bool classof(const Value *V) {
1638 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1642 //===----------------------------------------------------------------------===//
1644 //===----------------------------------------------------------------------===//
1646 /// @brief This class represents zero extension of integer types.
1647 class ZExtInst : public CastInst {
1648 /// @brief Private copy constructor
1649 ZExtInst(const ZExtInst &CI)
1650 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1653 /// @brief Constructor with insert-before-instruction semantics
1655 Value *S, ///< The value to be zero extended
1656 const Type *Ty, ///< The type to zero extend to
1657 const std::string &Name = "", ///< A name for the new instruction
1658 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1661 /// @brief Constructor with insert-at-end semantics.
1663 Value *S, ///< The value to be zero extended
1664 const Type *Ty, ///< The type to zero extend to
1665 const std::string &Name, ///< A name for the new instruction
1666 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1669 /// @brief Clone an identical ZExtInst
1670 virtual CastInst *clone() const;
1672 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1673 static inline bool classof(const ZExtInst *) { return true; }
1674 static inline bool classof(const Instruction *I) {
1675 return I->getOpcode() == ZExt;
1677 static inline bool classof(const Value *V) {
1678 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1682 //===----------------------------------------------------------------------===//
1684 //===----------------------------------------------------------------------===//
1686 /// @brief This class represents a sign extension of integer types.
1687 class SExtInst : public CastInst {
1688 /// @brief Private copy constructor
1689 SExtInst(const SExtInst &CI)
1690 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1693 /// @brief Constructor with insert-before-instruction semantics
1695 Value *S, ///< The value to be sign extended
1696 const Type *Ty, ///< The type to sign extend to
1697 const std::string &Name = "", ///< A name for the new instruction
1698 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1701 /// @brief Constructor with insert-at-end-of-block semantics
1703 Value *S, ///< The value to be sign extended
1704 const Type *Ty, ///< The type to sign extend to
1705 const std::string &Name, ///< A name for the new instruction
1706 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1709 /// @brief Clone an identical SExtInst
1710 virtual CastInst *clone() const;
1712 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1713 static inline bool classof(const SExtInst *) { return true; }
1714 static inline bool classof(const Instruction *I) {
1715 return I->getOpcode() == SExt;
1717 static inline bool classof(const Value *V) {
1718 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1722 //===----------------------------------------------------------------------===//
1723 // FPTruncInst Class
1724 //===----------------------------------------------------------------------===//
1726 /// @brief This class represents a truncation of floating point types.
1727 class FPTruncInst : public CastInst {
1728 FPTruncInst(const FPTruncInst &CI)
1729 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1732 /// @brief Constructor with insert-before-instruction semantics
1734 Value *S, ///< The value to be truncated
1735 const Type *Ty, ///< The type to truncate to
1736 const std::string &Name = "", ///< A name for the new instruction
1737 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1740 /// @brief Constructor with insert-before-instruction semantics
1742 Value *S, ///< The value to be truncated
1743 const Type *Ty, ///< The type to truncate to
1744 const std::string &Name, ///< A name for the new instruction
1745 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1748 /// @brief Clone an identical FPTruncInst
1749 virtual CastInst *clone() const;
1751 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1752 static inline bool classof(const FPTruncInst *) { return true; }
1753 static inline bool classof(const Instruction *I) {
1754 return I->getOpcode() == FPTrunc;
1756 static inline bool classof(const Value *V) {
1757 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1761 //===----------------------------------------------------------------------===//
1763 //===----------------------------------------------------------------------===//
1765 /// @brief This class represents an extension of floating point types.
1766 class FPExtInst : public CastInst {
1767 FPExtInst(const FPExtInst &CI)
1768 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1771 /// @brief Constructor with insert-before-instruction semantics
1773 Value *S, ///< The value to be extended
1774 const Type *Ty, ///< The type to extend to
1775 const std::string &Name = "", ///< A name for the new instruction
1776 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1779 /// @brief Constructor with insert-at-end-of-block semantics
1781 Value *S, ///< The value to be extended
1782 const Type *Ty, ///< The type to extend to
1783 const std::string &Name, ///< A name for the new instruction
1784 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1787 /// @brief Clone an identical FPExtInst
1788 virtual CastInst *clone() const;
1790 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1791 static inline bool classof(const FPExtInst *) { return true; }
1792 static inline bool classof(const Instruction *I) {
1793 return I->getOpcode() == FPExt;
1795 static inline bool classof(const Value *V) {
1796 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1800 //===----------------------------------------------------------------------===//
1802 //===----------------------------------------------------------------------===//
1804 /// @brief This class represents a cast unsigned integer to floating point.
1805 class UIToFPInst : public CastInst {
1806 UIToFPInst(const UIToFPInst &CI)
1807 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1810 /// @brief Constructor with insert-before-instruction semantics
1812 Value *S, ///< The value to be converted
1813 const Type *Ty, ///< The type to convert to
1814 const std::string &Name = "", ///< A name for the new instruction
1815 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1818 /// @brief Constructor with insert-at-end-of-block semantics
1820 Value *S, ///< The value to be converted
1821 const Type *Ty, ///< The type to convert to
1822 const std::string &Name, ///< A name for the new instruction
1823 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1826 /// @brief Clone an identical UIToFPInst
1827 virtual CastInst *clone() const;
1829 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1830 static inline bool classof(const UIToFPInst *) { return true; }
1831 static inline bool classof(const Instruction *I) {
1832 return I->getOpcode() == UIToFP;
1834 static inline bool classof(const Value *V) {
1835 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1839 //===----------------------------------------------------------------------===//
1841 //===----------------------------------------------------------------------===//
1843 /// @brief This class represents a cast from signed integer to floating point.
1844 class SIToFPInst : public CastInst {
1845 SIToFPInst(const SIToFPInst &CI)
1846 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1849 /// @brief Constructor with insert-before-instruction semantics
1851 Value *S, ///< The value to be converted
1852 const Type *Ty, ///< The type to convert to
1853 const std::string &Name = "", ///< A name for the new instruction
1854 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1857 /// @brief Constructor with insert-at-end-of-block semantics
1859 Value *S, ///< The value to be converted
1860 const Type *Ty, ///< The type to convert to
1861 const std::string &Name, ///< A name for the new instruction
1862 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1865 /// @brief Clone an identical SIToFPInst
1866 virtual CastInst *clone() const;
1868 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1869 static inline bool classof(const SIToFPInst *) { return true; }
1870 static inline bool classof(const Instruction *I) {
1871 return I->getOpcode() == SIToFP;
1873 static inline bool classof(const Value *V) {
1874 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1878 //===----------------------------------------------------------------------===//
1880 //===----------------------------------------------------------------------===//
1882 /// @brief This class represents a cast from floating point to unsigned integer
1883 class FPToUIInst : public CastInst {
1884 FPToUIInst(const FPToUIInst &CI)
1885 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1888 /// @brief Constructor with insert-before-instruction semantics
1890 Value *S, ///< The value to be converted
1891 const Type *Ty, ///< The type to convert to
1892 const std::string &Name = "", ///< A name for the new instruction
1893 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1896 /// @brief Constructor with insert-at-end-of-block semantics
1898 Value *S, ///< The value to be converted
1899 const Type *Ty, ///< The type to convert to
1900 const std::string &Name, ///< A name for the new instruction
1901 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
1904 /// @brief Clone an identical FPToUIInst
1905 virtual CastInst *clone() const;
1907 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1908 static inline bool classof(const FPToUIInst *) { return true; }
1909 static inline bool classof(const Instruction *I) {
1910 return I->getOpcode() == FPToUI;
1912 static inline bool classof(const Value *V) {
1913 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1917 //===----------------------------------------------------------------------===//
1919 //===----------------------------------------------------------------------===//
1921 /// @brief This class represents a cast from floating point to signed integer.
1922 class FPToSIInst : public CastInst {
1923 FPToSIInst(const FPToSIInst &CI)
1924 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
1927 /// @brief Constructor with insert-before-instruction semantics
1929 Value *S, ///< The value to be converted
1930 const Type *Ty, ///< The type to convert to
1931 const std::string &Name = "", ///< A name for the new instruction
1932 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1935 /// @brief Constructor with insert-at-end-of-block semantics
1937 Value *S, ///< The value to be converted
1938 const Type *Ty, ///< The type to convert to
1939 const std::string &Name, ///< A name for the new instruction
1940 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1943 /// @brief Clone an identical FPToSIInst
1944 virtual CastInst *clone() const;
1946 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1947 static inline bool classof(const FPToSIInst *) { return true; }
1948 static inline bool classof(const Instruction *I) {
1949 return I->getOpcode() == FPToSI;
1951 static inline bool classof(const Value *V) {
1952 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1956 //===----------------------------------------------------------------------===//
1957 // IntToPtrInst Class
1958 //===----------------------------------------------------------------------===//
1960 /// @brief This class represents a cast from an integer to a pointer.
1961 class IntToPtrInst : public CastInst {
1962 IntToPtrInst(const IntToPtrInst &CI)
1963 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
1966 /// @brief Constructor with insert-before-instruction semantics
1968 Value *S, ///< The value to be converted
1969 const Type *Ty, ///< The type to convert to
1970 const std::string &Name = "", ///< A name for the new instruction
1971 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1974 /// @brief Constructor with insert-at-end-of-block semantics
1976 Value *S, ///< The value to be converted
1977 const Type *Ty, ///< The type to convert to
1978 const std::string &Name, ///< A name for the new instruction
1979 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1982 /// @brief Clone an identical IntToPtrInst
1983 virtual CastInst *clone() const;
1985 // Methods for support type inquiry through isa, cast, and dyn_cast:
1986 static inline bool classof(const IntToPtrInst *) { return true; }
1987 static inline bool classof(const Instruction *I) {
1988 return I->getOpcode() == IntToPtr;
1990 static inline bool classof(const Value *V) {
1991 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1995 //===----------------------------------------------------------------------===//
1996 // PtrToIntInst Class
1997 //===----------------------------------------------------------------------===//
1999 /// @brief This class represents a cast from a pointer to an integer
2000 class PtrToIntInst : public CastInst {
2001 PtrToIntInst(const PtrToIntInst &CI)
2002 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2005 /// @brief Constructor with insert-before-instruction semantics
2007 Value *S, ///< The value to be converted
2008 const Type *Ty, ///< The type to convert to
2009 const std::string &Name = "", ///< A name for the new instruction
2010 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2013 /// @brief Constructor with insert-at-end-of-block semantics
2015 Value *S, ///< The value to be converted
2016 const Type *Ty, ///< The type to convert to
2017 const std::string &Name, ///< A name for the new instruction
2018 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2021 /// @brief Clone an identical PtrToIntInst
2022 virtual CastInst *clone() const;
2024 // Methods for support type inquiry through isa, cast, and dyn_cast:
2025 static inline bool classof(const PtrToIntInst *) { return true; }
2026 static inline bool classof(const Instruction *I) {
2027 return I->getOpcode() == PtrToInt;
2029 static inline bool classof(const Value *V) {
2030 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2034 //===----------------------------------------------------------------------===//
2035 // BitCastInst Class
2036 //===----------------------------------------------------------------------===//
2038 /// @brief This class represents a no-op cast from one type to another.
2039 class BitCastInst : public CastInst {
2040 BitCastInst(const BitCastInst &CI)
2041 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2044 /// @brief Constructor with insert-before-instruction semantics
2046 Value *S, ///< The value to be casted
2047 const Type *Ty, ///< The type to casted to
2048 const std::string &Name = "", ///< A name for the new instruction
2049 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2052 /// @brief Constructor with insert-at-end-of-block semantics
2054 Value *S, ///< The value to be casted
2055 const Type *Ty, ///< The type to casted to
2056 const std::string &Name, ///< A name for the new instruction
2057 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2060 /// @brief Clone an identical BitCastInst
2061 virtual CastInst *clone() const;
2063 // Methods for support type inquiry through isa, cast, and dyn_cast:
2064 static inline bool classof(const BitCastInst *) { return true; }
2065 static inline bool classof(const Instruction *I) {
2066 return I->getOpcode() == BitCast;
2068 static inline bool classof(const Value *V) {
2069 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2073 } // End llvm namespace