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 // Accessor methods for consistency with other memory operations
196 Value *getPointerOperand() { return getOperand(0); }
197 const Value *getPointerOperand() const { return getOperand(0); }
199 // Methods for support type inquiry through isa, cast, and dyn_cast:
200 static inline bool classof(const FreeInst *) { return true; }
201 static inline bool classof(const Instruction *I) {
202 return (I->getOpcode() == Instruction::Free);
204 static inline bool classof(const Value *V) {
205 return isa<Instruction>(V) && classof(cast<Instruction>(V));
210 //===----------------------------------------------------------------------===//
212 //===----------------------------------------------------------------------===//
214 /// LoadInst - an instruction for reading from memory. This uses the
215 /// SubclassData field in Value to store whether or not the load is volatile.
217 class LoadInst : public UnaryInstruction {
219 LoadInst(const LoadInst &LI)
220 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
221 setVolatile(LI.isVolatile());
222 setAlignment(LI.getAlignment());
230 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
231 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
232 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false,
233 Instruction *InsertBefore = 0);
234 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
235 Instruction *InsertBefore = 0);
236 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
237 BasicBlock *InsertAtEnd);
238 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
239 BasicBlock *InsertAtEnd);
241 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
242 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
243 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
244 Instruction *InsertBefore = 0);
245 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
246 BasicBlock *InsertAtEnd);
248 /// isVolatile - Return true if this is a load from a volatile memory
251 bool isVolatile() const { return SubclassData & 1; }
253 /// setVolatile - Specify whether this is a volatile load or not.
255 void setVolatile(bool V) {
256 SubclassData = (SubclassData & ~1) | V;
259 virtual LoadInst *clone() const;
261 /// getAlignment - Return the alignment of the access that is being performed
263 unsigned getAlignment() const {
264 return (1 << (SubclassData>>1)) >> 1;
267 void setAlignment(unsigned Align);
269 Value *getPointerOperand() { return getOperand(0); }
270 const Value *getPointerOperand() const { return getOperand(0); }
271 static unsigned getPointerOperandIndex() { return 0U; }
273 // Methods for support type inquiry through isa, cast, and dyn_cast:
274 static inline bool classof(const LoadInst *) { return true; }
275 static inline bool classof(const Instruction *I) {
276 return I->getOpcode() == Instruction::Load;
278 static inline bool classof(const Value *V) {
279 return isa<Instruction>(V) && classof(cast<Instruction>(V));
284 //===----------------------------------------------------------------------===//
286 //===----------------------------------------------------------------------===//
288 /// StoreInst - an instruction for storing to memory
290 class StoreInst : public Instruction {
293 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
294 Ops[0].init(SI.Ops[0], this);
295 Ops[1].init(SI.Ops[1], this);
296 setVolatile(SI.isVolatile());
297 setAlignment(SI.getAlignment());
305 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
306 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
307 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
308 Instruction *InsertBefore = 0);
309 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
310 unsigned Align, Instruction *InsertBefore = 0);
311 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
312 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
313 unsigned Align, BasicBlock *InsertAtEnd);
316 /// isVolatile - Return true if this is a load from a volatile memory
319 bool isVolatile() const { return SubclassData & 1; }
321 /// setVolatile - Specify whether this is a volatile load or not.
323 void setVolatile(bool V) {
324 SubclassData = (SubclassData & ~1) | V;
327 /// Transparently provide more efficient getOperand methods.
328 Value *getOperand(unsigned i) const {
329 assert(i < 2 && "getOperand() out of range!");
332 void setOperand(unsigned i, Value *Val) {
333 assert(i < 2 && "setOperand() out of range!");
336 unsigned getNumOperands() const { return 2; }
338 /// getAlignment - Return the alignment of the access that is being performed
340 unsigned getAlignment() const {
341 return (1 << (SubclassData>>1)) >> 1;
344 void setAlignment(unsigned Align);
346 virtual StoreInst *clone() const;
348 Value *getPointerOperand() { return getOperand(1); }
349 const Value *getPointerOperand() const { return getOperand(1); }
350 static unsigned getPointerOperandIndex() { return 1U; }
352 // Methods for support type inquiry through isa, cast, and dyn_cast:
353 static inline bool classof(const StoreInst *) { return true; }
354 static inline bool classof(const Instruction *I) {
355 return I->getOpcode() == Instruction::Store;
357 static inline bool classof(const Value *V) {
358 return isa<Instruction>(V) && classof(cast<Instruction>(V));
363 //===----------------------------------------------------------------------===//
364 // GetElementPtrInst Class
365 //===----------------------------------------------------------------------===//
367 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
368 /// access elements of arrays and structs
370 class GetElementPtrInst : public Instruction {
371 GetElementPtrInst(const GetElementPtrInst &GEPI)
372 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
373 0, GEPI.getNumOperands()) {
374 Use *OL = OperandList = new Use[NumOperands];
375 Use *GEPIOL = GEPI.OperandList;
376 for (unsigned i = 0, E = NumOperands; i != E; ++i)
377 OL[i].init(GEPIOL[i], this);
379 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
380 void init(Value *Ptr, Value *Idx0, Value *Idx1);
381 void init(Value *Ptr, Value *Idx);
383 /// Constructors - Create a getelementptr instruction with a base pointer an
384 /// list of indices. The first ctor can optionally insert before an existing
385 /// instruction, the second appends the new instruction to the specified
387 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
388 const std::string &Name = "", Instruction *InsertBefore =0);
389 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
390 const std::string &Name, BasicBlock *InsertAtEnd);
392 /// Constructors - These two constructors are convenience methods because one
393 /// and two index getelementptr instructions are so common.
394 GetElementPtrInst(Value *Ptr, Value *Idx,
395 const std::string &Name = "", Instruction *InsertBefore =0);
396 GetElementPtrInst(Value *Ptr, Value *Idx,
397 const std::string &Name, BasicBlock *InsertAtEnd);
398 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
399 const std::string &Name = "", Instruction *InsertBefore =0);
400 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
401 const std::string &Name, BasicBlock *InsertAtEnd);
402 ~GetElementPtrInst();
404 virtual GetElementPtrInst *clone() const;
406 // getType - Overload to return most specific pointer type...
407 inline const PointerType *getType() const {
408 return reinterpret_cast<const PointerType*>(Instruction::getType());
411 /// getIndexedType - Returns the type of the element that would be loaded with
412 /// a load instruction with the specified parameters.
414 /// A null type is returned if the indices are invalid for the specified
417 static const Type *getIndexedType(const Type *Ptr,
418 Value* const *Idx, unsigned NumIdx,
419 bool AllowStructLeaf = false);
421 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
422 bool AllowStructLeaf = false);
423 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
425 inline op_iterator idx_begin() { return op_begin()+1; }
426 inline const_op_iterator idx_begin() const { return op_begin()+1; }
427 inline op_iterator idx_end() { return op_end(); }
428 inline const_op_iterator idx_end() const { return op_end(); }
430 Value *getPointerOperand() {
431 return getOperand(0);
433 const Value *getPointerOperand() const {
434 return getOperand(0);
436 static unsigned getPointerOperandIndex() {
437 return 0U; // get index for modifying correct operand
440 inline unsigned getNumIndices() const { // Note: always non-negative
441 return getNumOperands() - 1;
444 inline bool hasIndices() const {
445 return getNumOperands() > 1;
448 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
449 /// zeros. If so, the result pointer and the first operand have the same
450 /// value, just potentially different types.
451 bool hasAllZeroIndices() const;
453 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
454 /// constant integers. If so, the result pointer and the first operand have
455 /// a constant offset between them.
456 bool hasAllConstantIndices() const;
459 // Methods for support type inquiry through isa, cast, and dyn_cast:
460 static inline bool classof(const GetElementPtrInst *) { return true; }
461 static inline bool classof(const Instruction *I) {
462 return (I->getOpcode() == Instruction::GetElementPtr);
464 static inline bool classof(const Value *V) {
465 return isa<Instruction>(V) && classof(cast<Instruction>(V));
469 //===----------------------------------------------------------------------===//
471 //===----------------------------------------------------------------------===//
473 /// This instruction compares its operands according to the predicate given
474 /// to the constructor. It only operates on integers, pointers, or packed
475 /// vectors of integrals. The two operands must be the same type.
476 /// @brief Represent an integer comparison operator.
477 class ICmpInst: public CmpInst {
479 /// This enumeration lists the possible predicates for the ICmpInst. The
480 /// values in the range 0-31 are reserved for FCmpInst while values in the
481 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
482 /// predicate values are not overlapping between the classes.
484 ICMP_EQ = 32, ///< equal
485 ICMP_NE = 33, ///< not equal
486 ICMP_UGT = 34, ///< unsigned greater than
487 ICMP_UGE = 35, ///< unsigned greater or equal
488 ICMP_ULT = 36, ///< unsigned less than
489 ICMP_ULE = 37, ///< unsigned less or equal
490 ICMP_SGT = 38, ///< signed greater than
491 ICMP_SGE = 39, ///< signed greater or equal
492 ICMP_SLT = 40, ///< signed less than
493 ICMP_SLE = 41, ///< signed less or equal
494 FIRST_ICMP_PREDICATE = ICMP_EQ,
495 LAST_ICMP_PREDICATE = ICMP_SLE,
496 BAD_ICMP_PREDICATE = ICMP_SLE + 1
499 /// @brief Constructor with insert-before-instruction semantics.
501 Predicate pred, ///< The predicate to use for the comparison
502 Value *LHS, ///< The left-hand-side of the expression
503 Value *RHS, ///< The right-hand-side of the expression
504 const std::string &Name = "", ///< Name of the instruction
505 Instruction *InsertBefore = 0 ///< Where to insert
506 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
509 /// @brief Constructor with insert-at-block-end semantics.
511 Predicate pred, ///< The predicate to use for the comparison
512 Value *LHS, ///< The left-hand-side of the expression
513 Value *RHS, ///< The right-hand-side of the expression
514 const std::string &Name, ///< Name of the instruction
515 BasicBlock *InsertAtEnd ///< Block to insert into.
516 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
519 /// @brief Return the predicate for this instruction.
520 Predicate getPredicate() const { return Predicate(SubclassData); }
522 /// @brief Set the predicate for this instruction to the specified value.
523 void setPredicate(Predicate P) { SubclassData = P; }
525 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
526 /// @returns the inverse predicate for the instruction's current predicate.
527 /// @brief Return the inverse of the instruction's predicate.
528 Predicate getInversePredicate() const {
529 return getInversePredicate(getPredicate());
532 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
533 /// @returns the inverse predicate for predicate provided in \p pred.
534 /// @brief Return the inverse of a given predicate
535 static Predicate getInversePredicate(Predicate pred);
537 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
538 /// @returns the predicate that would be the result of exchanging the two
539 /// operands of the ICmpInst instruction without changing the result
541 /// @brief Return the predicate as if the operands were swapped
542 Predicate getSwappedPredicate() const {
543 return getSwappedPredicate(getPredicate());
546 /// This is a static version that you can use without an instruction
548 /// @brief Return the predicate as if the operands were swapped.
549 static Predicate getSwappedPredicate(Predicate pred);
551 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
552 /// @returns the predicate that would be the result if the operand were
553 /// regarded as signed.
554 /// @brief Return the signed version of the predicate
555 Predicate getSignedPredicate() const {
556 return getSignedPredicate(getPredicate());
559 /// This is a static version that you can use without an instruction.
560 /// @brief Return the signed version of the predicate.
561 static Predicate getSignedPredicate(Predicate pred);
563 /// This also tests for commutativity. If isEquality() returns true then
564 /// the predicate is also commutative.
565 /// @returns true if the predicate of this instruction is EQ or NE.
566 /// @brief Determine if this is an equality predicate.
567 bool isEquality() const {
568 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
571 /// @returns true if the predicate of this ICmpInst is commutative
572 /// @brief Determine if this relation is commutative.
573 bool isCommutative() const { return isEquality(); }
575 /// @returns true if the predicate is relational (not EQ or NE).
576 /// @brief Determine if this a relational predicate.
577 bool isRelational() const {
578 return !isEquality();
581 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
582 /// @brief Determine if this instruction's predicate is signed.
583 bool isSignedPredicate() { return isSignedPredicate(getPredicate()); }
585 /// @returns true if the predicate provided is signed, false otherwise
586 /// @brief Determine if the predicate is signed.
587 static bool isSignedPredicate(Predicate pred);
589 /// Initialize a set of values that all satisfy the predicate with C.
590 /// @brief Make a ConstantRange for a relation with a constant value.
591 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
593 /// Exchange the two operands to this instruction in such a way that it does
594 /// not modify the semantics of the instruction. The predicate value may be
595 /// changed to retain the same result if the predicate is order dependent
597 /// @brief Swap operands and adjust predicate.
598 void swapOperands() {
599 SubclassData = getSwappedPredicate();
600 std::swap(Ops[0], Ops[1]);
603 // Methods for support type inquiry through isa, cast, and dyn_cast:
604 static inline bool classof(const ICmpInst *) { return true; }
605 static inline bool classof(const Instruction *I) {
606 return I->getOpcode() == Instruction::ICmp;
608 static inline bool classof(const Value *V) {
609 return isa<Instruction>(V) && classof(cast<Instruction>(V));
613 //===----------------------------------------------------------------------===//
615 //===----------------------------------------------------------------------===//
617 /// This instruction compares its operands according to the predicate given
618 /// to the constructor. It only operates on floating point values or packed
619 /// vectors of floating point values. The operands must be identical types.
620 /// @brief Represents a floating point comparison operator.
621 class FCmpInst: public CmpInst {
623 /// This enumeration lists the possible predicates for the FCmpInst. Values
624 /// in the range 0-31 are reserved for FCmpInst.
626 // Opcode U L G E Intuitive operation
627 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
628 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
629 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
630 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
631 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
632 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
633 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
634 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
635 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
636 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
637 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
638 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
639 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
640 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
641 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
642 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
643 FIRST_FCMP_PREDICATE = FCMP_FALSE,
644 LAST_FCMP_PREDICATE = FCMP_TRUE,
645 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
648 /// @brief Constructor with insert-before-instruction semantics.
650 Predicate pred, ///< The predicate to use for the comparison
651 Value *LHS, ///< The left-hand-side of the expression
652 Value *RHS, ///< The right-hand-side of the expression
653 const std::string &Name = "", ///< Name of the instruction
654 Instruction *InsertBefore = 0 ///< Where to insert
655 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
658 /// @brief Constructor with insert-at-block-end semantics.
660 Predicate pred, ///< The predicate to use for the comparison
661 Value *LHS, ///< The left-hand-side of the expression
662 Value *RHS, ///< The right-hand-side of the expression
663 const std::string &Name, ///< Name of the instruction
664 BasicBlock *InsertAtEnd ///< Block to insert into.
665 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
668 /// @brief Return the predicate for this instruction.
669 Predicate getPredicate() const { return Predicate(SubclassData); }
671 /// @brief Set the predicate for this instruction to the specified value.
672 void setPredicate(Predicate P) { SubclassData = P; }
674 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
675 /// @returns the inverse predicate for the instructions current predicate.
676 /// @brief Return the inverse of the predicate
677 Predicate getInversePredicate() const {
678 return getInversePredicate(getPredicate());
681 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
682 /// @returns the inverse predicate for \p pred.
683 /// @brief Return the inverse of a given predicate
684 static Predicate getInversePredicate(Predicate pred);
686 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
687 /// @returns the predicate that would be the result of exchanging the two
688 /// operands of the ICmpInst instruction without changing the result
690 /// @brief Return the predicate as if the operands were swapped
691 Predicate getSwappedPredicate() const {
692 return getSwappedPredicate(getPredicate());
695 /// This is a static version that you can use without an instruction
697 /// @brief Return the predicate as if the operands were swapped.
698 static Predicate getSwappedPredicate(Predicate Opcode);
700 /// This also tests for commutativity. If isEquality() returns true then
701 /// the predicate is also commutative. Only the equality predicates are
703 /// @returns true if the predicate of this instruction is EQ or NE.
704 /// @brief Determine if this is an equality predicate.
705 bool isEquality() const {
706 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
707 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
709 bool isCommutative() const { return isEquality(); }
711 /// @returns true if the predicate is relational (not EQ or NE).
712 /// @brief Determine if this a relational predicate.
713 bool isRelational() const { return !isEquality(); }
715 /// Exchange the two operands to this instruction in such a way that it does
716 /// not modify the semantics of the instruction. The predicate value may be
717 /// changed to retain the same result if the predicate is order dependent
719 /// @brief Swap operands and adjust predicate.
720 void swapOperands() {
721 SubclassData = getSwappedPredicate();
722 std::swap(Ops[0], Ops[1]);
725 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
726 static inline bool classof(const FCmpInst *) { return true; }
727 static inline bool classof(const Instruction *I) {
728 return I->getOpcode() == Instruction::FCmp;
730 static inline bool classof(const Value *V) {
731 return isa<Instruction>(V) && classof(cast<Instruction>(V));
735 //===----------------------------------------------------------------------===//
737 //===----------------------------------------------------------------------===//
739 /// CallInst - This class represents a function call, abstracting a target
740 /// machine's calling convention. This class uses low bit of the SubClassData
741 /// field to indicate whether or not this is a tail call. The rest of the bits
742 /// hold the calling convention of the call.
744 class CallInst : public Instruction {
745 ParamAttrsList *ParamAttrs; ///< parameter attributes for call
746 CallInst(const CallInst &CI);
747 void init(Value *Func, Value* const *Params, unsigned NumParams);
748 void init(Value *Func, Value *Actual1, Value *Actual2);
749 void init(Value *Func, Value *Actual);
750 void init(Value *Func);
753 CallInst(Value *F, Value* const *Args, unsigned NumArgs,
754 const std::string &Name = "", Instruction *InsertBefore = 0);
755 CallInst(Value *F, Value *const *Args, unsigned NumArgs,
756 const std::string &Name, BasicBlock *InsertAtEnd);
758 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
759 // actuals, respectively.
760 CallInst(Value *F, Value *Actual1, Value *Actual2,
761 const std::string& Name = "", Instruction *InsertBefore = 0);
762 CallInst(Value *F, Value *Actual1, Value *Actual2,
763 const std::string& Name, BasicBlock *InsertAtEnd);
764 CallInst(Value *F, Value *Actual, const std::string& Name = "",
765 Instruction *InsertBefore = 0);
766 CallInst(Value *F, Value *Actual, const std::string& Name,
767 BasicBlock *InsertAtEnd);
768 explicit CallInst(Value *F, const std::string &Name = "",
769 Instruction *InsertBefore = 0);
770 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
773 virtual CallInst *clone() const;
775 bool isTailCall() const { return SubclassData & 1; }
776 void setTailCall(bool isTailCall = true) {
777 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
780 /// getCallingConv/setCallingConv - Get or set the calling convention of this
782 unsigned getCallingConv() const { return SubclassData >> 1; }
783 void setCallingConv(unsigned CC) {
784 SubclassData = (SubclassData & 1) | (CC << 1);
787 /// Obtains a pointer to the ParamAttrsList object which holds the
788 /// parameter attributes information, if any.
789 /// @returns 0 if no attributes have been set.
790 /// @brief Get the parameter attributes.
791 ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
793 /// Sets the parameter attributes for this CallInst. To construct a
794 /// ParamAttrsList, see ParameterAttributes.h
795 /// @brief Set the parameter attributes.
796 void setParamAttrs(ParamAttrsList *attrs);
798 /// getCalledFunction - Return the function being called by this instruction
799 /// if it is a direct call. If it is a call through a function pointer,
801 Function *getCalledFunction() const {
802 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
805 /// getCalledValue - Get a pointer to the function that is invoked by this
807 inline const Value *getCalledValue() const { return getOperand(0); }
808 inline Value *getCalledValue() { return getOperand(0); }
810 // Methods for support type inquiry through isa, cast, and dyn_cast:
811 static inline bool classof(const CallInst *) { return true; }
812 static inline bool classof(const Instruction *I) {
813 return I->getOpcode() == Instruction::Call;
815 static inline bool classof(const Value *V) {
816 return isa<Instruction>(V) && classof(cast<Instruction>(V));
820 //===----------------------------------------------------------------------===//
822 //===----------------------------------------------------------------------===//
824 /// SelectInst - This class represents the LLVM 'select' instruction.
826 class SelectInst : public Instruction {
829 void init(Value *C, Value *S1, Value *S2) {
830 Ops[0].init(C, this);
831 Ops[1].init(S1, this);
832 Ops[2].init(S2, this);
835 SelectInst(const SelectInst &SI)
836 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
837 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
840 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
841 Instruction *InsertBefore = 0)
842 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
846 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
847 BasicBlock *InsertAtEnd)
848 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
853 Value *getCondition() const { return Ops[0]; }
854 Value *getTrueValue() const { return Ops[1]; }
855 Value *getFalseValue() const { return Ops[2]; }
857 /// Transparently provide more efficient getOperand methods.
858 Value *getOperand(unsigned i) const {
859 assert(i < 3 && "getOperand() out of range!");
862 void setOperand(unsigned i, Value *Val) {
863 assert(i < 3 && "setOperand() out of range!");
866 unsigned getNumOperands() const { return 3; }
868 OtherOps getOpcode() const {
869 return static_cast<OtherOps>(Instruction::getOpcode());
872 virtual SelectInst *clone() const;
874 // Methods for support type inquiry through isa, cast, and dyn_cast:
875 static inline bool classof(const SelectInst *) { return true; }
876 static inline bool classof(const Instruction *I) {
877 return I->getOpcode() == Instruction::Select;
879 static inline bool classof(const Value *V) {
880 return isa<Instruction>(V) && classof(cast<Instruction>(V));
884 //===----------------------------------------------------------------------===//
886 //===----------------------------------------------------------------------===//
888 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
889 /// an argument of the specified type given a va_list and increments that list
891 class VAArgInst : public UnaryInstruction {
892 VAArgInst(const VAArgInst &VAA)
893 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
895 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
896 Instruction *InsertBefore = 0)
897 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
900 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
901 BasicBlock *InsertAtEnd)
902 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
906 virtual VAArgInst *clone() const;
908 // Methods for support type inquiry through isa, cast, and dyn_cast:
909 static inline bool classof(const VAArgInst *) { return true; }
910 static inline bool classof(const Instruction *I) {
911 return I->getOpcode() == VAArg;
913 static inline bool classof(const Value *V) {
914 return isa<Instruction>(V) && classof(cast<Instruction>(V));
918 //===----------------------------------------------------------------------===//
919 // ExtractElementInst Class
920 //===----------------------------------------------------------------------===//
922 /// ExtractElementInst - This instruction extracts a single (scalar)
923 /// element from a VectorType value
925 class ExtractElementInst : public Instruction {
927 ExtractElementInst(const ExtractElementInst &EE) :
928 Instruction(EE.getType(), ExtractElement, Ops, 2) {
929 Ops[0].init(EE.Ops[0], this);
930 Ops[1].init(EE.Ops[1], this);
934 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
935 Instruction *InsertBefore = 0);
936 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
937 Instruction *InsertBefore = 0);
938 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
939 BasicBlock *InsertAtEnd);
940 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
941 BasicBlock *InsertAtEnd);
943 /// isValidOperands - Return true if an extractelement instruction can be
944 /// formed with the specified operands.
945 static bool isValidOperands(const Value *Vec, const Value *Idx);
947 virtual ExtractElementInst *clone() const;
949 /// Transparently provide more efficient getOperand methods.
950 Value *getOperand(unsigned i) const {
951 assert(i < 2 && "getOperand() out of range!");
954 void setOperand(unsigned i, Value *Val) {
955 assert(i < 2 && "setOperand() out of range!");
958 unsigned getNumOperands() const { return 2; }
960 // Methods for support type inquiry through isa, cast, and dyn_cast:
961 static inline bool classof(const ExtractElementInst *) { return true; }
962 static inline bool classof(const Instruction *I) {
963 return I->getOpcode() == Instruction::ExtractElement;
965 static inline bool classof(const Value *V) {
966 return isa<Instruction>(V) && classof(cast<Instruction>(V));
970 //===----------------------------------------------------------------------===//
971 // InsertElementInst Class
972 //===----------------------------------------------------------------------===//
974 /// InsertElementInst - This instruction inserts a single (scalar)
975 /// element into a VectorType value
977 class InsertElementInst : public Instruction {
979 InsertElementInst(const InsertElementInst &IE);
981 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
982 const std::string &Name = "",Instruction *InsertBefore = 0);
983 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
984 const std::string &Name = "",Instruction *InsertBefore = 0);
985 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
986 const std::string &Name, BasicBlock *InsertAtEnd);
987 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
988 const std::string &Name, BasicBlock *InsertAtEnd);
990 /// isValidOperands - Return true if an insertelement instruction can be
991 /// formed with the specified operands.
992 static bool isValidOperands(const Value *Vec, const Value *NewElt,
995 virtual InsertElementInst *clone() const;
997 /// getType - Overload to return most specific vector type.
999 inline const VectorType *getType() const {
1000 return reinterpret_cast<const VectorType*>(Instruction::getType());
1003 /// Transparently provide more efficient getOperand methods.
1004 Value *getOperand(unsigned i) const {
1005 assert(i < 3 && "getOperand() out of range!");
1008 void setOperand(unsigned i, Value *Val) {
1009 assert(i < 3 && "setOperand() out of range!");
1012 unsigned getNumOperands() const { return 3; }
1014 // Methods for support type inquiry through isa, cast, and dyn_cast:
1015 static inline bool classof(const InsertElementInst *) { return true; }
1016 static inline bool classof(const Instruction *I) {
1017 return I->getOpcode() == Instruction::InsertElement;
1019 static inline bool classof(const Value *V) {
1020 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1024 //===----------------------------------------------------------------------===//
1025 // ShuffleVectorInst Class
1026 //===----------------------------------------------------------------------===//
1028 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1031 class ShuffleVectorInst : public Instruction {
1033 ShuffleVectorInst(const ShuffleVectorInst &IE);
1035 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1036 const std::string &Name = "", Instruction *InsertBefor = 0);
1037 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1038 const std::string &Name, BasicBlock *InsertAtEnd);
1040 /// isValidOperands - Return true if a shufflevector instruction can be
1041 /// formed with the specified operands.
1042 static bool isValidOperands(const Value *V1, const Value *V2,
1045 virtual ShuffleVectorInst *clone() const;
1047 /// getType - Overload to return most specific vector type.
1049 inline const VectorType *getType() const {
1050 return reinterpret_cast<const VectorType*>(Instruction::getType());
1053 /// Transparently provide more efficient getOperand methods.
1054 Value *getOperand(unsigned i) const {
1055 assert(i < 3 && "getOperand() out of range!");
1058 void setOperand(unsigned i, Value *Val) {
1059 assert(i < 3 && "setOperand() out of range!");
1062 unsigned getNumOperands() const { return 3; }
1064 // Methods for support type inquiry through isa, cast, and dyn_cast:
1065 static inline bool classof(const ShuffleVectorInst *) { return true; }
1066 static inline bool classof(const Instruction *I) {
1067 return I->getOpcode() == Instruction::ShuffleVector;
1069 static inline bool classof(const Value *V) {
1070 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1075 //===----------------------------------------------------------------------===//
1077 //===----------------------------------------------------------------------===//
1079 // PHINode - The PHINode class is used to represent the magical mystical PHI
1080 // node, that can not exist in nature, but can be synthesized in a computer
1081 // scientist's overactive imagination.
1083 class PHINode : public Instruction {
1084 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1085 /// the number actually in use.
1086 unsigned ReservedSpace;
1087 PHINode(const PHINode &PN);
1089 explicit PHINode(const Type *Ty, const std::string &Name = "",
1090 Instruction *InsertBefore = 0)
1091 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1096 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1097 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1104 /// reserveOperandSpace - This method can be used to avoid repeated
1105 /// reallocation of PHI operand lists by reserving space for the correct
1106 /// number of operands before adding them. Unlike normal vector reserves,
1107 /// this method can also be used to trim the operand space.
1108 void reserveOperandSpace(unsigned NumValues) {
1109 resizeOperands(NumValues*2);
1112 virtual PHINode *clone() const;
1114 /// getNumIncomingValues - Return the number of incoming edges
1116 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1118 /// getIncomingValue - Return incoming value number x
1120 Value *getIncomingValue(unsigned i) const {
1121 assert(i*2 < getNumOperands() && "Invalid value number!");
1122 return getOperand(i*2);
1124 void setIncomingValue(unsigned i, Value *V) {
1125 assert(i*2 < getNumOperands() && "Invalid value number!");
1128 unsigned getOperandNumForIncomingValue(unsigned i) {
1132 /// getIncomingBlock - Return incoming basic block number x
1134 BasicBlock *getIncomingBlock(unsigned i) const {
1135 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1137 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1138 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1140 unsigned getOperandNumForIncomingBlock(unsigned i) {
1144 /// addIncoming - Add an incoming value to the end of the PHI list
1146 void addIncoming(Value *V, BasicBlock *BB) {
1147 assert(getType() == V->getType() &&
1148 "All operands to PHI node must be the same type as the PHI node!");
1149 unsigned OpNo = NumOperands;
1150 if (OpNo+2 > ReservedSpace)
1151 resizeOperands(0); // Get more space!
1152 // Initialize some new operands.
1153 NumOperands = OpNo+2;
1154 OperandList[OpNo].init(V, this);
1155 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1158 /// removeIncomingValue - Remove an incoming value. This is useful if a
1159 /// predecessor basic block is deleted. The value removed is returned.
1161 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1162 /// is true), the PHI node is destroyed and any uses of it are replaced with
1163 /// dummy values. The only time there should be zero incoming values to a PHI
1164 /// node is when the block is dead, so this strategy is sound.
1166 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1168 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1169 int Idx = getBasicBlockIndex(BB);
1170 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1171 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1174 /// getBasicBlockIndex - Return the first index of the specified basic
1175 /// block in the value list for this PHI. Returns -1 if no instance.
1177 int getBasicBlockIndex(const BasicBlock *BB) const {
1178 Use *OL = OperandList;
1179 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1180 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1184 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1185 return getIncomingValue(getBasicBlockIndex(BB));
1188 /// hasConstantValue - If the specified PHI node always merges together the
1189 /// same value, return the value, otherwise return null.
1191 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1193 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1194 static inline bool classof(const PHINode *) { return true; }
1195 static inline bool classof(const Instruction *I) {
1196 return I->getOpcode() == Instruction::PHI;
1198 static inline bool classof(const Value *V) {
1199 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1202 void resizeOperands(unsigned NumOperands);
1205 //===----------------------------------------------------------------------===//
1207 //===----------------------------------------------------------------------===//
1209 //===---------------------------------------------------------------------------
1210 /// ReturnInst - Return a value (possibly void), from a function. Execution
1211 /// does not continue in this function any longer.
1213 class ReturnInst : public TerminatorInst {
1214 Use RetVal; // Return Value: null if 'void'.
1215 ReturnInst(const ReturnInst &RI);
1216 void init(Value *RetVal);
1219 // ReturnInst constructors:
1220 // ReturnInst() - 'ret void' instruction
1221 // ReturnInst( null) - 'ret void' instruction
1222 // ReturnInst(Value* X) - 'ret X' instruction
1223 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1224 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1225 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1226 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1228 // NOTE: If the Value* passed is of type void then the constructor behaves as
1229 // if it was passed NULL.
1230 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1231 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1232 explicit ReturnInst(BasicBlock *InsertAtEnd);
1234 virtual ReturnInst *clone() const;
1236 // Transparently provide more efficient getOperand methods.
1237 Value *getOperand(unsigned i) const {
1238 assert(i < getNumOperands() && "getOperand() out of range!");
1241 void setOperand(unsigned i, Value *Val) {
1242 assert(i < getNumOperands() && "setOperand() out of range!");
1246 Value *getReturnValue() const { return RetVal; }
1248 unsigned getNumSuccessors() const { return 0; }
1250 // Methods for support type inquiry through isa, cast, and dyn_cast:
1251 static inline bool classof(const ReturnInst *) { return true; }
1252 static inline bool classof(const Instruction *I) {
1253 return (I->getOpcode() == Instruction::Ret);
1255 static inline bool classof(const Value *V) {
1256 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1259 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1260 virtual unsigned getNumSuccessorsV() const;
1261 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1264 //===----------------------------------------------------------------------===//
1266 //===----------------------------------------------------------------------===//
1268 //===---------------------------------------------------------------------------
1269 /// BranchInst - Conditional or Unconditional Branch instruction.
1271 class BranchInst : public TerminatorInst {
1272 /// Ops list - Branches are strange. The operands are ordered:
1273 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1274 /// they don't have to check for cond/uncond branchness.
1276 BranchInst(const BranchInst &BI);
1279 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1280 // BranchInst(BB *B) - 'br B'
1281 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1282 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1283 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1284 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1285 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1286 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1287 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1288 Instruction *InsertBefore = 0);
1289 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1290 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1291 BasicBlock *InsertAtEnd);
1293 /// Transparently provide more efficient getOperand methods.
1294 Value *getOperand(unsigned i) const {
1295 assert(i < getNumOperands() && "getOperand() out of range!");
1298 void setOperand(unsigned i, Value *Val) {
1299 assert(i < getNumOperands() && "setOperand() out of range!");
1303 virtual BranchInst *clone() const;
1305 inline bool isUnconditional() const { return getNumOperands() == 1; }
1306 inline bool isConditional() const { return getNumOperands() == 3; }
1308 inline Value *getCondition() const {
1309 assert(isConditional() && "Cannot get condition of an uncond branch!");
1310 return getOperand(2);
1313 void setCondition(Value *V) {
1314 assert(isConditional() && "Cannot set condition of unconditional branch!");
1318 // setUnconditionalDest - Change the current branch to an unconditional branch
1319 // targeting the specified block.
1320 // FIXME: Eliminate this ugly method.
1321 void setUnconditionalDest(BasicBlock *Dest) {
1322 if (isConditional()) { // Convert this to an uncond branch.
1327 setOperand(0, reinterpret_cast<Value*>(Dest));
1330 unsigned getNumSuccessors() const { return 1+isConditional(); }
1332 BasicBlock *getSuccessor(unsigned i) const {
1333 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1334 return cast<BasicBlock>(getOperand(i));
1337 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1338 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1339 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1342 // Methods for support type inquiry through isa, cast, and dyn_cast:
1343 static inline bool classof(const BranchInst *) { return true; }
1344 static inline bool classof(const Instruction *I) {
1345 return (I->getOpcode() == Instruction::Br);
1347 static inline bool classof(const Value *V) {
1348 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1351 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1352 virtual unsigned getNumSuccessorsV() const;
1353 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1356 //===----------------------------------------------------------------------===//
1358 //===----------------------------------------------------------------------===//
1360 //===---------------------------------------------------------------------------
1361 /// SwitchInst - Multiway switch
1363 class SwitchInst : public TerminatorInst {
1364 unsigned ReservedSpace;
1365 // Operand[0] = Value to switch on
1366 // Operand[1] = Default basic block destination
1367 // Operand[2n ] = Value to match
1368 // Operand[2n+1] = BasicBlock to go to on match
1369 SwitchInst(const SwitchInst &RI);
1370 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1371 void resizeOperands(unsigned No);
1373 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1374 /// switch on and a default destination. The number of additional cases can
1375 /// be specified here to make memory allocation more efficient. This
1376 /// constructor can also autoinsert before another instruction.
1377 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1378 Instruction *InsertBefore = 0);
1380 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1381 /// switch on and a default destination. The number of additional cases can
1382 /// be specified here to make memory allocation more efficient. This
1383 /// constructor also autoinserts at the end of the specified BasicBlock.
1384 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1385 BasicBlock *InsertAtEnd);
1389 // Accessor Methods for Switch stmt
1390 inline Value *getCondition() const { return getOperand(0); }
1391 void setCondition(Value *V) { setOperand(0, V); }
1393 inline BasicBlock *getDefaultDest() const {
1394 return cast<BasicBlock>(getOperand(1));
1397 /// getNumCases - return the number of 'cases' in this switch instruction.
1398 /// Note that case #0 is always the default case.
1399 unsigned getNumCases() const {
1400 return getNumOperands()/2;
1403 /// getCaseValue - Return the specified case value. Note that case #0, the
1404 /// default destination, does not have a case value.
1405 ConstantInt *getCaseValue(unsigned i) {
1406 assert(i && i < getNumCases() && "Illegal case value to get!");
1407 return getSuccessorValue(i);
1410 /// getCaseValue - Return the specified case value. Note that case #0, the
1411 /// default destination, does not have a case value.
1412 const ConstantInt *getCaseValue(unsigned i) const {
1413 assert(i && i < getNumCases() && "Illegal case value to get!");
1414 return getSuccessorValue(i);
1417 /// findCaseValue - Search all of the case values for the specified constant.
1418 /// If it is explicitly handled, return the case number of it, otherwise
1419 /// return 0 to indicate that it is handled by the default handler.
1420 unsigned findCaseValue(const ConstantInt *C) const {
1421 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1422 if (getCaseValue(i) == C)
1427 /// findCaseDest - Finds the unique case value for a given successor. Returns
1428 /// null if the successor is not found, not unique, or is the default case.
1429 ConstantInt *findCaseDest(BasicBlock *BB) {
1430 if (BB == getDefaultDest()) return NULL;
1432 ConstantInt *CI = NULL;
1433 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1434 if (getSuccessor(i) == BB) {
1435 if (CI) return NULL; // Multiple cases lead to BB.
1436 else CI = getCaseValue(i);
1442 /// addCase - Add an entry to the switch instruction...
1444 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1446 /// removeCase - This method removes the specified successor from the switch
1447 /// instruction. Note that this cannot be used to remove the default
1448 /// destination (successor #0).
1450 void removeCase(unsigned idx);
1452 virtual SwitchInst *clone() const;
1454 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1455 BasicBlock *getSuccessor(unsigned idx) const {
1456 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1457 return cast<BasicBlock>(getOperand(idx*2+1));
1459 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1460 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1461 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1464 // getSuccessorValue - Return the value associated with the specified
1466 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1467 assert(idx < getNumSuccessors() && "Successor # out of range!");
1468 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1471 // Methods for support type inquiry through isa, cast, and dyn_cast:
1472 static inline bool classof(const SwitchInst *) { return true; }
1473 static inline bool classof(const Instruction *I) {
1474 return I->getOpcode() == Instruction::Switch;
1476 static inline bool classof(const Value *V) {
1477 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1480 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1481 virtual unsigned getNumSuccessorsV() const;
1482 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1485 //===----------------------------------------------------------------------===//
1487 //===----------------------------------------------------------------------===//
1489 //===---------------------------------------------------------------------------
1491 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1492 /// calling convention of the call.
1494 class InvokeInst : public TerminatorInst {
1495 ParamAttrsList *ParamAttrs;
1496 InvokeInst(const InvokeInst &BI);
1497 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1498 Value* const *Args, unsigned NumArgs);
1500 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1501 Value* const* Args, unsigned NumArgs, const std::string &Name = "",
1502 Instruction *InsertBefore = 0);
1503 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1504 Value* const* Args, unsigned NumArgs, const std::string &Name,
1505 BasicBlock *InsertAtEnd);
1508 virtual InvokeInst *clone() const;
1510 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1512 unsigned getCallingConv() const { return SubclassData; }
1513 void setCallingConv(unsigned CC) {
1517 /// Obtains a pointer to the ParamAttrsList object which holds the
1518 /// parameter attributes information, if any.
1519 /// @returns 0 if no attributes have been set.
1520 /// @brief Get the parameter attributes.
1521 ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
1523 /// Sets the parameter attributes for this InvokeInst. To construct a
1524 /// ParamAttrsList, see ParameterAttributes.h
1525 /// @brief Set the parameter attributes.
1526 void setParamAttrs(ParamAttrsList *attrs);
1528 /// getCalledFunction - Return the function called, or null if this is an
1529 /// indirect function invocation.
1531 Function *getCalledFunction() const {
1532 return dyn_cast<Function>(getOperand(0));
1535 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1536 inline Value *getCalledValue() const { return getOperand(0); }
1538 // get*Dest - Return the destination basic blocks...
1539 BasicBlock *getNormalDest() const {
1540 return cast<BasicBlock>(getOperand(1));
1542 BasicBlock *getUnwindDest() const {
1543 return cast<BasicBlock>(getOperand(2));
1545 void setNormalDest(BasicBlock *B) {
1546 setOperand(1, reinterpret_cast<Value*>(B));
1549 void setUnwindDest(BasicBlock *B) {
1550 setOperand(2, reinterpret_cast<Value*>(B));
1553 inline BasicBlock *getSuccessor(unsigned i) const {
1554 assert(i < 2 && "Successor # out of range for invoke!");
1555 return i == 0 ? getNormalDest() : getUnwindDest();
1558 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1559 assert(idx < 2 && "Successor # out of range for invoke!");
1560 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1563 unsigned getNumSuccessors() const { return 2; }
1565 // Methods for support type inquiry through isa, cast, and dyn_cast:
1566 static inline bool classof(const InvokeInst *) { return true; }
1567 static inline bool classof(const Instruction *I) {
1568 return (I->getOpcode() == Instruction::Invoke);
1570 static inline bool classof(const Value *V) {
1571 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1574 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1575 virtual unsigned getNumSuccessorsV() const;
1576 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1580 //===----------------------------------------------------------------------===//
1582 //===----------------------------------------------------------------------===//
1584 //===---------------------------------------------------------------------------
1585 /// UnwindInst - Immediately exit the current function, unwinding the stack
1586 /// until an invoke instruction is found.
1588 class UnwindInst : public TerminatorInst {
1590 explicit UnwindInst(Instruction *InsertBefore = 0);
1591 explicit UnwindInst(BasicBlock *InsertAtEnd);
1593 virtual UnwindInst *clone() const;
1595 unsigned getNumSuccessors() const { return 0; }
1597 // Methods for support type inquiry through isa, cast, and dyn_cast:
1598 static inline bool classof(const UnwindInst *) { return true; }
1599 static inline bool classof(const Instruction *I) {
1600 return I->getOpcode() == Instruction::Unwind;
1602 static inline bool classof(const Value *V) {
1603 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1606 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1607 virtual unsigned getNumSuccessorsV() const;
1608 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1611 //===----------------------------------------------------------------------===//
1612 // UnreachableInst Class
1613 //===----------------------------------------------------------------------===//
1615 //===---------------------------------------------------------------------------
1616 /// UnreachableInst - This function has undefined behavior. In particular, the
1617 /// presence of this instruction indicates some higher level knowledge that the
1618 /// end of the block cannot be reached.
1620 class UnreachableInst : public TerminatorInst {
1622 explicit UnreachableInst(Instruction *InsertBefore = 0);
1623 explicit UnreachableInst(BasicBlock *InsertAtEnd);
1625 virtual UnreachableInst *clone() const;
1627 unsigned getNumSuccessors() const { return 0; }
1629 // Methods for support type inquiry through isa, cast, and dyn_cast:
1630 static inline bool classof(const UnreachableInst *) { return true; }
1631 static inline bool classof(const Instruction *I) {
1632 return I->getOpcode() == Instruction::Unreachable;
1634 static inline bool classof(const Value *V) {
1635 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1638 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1639 virtual unsigned getNumSuccessorsV() const;
1640 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1643 //===----------------------------------------------------------------------===//
1645 //===----------------------------------------------------------------------===//
1647 /// @brief This class represents a truncation of integer types.
1648 class TruncInst : public CastInst {
1649 /// Private copy constructor
1650 TruncInst(const TruncInst &CI)
1651 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1654 /// @brief Constructor with insert-before-instruction 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 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1662 /// @brief Constructor with insert-at-end-of-block semantics
1664 Value *S, ///< The value to be truncated
1665 const Type *Ty, ///< The (smaller) type to truncate to
1666 const std::string &Name, ///< A name for the new instruction
1667 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1670 /// @brief Clone an identical TruncInst
1671 virtual CastInst *clone() const;
1673 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1674 static inline bool classof(const TruncInst *) { return true; }
1675 static inline bool classof(const Instruction *I) {
1676 return I->getOpcode() == Trunc;
1678 static inline bool classof(const Value *V) {
1679 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1683 //===----------------------------------------------------------------------===//
1685 //===----------------------------------------------------------------------===//
1687 /// @brief This class represents zero extension of integer types.
1688 class ZExtInst : public CastInst {
1689 /// @brief Private copy constructor
1690 ZExtInst(const ZExtInst &CI)
1691 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1694 /// @brief Constructor with insert-before-instruction 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 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1702 /// @brief Constructor with insert-at-end semantics.
1704 Value *S, ///< The value to be zero extended
1705 const Type *Ty, ///< The type to zero extend to
1706 const std::string &Name, ///< A name for the new instruction
1707 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1710 /// @brief Clone an identical ZExtInst
1711 virtual CastInst *clone() const;
1713 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1714 static inline bool classof(const ZExtInst *) { return true; }
1715 static inline bool classof(const Instruction *I) {
1716 return I->getOpcode() == ZExt;
1718 static inline bool classof(const Value *V) {
1719 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1723 //===----------------------------------------------------------------------===//
1725 //===----------------------------------------------------------------------===//
1727 /// @brief This class represents a sign extension of integer types.
1728 class SExtInst : public CastInst {
1729 /// @brief Private copy constructor
1730 SExtInst(const SExtInst &CI)
1731 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1734 /// @brief Constructor with insert-before-instruction 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 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1742 /// @brief Constructor with insert-at-end-of-block semantics
1744 Value *S, ///< The value to be sign extended
1745 const Type *Ty, ///< The type to sign extend to
1746 const std::string &Name, ///< A name for the new instruction
1747 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1750 /// @brief Clone an identical SExtInst
1751 virtual CastInst *clone() const;
1753 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1754 static inline bool classof(const SExtInst *) { return true; }
1755 static inline bool classof(const Instruction *I) {
1756 return I->getOpcode() == SExt;
1758 static inline bool classof(const Value *V) {
1759 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1763 //===----------------------------------------------------------------------===//
1764 // FPTruncInst Class
1765 //===----------------------------------------------------------------------===//
1767 /// @brief This class represents a truncation of floating point types.
1768 class FPTruncInst : public CastInst {
1769 FPTruncInst(const FPTruncInst &CI)
1770 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
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 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1781 /// @brief Constructor with insert-before-instruction semantics
1783 Value *S, ///< The value to be truncated
1784 const Type *Ty, ///< The type to truncate to
1785 const std::string &Name, ///< A name for the new instruction
1786 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1789 /// @brief Clone an identical FPTruncInst
1790 virtual CastInst *clone() const;
1792 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1793 static inline bool classof(const FPTruncInst *) { return true; }
1794 static inline bool classof(const Instruction *I) {
1795 return I->getOpcode() == FPTrunc;
1797 static inline bool classof(const Value *V) {
1798 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1802 //===----------------------------------------------------------------------===//
1804 //===----------------------------------------------------------------------===//
1806 /// @brief This class represents an extension of floating point types.
1807 class FPExtInst : public CastInst {
1808 FPExtInst(const FPExtInst &CI)
1809 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1812 /// @brief Constructor with insert-before-instruction 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 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1820 /// @brief Constructor with insert-at-end-of-block semantics
1822 Value *S, ///< The value to be extended
1823 const Type *Ty, ///< The type to extend to
1824 const std::string &Name, ///< A name for the new instruction
1825 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1828 /// @brief Clone an identical FPExtInst
1829 virtual CastInst *clone() const;
1831 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1832 static inline bool classof(const FPExtInst *) { return true; }
1833 static inline bool classof(const Instruction *I) {
1834 return I->getOpcode() == FPExt;
1836 static inline bool classof(const Value *V) {
1837 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1841 //===----------------------------------------------------------------------===//
1843 //===----------------------------------------------------------------------===//
1845 /// @brief This class represents a cast unsigned integer to floating point.
1846 class UIToFPInst : public CastInst {
1847 UIToFPInst(const UIToFPInst &CI)
1848 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1851 /// @brief Constructor with insert-before-instruction 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 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1859 /// @brief Constructor with insert-at-end-of-block semantics
1861 Value *S, ///< The value to be converted
1862 const Type *Ty, ///< The type to convert to
1863 const std::string &Name, ///< A name for the new instruction
1864 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1867 /// @brief Clone an identical UIToFPInst
1868 virtual CastInst *clone() const;
1870 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1871 static inline bool classof(const UIToFPInst *) { return true; }
1872 static inline bool classof(const Instruction *I) {
1873 return I->getOpcode() == UIToFP;
1875 static inline bool classof(const Value *V) {
1876 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1880 //===----------------------------------------------------------------------===//
1882 //===----------------------------------------------------------------------===//
1884 /// @brief This class represents a cast from signed integer to floating point.
1885 class SIToFPInst : public CastInst {
1886 SIToFPInst(const SIToFPInst &CI)
1887 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1890 /// @brief Constructor with insert-before-instruction 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 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1898 /// @brief Constructor with insert-at-end-of-block semantics
1900 Value *S, ///< The value to be converted
1901 const Type *Ty, ///< The type to convert to
1902 const std::string &Name, ///< A name for the new instruction
1903 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1906 /// @brief Clone an identical SIToFPInst
1907 virtual CastInst *clone() const;
1909 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1910 static inline bool classof(const SIToFPInst *) { return true; }
1911 static inline bool classof(const Instruction *I) {
1912 return I->getOpcode() == SIToFP;
1914 static inline bool classof(const Value *V) {
1915 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1919 //===----------------------------------------------------------------------===//
1921 //===----------------------------------------------------------------------===//
1923 /// @brief This class represents a cast from floating point to unsigned integer
1924 class FPToUIInst : public CastInst {
1925 FPToUIInst(const FPToUIInst &CI)
1926 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1929 /// @brief Constructor with insert-before-instruction 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 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1937 /// @brief Constructor with insert-at-end-of-block semantics
1939 Value *S, ///< The value to be converted
1940 const Type *Ty, ///< The type to convert to
1941 const std::string &Name, ///< A name for the new instruction
1942 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
1945 /// @brief Clone an identical FPToUIInst
1946 virtual CastInst *clone() const;
1948 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1949 static inline bool classof(const FPToUIInst *) { return true; }
1950 static inline bool classof(const Instruction *I) {
1951 return I->getOpcode() == FPToUI;
1953 static inline bool classof(const Value *V) {
1954 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1958 //===----------------------------------------------------------------------===//
1960 //===----------------------------------------------------------------------===//
1962 /// @brief This class represents a cast from floating point to signed integer.
1963 class FPToSIInst : public CastInst {
1964 FPToSIInst(const FPToSIInst &CI)
1965 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
1968 /// @brief Constructor with insert-before-instruction 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 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1976 /// @brief Constructor with insert-at-end-of-block semantics
1978 Value *S, ///< The value to be converted
1979 const Type *Ty, ///< The type to convert to
1980 const std::string &Name, ///< A name for the new instruction
1981 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1984 /// @brief Clone an identical FPToSIInst
1985 virtual CastInst *clone() const;
1987 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1988 static inline bool classof(const FPToSIInst *) { return true; }
1989 static inline bool classof(const Instruction *I) {
1990 return I->getOpcode() == FPToSI;
1992 static inline bool classof(const Value *V) {
1993 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1997 //===----------------------------------------------------------------------===//
1998 // IntToPtrInst Class
1999 //===----------------------------------------------------------------------===//
2001 /// @brief This class represents a cast from an integer to a pointer.
2002 class IntToPtrInst : public CastInst {
2003 IntToPtrInst(const IntToPtrInst &CI)
2004 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2007 /// @brief Constructor with insert-before-instruction 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 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2015 /// @brief Constructor with insert-at-end-of-block semantics
2017 Value *S, ///< The value to be converted
2018 const Type *Ty, ///< The type to convert to
2019 const std::string &Name, ///< A name for the new instruction
2020 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2023 /// @brief Clone an identical IntToPtrInst
2024 virtual CastInst *clone() const;
2026 // Methods for support type inquiry through isa, cast, and dyn_cast:
2027 static inline bool classof(const IntToPtrInst *) { return true; }
2028 static inline bool classof(const Instruction *I) {
2029 return I->getOpcode() == IntToPtr;
2031 static inline bool classof(const Value *V) {
2032 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2036 //===----------------------------------------------------------------------===//
2037 // PtrToIntInst Class
2038 //===----------------------------------------------------------------------===//
2040 /// @brief This class represents a cast from a pointer to an integer
2041 class PtrToIntInst : public CastInst {
2042 PtrToIntInst(const PtrToIntInst &CI)
2043 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2046 /// @brief Constructor with insert-before-instruction 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 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2054 /// @brief Constructor with insert-at-end-of-block semantics
2056 Value *S, ///< The value to be converted
2057 const Type *Ty, ///< The type to convert to
2058 const std::string &Name, ///< A name for the new instruction
2059 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2062 /// @brief Clone an identical PtrToIntInst
2063 virtual CastInst *clone() const;
2065 // Methods for support type inquiry through isa, cast, and dyn_cast:
2066 static inline bool classof(const PtrToIntInst *) { return true; }
2067 static inline bool classof(const Instruction *I) {
2068 return I->getOpcode() == PtrToInt;
2070 static inline bool classof(const Value *V) {
2071 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2075 //===----------------------------------------------------------------------===//
2076 // BitCastInst Class
2077 //===----------------------------------------------------------------------===//
2079 /// @brief This class represents a no-op cast from one type to another.
2080 class BitCastInst : public CastInst {
2081 BitCastInst(const BitCastInst &CI)
2082 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2085 /// @brief Constructor with insert-before-instruction 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 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2093 /// @brief Constructor with insert-at-end-of-block semantics
2095 Value *S, ///< The value to be casted
2096 const Type *Ty, ///< The type to casted to
2097 const std::string &Name, ///< A name for the new instruction
2098 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2101 /// @brief Clone an identical BitCastInst
2102 virtual CastInst *clone() const;
2104 // Methods for support type inquiry through isa, cast, and dyn_cast:
2105 static inline bool classof(const BitCastInst *) { return true; }
2106 static inline bool classof(const Instruction *I) {
2107 return I->getOpcode() == BitCast;
2109 static inline bool classof(const Value *V) {
2110 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2114 } // End llvm namespace