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 // Methods for support type inquiry through isa, cast, and dyn_cast:
413 static inline bool classof(const GetElementPtrInst *) { return true; }
414 static inline bool classof(const Instruction *I) {
415 return (I->getOpcode() == Instruction::GetElementPtr);
417 static inline bool classof(const Value *V) {
418 return isa<Instruction>(V) && classof(cast<Instruction>(V));
422 //===----------------------------------------------------------------------===//
424 //===----------------------------------------------------------------------===//
426 /// This instruction compares its operands according to the predicate given
427 /// to the constructor. It only operates on integers, pointers, or packed
428 /// vectors of integrals. The two operands must be the same type.
429 /// @brief Represent an integer comparison operator.
430 class ICmpInst: public CmpInst {
432 /// This enumeration lists the possible predicates for the ICmpInst. The
433 /// values in the range 0-31 are reserved for FCmpInst while values in the
434 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
435 /// predicate values are not overlapping between the classes.
437 ICMP_EQ = 32, ///< equal
438 ICMP_NE = 33, ///< not equal
439 ICMP_UGT = 34, ///< unsigned greater than
440 ICMP_UGE = 35, ///< unsigned greater or equal
441 ICMP_ULT = 36, ///< unsigned less than
442 ICMP_ULE = 37, ///< unsigned less or equal
443 ICMP_SGT = 38, ///< signed greater than
444 ICMP_SGE = 39, ///< signed greater or equal
445 ICMP_SLT = 40, ///< signed less than
446 ICMP_SLE = 41, ///< signed less or equal
447 FIRST_ICMP_PREDICATE = ICMP_EQ,
448 LAST_ICMP_PREDICATE = ICMP_SLE,
449 BAD_ICMP_PREDICATE = ICMP_SLE + 1
452 /// @brief Constructor with insert-before-instruction semantics.
454 Predicate pred, ///< The predicate to use for the comparison
455 Value *LHS, ///< The left-hand-side of the expression
456 Value *RHS, ///< The right-hand-side of the expression
457 const std::string &Name = "", ///< Name of the instruction
458 Instruction *InsertBefore = 0 ///< Where to insert
459 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
462 /// @brief Constructor with insert-at-block-end semantics.
464 Predicate pred, ///< The predicate to use for the comparison
465 Value *LHS, ///< The left-hand-side of the expression
466 Value *RHS, ///< The right-hand-side of the expression
467 const std::string &Name, ///< Name of the instruction
468 BasicBlock *InsertAtEnd ///< Block to insert into.
469 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
472 /// @brief Return the predicate for this instruction.
473 Predicate getPredicate() const { return Predicate(SubclassData); }
475 /// @brief Set the predicate for this instruction to the specified value.
476 void setPredicate(Predicate P) { SubclassData = P; }
478 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
479 /// @returns the inverse predicate for the instruction's current predicate.
480 /// @brief Return the inverse of the instruction's predicate.
481 Predicate getInversePredicate() const {
482 return getInversePredicate(getPredicate());
485 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
486 /// @returns the inverse predicate for predicate provided in \p pred.
487 /// @brief Return the inverse of a given predicate
488 static Predicate getInversePredicate(Predicate pred);
490 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
491 /// @returns the predicate that would be the result of exchanging the two
492 /// operands of the ICmpInst instruction without changing the result
494 /// @brief Return the predicate as if the operands were swapped
495 Predicate getSwappedPredicate() const {
496 return getSwappedPredicate(getPredicate());
499 /// This is a static version that you can use without an instruction
501 /// @brief Return the predicate as if the operands were swapped.
502 static Predicate getSwappedPredicate(Predicate pred);
504 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
505 /// @returns the predicate that would be the result if the operand were
506 /// regarded as signed.
507 /// @brief Return the signed version of the predicate
508 Predicate getSignedPredicate() const {
509 return getSignedPredicate(getPredicate());
512 /// This is a static version that you can use without an instruction.
513 /// @brief Return the signed version of the predicate.
514 static Predicate getSignedPredicate(Predicate pred);
516 /// This also tests for commutativity. If isEquality() returns true then
517 /// the predicate is also commutative.
518 /// @returns true if the predicate of this instruction is EQ or NE.
519 /// @brief Determine if this is an equality predicate.
520 bool isEquality() const {
521 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
524 /// @returns true if the predicate of this ICmpInst is commutative
525 /// @brief Determine if this relation is commutative.
526 bool isCommutative() const { return isEquality(); }
528 /// @returns true if the predicate is relational (not EQ or NE).
529 /// @brief Determine if this a relational predicate.
530 bool isRelational() const {
531 return !isEquality();
534 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
535 /// @brief Determine if this instruction's predicate is signed.
536 bool isSignedPredicate() { return isSignedPredicate(getPredicate()); }
538 /// @returns true if the predicate provided is signed, false otherwise
539 /// @brief Determine if the predicate is signed.
540 static bool isSignedPredicate(Predicate pred);
542 /// Initialize a set of values that all satisfy the predicate with C.
543 /// @brief Make a ConstantRange for a relation with a constant value.
544 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
546 /// Exchange the two operands to this instruction in such a way that it does
547 /// not modify the semantics of the instruction. The predicate value may be
548 /// changed to retain the same result if the predicate is order dependent
550 /// @brief Swap operands and adjust predicate.
551 void swapOperands() {
552 SubclassData = getSwappedPredicate();
553 std::swap(Ops[0], Ops[1]);
556 // Methods for support type inquiry through isa, cast, and dyn_cast:
557 static inline bool classof(const ICmpInst *) { return true; }
558 static inline bool classof(const Instruction *I) {
559 return I->getOpcode() == Instruction::ICmp;
561 static inline bool classof(const Value *V) {
562 return isa<Instruction>(V) && classof(cast<Instruction>(V));
566 //===----------------------------------------------------------------------===//
568 //===----------------------------------------------------------------------===//
570 /// This instruction compares its operands according to the predicate given
571 /// to the constructor. It only operates on floating point values or packed
572 /// vectors of floating point values. The operands must be identical types.
573 /// @brief Represents a floating point comparison operator.
574 class FCmpInst: public CmpInst {
576 /// This enumeration lists the possible predicates for the FCmpInst. Values
577 /// in the range 0-31 are reserved for FCmpInst.
579 // Opcode U L G E Intuitive operation
580 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
581 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
582 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
583 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
584 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
585 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
586 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
587 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
588 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
589 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
590 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
591 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
592 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
593 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
594 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
595 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
596 FIRST_FCMP_PREDICATE = FCMP_FALSE,
597 LAST_FCMP_PREDICATE = FCMP_TRUE,
598 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
601 /// @brief Constructor with insert-before-instruction semantics.
603 Predicate pred, ///< The predicate to use for the comparison
604 Value *LHS, ///< The left-hand-side of the expression
605 Value *RHS, ///< The right-hand-side of the expression
606 const std::string &Name = "", ///< Name of the instruction
607 Instruction *InsertBefore = 0 ///< Where to insert
608 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
611 /// @brief Constructor with insert-at-block-end semantics.
613 Predicate pred, ///< The predicate to use for the comparison
614 Value *LHS, ///< The left-hand-side of the expression
615 Value *RHS, ///< The right-hand-side of the expression
616 const std::string &Name, ///< Name of the instruction
617 BasicBlock *InsertAtEnd ///< Block to insert into.
618 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
621 /// @brief Return the predicate for this instruction.
622 Predicate getPredicate() const { return Predicate(SubclassData); }
624 /// @brief Set the predicate for this instruction to the specified value.
625 void setPredicate(Predicate P) { SubclassData = P; }
627 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
628 /// @returns the inverse predicate for the instructions current predicate.
629 /// @brief Return the inverse of the predicate
630 Predicate getInversePredicate() const {
631 return getInversePredicate(getPredicate());
634 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
635 /// @returns the inverse predicate for \p pred.
636 /// @brief Return the inverse of a given predicate
637 static Predicate getInversePredicate(Predicate pred);
639 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
640 /// @returns the predicate that would be the result of exchanging the two
641 /// operands of the ICmpInst instruction without changing the result
643 /// @brief Return the predicate as if the operands were swapped
644 Predicate getSwappedPredicate() const {
645 return getSwappedPredicate(getPredicate());
648 /// This is a static version that you can use without an instruction
650 /// @brief Return the predicate as if the operands were swapped.
651 static Predicate getSwappedPredicate(Predicate Opcode);
653 /// This also tests for commutativity. If isEquality() returns true then
654 /// the predicate is also commutative. Only the equality predicates are
656 /// @returns true if the predicate of this instruction is EQ or NE.
657 /// @brief Determine if this is an equality predicate.
658 bool isEquality() const {
659 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
660 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
662 bool isCommutative() const { return isEquality(); }
664 /// @returns true if the predicate is relational (not EQ or NE).
665 /// @brief Determine if this a relational predicate.
666 bool isRelational() const { return !isEquality(); }
668 /// Exchange the two operands to this instruction in such a way that it does
669 /// not modify the semantics of the instruction. The predicate value may be
670 /// changed to retain the same result if the predicate is order dependent
672 /// @brief Swap operands and adjust predicate.
673 void swapOperands() {
674 SubclassData = getSwappedPredicate();
675 std::swap(Ops[0], Ops[1]);
678 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
679 static inline bool classof(const FCmpInst *) { return true; }
680 static inline bool classof(const Instruction *I) {
681 return I->getOpcode() == Instruction::FCmp;
683 static inline bool classof(const Value *V) {
684 return isa<Instruction>(V) && classof(cast<Instruction>(V));
688 //===----------------------------------------------------------------------===//
690 //===----------------------------------------------------------------------===//
692 /// CallInst - This class represents a function call, abstracting a target
693 /// machine's calling convention. This class uses low bit of the SubClassData
694 /// field to indicate whether or not this is a tail call. The rest of the bits
695 /// hold the calling convention of the call.
697 class CallInst : public Instruction {
698 ParamAttrsList *ParamAttrs; ///< parameter attributes for call
699 CallInst(const CallInst &CI);
700 void init(Value *Func, Value* const *Params, unsigned NumParams);
701 void init(Value *Func, Value *Actual1, Value *Actual2);
702 void init(Value *Func, Value *Actual);
703 void init(Value *Func);
706 CallInst(Value *F, Value* const *Args, unsigned NumArgs,
707 const std::string &Name = "", Instruction *InsertBefore = 0);
708 CallInst(Value *F, Value *const *Args, unsigned NumArgs,
709 const std::string &Name, BasicBlock *InsertAtEnd);
711 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
712 // actuals, respectively.
713 CallInst(Value *F, Value *Actual1, Value *Actual2,
714 const std::string& Name = "", Instruction *InsertBefore = 0);
715 CallInst(Value *F, Value *Actual1, Value *Actual2,
716 const std::string& Name, BasicBlock *InsertAtEnd);
717 CallInst(Value *F, Value *Actual, const std::string& Name = "",
718 Instruction *InsertBefore = 0);
719 CallInst(Value *F, Value *Actual, const std::string& Name,
720 BasicBlock *InsertAtEnd);
721 explicit CallInst(Value *F, const std::string &Name = "",
722 Instruction *InsertBefore = 0);
723 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
726 virtual CallInst *clone() const;
728 bool isTailCall() const { return SubclassData & 1; }
729 void setTailCall(bool isTailCall = true) {
730 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
733 /// getCallingConv/setCallingConv - Get or set the calling convention of this
735 unsigned getCallingConv() const { return SubclassData >> 1; }
736 void setCallingConv(unsigned CC) {
737 SubclassData = (SubclassData & 1) | (CC << 1);
740 /// Obtains a pointer to the ParamAttrsList object which holds the
741 /// parameter attributes information, if any.
742 /// @returns 0 if no attributes have been set.
743 /// @brief Get the parameter attributes.
744 ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
746 /// Sets the parameter attributes for this CallInst. To construct a
747 /// ParamAttrsList, see ParameterAttributes.h
748 /// @brief Set the parameter attributes.
749 void setParamAttrs(ParamAttrsList *attrs) { ParamAttrs = attrs; }
751 /// getCalledFunction - Return the function being called by this instruction
752 /// if it is a direct call. If it is a call through a function pointer,
754 Function *getCalledFunction() const {
755 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
758 /// getCalledValue - Get a pointer to the function that is invoked by this
760 inline const Value *getCalledValue() const { return getOperand(0); }
761 inline Value *getCalledValue() { return getOperand(0); }
763 // Methods for support type inquiry through isa, cast, and dyn_cast:
764 static inline bool classof(const CallInst *) { return true; }
765 static inline bool classof(const Instruction *I) {
766 return I->getOpcode() == Instruction::Call;
768 static inline bool classof(const Value *V) {
769 return isa<Instruction>(V) && classof(cast<Instruction>(V));
773 //===----------------------------------------------------------------------===//
775 //===----------------------------------------------------------------------===//
777 /// SelectInst - This class represents the LLVM 'select' instruction.
779 class SelectInst : public Instruction {
782 void init(Value *C, Value *S1, Value *S2) {
783 Ops[0].init(C, this);
784 Ops[1].init(S1, this);
785 Ops[2].init(S2, this);
788 SelectInst(const SelectInst &SI)
789 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
790 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
793 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
794 Instruction *InsertBefore = 0)
795 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
799 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
800 BasicBlock *InsertAtEnd)
801 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
806 Value *getCondition() const { return Ops[0]; }
807 Value *getTrueValue() const { return Ops[1]; }
808 Value *getFalseValue() const { return Ops[2]; }
810 /// Transparently provide more efficient getOperand methods.
811 Value *getOperand(unsigned i) const {
812 assert(i < 3 && "getOperand() out of range!");
815 void setOperand(unsigned i, Value *Val) {
816 assert(i < 3 && "setOperand() out of range!");
819 unsigned getNumOperands() const { return 3; }
821 OtherOps getOpcode() const {
822 return static_cast<OtherOps>(Instruction::getOpcode());
825 virtual SelectInst *clone() const;
827 // Methods for support type inquiry through isa, cast, and dyn_cast:
828 static inline bool classof(const SelectInst *) { return true; }
829 static inline bool classof(const Instruction *I) {
830 return I->getOpcode() == Instruction::Select;
832 static inline bool classof(const Value *V) {
833 return isa<Instruction>(V) && classof(cast<Instruction>(V));
837 //===----------------------------------------------------------------------===//
839 //===----------------------------------------------------------------------===//
841 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
842 /// an argument of the specified type given a va_list and increments that list
844 class VAArgInst : public UnaryInstruction {
845 VAArgInst(const VAArgInst &VAA)
846 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
848 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
849 Instruction *InsertBefore = 0)
850 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
853 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
854 BasicBlock *InsertAtEnd)
855 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
859 virtual VAArgInst *clone() const;
861 // Methods for support type inquiry through isa, cast, and dyn_cast:
862 static inline bool classof(const VAArgInst *) { return true; }
863 static inline bool classof(const Instruction *I) {
864 return I->getOpcode() == VAArg;
866 static inline bool classof(const Value *V) {
867 return isa<Instruction>(V) && classof(cast<Instruction>(V));
871 //===----------------------------------------------------------------------===//
872 // ExtractElementInst Class
873 //===----------------------------------------------------------------------===//
875 /// ExtractElementInst - This instruction extracts a single (scalar)
876 /// element from a VectorType value
878 class ExtractElementInst : public Instruction {
880 ExtractElementInst(const ExtractElementInst &EE) :
881 Instruction(EE.getType(), ExtractElement, Ops, 2) {
882 Ops[0].init(EE.Ops[0], this);
883 Ops[1].init(EE.Ops[1], this);
887 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
888 Instruction *InsertBefore = 0);
889 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
890 Instruction *InsertBefore = 0);
891 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
892 BasicBlock *InsertAtEnd);
893 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
894 BasicBlock *InsertAtEnd);
896 /// isValidOperands - Return true if an extractelement instruction can be
897 /// formed with the specified operands.
898 static bool isValidOperands(const Value *Vec, const Value *Idx);
900 virtual ExtractElementInst *clone() const;
902 /// Transparently provide more efficient getOperand methods.
903 Value *getOperand(unsigned i) const {
904 assert(i < 2 && "getOperand() out of range!");
907 void setOperand(unsigned i, Value *Val) {
908 assert(i < 2 && "setOperand() out of range!");
911 unsigned getNumOperands() const { return 2; }
913 // Methods for support type inquiry through isa, cast, and dyn_cast:
914 static inline bool classof(const ExtractElementInst *) { return true; }
915 static inline bool classof(const Instruction *I) {
916 return I->getOpcode() == Instruction::ExtractElement;
918 static inline bool classof(const Value *V) {
919 return isa<Instruction>(V) && classof(cast<Instruction>(V));
923 //===----------------------------------------------------------------------===//
924 // InsertElementInst Class
925 //===----------------------------------------------------------------------===//
927 /// InsertElementInst - This instruction inserts a single (scalar)
928 /// element into a VectorType value
930 class InsertElementInst : public Instruction {
932 InsertElementInst(const InsertElementInst &IE);
934 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
935 const std::string &Name = "",Instruction *InsertBefore = 0);
936 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
937 const std::string &Name = "",Instruction *InsertBefore = 0);
938 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
939 const std::string &Name, BasicBlock *InsertAtEnd);
940 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
941 const std::string &Name, BasicBlock *InsertAtEnd);
943 /// isValidOperands - Return true if an insertelement instruction can be
944 /// formed with the specified operands.
945 static bool isValidOperands(const Value *Vec, const Value *NewElt,
948 virtual InsertElementInst *clone() const;
950 /// getType - Overload to return most specific vector type.
952 inline const VectorType *getType() const {
953 return reinterpret_cast<const VectorType*>(Instruction::getType());
956 /// Transparently provide more efficient getOperand methods.
957 Value *getOperand(unsigned i) const {
958 assert(i < 3 && "getOperand() out of range!");
961 void setOperand(unsigned i, Value *Val) {
962 assert(i < 3 && "setOperand() out of range!");
965 unsigned getNumOperands() const { return 3; }
967 // Methods for support type inquiry through isa, cast, and dyn_cast:
968 static inline bool classof(const InsertElementInst *) { return true; }
969 static inline bool classof(const Instruction *I) {
970 return I->getOpcode() == Instruction::InsertElement;
972 static inline bool classof(const Value *V) {
973 return isa<Instruction>(V) && classof(cast<Instruction>(V));
977 //===----------------------------------------------------------------------===//
978 // ShuffleVectorInst Class
979 //===----------------------------------------------------------------------===//
981 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
984 class ShuffleVectorInst : public Instruction {
986 ShuffleVectorInst(const ShuffleVectorInst &IE);
988 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
989 const std::string &Name = "", Instruction *InsertBefor = 0);
990 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
991 const std::string &Name, BasicBlock *InsertAtEnd);
993 /// isValidOperands - Return true if a shufflevector instruction can be
994 /// formed with the specified operands.
995 static bool isValidOperands(const Value *V1, const Value *V2,
998 virtual ShuffleVectorInst *clone() const;
1000 /// getType - Overload to return most specific vector type.
1002 inline const VectorType *getType() const {
1003 return reinterpret_cast<const VectorType*>(Instruction::getType());
1006 /// Transparently provide more efficient getOperand methods.
1007 Value *getOperand(unsigned i) const {
1008 assert(i < 3 && "getOperand() out of range!");
1011 void setOperand(unsigned i, Value *Val) {
1012 assert(i < 3 && "setOperand() out of range!");
1015 unsigned getNumOperands() const { return 3; }
1017 // Methods for support type inquiry through isa, cast, and dyn_cast:
1018 static inline bool classof(const ShuffleVectorInst *) { return true; }
1019 static inline bool classof(const Instruction *I) {
1020 return I->getOpcode() == Instruction::ShuffleVector;
1022 static inline bool classof(const Value *V) {
1023 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1028 //===----------------------------------------------------------------------===//
1030 //===----------------------------------------------------------------------===//
1032 // PHINode - The PHINode class is used to represent the magical mystical PHI
1033 // node, that can not exist in nature, but can be synthesized in a computer
1034 // scientist's overactive imagination.
1036 class PHINode : public Instruction {
1037 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1038 /// the number actually in use.
1039 unsigned ReservedSpace;
1040 PHINode(const PHINode &PN);
1042 explicit PHINode(const Type *Ty, const std::string &Name = "",
1043 Instruction *InsertBefore = 0)
1044 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1049 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1050 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1057 /// reserveOperandSpace - This method can be used to avoid repeated
1058 /// reallocation of PHI operand lists by reserving space for the correct
1059 /// number of operands before adding them. Unlike normal vector reserves,
1060 /// this method can also be used to trim the operand space.
1061 void reserveOperandSpace(unsigned NumValues) {
1062 resizeOperands(NumValues*2);
1065 virtual PHINode *clone() const;
1067 /// getNumIncomingValues - Return the number of incoming edges
1069 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1071 /// getIncomingValue - Return incoming value number x
1073 Value *getIncomingValue(unsigned i) const {
1074 assert(i*2 < getNumOperands() && "Invalid value number!");
1075 return getOperand(i*2);
1077 void setIncomingValue(unsigned i, Value *V) {
1078 assert(i*2 < getNumOperands() && "Invalid value number!");
1081 unsigned getOperandNumForIncomingValue(unsigned i) {
1085 /// getIncomingBlock - Return incoming basic block number x
1087 BasicBlock *getIncomingBlock(unsigned i) const {
1088 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1090 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1091 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1093 unsigned getOperandNumForIncomingBlock(unsigned i) {
1097 /// addIncoming - Add an incoming value to the end of the PHI list
1099 void addIncoming(Value *V, BasicBlock *BB) {
1100 assert(getType() == V->getType() &&
1101 "All operands to PHI node must be the same type as the PHI node!");
1102 unsigned OpNo = NumOperands;
1103 if (OpNo+2 > ReservedSpace)
1104 resizeOperands(0); // Get more space!
1105 // Initialize some new operands.
1106 NumOperands = OpNo+2;
1107 OperandList[OpNo].init(V, this);
1108 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1111 /// removeIncomingValue - Remove an incoming value. This is useful if a
1112 /// predecessor basic block is deleted. The value removed is returned.
1114 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1115 /// is true), the PHI node is destroyed and any uses of it are replaced with
1116 /// dummy values. The only time there should be zero incoming values to a PHI
1117 /// node is when the block is dead, so this strategy is sound.
1119 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1121 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1122 int Idx = getBasicBlockIndex(BB);
1123 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1124 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1127 /// getBasicBlockIndex - Return the first index of the specified basic
1128 /// block in the value list for this PHI. Returns -1 if no instance.
1130 int getBasicBlockIndex(const BasicBlock *BB) const {
1131 Use *OL = OperandList;
1132 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1133 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1137 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1138 return getIncomingValue(getBasicBlockIndex(BB));
1141 /// hasConstantValue - If the specified PHI node always merges together the
1142 /// same value, return the value, otherwise return null.
1144 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1146 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1147 static inline bool classof(const PHINode *) { return true; }
1148 static inline bool classof(const Instruction *I) {
1149 return I->getOpcode() == Instruction::PHI;
1151 static inline bool classof(const Value *V) {
1152 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1155 void resizeOperands(unsigned NumOperands);
1158 //===----------------------------------------------------------------------===//
1160 //===----------------------------------------------------------------------===//
1162 //===---------------------------------------------------------------------------
1163 /// ReturnInst - Return a value (possibly void), from a function. Execution
1164 /// does not continue in this function any longer.
1166 class ReturnInst : public TerminatorInst {
1167 Use RetVal; // Return Value: null if 'void'.
1168 ReturnInst(const ReturnInst &RI);
1169 void init(Value *RetVal);
1172 // ReturnInst constructors:
1173 // ReturnInst() - 'ret void' instruction
1174 // ReturnInst( null) - 'ret void' instruction
1175 // ReturnInst(Value* X) - 'ret X' instruction
1176 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1177 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1178 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1179 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1181 // NOTE: If the Value* passed is of type void then the constructor behaves as
1182 // if it was passed NULL.
1183 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1184 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1185 explicit ReturnInst(BasicBlock *InsertAtEnd);
1187 virtual ReturnInst *clone() const;
1189 // Transparently provide more efficient getOperand methods.
1190 Value *getOperand(unsigned i) const {
1191 assert(i < getNumOperands() && "getOperand() out of range!");
1194 void setOperand(unsigned i, Value *Val) {
1195 assert(i < getNumOperands() && "setOperand() out of range!");
1199 Value *getReturnValue() const { return RetVal; }
1201 unsigned getNumSuccessors() const { return 0; }
1203 // Methods for support type inquiry through isa, cast, and dyn_cast:
1204 static inline bool classof(const ReturnInst *) { return true; }
1205 static inline bool classof(const Instruction *I) {
1206 return (I->getOpcode() == Instruction::Ret);
1208 static inline bool classof(const Value *V) {
1209 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1212 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1213 virtual unsigned getNumSuccessorsV() const;
1214 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1217 //===----------------------------------------------------------------------===//
1219 //===----------------------------------------------------------------------===//
1221 //===---------------------------------------------------------------------------
1222 /// BranchInst - Conditional or Unconditional Branch instruction.
1224 class BranchInst : public TerminatorInst {
1225 /// Ops list - Branches are strange. The operands are ordered:
1226 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1227 /// they don't have to check for cond/uncond branchness.
1229 BranchInst(const BranchInst &BI);
1232 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1233 // BranchInst(BB *B) - 'br B'
1234 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1235 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1236 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1237 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1238 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1239 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1240 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1241 Instruction *InsertBefore = 0);
1242 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1243 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1244 BasicBlock *InsertAtEnd);
1246 /// Transparently provide more efficient getOperand methods.
1247 Value *getOperand(unsigned i) const {
1248 assert(i < getNumOperands() && "getOperand() out of range!");
1251 void setOperand(unsigned i, Value *Val) {
1252 assert(i < getNumOperands() && "setOperand() out of range!");
1256 virtual BranchInst *clone() const;
1258 inline bool isUnconditional() const { return getNumOperands() == 1; }
1259 inline bool isConditional() const { return getNumOperands() == 3; }
1261 inline Value *getCondition() const {
1262 assert(isConditional() && "Cannot get condition of an uncond branch!");
1263 return getOperand(2);
1266 void setCondition(Value *V) {
1267 assert(isConditional() && "Cannot set condition of unconditional branch!");
1271 // setUnconditionalDest - Change the current branch to an unconditional branch
1272 // targeting the specified block.
1273 // FIXME: Eliminate this ugly method.
1274 void setUnconditionalDest(BasicBlock *Dest) {
1275 if (isConditional()) { // Convert this to an uncond branch.
1280 setOperand(0, reinterpret_cast<Value*>(Dest));
1283 unsigned getNumSuccessors() const { return 1+isConditional(); }
1285 BasicBlock *getSuccessor(unsigned i) const {
1286 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1287 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1288 cast<BasicBlock>(getOperand(1));
1291 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1292 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1293 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1296 // Methods for support type inquiry through isa, cast, and dyn_cast:
1297 static inline bool classof(const BranchInst *) { return true; }
1298 static inline bool classof(const Instruction *I) {
1299 return (I->getOpcode() == Instruction::Br);
1301 static inline bool classof(const Value *V) {
1302 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1305 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1306 virtual unsigned getNumSuccessorsV() const;
1307 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1310 //===----------------------------------------------------------------------===//
1312 //===----------------------------------------------------------------------===//
1314 //===---------------------------------------------------------------------------
1315 /// SwitchInst - Multiway switch
1317 class SwitchInst : public TerminatorInst {
1318 unsigned ReservedSpace;
1319 // Operand[0] = Value to switch on
1320 // Operand[1] = Default basic block destination
1321 // Operand[2n ] = Value to match
1322 // Operand[2n+1] = BasicBlock to go to on match
1323 SwitchInst(const SwitchInst &RI);
1324 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1325 void resizeOperands(unsigned No);
1327 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1328 /// switch on and a default destination. The number of additional cases can
1329 /// be specified here to make memory allocation more efficient. This
1330 /// constructor can also autoinsert before another instruction.
1331 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1332 Instruction *InsertBefore = 0);
1334 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1335 /// switch on and a default destination. The number of additional cases can
1336 /// be specified here to make memory allocation more efficient. This
1337 /// constructor also autoinserts at the end of the specified BasicBlock.
1338 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1339 BasicBlock *InsertAtEnd);
1343 // Accessor Methods for Switch stmt
1344 inline Value *getCondition() const { return getOperand(0); }
1345 void setCondition(Value *V) { setOperand(0, V); }
1347 inline BasicBlock *getDefaultDest() const {
1348 return cast<BasicBlock>(getOperand(1));
1351 /// getNumCases - return the number of 'cases' in this switch instruction.
1352 /// Note that case #0 is always the default case.
1353 unsigned getNumCases() const {
1354 return getNumOperands()/2;
1357 /// getCaseValue - Return the specified case value. Note that case #0, the
1358 /// default destination, does not have a case value.
1359 ConstantInt *getCaseValue(unsigned i) {
1360 assert(i && i < getNumCases() && "Illegal case value to get!");
1361 return getSuccessorValue(i);
1364 /// getCaseValue - Return the specified case value. Note that case #0, the
1365 /// default destination, does not have a case value.
1366 const ConstantInt *getCaseValue(unsigned i) const {
1367 assert(i && i < getNumCases() && "Illegal case value to get!");
1368 return getSuccessorValue(i);
1371 /// findCaseValue - Search all of the case values for the specified constant.
1372 /// If it is explicitly handled, return the case number of it, otherwise
1373 /// return 0 to indicate that it is handled by the default handler.
1374 unsigned findCaseValue(const ConstantInt *C) const {
1375 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1376 if (getCaseValue(i) == C)
1381 /// findCaseDest - Finds the unique case value for a given successor. Returns
1382 /// null if the successor is not found, not unique, or is the default case.
1383 ConstantInt *findCaseDest(BasicBlock *BB) {
1384 if (BB == getDefaultDest()) return NULL;
1386 ConstantInt *CI = NULL;
1387 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1388 if (getSuccessor(i) == BB) {
1389 if (CI) return NULL; // Multiple cases lead to BB.
1390 else CI = getCaseValue(i);
1396 /// addCase - Add an entry to the switch instruction...
1398 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1400 /// removeCase - This method removes the specified successor from the switch
1401 /// instruction. Note that this cannot be used to remove the default
1402 /// destination (successor #0).
1404 void removeCase(unsigned idx);
1406 virtual SwitchInst *clone() const;
1408 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1409 BasicBlock *getSuccessor(unsigned idx) const {
1410 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1411 return cast<BasicBlock>(getOperand(idx*2+1));
1413 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1414 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1415 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1418 // getSuccessorValue - Return the value associated with the specified
1420 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1421 assert(idx < getNumSuccessors() && "Successor # out of range!");
1422 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1425 // Methods for support type inquiry through isa, cast, and dyn_cast:
1426 static inline bool classof(const SwitchInst *) { return true; }
1427 static inline bool classof(const Instruction *I) {
1428 return I->getOpcode() == Instruction::Switch;
1430 static inline bool classof(const Value *V) {
1431 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1434 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1435 virtual unsigned getNumSuccessorsV() const;
1436 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1439 //===----------------------------------------------------------------------===//
1441 //===----------------------------------------------------------------------===//
1443 //===---------------------------------------------------------------------------
1445 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1446 /// calling convention of the call.
1448 class InvokeInst : public TerminatorInst {
1449 ParamAttrsList *ParamAttrs;
1450 InvokeInst(const InvokeInst &BI);
1451 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1452 Value* const *Args, unsigned NumArgs);
1454 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1455 Value* const* Args, unsigned NumArgs, const std::string &Name = "",
1456 Instruction *InsertBefore = 0);
1457 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1458 Value* const* Args, unsigned NumArgs, const std::string &Name,
1459 BasicBlock *InsertAtEnd);
1462 virtual InvokeInst *clone() const;
1464 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1466 unsigned getCallingConv() const { return SubclassData; }
1467 void setCallingConv(unsigned CC) {
1471 /// Obtains a pointer to the ParamAttrsList object which holds the
1472 /// parameter attributes information, if any.
1473 /// @returns 0 if no attributes have been set.
1474 /// @brief Get the parameter attributes.
1475 ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
1477 /// Sets the parameter attributes for this InvokeInst. To construct a
1478 /// ParamAttrsList, see ParameterAttributes.h
1479 /// @brief Set the parameter attributes.
1480 void setParamAttrs(ParamAttrsList *attrs) { ParamAttrs = attrs; }
1482 /// getCalledFunction - Return the function called, or null if this is an
1483 /// indirect function invocation.
1485 Function *getCalledFunction() const {
1486 return dyn_cast<Function>(getOperand(0));
1489 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1490 inline Value *getCalledValue() const { return getOperand(0); }
1492 // get*Dest - Return the destination basic blocks...
1493 BasicBlock *getNormalDest() const {
1494 return cast<BasicBlock>(getOperand(1));
1496 BasicBlock *getUnwindDest() const {
1497 return cast<BasicBlock>(getOperand(2));
1499 void setNormalDest(BasicBlock *B) {
1500 setOperand(1, reinterpret_cast<Value*>(B));
1503 void setUnwindDest(BasicBlock *B) {
1504 setOperand(2, reinterpret_cast<Value*>(B));
1507 inline BasicBlock *getSuccessor(unsigned i) const {
1508 assert(i < 2 && "Successor # out of range for invoke!");
1509 return i == 0 ? getNormalDest() : getUnwindDest();
1512 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1513 assert(idx < 2 && "Successor # out of range for invoke!");
1514 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1517 unsigned getNumSuccessors() const { return 2; }
1519 // Methods for support type inquiry through isa, cast, and dyn_cast:
1520 static inline bool classof(const InvokeInst *) { return true; }
1521 static inline bool classof(const Instruction *I) {
1522 return (I->getOpcode() == Instruction::Invoke);
1524 static inline bool classof(const Value *V) {
1525 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1528 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1529 virtual unsigned getNumSuccessorsV() const;
1530 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1534 //===----------------------------------------------------------------------===//
1536 //===----------------------------------------------------------------------===//
1538 //===---------------------------------------------------------------------------
1539 /// UnwindInst - Immediately exit the current function, unwinding the stack
1540 /// until an invoke instruction is found.
1542 class UnwindInst : public TerminatorInst {
1544 explicit UnwindInst(Instruction *InsertBefore = 0);
1545 explicit UnwindInst(BasicBlock *InsertAtEnd);
1547 virtual UnwindInst *clone() const;
1549 unsigned getNumSuccessors() const { return 0; }
1551 // Methods for support type inquiry through isa, cast, and dyn_cast:
1552 static inline bool classof(const UnwindInst *) { return true; }
1553 static inline bool classof(const Instruction *I) {
1554 return I->getOpcode() == Instruction::Unwind;
1556 static inline bool classof(const Value *V) {
1557 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1560 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1561 virtual unsigned getNumSuccessorsV() const;
1562 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1565 //===----------------------------------------------------------------------===//
1566 // UnreachableInst Class
1567 //===----------------------------------------------------------------------===//
1569 //===---------------------------------------------------------------------------
1570 /// UnreachableInst - This function has undefined behavior. In particular, the
1571 /// presence of this instruction indicates some higher level knowledge that the
1572 /// end of the block cannot be reached.
1574 class UnreachableInst : public TerminatorInst {
1576 explicit UnreachableInst(Instruction *InsertBefore = 0);
1577 explicit UnreachableInst(BasicBlock *InsertAtEnd);
1579 virtual UnreachableInst *clone() const;
1581 unsigned getNumSuccessors() const { return 0; }
1583 // Methods for support type inquiry through isa, cast, and dyn_cast:
1584 static inline bool classof(const UnreachableInst *) { return true; }
1585 static inline bool classof(const Instruction *I) {
1586 return I->getOpcode() == Instruction::Unreachable;
1588 static inline bool classof(const Value *V) {
1589 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1592 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1593 virtual unsigned getNumSuccessorsV() const;
1594 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1597 //===----------------------------------------------------------------------===//
1599 //===----------------------------------------------------------------------===//
1601 /// @brief This class represents a truncation of integer types.
1602 class TruncInst : public CastInst {
1603 /// Private copy constructor
1604 TruncInst(const TruncInst &CI)
1605 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1608 /// @brief Constructor with insert-before-instruction semantics
1610 Value *S, ///< The value to be truncated
1611 const Type *Ty, ///< The (smaller) type to truncate to
1612 const std::string &Name = "", ///< A name for the new instruction
1613 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1616 /// @brief Constructor with insert-at-end-of-block semantics
1618 Value *S, ///< The value to be truncated
1619 const Type *Ty, ///< The (smaller) type to truncate to
1620 const std::string &Name, ///< A name for the new instruction
1621 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1624 /// @brief Clone an identical TruncInst
1625 virtual CastInst *clone() const;
1627 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1628 static inline bool classof(const TruncInst *) { return true; }
1629 static inline bool classof(const Instruction *I) {
1630 return I->getOpcode() == Trunc;
1632 static inline bool classof(const Value *V) {
1633 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1637 //===----------------------------------------------------------------------===//
1639 //===----------------------------------------------------------------------===//
1641 /// @brief This class represents zero extension of integer types.
1642 class ZExtInst : public CastInst {
1643 /// @brief Private copy constructor
1644 ZExtInst(const ZExtInst &CI)
1645 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1648 /// @brief Constructor with insert-before-instruction semantics
1650 Value *S, ///< The value to be zero extended
1651 const Type *Ty, ///< The type to zero extend to
1652 const std::string &Name = "", ///< A name for the new instruction
1653 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1656 /// @brief Constructor with insert-at-end semantics.
1658 Value *S, ///< The value to be zero extended
1659 const Type *Ty, ///< The type to zero extend to
1660 const std::string &Name, ///< A name for the new instruction
1661 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1664 /// @brief Clone an identical ZExtInst
1665 virtual CastInst *clone() const;
1667 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1668 static inline bool classof(const ZExtInst *) { return true; }
1669 static inline bool classof(const Instruction *I) {
1670 return I->getOpcode() == ZExt;
1672 static inline bool classof(const Value *V) {
1673 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1677 //===----------------------------------------------------------------------===//
1679 //===----------------------------------------------------------------------===//
1681 /// @brief This class represents a sign extension of integer types.
1682 class SExtInst : public CastInst {
1683 /// @brief Private copy constructor
1684 SExtInst(const SExtInst &CI)
1685 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1688 /// @brief Constructor with insert-before-instruction semantics
1690 Value *S, ///< The value to be sign extended
1691 const Type *Ty, ///< The type to sign extend to
1692 const std::string &Name = "", ///< A name for the new instruction
1693 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1696 /// @brief Constructor with insert-at-end-of-block semantics
1698 Value *S, ///< The value to be sign extended
1699 const Type *Ty, ///< The type to sign extend to
1700 const std::string &Name, ///< A name for the new instruction
1701 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1704 /// @brief Clone an identical SExtInst
1705 virtual CastInst *clone() const;
1707 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1708 static inline bool classof(const SExtInst *) { return true; }
1709 static inline bool classof(const Instruction *I) {
1710 return I->getOpcode() == SExt;
1712 static inline bool classof(const Value *V) {
1713 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1717 //===----------------------------------------------------------------------===//
1718 // FPTruncInst Class
1719 //===----------------------------------------------------------------------===//
1721 /// @brief This class represents a truncation of floating point types.
1722 class FPTruncInst : public CastInst {
1723 FPTruncInst(const FPTruncInst &CI)
1724 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1727 /// @brief Constructor with insert-before-instruction semantics
1729 Value *S, ///< The value to be truncated
1730 const Type *Ty, ///< The type to truncate to
1731 const std::string &Name = "", ///< A name for the new instruction
1732 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1735 /// @brief Constructor with insert-before-instruction semantics
1737 Value *S, ///< The value to be truncated
1738 const Type *Ty, ///< The type to truncate to
1739 const std::string &Name, ///< A name for the new instruction
1740 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1743 /// @brief Clone an identical FPTruncInst
1744 virtual CastInst *clone() const;
1746 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1747 static inline bool classof(const FPTruncInst *) { return true; }
1748 static inline bool classof(const Instruction *I) {
1749 return I->getOpcode() == FPTrunc;
1751 static inline bool classof(const Value *V) {
1752 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1756 //===----------------------------------------------------------------------===//
1758 //===----------------------------------------------------------------------===//
1760 /// @brief This class represents an extension of floating point types.
1761 class FPExtInst : public CastInst {
1762 FPExtInst(const FPExtInst &CI)
1763 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1766 /// @brief Constructor with insert-before-instruction semantics
1768 Value *S, ///< The value to be extended
1769 const Type *Ty, ///< The type to extend to
1770 const std::string &Name = "", ///< A name for the new instruction
1771 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1774 /// @brief Constructor with insert-at-end-of-block semantics
1776 Value *S, ///< The value to be extended
1777 const Type *Ty, ///< The type to extend to
1778 const std::string &Name, ///< A name for the new instruction
1779 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1782 /// @brief Clone an identical FPExtInst
1783 virtual CastInst *clone() const;
1785 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1786 static inline bool classof(const FPExtInst *) { return true; }
1787 static inline bool classof(const Instruction *I) {
1788 return I->getOpcode() == FPExt;
1790 static inline bool classof(const Value *V) {
1791 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1795 //===----------------------------------------------------------------------===//
1797 //===----------------------------------------------------------------------===//
1799 /// @brief This class represents a cast unsigned integer to floating point.
1800 class UIToFPInst : public CastInst {
1801 UIToFPInst(const UIToFPInst &CI)
1802 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1805 /// @brief Constructor with insert-before-instruction semantics
1807 Value *S, ///< The value to be converted
1808 const Type *Ty, ///< The type to convert to
1809 const std::string &Name = "", ///< A name for the new instruction
1810 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1813 /// @brief Constructor with insert-at-end-of-block semantics
1815 Value *S, ///< The value to be converted
1816 const Type *Ty, ///< The type to convert to
1817 const std::string &Name, ///< A name for the new instruction
1818 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1821 /// @brief Clone an identical UIToFPInst
1822 virtual CastInst *clone() const;
1824 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1825 static inline bool classof(const UIToFPInst *) { return true; }
1826 static inline bool classof(const Instruction *I) {
1827 return I->getOpcode() == UIToFP;
1829 static inline bool classof(const Value *V) {
1830 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1834 //===----------------------------------------------------------------------===//
1836 //===----------------------------------------------------------------------===//
1838 /// @brief This class represents a cast from signed integer to floating point.
1839 class SIToFPInst : public CastInst {
1840 SIToFPInst(const SIToFPInst &CI)
1841 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1844 /// @brief Constructor with insert-before-instruction semantics
1846 Value *S, ///< The value to be converted
1847 const Type *Ty, ///< The type to convert to
1848 const std::string &Name = "", ///< A name for the new instruction
1849 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1852 /// @brief Constructor with insert-at-end-of-block semantics
1854 Value *S, ///< The value to be converted
1855 const Type *Ty, ///< The type to convert to
1856 const std::string &Name, ///< A name for the new instruction
1857 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1860 /// @brief Clone an identical SIToFPInst
1861 virtual CastInst *clone() const;
1863 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1864 static inline bool classof(const SIToFPInst *) { return true; }
1865 static inline bool classof(const Instruction *I) {
1866 return I->getOpcode() == SIToFP;
1868 static inline bool classof(const Value *V) {
1869 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1873 //===----------------------------------------------------------------------===//
1875 //===----------------------------------------------------------------------===//
1877 /// @brief This class represents a cast from floating point to unsigned integer
1878 class FPToUIInst : public CastInst {
1879 FPToUIInst(const FPToUIInst &CI)
1880 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1883 /// @brief Constructor with insert-before-instruction semantics
1885 Value *S, ///< The value to be converted
1886 const Type *Ty, ///< The type to convert to
1887 const std::string &Name = "", ///< A name for the new instruction
1888 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1891 /// @brief Constructor with insert-at-end-of-block semantics
1893 Value *S, ///< The value to be converted
1894 const Type *Ty, ///< The type to convert to
1895 const std::string &Name, ///< A name for the new instruction
1896 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
1899 /// @brief Clone an identical FPToUIInst
1900 virtual CastInst *clone() const;
1902 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1903 static inline bool classof(const FPToUIInst *) { return true; }
1904 static inline bool classof(const Instruction *I) {
1905 return I->getOpcode() == FPToUI;
1907 static inline bool classof(const Value *V) {
1908 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1912 //===----------------------------------------------------------------------===//
1914 //===----------------------------------------------------------------------===//
1916 /// @brief This class represents a cast from floating point to signed integer.
1917 class FPToSIInst : public CastInst {
1918 FPToSIInst(const FPToSIInst &CI)
1919 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
1922 /// @brief Constructor with insert-before-instruction semantics
1924 Value *S, ///< The value to be converted
1925 const Type *Ty, ///< The type to convert to
1926 const std::string &Name = "", ///< A name for the new instruction
1927 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1930 /// @brief Constructor with insert-at-end-of-block semantics
1932 Value *S, ///< The value to be converted
1933 const Type *Ty, ///< The type to convert to
1934 const std::string &Name, ///< A name for the new instruction
1935 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1938 /// @brief Clone an identical FPToSIInst
1939 virtual CastInst *clone() const;
1941 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1942 static inline bool classof(const FPToSIInst *) { return true; }
1943 static inline bool classof(const Instruction *I) {
1944 return I->getOpcode() == FPToSI;
1946 static inline bool classof(const Value *V) {
1947 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1951 //===----------------------------------------------------------------------===//
1952 // IntToPtrInst Class
1953 //===----------------------------------------------------------------------===//
1955 /// @brief This class represents a cast from an integer to a pointer.
1956 class IntToPtrInst : public CastInst {
1957 IntToPtrInst(const IntToPtrInst &CI)
1958 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
1961 /// @brief Constructor with insert-before-instruction semantics
1963 Value *S, ///< The value to be converted
1964 const Type *Ty, ///< The type to convert to
1965 const std::string &Name = "", ///< A name for the new instruction
1966 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1969 /// @brief Constructor with insert-at-end-of-block semantics
1971 Value *S, ///< The value to be converted
1972 const Type *Ty, ///< The type to convert to
1973 const std::string &Name, ///< A name for the new instruction
1974 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1977 /// @brief Clone an identical IntToPtrInst
1978 virtual CastInst *clone() const;
1980 // Methods for support type inquiry through isa, cast, and dyn_cast:
1981 static inline bool classof(const IntToPtrInst *) { return true; }
1982 static inline bool classof(const Instruction *I) {
1983 return I->getOpcode() == IntToPtr;
1985 static inline bool classof(const Value *V) {
1986 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1990 //===----------------------------------------------------------------------===//
1991 // PtrToIntInst Class
1992 //===----------------------------------------------------------------------===//
1994 /// @brief This class represents a cast from a pointer to an integer
1995 class PtrToIntInst : public CastInst {
1996 PtrToIntInst(const PtrToIntInst &CI)
1997 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2000 /// @brief Constructor with insert-before-instruction semantics
2002 Value *S, ///< The value to be converted
2003 const Type *Ty, ///< The type to convert to
2004 const std::string &Name = "", ///< A name for the new instruction
2005 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2008 /// @brief Constructor with insert-at-end-of-block semantics
2010 Value *S, ///< The value to be converted
2011 const Type *Ty, ///< The type to convert to
2012 const std::string &Name, ///< A name for the new instruction
2013 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2016 /// @brief Clone an identical PtrToIntInst
2017 virtual CastInst *clone() const;
2019 // Methods for support type inquiry through isa, cast, and dyn_cast:
2020 static inline bool classof(const PtrToIntInst *) { return true; }
2021 static inline bool classof(const Instruction *I) {
2022 return I->getOpcode() == PtrToInt;
2024 static inline bool classof(const Value *V) {
2025 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2029 //===----------------------------------------------------------------------===//
2030 // BitCastInst Class
2031 //===----------------------------------------------------------------------===//
2033 /// @brief This class represents a no-op cast from one type to another.
2034 class BitCastInst : public CastInst {
2035 BitCastInst(const BitCastInst &CI)
2036 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2039 /// @brief Constructor with insert-before-instruction semantics
2041 Value *S, ///< The value to be casted
2042 const Type *Ty, ///< The type to casted to
2043 const std::string &Name = "", ///< A name for the new instruction
2044 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2047 /// @brief Constructor with insert-at-end-of-block semantics
2049 Value *S, ///< The value to be casted
2050 const Type *Ty, ///< The type to casted to
2051 const std::string &Name, ///< A name for the new instruction
2052 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2055 /// @brief Clone an identical BitCastInst
2056 virtual CastInst *clone() const;
2058 // Methods for support type inquiry through isa, cast, and dyn_cast:
2059 static inline bool classof(const BitCastInst *) { return true; }
2060 static inline bool classof(const Instruction *I) {
2061 return I->getOpcode() == BitCast;
2063 static inline bool classof(const Value *V) {
2064 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2068 } // End llvm namespace