1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the class definitions of all of the subclasses of the
11 // Instruction class. This is meant to be an easy way to get access to all
12 // instruction subclasses.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_INSTRUCTIONS_H
17 #define LLVM_INSTRUCTIONS_H
19 #include "llvm/InstrTypes.h"
20 #include <vector> // fixme remove.
29 //===----------------------------------------------------------------------===//
30 // AllocationInst Class
31 //===----------------------------------------------------------------------===//
33 /// AllocationInst - This class is the common base class of MallocInst and
36 class AllocationInst : public UnaryInstruction {
39 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
40 const std::string &Name = "", Instruction *InsertBefore = 0);
41 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
42 const std::string &Name, BasicBlock *InsertAtEnd);
44 // Out of line virtual method, so the vtable, etc has a home.
45 virtual ~AllocationInst();
47 /// isArrayAllocation - Return true if there is an allocation size parameter
48 /// to the allocation instruction that is not 1.
50 bool isArrayAllocation() const;
52 /// getArraySize - Get the number of element allocated, for a simple
53 /// allocation of a single element, this will return a constant 1 value.
55 inline const Value *getArraySize() const { return getOperand(0); }
56 inline Value *getArraySize() { return getOperand(0); }
58 /// getType - Overload to return most specific pointer type
60 inline const PointerType *getType() const {
61 return reinterpret_cast<const PointerType*>(Instruction::getType());
64 /// getAllocatedType - Return the type that is being allocated by the
67 const Type *getAllocatedType() const;
69 /// getAlignment - Return the alignment of the memory that is being allocated
70 /// by the instruction.
72 unsigned getAlignment() const { return Alignment; }
73 void setAlignment(unsigned Align) {
74 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
78 virtual Instruction *clone() const = 0;
80 // Methods for support type inquiry through isa, cast, and dyn_cast:
81 static inline bool classof(const AllocationInst *) { return true; }
82 static inline bool classof(const Instruction *I) {
83 return I->getOpcode() == Instruction::Alloca ||
84 I->getOpcode() == Instruction::Malloc;
86 static inline bool classof(const Value *V) {
87 return isa<Instruction>(V) && classof(cast<Instruction>(V));
92 //===----------------------------------------------------------------------===//
94 //===----------------------------------------------------------------------===//
96 /// MallocInst - an instruction to allocated memory on the heap
98 class MallocInst : public AllocationInst {
99 MallocInst(const MallocInst &MI);
101 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
102 const std::string &Name = "",
103 Instruction *InsertBefore = 0)
104 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
105 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
106 BasicBlock *InsertAtEnd)
107 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
109 MallocInst(const Type *Ty, const std::string &Name,
110 Instruction *InsertBefore = 0)
111 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
112 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
113 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
115 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
116 const std::string &Name, BasicBlock *InsertAtEnd)
117 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
118 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
119 const std::string &Name = "",
120 Instruction *InsertBefore = 0)
121 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
123 virtual MallocInst *clone() const;
125 // Methods for support type inquiry through isa, cast, and dyn_cast:
126 static inline bool classof(const MallocInst *) { return true; }
127 static inline bool classof(const Instruction *I) {
128 return (I->getOpcode() == Instruction::Malloc);
130 static inline bool classof(const Value *V) {
131 return isa<Instruction>(V) && classof(cast<Instruction>(V));
136 //===----------------------------------------------------------------------===//
138 //===----------------------------------------------------------------------===//
140 /// AllocaInst - an instruction to allocate memory on the stack
142 class AllocaInst : public AllocationInst {
143 AllocaInst(const AllocaInst &);
145 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
146 const std::string &Name = "",
147 Instruction *InsertBefore = 0)
148 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
149 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
150 BasicBlock *InsertAtEnd)
151 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
153 AllocaInst(const Type *Ty, const std::string &Name,
154 Instruction *InsertBefore = 0)
155 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
156 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
157 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
159 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
160 const std::string &Name = "", Instruction *InsertBefore = 0)
161 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
162 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
163 const std::string &Name, BasicBlock *InsertAtEnd)
164 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
166 virtual AllocaInst *clone() const;
168 // Methods for support type inquiry through isa, cast, and dyn_cast:
169 static inline bool classof(const AllocaInst *) { return true; }
170 static inline bool classof(const Instruction *I) {
171 return (I->getOpcode() == Instruction::Alloca);
173 static inline bool classof(const Value *V) {
174 return isa<Instruction>(V) && classof(cast<Instruction>(V));
179 //===----------------------------------------------------------------------===//
181 //===----------------------------------------------------------------------===//
183 /// FreeInst - an instruction to deallocate memory
185 class FreeInst : public UnaryInstruction {
188 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
189 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
191 virtual FreeInst *clone() const;
193 virtual bool mayWriteToMemory() const { return true; }
195 // Methods for support type inquiry through isa, cast, and dyn_cast:
196 static inline bool classof(const FreeInst *) { return true; }
197 static inline bool classof(const Instruction *I) {
198 return (I->getOpcode() == Instruction::Free);
200 static inline bool classof(const Value *V) {
201 return isa<Instruction>(V) && classof(cast<Instruction>(V));
206 //===----------------------------------------------------------------------===//
208 //===----------------------------------------------------------------------===//
210 /// LoadInst - an instruction for reading from memory. This uses the
211 /// SubclassData field in Value to store whether or not the load is volatile.
213 class LoadInst : public UnaryInstruction {
214 LoadInst(const LoadInst &LI)
215 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
216 setVolatile(LI.isVolatile());
224 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
225 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
226 explicit LoadInst(Value *Ptr, const std::string &Name = "",
227 bool isVolatile = false, Instruction *InsertBefore = 0);
228 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
229 BasicBlock *InsertAtEnd);
231 /// isVolatile - Return true if this is a load from a volatile memory
234 bool isVolatile() const { return SubclassData; }
236 /// setVolatile - Specify whether this is a volatile load or not.
238 void setVolatile(bool V) { SubclassData = V; }
240 virtual LoadInst *clone() const;
242 virtual bool mayWriteToMemory() const { return isVolatile(); }
244 Value *getPointerOperand() { return getOperand(0); }
245 const Value *getPointerOperand() const { return getOperand(0); }
246 static unsigned getPointerOperandIndex() { return 0U; }
248 // Methods for support type inquiry through isa, cast, and dyn_cast:
249 static inline bool classof(const LoadInst *) { return true; }
250 static inline bool classof(const Instruction *I) {
251 return I->getOpcode() == Instruction::Load;
253 static inline bool classof(const Value *V) {
254 return isa<Instruction>(V) && classof(cast<Instruction>(V));
259 //===----------------------------------------------------------------------===//
261 //===----------------------------------------------------------------------===//
263 /// StoreInst - an instruction for storing to memory
265 class StoreInst : public Instruction {
267 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
268 Ops[0].init(SI.Ops[0], this);
269 Ops[1].init(SI.Ops[1], this);
270 setVolatile(SI.isVolatile());
277 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
278 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
279 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
280 Instruction *InsertBefore = 0);
281 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
284 /// isVolatile - Return true if this is a load from a volatile memory
287 bool isVolatile() const { return SubclassData; }
289 /// setVolatile - Specify whether this is a volatile load or not.
291 void setVolatile(bool V) { SubclassData = V; }
293 /// Transparently provide more efficient getOperand methods.
294 Value *getOperand(unsigned i) const {
295 assert(i < 2 && "getOperand() out of range!");
298 void setOperand(unsigned i, Value *Val) {
299 assert(i < 2 && "setOperand() out of range!");
302 unsigned getNumOperands() const { return 2; }
305 virtual StoreInst *clone() const;
307 virtual bool mayWriteToMemory() const { return true; }
309 Value *getPointerOperand() { return getOperand(1); }
310 const Value *getPointerOperand() const { return getOperand(1); }
311 static unsigned getPointerOperandIndex() { return 1U; }
313 // Methods for support type inquiry through isa, cast, and dyn_cast:
314 static inline bool classof(const StoreInst *) { return true; }
315 static inline bool classof(const Instruction *I) {
316 return I->getOpcode() == Instruction::Store;
318 static inline bool classof(const Value *V) {
319 return isa<Instruction>(V) && classof(cast<Instruction>(V));
324 //===----------------------------------------------------------------------===//
325 // GetElementPtrInst Class
326 //===----------------------------------------------------------------------===//
328 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
329 /// access elements of arrays and structs
331 class GetElementPtrInst : public Instruction {
332 GetElementPtrInst(const GetElementPtrInst &GEPI)
333 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
334 0, GEPI.getNumOperands()) {
335 Use *OL = OperandList = new Use[NumOperands];
336 Use *GEPIOL = GEPI.OperandList;
337 for (unsigned i = 0, E = NumOperands; i != E; ++i)
338 OL[i].init(GEPIOL[i], this);
340 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
341 void init(Value *Ptr, Value *Idx0, Value *Idx1);
342 void init(Value *Ptr, Value *Idx);
344 /// Constructors - Create a getelementptr instruction with a base pointer an
345 /// list of indices. The first ctor can optionally insert before an existing
346 /// instruction, the second appends the new instruction to the specified
348 GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
349 const std::string &Name = "", Instruction *InsertBefore =0);
350 GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
351 const std::string &Name, BasicBlock *InsertAtEnd);
352 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
353 const std::string &Name = "", Instruction *InsertBefore =0);
354 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
355 const std::string &Name, BasicBlock *InsertAtEnd);
357 /// Constructors - These two constructors are convenience methods because one
358 /// and two index getelementptr instructions are so common.
359 GetElementPtrInst(Value *Ptr, Value *Idx,
360 const std::string &Name = "", Instruction *InsertBefore =0);
361 GetElementPtrInst(Value *Ptr, Value *Idx,
362 const std::string &Name, BasicBlock *InsertAtEnd);
363 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
364 const std::string &Name = "", Instruction *InsertBefore =0);
365 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
366 const std::string &Name, BasicBlock *InsertAtEnd);
367 ~GetElementPtrInst();
369 virtual GetElementPtrInst *clone() const;
371 // getType - Overload to return most specific pointer type...
372 inline const PointerType *getType() const {
373 return reinterpret_cast<const PointerType*>(Instruction::getType());
376 /// getIndexedType - Returns the type of the element that would be loaded with
377 /// a load instruction with the specified parameters.
379 /// A null type is returned if the indices are invalid for the specified
382 static const Type *getIndexedType(const Type *Ptr,
383 Value* const *Idx, unsigned NumIdx,
384 bool AllowStructLeaf = false);
386 static const Type *getIndexedType(const Type *Ptr,
387 const std::vector<Value*> &Indices,
388 bool AllowStructLeaf = false) {
389 return getIndexedType(Ptr, &Indices[0], Indices.size(), AllowStructLeaf);
391 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
392 bool AllowStructLeaf = false);
393 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
395 inline op_iterator idx_begin() { return op_begin()+1; }
396 inline const_op_iterator idx_begin() const { return op_begin()+1; }
397 inline op_iterator idx_end() { return op_end(); }
398 inline const_op_iterator idx_end() const { return op_end(); }
400 Value *getPointerOperand() {
401 return getOperand(0);
403 const Value *getPointerOperand() const {
404 return getOperand(0);
406 static unsigned getPointerOperandIndex() {
407 return 0U; // get index for modifying correct operand
410 inline unsigned getNumIndices() const { // Note: always non-negative
411 return getNumOperands() - 1;
414 inline bool hasIndices() const {
415 return getNumOperands() > 1;
418 // Methods for support type inquiry through isa, cast, and dyn_cast:
419 static inline bool classof(const GetElementPtrInst *) { return true; }
420 static inline bool classof(const Instruction *I) {
421 return (I->getOpcode() == Instruction::GetElementPtr);
423 static inline bool classof(const Value *V) {
424 return isa<Instruction>(V) && classof(cast<Instruction>(V));
428 //===----------------------------------------------------------------------===//
430 //===----------------------------------------------------------------------===//
432 /// This instruction compares its operands according to the predicate given
433 /// to the constructor. It only operates on integers, pointers, or packed
434 /// vectors of integrals. The two operands must be the same type.
435 /// @brief Represent an integer comparison operator.
436 class ICmpInst: public CmpInst {
438 /// This enumeration lists the possible predicates for the ICmpInst. The
439 /// values in the range 0-31 are reserved for FCmpInst while values in the
440 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
441 /// predicate values are not overlapping between the classes.
443 ICMP_EQ = 32, ///< equal
444 ICMP_NE = 33, ///< not equal
445 ICMP_UGT = 34, ///< unsigned greater than
446 ICMP_UGE = 35, ///< unsigned greater or equal
447 ICMP_ULT = 36, ///< unsigned less than
448 ICMP_ULE = 37, ///< unsigned less or equal
449 ICMP_SGT = 38, ///< signed greater than
450 ICMP_SGE = 39, ///< signed greater or equal
451 ICMP_SLT = 40, ///< signed less than
452 ICMP_SLE = 41, ///< signed less or equal
453 FIRST_ICMP_PREDICATE = ICMP_EQ,
454 LAST_ICMP_PREDICATE = ICMP_SLE,
455 BAD_ICMP_PREDICATE = ICMP_SLE + 1
458 /// @brief Constructor with insert-before-instruction semantics.
460 Predicate pred, ///< The predicate to use for the comparison
461 Value *LHS, ///< The left-hand-side of the expression
462 Value *RHS, ///< The right-hand-side of the expression
463 const std::string &Name = "", ///< Name of the instruction
464 Instruction *InsertBefore = 0 ///< Where to insert
465 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
468 /// @brief Constructor with insert-at-block-end semantics.
470 Predicate pred, ///< The predicate to use for the comparison
471 Value *LHS, ///< The left-hand-side of the expression
472 Value *RHS, ///< The right-hand-side of the expression
473 const std::string &Name, ///< Name of the instruction
474 BasicBlock *InsertAtEnd ///< Block to insert into.
475 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
478 /// @brief Return the predicate for this instruction.
479 Predicate getPredicate() const { return Predicate(SubclassData); }
481 /// @brief Set the predicate for this instruction to the specified value.
482 void setPredicate(Predicate P) { SubclassData = P; }
484 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
485 /// @returns the inverse predicate for the instruction's current predicate.
486 /// @brief Return the inverse of the instruction's predicate.
487 Predicate getInversePredicate() const {
488 return getInversePredicate(getPredicate());
491 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
492 /// @returns the inverse predicate for predicate provided in \p pred.
493 /// @brief Return the inverse of a given predicate
494 static Predicate getInversePredicate(Predicate pred);
496 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
497 /// @returns the predicate that would be the result of exchanging the two
498 /// operands of the ICmpInst instruction without changing the result
500 /// @brief Return the predicate as if the operands were swapped
501 Predicate getSwappedPredicate() const {
502 return getSwappedPredicate(getPredicate());
505 /// This is a static version that you can use without an instruction
507 /// @brief Return the predicate as if the operands were swapped.
508 static Predicate getSwappedPredicate(Predicate pred);
510 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
511 /// @returns the predicate that would be the result if the operand were
512 /// regarded as signed.
513 /// @brief Return the signed version of the predicate
514 Predicate getSignedPredicate() const {
515 return getSignedPredicate(getPredicate());
518 /// This is a static version that you can use without an instruction.
519 /// @brief Return the signed version of the predicate.
520 static Predicate getSignedPredicate(Predicate pred);
522 /// This also tests for commutativity. If isEquality() returns true then
523 /// the predicate is also commutative.
524 /// @returns true if the predicate of this instruction is EQ or NE.
525 /// @brief Determine if this is an equality predicate.
526 bool isEquality() const {
527 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
530 /// @returns true if the predicate of this ICmpInst is commutative
531 /// @brief Determine if this relation is commutative.
532 bool isCommutative() const { return isEquality(); }
534 /// @returns true if the predicate is relational (not EQ or NE).
535 /// @brief Determine if this a relational predicate.
536 bool isRelational() const {
537 return !isEquality();
540 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
541 /// @brief Determine if this instruction's predicate is signed.
542 bool isSignedPredicate() { return isSignedPredicate(getPredicate()); }
544 /// @returns true if the predicate provided is signed, false otherwise
545 /// @brief Determine if the predicate is signed.
546 static bool isSignedPredicate(Predicate pred);
548 /// Exchange the two operands to this instruction in such a way that it does
549 /// not modify the semantics of the instruction. The predicate value may be
550 /// changed to retain the same result if the predicate is order dependent
552 /// @brief Swap operands and adjust predicate.
553 void swapOperands() {
554 SubclassData = getSwappedPredicate();
555 std::swap(Ops[0], Ops[1]);
558 // Methods for support type inquiry through isa, cast, and dyn_cast:
559 static inline bool classof(const ICmpInst *) { return true; }
560 static inline bool classof(const Instruction *I) {
561 return I->getOpcode() == Instruction::ICmp;
563 static inline bool classof(const Value *V) {
564 return isa<Instruction>(V) && classof(cast<Instruction>(V));
568 //===----------------------------------------------------------------------===//
570 //===----------------------------------------------------------------------===//
572 /// This instruction compares its operands according to the predicate given
573 /// to the constructor. It only operates on floating point values or packed
574 /// vectors of floating point values. The operands must be identical types.
575 /// @brief Represents a floating point comparison operator.
576 class FCmpInst: public CmpInst {
578 /// This enumeration lists the possible predicates for the FCmpInst. Values
579 /// in the range 0-31 are reserved for FCmpInst.
581 // Opcode U L G E Intuitive operation
582 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
583 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
584 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
585 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
586 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
587 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
588 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
589 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
590 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
591 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
592 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
593 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
594 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
595 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
596 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
597 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
598 FIRST_FCMP_PREDICATE = FCMP_FALSE,
599 LAST_FCMP_PREDICATE = FCMP_TRUE,
600 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
603 /// @brief Constructor with insert-before-instruction semantics.
605 Predicate pred, ///< The predicate to use for the comparison
606 Value *LHS, ///< The left-hand-side of the expression
607 Value *RHS, ///< The right-hand-side of the expression
608 const std::string &Name = "", ///< Name of the instruction
609 Instruction *InsertBefore = 0 ///< Where to insert
610 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
613 /// @brief Constructor with insert-at-block-end semantics.
615 Predicate pred, ///< The predicate to use for the comparison
616 Value *LHS, ///< The left-hand-side of the expression
617 Value *RHS, ///< The right-hand-side of the expression
618 const std::string &Name, ///< Name of the instruction
619 BasicBlock *InsertAtEnd ///< Block to insert into.
620 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
623 /// @brief Return the predicate for this instruction.
624 Predicate getPredicate() const { return Predicate(SubclassData); }
626 /// @brief Set the predicate for this instruction to the specified value.
627 void setPredicate(Predicate P) { SubclassData = P; }
629 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
630 /// @returns the inverse predicate for the instructions current predicate.
631 /// @brief Return the inverse of the predicate
632 Predicate getInversePredicate() const {
633 return getInversePredicate(getPredicate());
636 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
637 /// @returns the inverse predicate for \p pred.
638 /// @brief Return the inverse of a given predicate
639 static Predicate getInversePredicate(Predicate pred);
641 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
642 /// @returns the predicate that would be the result of exchanging the two
643 /// operands of the ICmpInst instruction without changing the result
645 /// @brief Return the predicate as if the operands were swapped
646 Predicate getSwappedPredicate() const {
647 return getSwappedPredicate(getPredicate());
650 /// This is a static version that you can use without an instruction
652 /// @brief Return the predicate as if the operands were swapped.
653 static Predicate getSwappedPredicate(Predicate Opcode);
655 /// This also tests for commutativity. If isEquality() returns true then
656 /// the predicate is also commutative. Only the equality predicates are
658 /// @returns true if the predicate of this instruction is EQ or NE.
659 /// @brief Determine if this is an equality predicate.
660 bool isEquality() const {
661 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
662 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
664 bool isCommutative() const { return isEquality(); }
666 /// @returns true if the predicate is relational (not EQ or NE).
667 /// @brief Determine if this a relational predicate.
668 bool isRelational() const { return !isEquality(); }
670 /// Exchange the two operands to this instruction in such a way that it does
671 /// not modify the semantics of the instruction. The predicate value may be
672 /// changed to retain the same result if the predicate is order dependent
674 /// @brief Swap operands and adjust predicate.
675 void swapOperands() {
676 SubclassData = getSwappedPredicate();
677 std::swap(Ops[0], Ops[1]);
680 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
681 static inline bool classof(const FCmpInst *) { return true; }
682 static inline bool classof(const Instruction *I) {
683 return I->getOpcode() == Instruction::FCmp;
685 static inline bool classof(const Value *V) {
686 return isa<Instruction>(V) && classof(cast<Instruction>(V));
690 //===----------------------------------------------------------------------===//
692 //===----------------------------------------------------------------------===//
694 /// CallInst - This class represents a function call, abstracting a target
695 /// machine's calling convention. This class uses low bit of the SubClassData
696 /// field to indicate whether or not this is a tail call. The rest of the bits
697 /// hold the calling convention of the call.
699 class CallInst : public Instruction {
700 CallInst(const CallInst &CI);
701 void init(Value *Func, const std::vector<Value*> &Params);
702 void init(Value *Func, Value *Actual1, Value *Actual2);
703 void init(Value *Func, Value *Actual);
704 void init(Value *Func);
707 CallInst(Value *F, const std::vector<Value*> &Par,
708 const std::string &Name = "", Instruction *InsertBefore = 0);
709 CallInst(Value *F, const std::vector<Value*> &Par,
710 const std::string &Name, BasicBlock *InsertAtEnd);
712 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
713 // actuals, respectively.
714 CallInst(Value *F, Value *Actual1, Value *Actual2,
715 const std::string& Name = "", Instruction *InsertBefore = 0);
716 CallInst(Value *F, Value *Actual1, Value *Actual2,
717 const std::string& Name, BasicBlock *InsertAtEnd);
718 CallInst(Value *F, Value *Actual, const std::string& Name = "",
719 Instruction *InsertBefore = 0);
720 CallInst(Value *F, Value *Actual, const std::string& Name,
721 BasicBlock *InsertAtEnd);
722 explicit CallInst(Value *F, const std::string &Name = "",
723 Instruction *InsertBefore = 0);
724 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
727 virtual CallInst *clone() const;
728 bool mayWriteToMemory() const { return true; }
730 bool isTailCall() const { return SubclassData & 1; }
731 void setTailCall(bool isTailCall = true) {
732 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
735 /// getCallingConv/setCallingConv - Get or set the calling convention of this
737 unsigned getCallingConv() const { return SubclassData >> 1; }
738 void setCallingConv(unsigned CC) {
739 SubclassData = (SubclassData & 1) | (CC << 1);
742 /// getCalledFunction - Return the function being called by this instruction
743 /// if it is a direct call. If it is a call through a function pointer,
745 Function *getCalledFunction() const {
746 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
749 /// getCalledValue - Get a pointer to the function that is invoked by this
751 inline const Value *getCalledValue() const { return getOperand(0); }
752 inline Value *getCalledValue() { return getOperand(0); }
754 // Methods for support type inquiry through isa, cast, and dyn_cast:
755 static inline bool classof(const CallInst *) { return true; }
756 static inline bool classof(const Instruction *I) {
757 return I->getOpcode() == Instruction::Call;
759 static inline bool classof(const Value *V) {
760 return isa<Instruction>(V) && classof(cast<Instruction>(V));
764 //===----------------------------------------------------------------------===//
766 //===----------------------------------------------------------------------===//
768 /// SelectInst - This class represents the LLVM 'select' instruction.
770 class SelectInst : public Instruction {
773 void init(Value *C, Value *S1, Value *S2) {
774 Ops[0].init(C, this);
775 Ops[1].init(S1, this);
776 Ops[2].init(S2, this);
779 SelectInst(const SelectInst &SI)
780 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
781 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
784 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
785 Instruction *InsertBefore = 0)
786 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
787 Name, InsertBefore) {
790 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
791 BasicBlock *InsertAtEnd)
792 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
797 Value *getCondition() const { return Ops[0]; }
798 Value *getTrueValue() const { return Ops[1]; }
799 Value *getFalseValue() const { return Ops[2]; }
801 /// Transparently provide more efficient getOperand methods.
802 Value *getOperand(unsigned i) const {
803 assert(i < 3 && "getOperand() out of range!");
806 void setOperand(unsigned i, Value *Val) {
807 assert(i < 3 && "setOperand() out of range!");
810 unsigned getNumOperands() const { return 3; }
812 OtherOps getOpcode() const {
813 return static_cast<OtherOps>(Instruction::getOpcode());
816 virtual SelectInst *clone() const;
818 // Methods for support type inquiry through isa, cast, and dyn_cast:
819 static inline bool classof(const SelectInst *) { return true; }
820 static inline bool classof(const Instruction *I) {
821 return I->getOpcode() == Instruction::Select;
823 static inline bool classof(const Value *V) {
824 return isa<Instruction>(V) && classof(cast<Instruction>(V));
828 //===----------------------------------------------------------------------===//
830 //===----------------------------------------------------------------------===//
832 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
833 /// an argument of the specified type given a va_list and increments that list
835 class VAArgInst : public UnaryInstruction {
836 VAArgInst(const VAArgInst &VAA)
837 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
839 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
840 Instruction *InsertBefore = 0)
841 : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) {
843 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
844 BasicBlock *InsertAtEnd)
845 : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) {
848 virtual VAArgInst *clone() const;
849 bool mayWriteToMemory() const { return true; }
851 // Methods for support type inquiry through isa, cast, and dyn_cast:
852 static inline bool classof(const VAArgInst *) { return true; }
853 static inline bool classof(const Instruction *I) {
854 return I->getOpcode() == VAArg;
856 static inline bool classof(const Value *V) {
857 return isa<Instruction>(V) && classof(cast<Instruction>(V));
861 //===----------------------------------------------------------------------===//
862 // ExtractElementInst Class
863 //===----------------------------------------------------------------------===//
865 /// ExtractElementInst - This instruction extracts a single (scalar)
866 /// element from a PackedType value
868 class ExtractElementInst : public Instruction {
870 ExtractElementInst(const ExtractElementInst &EE) :
871 Instruction(EE.getType(), ExtractElement, Ops, 2) {
872 Ops[0].init(EE.Ops[0], this);
873 Ops[1].init(EE.Ops[1], this);
877 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
878 Instruction *InsertBefore = 0);
879 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
880 Instruction *InsertBefore = 0);
881 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
882 BasicBlock *InsertAtEnd);
883 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
884 BasicBlock *InsertAtEnd);
886 /// isValidOperands - Return true if an extractelement instruction can be
887 /// formed with the specified operands.
888 static bool isValidOperands(const Value *Vec, const Value *Idx);
890 virtual ExtractElementInst *clone() const;
892 virtual bool mayWriteToMemory() const { return false; }
894 /// Transparently provide more efficient getOperand methods.
895 Value *getOperand(unsigned i) const {
896 assert(i < 2 && "getOperand() out of range!");
899 void setOperand(unsigned i, Value *Val) {
900 assert(i < 2 && "setOperand() out of range!");
903 unsigned getNumOperands() const { return 2; }
905 // Methods for support type inquiry through isa, cast, and dyn_cast:
906 static inline bool classof(const ExtractElementInst *) { return true; }
907 static inline bool classof(const Instruction *I) {
908 return I->getOpcode() == Instruction::ExtractElement;
910 static inline bool classof(const Value *V) {
911 return isa<Instruction>(V) && classof(cast<Instruction>(V));
915 //===----------------------------------------------------------------------===//
916 // InsertElementInst Class
917 //===----------------------------------------------------------------------===//
919 /// InsertElementInst - This instruction inserts a single (scalar)
920 /// element into a PackedType value
922 class InsertElementInst : public Instruction {
924 InsertElementInst(const InsertElementInst &IE);
926 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
927 const std::string &Name = "",Instruction *InsertBefore = 0);
928 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
929 const std::string &Name = "",Instruction *InsertBefore = 0);
930 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
931 const std::string &Name, BasicBlock *InsertAtEnd);
932 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
933 const std::string &Name, BasicBlock *InsertAtEnd);
935 /// isValidOperands - Return true if an insertelement instruction can be
936 /// formed with the specified operands.
937 static bool isValidOperands(const Value *Vec, const Value *NewElt,
940 virtual InsertElementInst *clone() const;
942 virtual bool mayWriteToMemory() const { return false; }
944 /// getType - Overload to return most specific packed type.
946 inline const PackedType *getType() const {
947 return reinterpret_cast<const PackedType*>(Instruction::getType());
950 /// Transparently provide more efficient getOperand methods.
951 Value *getOperand(unsigned i) const {
952 assert(i < 3 && "getOperand() out of range!");
955 void setOperand(unsigned i, Value *Val) {
956 assert(i < 3 && "setOperand() out of range!");
959 unsigned getNumOperands() const { return 3; }
961 // Methods for support type inquiry through isa, cast, and dyn_cast:
962 static inline bool classof(const InsertElementInst *) { return true; }
963 static inline bool classof(const Instruction *I) {
964 return I->getOpcode() == Instruction::InsertElement;
966 static inline bool classof(const Value *V) {
967 return isa<Instruction>(V) && classof(cast<Instruction>(V));
971 //===----------------------------------------------------------------------===//
972 // ShuffleVectorInst Class
973 //===----------------------------------------------------------------------===//
975 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
978 class ShuffleVectorInst : public Instruction {
980 ShuffleVectorInst(const ShuffleVectorInst &IE);
982 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
983 const std::string &Name = "", Instruction *InsertBefor = 0);
984 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
985 const std::string &Name, BasicBlock *InsertAtEnd);
987 /// isValidOperands - Return true if a shufflevector instruction can be
988 /// formed with the specified operands.
989 static bool isValidOperands(const Value *V1, const Value *V2,
992 virtual ShuffleVectorInst *clone() const;
994 virtual bool mayWriteToMemory() const { return false; }
996 /// getType - Overload to return most specific packed type.
998 inline const PackedType *getType() const {
999 return reinterpret_cast<const PackedType*>(Instruction::getType());
1002 /// Transparently provide more efficient getOperand methods.
1003 Value *getOperand(unsigned i) const {
1004 assert(i < 3 && "getOperand() out of range!");
1007 void setOperand(unsigned i, Value *Val) {
1008 assert(i < 3 && "setOperand() out of range!");
1011 unsigned getNumOperands() const { return 3; }
1013 // Methods for support type inquiry through isa, cast, and dyn_cast:
1014 static inline bool classof(const ShuffleVectorInst *) { return true; }
1015 static inline bool classof(const Instruction *I) {
1016 return I->getOpcode() == Instruction::ShuffleVector;
1018 static inline bool classof(const Value *V) {
1019 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1024 //===----------------------------------------------------------------------===//
1026 //===----------------------------------------------------------------------===//
1028 // PHINode - The PHINode class is used to represent the magical mystical PHI
1029 // node, that can not exist in nature, but can be synthesized in a computer
1030 // scientist's overactive imagination.
1032 class PHINode : public Instruction {
1033 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1034 /// the number actually in use.
1035 unsigned ReservedSpace;
1036 PHINode(const PHINode &PN);
1038 explicit PHINode(const Type *Ty, const std::string &Name = "",
1039 Instruction *InsertBefore = 0)
1040 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore),
1044 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1045 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
1051 /// reserveOperandSpace - This method can be used to avoid repeated
1052 /// reallocation of PHI operand lists by reserving space for the correct
1053 /// number of operands before adding them. Unlike normal vector reserves,
1054 /// this method can also be used to trim the operand space.
1055 void reserveOperandSpace(unsigned NumValues) {
1056 resizeOperands(NumValues*2);
1059 virtual PHINode *clone() const;
1061 /// getNumIncomingValues - Return the number of incoming edges
1063 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1065 /// getIncomingValue - Return incoming value number x
1067 Value *getIncomingValue(unsigned i) const {
1068 assert(i*2 < getNumOperands() && "Invalid value number!");
1069 return getOperand(i*2);
1071 void setIncomingValue(unsigned i, Value *V) {
1072 assert(i*2 < getNumOperands() && "Invalid value number!");
1075 unsigned getOperandNumForIncomingValue(unsigned i) {
1079 /// getIncomingBlock - Return incoming basic block number x
1081 BasicBlock *getIncomingBlock(unsigned i) const {
1082 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1084 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1085 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1087 unsigned getOperandNumForIncomingBlock(unsigned i) {
1091 /// addIncoming - Add an incoming value to the end of the PHI list
1093 void addIncoming(Value *V, BasicBlock *BB) {
1094 assert(getType() == V->getType() &&
1095 "All operands to PHI node must be the same type as the PHI node!");
1096 unsigned OpNo = NumOperands;
1097 if (OpNo+2 > ReservedSpace)
1098 resizeOperands(0); // Get more space!
1099 // Initialize some new operands.
1100 NumOperands = OpNo+2;
1101 OperandList[OpNo].init(V, this);
1102 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1105 /// removeIncomingValue - Remove an incoming value. This is useful if a
1106 /// predecessor basic block is deleted. The value removed is returned.
1108 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1109 /// is true), the PHI node is destroyed and any uses of it are replaced with
1110 /// dummy values. The only time there should be zero incoming values to a PHI
1111 /// node is when the block is dead, so this strategy is sound.
1113 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1115 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1116 int Idx = getBasicBlockIndex(BB);
1117 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1118 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1121 /// getBasicBlockIndex - Return the first index of the specified basic
1122 /// block in the value list for this PHI. Returns -1 if no instance.
1124 int getBasicBlockIndex(const BasicBlock *BB) const {
1125 Use *OL = OperandList;
1126 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1127 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1131 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1132 return getIncomingValue(getBasicBlockIndex(BB));
1135 /// hasConstantValue - If the specified PHI node always merges together the
1136 /// same value, return the value, otherwise return null.
1138 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1140 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1141 static inline bool classof(const PHINode *) { return true; }
1142 static inline bool classof(const Instruction *I) {
1143 return I->getOpcode() == Instruction::PHI;
1145 static inline bool classof(const Value *V) {
1146 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1149 void resizeOperands(unsigned NumOperands);
1152 //===----------------------------------------------------------------------===//
1154 //===----------------------------------------------------------------------===//
1156 //===---------------------------------------------------------------------------
1157 /// ReturnInst - Return a value (possibly void), from a function. Execution
1158 /// does not continue in this function any longer.
1160 class ReturnInst : public TerminatorInst {
1161 Use RetVal; // Possibly null retval.
1162 ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
1163 RI.getNumOperands()) {
1164 if (RI.getNumOperands())
1165 RetVal.init(RI.RetVal, this);
1168 void init(Value *RetVal);
1171 // ReturnInst constructors:
1172 // ReturnInst() - 'ret void' instruction
1173 // ReturnInst( null) - 'ret void' instruction
1174 // ReturnInst(Value* X) - 'ret X' instruction
1175 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1176 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1177 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1178 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1180 // NOTE: If the Value* passed is of type void then the constructor behaves as
1181 // if it was passed NULL.
1182 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
1183 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
1186 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
1187 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1190 explicit ReturnInst(BasicBlock *InsertAtEnd)
1191 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1194 virtual ReturnInst *clone() const;
1196 // Transparently provide more efficient getOperand methods.
1197 Value *getOperand(unsigned i) const {
1198 assert(i < getNumOperands() && "getOperand() out of range!");
1201 void setOperand(unsigned i, Value *Val) {
1202 assert(i < getNumOperands() && "setOperand() out of range!");
1206 Value *getReturnValue() const { return RetVal; }
1208 unsigned getNumSuccessors() const { return 0; }
1210 // Methods for support type inquiry through isa, cast, and dyn_cast:
1211 static inline bool classof(const ReturnInst *) { return true; }
1212 static inline bool classof(const Instruction *I) {
1213 return (I->getOpcode() == Instruction::Ret);
1215 static inline bool classof(const Value *V) {
1216 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1219 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1220 virtual unsigned getNumSuccessorsV() const;
1221 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1224 //===----------------------------------------------------------------------===//
1226 //===----------------------------------------------------------------------===//
1228 //===---------------------------------------------------------------------------
1229 /// BranchInst - Conditional or Unconditional Branch instruction.
1231 class BranchInst : public TerminatorInst {
1232 /// Ops list - Branches are strange. The operands are ordered:
1233 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1234 /// they don't have to check for cond/uncond branchness.
1236 BranchInst(const BranchInst &BI);
1239 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1240 // BranchInst(BB *B) - 'br B'
1241 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1242 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1243 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1244 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1245 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1246 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
1247 : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
1248 assert(IfTrue != 0 && "Branch destination may not be null!");
1249 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1251 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1252 Instruction *InsertBefore = 0)
1253 : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
1254 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1255 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1256 Ops[2].init(Cond, this);
1262 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
1263 : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
1264 assert(IfTrue != 0 && "Branch destination may not be null!");
1265 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1268 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1269 BasicBlock *InsertAtEnd)
1270 : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
1271 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1272 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1273 Ops[2].init(Cond, this);
1280 /// Transparently provide more efficient getOperand methods.
1281 Value *getOperand(unsigned i) const {
1282 assert(i < getNumOperands() && "getOperand() out of range!");
1285 void setOperand(unsigned i, Value *Val) {
1286 assert(i < getNumOperands() && "setOperand() out of range!");
1290 virtual BranchInst *clone() const;
1292 inline bool isUnconditional() const { return getNumOperands() == 1; }
1293 inline bool isConditional() const { return getNumOperands() == 3; }
1295 inline Value *getCondition() const {
1296 assert(isConditional() && "Cannot get condition of an uncond branch!");
1297 return getOperand(2);
1300 void setCondition(Value *V) {
1301 assert(isConditional() && "Cannot set condition of unconditional branch!");
1305 // setUnconditionalDest - Change the current branch to an unconditional branch
1306 // targeting the specified block.
1307 // FIXME: Eliminate this ugly method.
1308 void setUnconditionalDest(BasicBlock *Dest) {
1309 if (isConditional()) { // Convert this to an uncond branch.
1314 setOperand(0, reinterpret_cast<Value*>(Dest));
1317 unsigned getNumSuccessors() const { return 1+isConditional(); }
1319 BasicBlock *getSuccessor(unsigned i) const {
1320 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1321 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1322 cast<BasicBlock>(getOperand(1));
1325 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1326 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1327 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1330 // Methods for support type inquiry through isa, cast, and dyn_cast:
1331 static inline bool classof(const BranchInst *) { return true; }
1332 static inline bool classof(const Instruction *I) {
1333 return (I->getOpcode() == Instruction::Br);
1335 static inline bool classof(const Value *V) {
1336 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1339 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1340 virtual unsigned getNumSuccessorsV() const;
1341 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1344 //===----------------------------------------------------------------------===//
1346 //===----------------------------------------------------------------------===//
1348 //===---------------------------------------------------------------------------
1349 /// SwitchInst - Multiway switch
1351 class SwitchInst : public TerminatorInst {
1352 unsigned ReservedSpace;
1353 // Operand[0] = Value to switch on
1354 // Operand[1] = Default basic block destination
1355 // Operand[2n ] = Value to match
1356 // Operand[2n+1] = BasicBlock to go to on match
1357 SwitchInst(const SwitchInst &RI);
1358 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1359 void resizeOperands(unsigned No);
1361 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1362 /// switch on and a default destination. The number of additional cases can
1363 /// be specified here to make memory allocation more efficient. This
1364 /// constructor can also autoinsert before another instruction.
1365 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1366 Instruction *InsertBefore = 0)
1367 : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1368 init(Value, Default, NumCases);
1371 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1372 /// switch on and a default destination. The number of additional cases can
1373 /// be specified here to make memory allocation more efficient. This
1374 /// constructor also autoinserts at the end of the specified BasicBlock.
1375 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1376 BasicBlock *InsertAtEnd)
1377 : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1378 init(Value, Default, NumCases);
1383 // Accessor Methods for Switch stmt
1384 inline Value *getCondition() const { return getOperand(0); }
1385 void setCondition(Value *V) { setOperand(0, V); }
1387 inline BasicBlock *getDefaultDest() const {
1388 return cast<BasicBlock>(getOperand(1));
1391 /// getNumCases - return the number of 'cases' in this switch instruction.
1392 /// Note that case #0 is always the default case.
1393 unsigned getNumCases() const {
1394 return getNumOperands()/2;
1397 /// getCaseValue - Return the specified case value. Note that case #0, the
1398 /// default destination, does not have a case value.
1399 ConstantInt *getCaseValue(unsigned i) {
1400 assert(i && i < getNumCases() && "Illegal case value to get!");
1401 return getSuccessorValue(i);
1404 /// getCaseValue - Return the specified case value. Note that case #0, the
1405 /// default destination, does not have a case value.
1406 const ConstantInt *getCaseValue(unsigned i) const {
1407 assert(i && i < getNumCases() && "Illegal case value to get!");
1408 return getSuccessorValue(i);
1411 /// findCaseValue - Search all of the case values for the specified constant.
1412 /// If it is explicitly handled, return the case number of it, otherwise
1413 /// return 0 to indicate that it is handled by the default handler.
1414 unsigned findCaseValue(const ConstantInt *C) const {
1415 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1416 if (getCaseValue(i) == C)
1421 /// findCaseDest - Finds the unique case value for a given successor. Returns
1422 /// null if the successor is not found, not unique, or is the default case.
1423 ConstantInt *findCaseDest(BasicBlock *BB) {
1424 if (BB == getDefaultDest()) return NULL;
1426 ConstantInt *CI = NULL;
1427 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1428 if (getSuccessor(i) == BB) {
1429 if (CI) return NULL; // Multiple cases lead to BB.
1430 else CI = getCaseValue(i);
1436 /// addCase - Add an entry to the switch instruction...
1438 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1440 /// removeCase - This method removes the specified successor from the switch
1441 /// instruction. Note that this cannot be used to remove the default
1442 /// destination (successor #0).
1444 void removeCase(unsigned idx);
1446 virtual SwitchInst *clone() const;
1448 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1449 BasicBlock *getSuccessor(unsigned idx) const {
1450 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1451 return cast<BasicBlock>(getOperand(idx*2+1));
1453 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1454 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1455 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1458 // getSuccessorValue - Return the value associated with the specified
1460 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1461 assert(idx < getNumSuccessors() && "Successor # out of range!");
1462 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1465 // Methods for support type inquiry through isa, cast, and dyn_cast:
1466 static inline bool classof(const SwitchInst *) { return true; }
1467 static inline bool classof(const Instruction *I) {
1468 return I->getOpcode() == Instruction::Switch;
1470 static inline bool classof(const Value *V) {
1471 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1474 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1475 virtual unsigned getNumSuccessorsV() const;
1476 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1479 //===----------------------------------------------------------------------===//
1481 //===----------------------------------------------------------------------===//
1483 //===---------------------------------------------------------------------------
1485 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1486 /// calling convention of the call.
1488 class InvokeInst : public TerminatorInst {
1489 InvokeInst(const InvokeInst &BI);
1490 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1491 const std::vector<Value*> &Params);
1493 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1494 const std::vector<Value*> &Params, const std::string &Name = "",
1495 Instruction *InsertBefore = 0);
1496 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1497 const std::vector<Value*> &Params, const std::string &Name,
1498 BasicBlock *InsertAtEnd);
1501 virtual InvokeInst *clone() const;
1503 bool mayWriteToMemory() const { return true; }
1505 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1507 unsigned getCallingConv() const { return SubclassData; }
1508 void setCallingConv(unsigned CC) {
1512 /// getCalledFunction - Return the function called, or null if this is an
1513 /// indirect function invocation.
1515 Function *getCalledFunction() const {
1516 return dyn_cast<Function>(getOperand(0));
1519 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1520 inline Value *getCalledValue() const { return getOperand(0); }
1522 // get*Dest - Return the destination basic blocks...
1523 BasicBlock *getNormalDest() const {
1524 return cast<BasicBlock>(getOperand(1));
1526 BasicBlock *getUnwindDest() const {
1527 return cast<BasicBlock>(getOperand(2));
1529 void setNormalDest(BasicBlock *B) {
1530 setOperand(1, reinterpret_cast<Value*>(B));
1533 void setUnwindDest(BasicBlock *B) {
1534 setOperand(2, reinterpret_cast<Value*>(B));
1537 inline BasicBlock *getSuccessor(unsigned i) const {
1538 assert(i < 2 && "Successor # out of range for invoke!");
1539 return i == 0 ? getNormalDest() : getUnwindDest();
1542 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1543 assert(idx < 2 && "Successor # out of range for invoke!");
1544 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1547 unsigned getNumSuccessors() const { return 2; }
1549 // Methods for support type inquiry through isa, cast, and dyn_cast:
1550 static inline bool classof(const InvokeInst *) { return true; }
1551 static inline bool classof(const Instruction *I) {
1552 return (I->getOpcode() == Instruction::Invoke);
1554 static inline bool classof(const Value *V) {
1555 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1558 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1559 virtual unsigned getNumSuccessorsV() const;
1560 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1564 //===----------------------------------------------------------------------===//
1566 //===----------------------------------------------------------------------===//
1568 //===---------------------------------------------------------------------------
1569 /// UnwindInst - Immediately exit the current function, unwinding the stack
1570 /// until an invoke instruction is found.
1572 class UnwindInst : public TerminatorInst {
1574 explicit UnwindInst(Instruction *InsertBefore = 0)
1575 : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
1577 explicit UnwindInst(BasicBlock *InsertAtEnd)
1578 : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
1581 virtual UnwindInst *clone() const;
1583 unsigned getNumSuccessors() const { return 0; }
1585 // Methods for support type inquiry through isa, cast, and dyn_cast:
1586 static inline bool classof(const UnwindInst *) { return true; }
1587 static inline bool classof(const Instruction *I) {
1588 return I->getOpcode() == Instruction::Unwind;
1590 static inline bool classof(const Value *V) {
1591 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1594 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1595 virtual unsigned getNumSuccessorsV() const;
1596 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1599 //===----------------------------------------------------------------------===//
1600 // UnreachableInst Class
1601 //===----------------------------------------------------------------------===//
1603 //===---------------------------------------------------------------------------
1604 /// UnreachableInst - This function has undefined behavior. In particular, the
1605 /// presence of this instruction indicates some higher level knowledge that the
1606 /// end of the block cannot be reached.
1608 class UnreachableInst : public TerminatorInst {
1610 explicit UnreachableInst(Instruction *InsertBefore = 0)
1611 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
1613 explicit UnreachableInst(BasicBlock *InsertAtEnd)
1614 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
1617 virtual UnreachableInst *clone() const;
1619 unsigned getNumSuccessors() const { return 0; }
1621 // Methods for support type inquiry through isa, cast, and dyn_cast:
1622 static inline bool classof(const UnreachableInst *) { return true; }
1623 static inline bool classof(const Instruction *I) {
1624 return I->getOpcode() == Instruction::Unreachable;
1626 static inline bool classof(const Value *V) {
1627 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1630 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1631 virtual unsigned getNumSuccessorsV() const;
1632 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1635 //===----------------------------------------------------------------------===//
1637 //===----------------------------------------------------------------------===//
1639 /// @brief This class represents a truncation of integer types.
1640 class TruncInst : public CastInst {
1641 /// Private copy constructor
1642 TruncInst(const TruncInst &CI)
1643 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1646 /// @brief Constructor with insert-before-instruction semantics
1648 Value *S, ///< The value to be truncated
1649 const Type *Ty, ///< The (smaller) type to truncate to
1650 const std::string &Name = "", ///< A name for the new instruction
1651 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1654 /// @brief Constructor with insert-at-end-of-block semantics
1656 Value *S, ///< The value to be truncated
1657 const Type *Ty, ///< The (smaller) type to truncate to
1658 const std::string &Name, ///< A name for the new instruction
1659 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1662 /// @brief Clone an identical TruncInst
1663 virtual CastInst *clone() const;
1665 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1666 static inline bool classof(const TruncInst *) { return true; }
1667 static inline bool classof(const Instruction *I) {
1668 return I->getOpcode() == Trunc;
1670 static inline bool classof(const Value *V) {
1671 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1675 //===----------------------------------------------------------------------===//
1677 //===----------------------------------------------------------------------===//
1679 /// @brief This class represents zero extension of integer types.
1680 class ZExtInst : public CastInst {
1681 /// @brief Private copy constructor
1682 ZExtInst(const ZExtInst &CI)
1683 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1686 /// @brief Constructor with insert-before-instruction semantics
1688 Value *S, ///< The value to be zero extended
1689 const Type *Ty, ///< The type to zero extend to
1690 const std::string &Name = "", ///< A name for the new instruction
1691 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1694 /// @brief Constructor with insert-at-end semantics.
1696 Value *S, ///< The value to be zero extended
1697 const Type *Ty, ///< The type to zero extend to
1698 const std::string &Name, ///< A name for the new instruction
1699 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1702 /// @brief Clone an identical ZExtInst
1703 virtual CastInst *clone() const;
1705 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1706 static inline bool classof(const ZExtInst *) { return true; }
1707 static inline bool classof(const Instruction *I) {
1708 return I->getOpcode() == ZExt;
1710 static inline bool classof(const Value *V) {
1711 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1715 //===----------------------------------------------------------------------===//
1717 //===----------------------------------------------------------------------===//
1719 /// @brief This class represents a sign extension of integer types.
1720 class SExtInst : public CastInst {
1721 /// @brief Private copy constructor
1722 SExtInst(const SExtInst &CI)
1723 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1726 /// @brief Constructor with insert-before-instruction semantics
1728 Value *S, ///< The value to be sign extended
1729 const Type *Ty, ///< The type to sign extend to
1730 const std::string &Name = "", ///< A name for the new instruction
1731 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1734 /// @brief Constructor with insert-at-end-of-block semantics
1736 Value *S, ///< The value to be sign extended
1737 const Type *Ty, ///< The type to sign extend to
1738 const std::string &Name, ///< A name for the new instruction
1739 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1742 /// @brief Clone an identical SExtInst
1743 virtual CastInst *clone() const;
1745 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1746 static inline bool classof(const SExtInst *) { return true; }
1747 static inline bool classof(const Instruction *I) {
1748 return I->getOpcode() == SExt;
1750 static inline bool classof(const Value *V) {
1751 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1755 //===----------------------------------------------------------------------===//
1756 // FPTruncInst Class
1757 //===----------------------------------------------------------------------===//
1759 /// @brief This class represents a truncation of floating point types.
1760 class FPTruncInst : public CastInst {
1761 FPTruncInst(const FPTruncInst &CI)
1762 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1765 /// @brief Constructor with insert-before-instruction semantics
1767 Value *S, ///< The value to be truncated
1768 const Type *Ty, ///< The type to truncate to
1769 const std::string &Name = "", ///< A name for the new instruction
1770 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1773 /// @brief Constructor with insert-before-instruction semantics
1775 Value *S, ///< The value to be truncated
1776 const Type *Ty, ///< The type to truncate to
1777 const std::string &Name, ///< A name for the new instruction
1778 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1781 /// @brief Clone an identical FPTruncInst
1782 virtual CastInst *clone() const;
1784 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1785 static inline bool classof(const FPTruncInst *) { return true; }
1786 static inline bool classof(const Instruction *I) {
1787 return I->getOpcode() == FPTrunc;
1789 static inline bool classof(const Value *V) {
1790 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1794 //===----------------------------------------------------------------------===//
1796 //===----------------------------------------------------------------------===//
1798 /// @brief This class represents an extension of floating point types.
1799 class FPExtInst : public CastInst {
1800 FPExtInst(const FPExtInst &CI)
1801 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1804 /// @brief Constructor with insert-before-instruction semantics
1806 Value *S, ///< The value to be extended
1807 const Type *Ty, ///< The type to extend to
1808 const std::string &Name = "", ///< A name for the new instruction
1809 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1812 /// @brief Constructor with insert-at-end-of-block semantics
1814 Value *S, ///< The value to be extended
1815 const Type *Ty, ///< The type to extend to
1816 const std::string &Name, ///< A name for the new instruction
1817 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1820 /// @brief Clone an identical FPExtInst
1821 virtual CastInst *clone() const;
1823 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1824 static inline bool classof(const FPExtInst *) { return true; }
1825 static inline bool classof(const Instruction *I) {
1826 return I->getOpcode() == FPExt;
1828 static inline bool classof(const Value *V) {
1829 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1833 //===----------------------------------------------------------------------===//
1835 //===----------------------------------------------------------------------===//
1837 /// @brief This class represents a cast unsigned integer to floating point.
1838 class UIToFPInst : public CastInst {
1839 UIToFPInst(const UIToFPInst &CI)
1840 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1843 /// @brief Constructor with insert-before-instruction semantics
1845 Value *S, ///< The value to be converted
1846 const Type *Ty, ///< The type to convert to
1847 const std::string &Name = "", ///< A name for the new instruction
1848 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1851 /// @brief Constructor with insert-at-end-of-block semantics
1853 Value *S, ///< The value to be converted
1854 const Type *Ty, ///< The type to convert to
1855 const std::string &Name, ///< A name for the new instruction
1856 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1859 /// @brief Clone an identical UIToFPInst
1860 virtual CastInst *clone() const;
1862 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1863 static inline bool classof(const UIToFPInst *) { return true; }
1864 static inline bool classof(const Instruction *I) {
1865 return I->getOpcode() == UIToFP;
1867 static inline bool classof(const Value *V) {
1868 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1872 //===----------------------------------------------------------------------===//
1874 //===----------------------------------------------------------------------===//
1876 /// @brief This class represents a cast from signed integer to floating point.
1877 class SIToFPInst : public CastInst {
1878 SIToFPInst(const SIToFPInst &CI)
1879 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1882 /// @brief Constructor with insert-before-instruction semantics
1884 Value *S, ///< The value to be converted
1885 const Type *Ty, ///< The type to convert to
1886 const std::string &Name = "", ///< A name for the new instruction
1887 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1890 /// @brief Constructor with insert-at-end-of-block semantics
1892 Value *S, ///< The value to be converted
1893 const Type *Ty, ///< The type to convert to
1894 const std::string &Name, ///< A name for the new instruction
1895 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1898 /// @brief Clone an identical SIToFPInst
1899 virtual CastInst *clone() const;
1901 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1902 static inline bool classof(const SIToFPInst *) { return true; }
1903 static inline bool classof(const Instruction *I) {
1904 return I->getOpcode() == SIToFP;
1906 static inline bool classof(const Value *V) {
1907 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1911 //===----------------------------------------------------------------------===//
1913 //===----------------------------------------------------------------------===//
1915 /// @brief This class represents a cast from floating point to unsigned integer
1916 class FPToUIInst : public CastInst {
1917 FPToUIInst(const FPToUIInst &CI)
1918 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1921 /// @brief Constructor with insert-before-instruction semantics
1923 Value *S, ///< The value to be converted
1924 const Type *Ty, ///< The type to convert to
1925 const std::string &Name = "", ///< A name for the new instruction
1926 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1929 /// @brief Constructor with insert-at-end-of-block semantics
1931 Value *S, ///< The value to be converted
1932 const Type *Ty, ///< The type to convert to
1933 const std::string &Name, ///< A name for the new instruction
1934 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
1937 /// @brief Clone an identical FPToUIInst
1938 virtual CastInst *clone() const;
1940 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1941 static inline bool classof(const FPToUIInst *) { return true; }
1942 static inline bool classof(const Instruction *I) {
1943 return I->getOpcode() == FPToUI;
1945 static inline bool classof(const Value *V) {
1946 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1950 //===----------------------------------------------------------------------===//
1952 //===----------------------------------------------------------------------===//
1954 /// @brief This class represents a cast from floating point to signed integer.
1955 class FPToSIInst : public CastInst {
1956 FPToSIInst(const FPToSIInst &CI)
1957 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
1960 /// @brief Constructor with insert-before-instruction semantics
1962 Value *S, ///< The value to be converted
1963 const Type *Ty, ///< The type to convert to
1964 const std::string &Name = "", ///< A name for the new instruction
1965 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1968 /// @brief Constructor with insert-at-end-of-block semantics
1970 Value *S, ///< The value to be converted
1971 const Type *Ty, ///< The type to convert to
1972 const std::string &Name, ///< A name for the new instruction
1973 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1976 /// @brief Clone an identical FPToSIInst
1977 virtual CastInst *clone() const;
1979 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1980 static inline bool classof(const FPToSIInst *) { return true; }
1981 static inline bool classof(const Instruction *I) {
1982 return I->getOpcode() == FPToSI;
1984 static inline bool classof(const Value *V) {
1985 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1989 //===----------------------------------------------------------------------===//
1990 // IntToPtrInst Class
1991 //===----------------------------------------------------------------------===//
1993 /// @brief This class represents a cast from an integer to a pointer.
1994 class IntToPtrInst : public CastInst {
1995 IntToPtrInst(const IntToPtrInst &CI)
1996 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
1999 /// @brief Constructor with insert-before-instruction semantics
2001 Value *S, ///< The value to be converted
2002 const Type *Ty, ///< The type to convert to
2003 const std::string &Name = "", ///< A name for the new instruction
2004 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2007 /// @brief Constructor with insert-at-end-of-block semantics
2009 Value *S, ///< The value to be converted
2010 const Type *Ty, ///< The type to convert to
2011 const std::string &Name, ///< A name for the new instruction
2012 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2015 /// @brief Clone an identical IntToPtrInst
2016 virtual CastInst *clone() const;
2018 // Methods for support type inquiry through isa, cast, and dyn_cast:
2019 static inline bool classof(const IntToPtrInst *) { return true; }
2020 static inline bool classof(const Instruction *I) {
2021 return I->getOpcode() == IntToPtr;
2023 static inline bool classof(const Value *V) {
2024 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2028 //===----------------------------------------------------------------------===//
2029 // PtrToIntInst Class
2030 //===----------------------------------------------------------------------===//
2032 /// @brief This class represents a cast from a pointer to an integer
2033 class PtrToIntInst : public CastInst {
2034 PtrToIntInst(const PtrToIntInst &CI)
2035 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2038 /// @brief Constructor with insert-before-instruction semantics
2040 Value *S, ///< The value to be converted
2041 const Type *Ty, ///< The type to convert to
2042 const std::string &Name = "", ///< A name for the new instruction
2043 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2046 /// @brief Constructor with insert-at-end-of-block semantics
2048 Value *S, ///< The value to be converted
2049 const Type *Ty, ///< The type to convert to
2050 const std::string &Name, ///< A name for the new instruction
2051 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2054 /// @brief Clone an identical PtrToIntInst
2055 virtual CastInst *clone() const;
2057 // Methods for support type inquiry through isa, cast, and dyn_cast:
2058 static inline bool classof(const PtrToIntInst *) { return true; }
2059 static inline bool classof(const Instruction *I) {
2060 return I->getOpcode() == PtrToInt;
2062 static inline bool classof(const Value *V) {
2063 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2067 //===----------------------------------------------------------------------===//
2068 // BitCastInst Class
2069 //===----------------------------------------------------------------------===//
2071 /// @brief This class represents a no-op cast from one type to another.
2072 class BitCastInst : public CastInst {
2073 BitCastInst(const BitCastInst &CI)
2074 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2077 /// @brief Constructor with insert-before-instruction semantics
2079 Value *S, ///< The value to be casted
2080 const Type *Ty, ///< The type to casted to
2081 const std::string &Name = "", ///< A name for the new instruction
2082 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2085 /// @brief Constructor with insert-at-end-of-block semantics
2087 Value *S, ///< The value to be casted
2088 const Type *Ty, ///< The type to casted to
2089 const std::string &Name, ///< A name for the new instruction
2090 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2093 /// @brief Clone an identical BitCastInst
2094 virtual CastInst *clone() const;
2096 // Methods for support type inquiry through isa, cast, and dyn_cast:
2097 static inline bool classof(const BitCastInst *) { return true; }
2098 static inline bool classof(const Instruction *I) {
2099 return I->getOpcode() == BitCast;
2101 static inline bool classof(const Value *V) {
2102 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2106 } // End llvm namespace