1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the class definitions of all of the subclasses of the
11 // Instruction class. This is meant to be an easy way to get access to all
12 // instruction subclasses.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_INSTRUCTIONS_H
17 #define LLVM_INSTRUCTIONS_H
19 #include "llvm/InstrTypes.h"
31 //===----------------------------------------------------------------------===//
32 // AllocationInst Class
33 //===----------------------------------------------------------------------===//
35 /// AllocationInst - This class is the common base class of MallocInst and
38 class AllocationInst : public UnaryInstruction {
41 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
42 const std::string &Name = "", Instruction *InsertBefore = 0);
43 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
44 const std::string &Name, BasicBlock *InsertAtEnd);
46 // Out of line virtual method, so the vtable, etc has a home.
47 virtual ~AllocationInst();
49 /// isArrayAllocation - Return true if there is an allocation size parameter
50 /// to the allocation instruction that is not 1.
52 bool isArrayAllocation() const;
54 /// getArraySize - Get the number of element allocated, for a simple
55 /// allocation of a single element, this will return a constant 1 value.
57 inline const Value *getArraySize() const { return getOperand(0); }
58 inline Value *getArraySize() { return getOperand(0); }
60 /// getType - Overload to return most specific pointer type
62 inline const PointerType *getType() const {
63 return reinterpret_cast<const PointerType*>(Instruction::getType());
66 /// getAllocatedType - Return the type that is being allocated by the
69 const Type *getAllocatedType() const;
71 /// getAlignment - Return the alignment of the memory that is being allocated
72 /// by the instruction.
74 unsigned getAlignment() const { return Alignment; }
75 void setAlignment(unsigned Align) {
76 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
80 virtual Instruction *clone() const = 0;
82 // Methods for support type inquiry through isa, cast, and dyn_cast:
83 static inline bool classof(const AllocationInst *) { return true; }
84 static inline bool classof(const Instruction *I) {
85 return I->getOpcode() == Instruction::Alloca ||
86 I->getOpcode() == Instruction::Malloc;
88 static inline bool classof(const Value *V) {
89 return isa<Instruction>(V) && classof(cast<Instruction>(V));
94 //===----------------------------------------------------------------------===//
96 //===----------------------------------------------------------------------===//
98 /// MallocInst - an instruction to allocated memory on the heap
100 class MallocInst : public AllocationInst {
101 MallocInst(const MallocInst &MI);
103 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
104 const std::string &Name = "",
105 Instruction *InsertBefore = 0)
106 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
107 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
108 BasicBlock *InsertAtEnd)
109 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
111 MallocInst(const Type *Ty, const std::string &Name,
112 Instruction *InsertBefore = 0)
113 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
114 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
115 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
117 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
118 const std::string &Name, BasicBlock *InsertAtEnd)
119 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
120 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
121 const std::string &Name = "",
122 Instruction *InsertBefore = 0)
123 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
125 virtual MallocInst *clone() const;
127 // Methods for support type inquiry through isa, cast, and dyn_cast:
128 static inline bool classof(const MallocInst *) { return true; }
129 static inline bool classof(const Instruction *I) {
130 return (I->getOpcode() == Instruction::Malloc);
132 static inline bool classof(const Value *V) {
133 return isa<Instruction>(V) && classof(cast<Instruction>(V));
138 //===----------------------------------------------------------------------===//
140 //===----------------------------------------------------------------------===//
142 /// AllocaInst - an instruction to allocate memory on the stack
144 class AllocaInst : public AllocationInst {
145 AllocaInst(const AllocaInst &);
147 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
148 const std::string &Name = "",
149 Instruction *InsertBefore = 0)
150 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
151 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
152 BasicBlock *InsertAtEnd)
153 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
155 AllocaInst(const Type *Ty, const std::string &Name,
156 Instruction *InsertBefore = 0)
157 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
158 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
159 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
161 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
162 const std::string &Name = "", Instruction *InsertBefore = 0)
163 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
164 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
165 const std::string &Name, BasicBlock *InsertAtEnd)
166 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
168 virtual AllocaInst *clone() const;
170 // Methods for support type inquiry through isa, cast, and dyn_cast:
171 static inline bool classof(const AllocaInst *) { return true; }
172 static inline bool classof(const Instruction *I) {
173 return (I->getOpcode() == Instruction::Alloca);
175 static inline bool classof(const Value *V) {
176 return isa<Instruction>(V) && classof(cast<Instruction>(V));
181 //===----------------------------------------------------------------------===//
183 //===----------------------------------------------------------------------===//
185 /// FreeInst - an instruction to deallocate memory
187 class FreeInst : public UnaryInstruction {
190 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
191 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
193 virtual FreeInst *clone() const;
195 // Methods for support type inquiry through isa, cast, and dyn_cast:
196 static inline bool classof(const FreeInst *) { return true; }
197 static inline bool classof(const Instruction *I) {
198 return (I->getOpcode() == Instruction::Free);
200 static inline bool classof(const Value *V) {
201 return isa<Instruction>(V) && classof(cast<Instruction>(V));
206 //===----------------------------------------------------------------------===//
208 //===----------------------------------------------------------------------===//
210 /// LoadInst - an instruction for reading from memory. This uses the
211 /// SubclassData field in Value to store whether or not the load is volatile.
213 class LoadInst : public UnaryInstruction {
215 LoadInst(const LoadInst &LI)
216 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
217 setVolatile(LI.isVolatile());
218 setAlignment(LI.getAlignment());
226 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
227 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
228 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false,
229 Instruction *InsertBefore = 0);
230 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
231 Instruction *InsertBefore = 0);
232 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
233 BasicBlock *InsertAtEnd);
235 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
236 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
237 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
238 Instruction *InsertBefore = 0);
239 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
240 BasicBlock *InsertAtEnd);
242 /// isVolatile - Return true if this is a load from a volatile memory
245 bool isVolatile() const { return SubclassData & 1; }
247 /// setVolatile - Specify whether this is a volatile load or not.
249 void setVolatile(bool V) { SubclassData = (SubclassData & ~1) | unsigned(V); }
251 virtual LoadInst *clone() const;
253 /// getAlignment - Return the alignment of the access that is being performed
255 unsigned getAlignment() const {
256 signed Log2AlignVal = ((SubclassData>>1)-1);
257 return ((Log2AlignVal < 0) ? 0 : 1<<Log2AlignVal);
260 void setAlignment(unsigned Align);
262 Value *getPointerOperand() { return getOperand(0); }
263 const Value *getPointerOperand() const { return getOperand(0); }
264 static unsigned getPointerOperandIndex() { return 0U; }
266 // Methods for support type inquiry through isa, cast, and dyn_cast:
267 static inline bool classof(const LoadInst *) { return true; }
268 static inline bool classof(const Instruction *I) {
269 return I->getOpcode() == Instruction::Load;
271 static inline bool classof(const Value *V) {
272 return isa<Instruction>(V) && classof(cast<Instruction>(V));
277 //===----------------------------------------------------------------------===//
279 //===----------------------------------------------------------------------===//
281 /// StoreInst - an instruction for storing to memory
283 class StoreInst : public Instruction {
286 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
287 Ops[0].init(SI.Ops[0], this);
288 Ops[1].init(SI.Ops[1], this);
289 setVolatile(SI.isVolatile());
290 setAlignment(SI.getAlignment());
298 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
299 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
300 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
301 Instruction *InsertBefore = 0);
302 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
303 unsigned Align, Instruction *InsertBefore = 0);
304 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
307 /// isVolatile - Return true if this is a load from a volatile memory
310 bool isVolatile() const { return SubclassData & 1; }
312 /// setVolatile - Specify whether this is a volatile load or not.
314 void setVolatile(bool V) { SubclassData = (SubclassData & ~1) | unsigned(V); }
316 /// Transparently provide more efficient getOperand methods.
317 Value *getOperand(unsigned i) const {
318 assert(i < 2 && "getOperand() out of range!");
321 void setOperand(unsigned i, Value *Val) {
322 assert(i < 2 && "setOperand() out of range!");
325 unsigned getNumOperands() const { return 2; }
327 /// getAlignment - Return the alignment of the access that is being performed
329 unsigned getAlignment() const {
330 signed Log2AlignVal = ((SubclassData>>1)-1);
331 return ((Log2AlignVal < 0) ? 0 : 1<<Log2AlignVal);
334 void setAlignment(unsigned Align);
336 virtual StoreInst *clone() const;
338 Value *getPointerOperand() { return getOperand(1); }
339 const Value *getPointerOperand() const { return getOperand(1); }
340 static unsigned getPointerOperandIndex() { return 1U; }
342 // Methods for support type inquiry through isa, cast, and dyn_cast:
343 static inline bool classof(const StoreInst *) { return true; }
344 static inline bool classof(const Instruction *I) {
345 return I->getOpcode() == Instruction::Store;
347 static inline bool classof(const Value *V) {
348 return isa<Instruction>(V) && classof(cast<Instruction>(V));
353 //===----------------------------------------------------------------------===//
354 // GetElementPtrInst Class
355 //===----------------------------------------------------------------------===//
357 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
358 /// access elements of arrays and structs
360 class GetElementPtrInst : public Instruction {
361 GetElementPtrInst(const GetElementPtrInst &GEPI)
362 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
363 0, GEPI.getNumOperands()) {
364 Use *OL = OperandList = new Use[NumOperands];
365 Use *GEPIOL = GEPI.OperandList;
366 for (unsigned i = 0, E = NumOperands; i != E; ++i)
367 OL[i].init(GEPIOL[i], this);
369 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
370 void init(Value *Ptr, Value *Idx0, Value *Idx1);
371 void init(Value *Ptr, Value *Idx);
373 /// Constructors - Create a getelementptr instruction with a base pointer an
374 /// list of indices. The first ctor can optionally insert before an existing
375 /// instruction, the second appends the new instruction to the specified
377 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
378 const std::string &Name = "", Instruction *InsertBefore =0);
379 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
380 const std::string &Name, BasicBlock *InsertAtEnd);
382 /// Constructors - These two constructors are convenience methods because one
383 /// and two index getelementptr instructions are so common.
384 GetElementPtrInst(Value *Ptr, Value *Idx,
385 const std::string &Name = "", Instruction *InsertBefore =0);
386 GetElementPtrInst(Value *Ptr, Value *Idx,
387 const std::string &Name, BasicBlock *InsertAtEnd);
388 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
389 const std::string &Name = "", Instruction *InsertBefore =0);
390 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
391 const std::string &Name, BasicBlock *InsertAtEnd);
392 ~GetElementPtrInst();
394 virtual GetElementPtrInst *clone() const;
396 // getType - Overload to return most specific pointer type...
397 inline const PointerType *getType() const {
398 return reinterpret_cast<const PointerType*>(Instruction::getType());
401 /// getIndexedType - Returns the type of the element that would be loaded with
402 /// a load instruction with the specified parameters.
404 /// A null type is returned if the indices are invalid for the specified
407 static const Type *getIndexedType(const Type *Ptr,
408 Value* const *Idx, unsigned NumIdx,
409 bool AllowStructLeaf = false);
411 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
412 bool AllowStructLeaf = false);
413 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
415 inline op_iterator idx_begin() { return op_begin()+1; }
416 inline const_op_iterator idx_begin() const { return op_begin()+1; }
417 inline op_iterator idx_end() { return op_end(); }
418 inline const_op_iterator idx_end() const { return op_end(); }
420 Value *getPointerOperand() {
421 return getOperand(0);
423 const Value *getPointerOperand() const {
424 return getOperand(0);
426 static unsigned getPointerOperandIndex() {
427 return 0U; // get index for modifying correct operand
430 inline unsigned getNumIndices() const { // Note: always non-negative
431 return getNumOperands() - 1;
434 inline bool hasIndices() const {
435 return getNumOperands() > 1;
438 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
439 /// zeros. If so, the result pointer and the first operand have the same
440 /// value, just potentially different types.
441 bool hasAllZeroIndices() const;
443 // Methods for support type inquiry through isa, cast, and dyn_cast:
444 static inline bool classof(const GetElementPtrInst *) { return true; }
445 static inline bool classof(const Instruction *I) {
446 return (I->getOpcode() == Instruction::GetElementPtr);
448 static inline bool classof(const Value *V) {
449 return isa<Instruction>(V) && classof(cast<Instruction>(V));
453 //===----------------------------------------------------------------------===//
455 //===----------------------------------------------------------------------===//
457 /// This instruction compares its operands according to the predicate given
458 /// to the constructor. It only operates on integers, pointers, or packed
459 /// vectors of integrals. The two operands must be the same type.
460 /// @brief Represent an integer comparison operator.
461 class ICmpInst: public CmpInst {
463 /// This enumeration lists the possible predicates for the ICmpInst. The
464 /// values in the range 0-31 are reserved for FCmpInst while values in the
465 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
466 /// predicate values are not overlapping between the classes.
468 ICMP_EQ = 32, ///< equal
469 ICMP_NE = 33, ///< not equal
470 ICMP_UGT = 34, ///< unsigned greater than
471 ICMP_UGE = 35, ///< unsigned greater or equal
472 ICMP_ULT = 36, ///< unsigned less than
473 ICMP_ULE = 37, ///< unsigned less or equal
474 ICMP_SGT = 38, ///< signed greater than
475 ICMP_SGE = 39, ///< signed greater or equal
476 ICMP_SLT = 40, ///< signed less than
477 ICMP_SLE = 41, ///< signed less or equal
478 FIRST_ICMP_PREDICATE = ICMP_EQ,
479 LAST_ICMP_PREDICATE = ICMP_SLE,
480 BAD_ICMP_PREDICATE = ICMP_SLE + 1
483 /// @brief Constructor with insert-before-instruction semantics.
485 Predicate pred, ///< The predicate to use for the comparison
486 Value *LHS, ///< The left-hand-side of the expression
487 Value *RHS, ///< The right-hand-side of the expression
488 const std::string &Name = "", ///< Name of the instruction
489 Instruction *InsertBefore = 0 ///< Where to insert
490 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
493 /// @brief Constructor with insert-at-block-end semantics.
495 Predicate pred, ///< The predicate to use for the comparison
496 Value *LHS, ///< The left-hand-side of the expression
497 Value *RHS, ///< The right-hand-side of the expression
498 const std::string &Name, ///< Name of the instruction
499 BasicBlock *InsertAtEnd ///< Block to insert into.
500 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
503 /// @brief Return the predicate for this instruction.
504 Predicate getPredicate() const { return Predicate(SubclassData); }
506 /// @brief Set the predicate for this instruction to the specified value.
507 void setPredicate(Predicate P) { SubclassData = P; }
509 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
510 /// @returns the inverse predicate for the instruction's current predicate.
511 /// @brief Return the inverse of the instruction's predicate.
512 Predicate getInversePredicate() const {
513 return getInversePredicate(getPredicate());
516 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
517 /// @returns the inverse predicate for predicate provided in \p pred.
518 /// @brief Return the inverse of a given predicate
519 static Predicate getInversePredicate(Predicate pred);
521 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
522 /// @returns the predicate that would be the result of exchanging the two
523 /// operands of the ICmpInst instruction without changing the result
525 /// @brief Return the predicate as if the operands were swapped
526 Predicate getSwappedPredicate() const {
527 return getSwappedPredicate(getPredicate());
530 /// This is a static version that you can use without an instruction
532 /// @brief Return the predicate as if the operands were swapped.
533 static Predicate getSwappedPredicate(Predicate pred);
535 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
536 /// @returns the predicate that would be the result if the operand were
537 /// regarded as signed.
538 /// @brief Return the signed version of the predicate
539 Predicate getSignedPredicate() const {
540 return getSignedPredicate(getPredicate());
543 /// This is a static version that you can use without an instruction.
544 /// @brief Return the signed version of the predicate.
545 static Predicate getSignedPredicate(Predicate pred);
547 /// This also tests for commutativity. If isEquality() returns true then
548 /// the predicate is also commutative.
549 /// @returns true if the predicate of this instruction is EQ or NE.
550 /// @brief Determine if this is an equality predicate.
551 bool isEquality() const {
552 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
555 /// @returns true if the predicate of this ICmpInst is commutative
556 /// @brief Determine if this relation is commutative.
557 bool isCommutative() const { return isEquality(); }
559 /// @returns true if the predicate is relational (not EQ or NE).
560 /// @brief Determine if this a relational predicate.
561 bool isRelational() const {
562 return !isEquality();
565 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
566 /// @brief Determine if this instruction's predicate is signed.
567 bool isSignedPredicate() { return isSignedPredicate(getPredicate()); }
569 /// @returns true if the predicate provided is signed, false otherwise
570 /// @brief Determine if the predicate is signed.
571 static bool isSignedPredicate(Predicate pred);
573 /// Initialize a set of values that all satisfy the predicate with C.
574 /// @brief Make a ConstantRange for a relation with a constant value.
575 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
577 /// Exchange the two operands to this instruction in such a way that it does
578 /// not modify the semantics of the instruction. The predicate value may be
579 /// changed to retain the same result if the predicate is order dependent
581 /// @brief Swap operands and adjust predicate.
582 void swapOperands() {
583 SubclassData = getSwappedPredicate();
584 std::swap(Ops[0], Ops[1]);
587 // Methods for support type inquiry through isa, cast, and dyn_cast:
588 static inline bool classof(const ICmpInst *) { return true; }
589 static inline bool classof(const Instruction *I) {
590 return I->getOpcode() == Instruction::ICmp;
592 static inline bool classof(const Value *V) {
593 return isa<Instruction>(V) && classof(cast<Instruction>(V));
597 //===----------------------------------------------------------------------===//
599 //===----------------------------------------------------------------------===//
601 /// This instruction compares its operands according to the predicate given
602 /// to the constructor. It only operates on floating point values or packed
603 /// vectors of floating point values. The operands must be identical types.
604 /// @brief Represents a floating point comparison operator.
605 class FCmpInst: public CmpInst {
607 /// This enumeration lists the possible predicates for the FCmpInst. Values
608 /// in the range 0-31 are reserved for FCmpInst.
610 // Opcode U L G E Intuitive operation
611 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
612 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
613 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
614 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
615 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
616 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
617 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
618 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
619 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
620 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
621 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
622 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
623 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
624 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
625 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
626 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
627 FIRST_FCMP_PREDICATE = FCMP_FALSE,
628 LAST_FCMP_PREDICATE = FCMP_TRUE,
629 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
632 /// @brief Constructor with insert-before-instruction semantics.
634 Predicate pred, ///< The predicate to use for the comparison
635 Value *LHS, ///< The left-hand-side of the expression
636 Value *RHS, ///< The right-hand-side of the expression
637 const std::string &Name = "", ///< Name of the instruction
638 Instruction *InsertBefore = 0 ///< Where to insert
639 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
642 /// @brief Constructor with insert-at-block-end semantics.
644 Predicate pred, ///< The predicate to use for the comparison
645 Value *LHS, ///< The left-hand-side of the expression
646 Value *RHS, ///< The right-hand-side of the expression
647 const std::string &Name, ///< Name of the instruction
648 BasicBlock *InsertAtEnd ///< Block to insert into.
649 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
652 /// @brief Return the predicate for this instruction.
653 Predicate getPredicate() const { return Predicate(SubclassData); }
655 /// @brief Set the predicate for this instruction to the specified value.
656 void setPredicate(Predicate P) { SubclassData = P; }
658 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
659 /// @returns the inverse predicate for the instructions current predicate.
660 /// @brief Return the inverse of the predicate
661 Predicate getInversePredicate() const {
662 return getInversePredicate(getPredicate());
665 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
666 /// @returns the inverse predicate for \p pred.
667 /// @brief Return the inverse of a given predicate
668 static Predicate getInversePredicate(Predicate pred);
670 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
671 /// @returns the predicate that would be the result of exchanging the two
672 /// operands of the ICmpInst instruction without changing the result
674 /// @brief Return the predicate as if the operands were swapped
675 Predicate getSwappedPredicate() const {
676 return getSwappedPredicate(getPredicate());
679 /// This is a static version that you can use without an instruction
681 /// @brief Return the predicate as if the operands were swapped.
682 static Predicate getSwappedPredicate(Predicate Opcode);
684 /// This also tests for commutativity. If isEquality() returns true then
685 /// the predicate is also commutative. Only the equality predicates are
687 /// @returns true if the predicate of this instruction is EQ or NE.
688 /// @brief Determine if this is an equality predicate.
689 bool isEquality() const {
690 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
691 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
693 bool isCommutative() const { return isEquality(); }
695 /// @returns true if the predicate is relational (not EQ or NE).
696 /// @brief Determine if this a relational predicate.
697 bool isRelational() const { return !isEquality(); }
699 /// Exchange the two operands to this instruction in such a way that it does
700 /// not modify the semantics of the instruction. The predicate value may be
701 /// changed to retain the same result if the predicate is order dependent
703 /// @brief Swap operands and adjust predicate.
704 void swapOperands() {
705 SubclassData = getSwappedPredicate();
706 std::swap(Ops[0], Ops[1]);
709 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
710 static inline bool classof(const FCmpInst *) { return true; }
711 static inline bool classof(const Instruction *I) {
712 return I->getOpcode() == Instruction::FCmp;
714 static inline bool classof(const Value *V) {
715 return isa<Instruction>(V) && classof(cast<Instruction>(V));
719 //===----------------------------------------------------------------------===//
721 //===----------------------------------------------------------------------===//
723 /// CallInst - This class represents a function call, abstracting a target
724 /// machine's calling convention. This class uses low bit of the SubClassData
725 /// field to indicate whether or not this is a tail call. The rest of the bits
726 /// hold the calling convention of the call.
728 class CallInst : public Instruction {
729 ParamAttrsList *ParamAttrs; ///< parameter attributes for call
730 CallInst(const CallInst &CI);
731 void init(Value *Func, Value* const *Params, unsigned NumParams);
732 void init(Value *Func, Value *Actual1, Value *Actual2);
733 void init(Value *Func, Value *Actual);
734 void init(Value *Func);
737 CallInst(Value *F, Value* const *Args, unsigned NumArgs,
738 const std::string &Name = "", Instruction *InsertBefore = 0);
739 CallInst(Value *F, Value *const *Args, unsigned NumArgs,
740 const std::string &Name, BasicBlock *InsertAtEnd);
742 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
743 // actuals, respectively.
744 CallInst(Value *F, Value *Actual1, Value *Actual2,
745 const std::string& Name = "", Instruction *InsertBefore = 0);
746 CallInst(Value *F, Value *Actual1, Value *Actual2,
747 const std::string& Name, BasicBlock *InsertAtEnd);
748 CallInst(Value *F, Value *Actual, const std::string& Name = "",
749 Instruction *InsertBefore = 0);
750 CallInst(Value *F, Value *Actual, const std::string& Name,
751 BasicBlock *InsertAtEnd);
752 explicit CallInst(Value *F, const std::string &Name = "",
753 Instruction *InsertBefore = 0);
754 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
757 virtual CallInst *clone() const;
759 bool isTailCall() const { return SubclassData & 1; }
760 void setTailCall(bool isTailCall = true) {
761 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
764 /// getCallingConv/setCallingConv - Get or set the calling convention of this
766 unsigned getCallingConv() const { return SubclassData >> 1; }
767 void setCallingConv(unsigned CC) {
768 SubclassData = (SubclassData & 1) | (CC << 1);
771 /// Obtains a pointer to the ParamAttrsList object which holds the
772 /// parameter attributes information, if any.
773 /// @returns 0 if no attributes have been set.
774 /// @brief Get the parameter attributes.
775 ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
777 /// Sets the parameter attributes for this CallInst. To construct a
778 /// ParamAttrsList, see ParameterAttributes.h
779 /// @brief Set the parameter attributes.
780 void setParamAttrs(ParamAttrsList *attrs) { ParamAttrs = attrs; }
782 /// getCalledFunction - Return the function being called by this instruction
783 /// if it is a direct call. If it is a call through a function pointer,
785 Function *getCalledFunction() const {
786 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
789 /// getCalledValue - Get a pointer to the function that is invoked by this
791 inline const Value *getCalledValue() const { return getOperand(0); }
792 inline Value *getCalledValue() { return getOperand(0); }
794 // Methods for support type inquiry through isa, cast, and dyn_cast:
795 static inline bool classof(const CallInst *) { return true; }
796 static inline bool classof(const Instruction *I) {
797 return I->getOpcode() == Instruction::Call;
799 static inline bool classof(const Value *V) {
800 return isa<Instruction>(V) && classof(cast<Instruction>(V));
804 //===----------------------------------------------------------------------===//
806 //===----------------------------------------------------------------------===//
808 /// SelectInst - This class represents the LLVM 'select' instruction.
810 class SelectInst : public Instruction {
813 void init(Value *C, Value *S1, Value *S2) {
814 Ops[0].init(C, this);
815 Ops[1].init(S1, this);
816 Ops[2].init(S2, this);
819 SelectInst(const SelectInst &SI)
820 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
821 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
824 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
825 Instruction *InsertBefore = 0)
826 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
830 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
831 BasicBlock *InsertAtEnd)
832 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
837 Value *getCondition() const { return Ops[0]; }
838 Value *getTrueValue() const { return Ops[1]; }
839 Value *getFalseValue() const { return Ops[2]; }
841 /// Transparently provide more efficient getOperand methods.
842 Value *getOperand(unsigned i) const {
843 assert(i < 3 && "getOperand() out of range!");
846 void setOperand(unsigned i, Value *Val) {
847 assert(i < 3 && "setOperand() out of range!");
850 unsigned getNumOperands() const { return 3; }
852 OtherOps getOpcode() const {
853 return static_cast<OtherOps>(Instruction::getOpcode());
856 virtual SelectInst *clone() const;
858 // Methods for support type inquiry through isa, cast, and dyn_cast:
859 static inline bool classof(const SelectInst *) { return true; }
860 static inline bool classof(const Instruction *I) {
861 return I->getOpcode() == Instruction::Select;
863 static inline bool classof(const Value *V) {
864 return isa<Instruction>(V) && classof(cast<Instruction>(V));
868 //===----------------------------------------------------------------------===//
870 //===----------------------------------------------------------------------===//
872 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
873 /// an argument of the specified type given a va_list and increments that list
875 class VAArgInst : public UnaryInstruction {
876 VAArgInst(const VAArgInst &VAA)
877 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
879 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
880 Instruction *InsertBefore = 0)
881 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
884 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
885 BasicBlock *InsertAtEnd)
886 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
890 virtual VAArgInst *clone() const;
892 // Methods for support type inquiry through isa, cast, and dyn_cast:
893 static inline bool classof(const VAArgInst *) { return true; }
894 static inline bool classof(const Instruction *I) {
895 return I->getOpcode() == VAArg;
897 static inline bool classof(const Value *V) {
898 return isa<Instruction>(V) && classof(cast<Instruction>(V));
902 //===----------------------------------------------------------------------===//
903 // ExtractElementInst Class
904 //===----------------------------------------------------------------------===//
906 /// ExtractElementInst - This instruction extracts a single (scalar)
907 /// element from a VectorType value
909 class ExtractElementInst : public Instruction {
911 ExtractElementInst(const ExtractElementInst &EE) :
912 Instruction(EE.getType(), ExtractElement, Ops, 2) {
913 Ops[0].init(EE.Ops[0], this);
914 Ops[1].init(EE.Ops[1], this);
918 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
919 Instruction *InsertBefore = 0);
920 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
921 Instruction *InsertBefore = 0);
922 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
923 BasicBlock *InsertAtEnd);
924 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
925 BasicBlock *InsertAtEnd);
927 /// isValidOperands - Return true if an extractelement instruction can be
928 /// formed with the specified operands.
929 static bool isValidOperands(const Value *Vec, const Value *Idx);
931 virtual ExtractElementInst *clone() const;
933 /// Transparently provide more efficient getOperand methods.
934 Value *getOperand(unsigned i) const {
935 assert(i < 2 && "getOperand() out of range!");
938 void setOperand(unsigned i, Value *Val) {
939 assert(i < 2 && "setOperand() out of range!");
942 unsigned getNumOperands() const { return 2; }
944 // Methods for support type inquiry through isa, cast, and dyn_cast:
945 static inline bool classof(const ExtractElementInst *) { return true; }
946 static inline bool classof(const Instruction *I) {
947 return I->getOpcode() == Instruction::ExtractElement;
949 static inline bool classof(const Value *V) {
950 return isa<Instruction>(V) && classof(cast<Instruction>(V));
954 //===----------------------------------------------------------------------===//
955 // InsertElementInst Class
956 //===----------------------------------------------------------------------===//
958 /// InsertElementInst - This instruction inserts a single (scalar)
959 /// element into a VectorType value
961 class InsertElementInst : public Instruction {
963 InsertElementInst(const InsertElementInst &IE);
965 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
966 const std::string &Name = "",Instruction *InsertBefore = 0);
967 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
968 const std::string &Name = "",Instruction *InsertBefore = 0);
969 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
970 const std::string &Name, BasicBlock *InsertAtEnd);
971 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
972 const std::string &Name, BasicBlock *InsertAtEnd);
974 /// isValidOperands - Return true if an insertelement instruction can be
975 /// formed with the specified operands.
976 static bool isValidOperands(const Value *Vec, const Value *NewElt,
979 virtual InsertElementInst *clone() const;
981 /// getType - Overload to return most specific vector type.
983 inline const VectorType *getType() const {
984 return reinterpret_cast<const VectorType*>(Instruction::getType());
987 /// Transparently provide more efficient getOperand methods.
988 Value *getOperand(unsigned i) const {
989 assert(i < 3 && "getOperand() out of range!");
992 void setOperand(unsigned i, Value *Val) {
993 assert(i < 3 && "setOperand() out of range!");
996 unsigned getNumOperands() const { return 3; }
998 // Methods for support type inquiry through isa, cast, and dyn_cast:
999 static inline bool classof(const InsertElementInst *) { return true; }
1000 static inline bool classof(const Instruction *I) {
1001 return I->getOpcode() == Instruction::InsertElement;
1003 static inline bool classof(const Value *V) {
1004 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1008 //===----------------------------------------------------------------------===//
1009 // ShuffleVectorInst Class
1010 //===----------------------------------------------------------------------===//
1012 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1015 class ShuffleVectorInst : public Instruction {
1017 ShuffleVectorInst(const ShuffleVectorInst &IE);
1019 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1020 const std::string &Name = "", Instruction *InsertBefor = 0);
1021 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1022 const std::string &Name, BasicBlock *InsertAtEnd);
1024 /// isValidOperands - Return true if a shufflevector instruction can be
1025 /// formed with the specified operands.
1026 static bool isValidOperands(const Value *V1, const Value *V2,
1029 virtual ShuffleVectorInst *clone() const;
1031 /// getType - Overload to return most specific vector type.
1033 inline const VectorType *getType() const {
1034 return reinterpret_cast<const VectorType*>(Instruction::getType());
1037 /// Transparently provide more efficient getOperand methods.
1038 Value *getOperand(unsigned i) const {
1039 assert(i < 3 && "getOperand() out of range!");
1042 void setOperand(unsigned i, Value *Val) {
1043 assert(i < 3 && "setOperand() out of range!");
1046 unsigned getNumOperands() const { return 3; }
1048 // Methods for support type inquiry through isa, cast, and dyn_cast:
1049 static inline bool classof(const ShuffleVectorInst *) { return true; }
1050 static inline bool classof(const Instruction *I) {
1051 return I->getOpcode() == Instruction::ShuffleVector;
1053 static inline bool classof(const Value *V) {
1054 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1059 //===----------------------------------------------------------------------===//
1061 //===----------------------------------------------------------------------===//
1063 // PHINode - The PHINode class is used to represent the magical mystical PHI
1064 // node, that can not exist in nature, but can be synthesized in a computer
1065 // scientist's overactive imagination.
1067 class PHINode : public Instruction {
1068 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1069 /// the number actually in use.
1070 unsigned ReservedSpace;
1071 PHINode(const PHINode &PN);
1073 explicit PHINode(const Type *Ty, const std::string &Name = "",
1074 Instruction *InsertBefore = 0)
1075 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1080 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1081 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1088 /// reserveOperandSpace - This method can be used to avoid repeated
1089 /// reallocation of PHI operand lists by reserving space for the correct
1090 /// number of operands before adding them. Unlike normal vector reserves,
1091 /// this method can also be used to trim the operand space.
1092 void reserveOperandSpace(unsigned NumValues) {
1093 resizeOperands(NumValues*2);
1096 virtual PHINode *clone() const;
1098 /// getNumIncomingValues - Return the number of incoming edges
1100 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1102 /// getIncomingValue - Return incoming value number x
1104 Value *getIncomingValue(unsigned i) const {
1105 assert(i*2 < getNumOperands() && "Invalid value number!");
1106 return getOperand(i*2);
1108 void setIncomingValue(unsigned i, Value *V) {
1109 assert(i*2 < getNumOperands() && "Invalid value number!");
1112 unsigned getOperandNumForIncomingValue(unsigned i) {
1116 /// getIncomingBlock - Return incoming basic block number x
1118 BasicBlock *getIncomingBlock(unsigned i) const {
1119 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1121 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1122 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1124 unsigned getOperandNumForIncomingBlock(unsigned i) {
1128 /// addIncoming - Add an incoming value to the end of the PHI list
1130 void addIncoming(Value *V, BasicBlock *BB) {
1131 assert(getType() == V->getType() &&
1132 "All operands to PHI node must be the same type as the PHI node!");
1133 unsigned OpNo = NumOperands;
1134 if (OpNo+2 > ReservedSpace)
1135 resizeOperands(0); // Get more space!
1136 // Initialize some new operands.
1137 NumOperands = OpNo+2;
1138 OperandList[OpNo].init(V, this);
1139 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1142 /// removeIncomingValue - Remove an incoming value. This is useful if a
1143 /// predecessor basic block is deleted. The value removed is returned.
1145 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1146 /// is true), the PHI node is destroyed and any uses of it are replaced with
1147 /// dummy values. The only time there should be zero incoming values to a PHI
1148 /// node is when the block is dead, so this strategy is sound.
1150 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1152 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1153 int Idx = getBasicBlockIndex(BB);
1154 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1155 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1158 /// getBasicBlockIndex - Return the first index of the specified basic
1159 /// block in the value list for this PHI. Returns -1 if no instance.
1161 int getBasicBlockIndex(const BasicBlock *BB) const {
1162 Use *OL = OperandList;
1163 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1164 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1168 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1169 return getIncomingValue(getBasicBlockIndex(BB));
1172 /// hasConstantValue - If the specified PHI node always merges together the
1173 /// same value, return the value, otherwise return null.
1175 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1177 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1178 static inline bool classof(const PHINode *) { return true; }
1179 static inline bool classof(const Instruction *I) {
1180 return I->getOpcode() == Instruction::PHI;
1182 static inline bool classof(const Value *V) {
1183 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1186 void resizeOperands(unsigned NumOperands);
1189 //===----------------------------------------------------------------------===//
1191 //===----------------------------------------------------------------------===//
1193 //===---------------------------------------------------------------------------
1194 /// ReturnInst - Return a value (possibly void), from a function. Execution
1195 /// does not continue in this function any longer.
1197 class ReturnInst : public TerminatorInst {
1198 Use RetVal; // Return Value: null if 'void'.
1199 ReturnInst(const ReturnInst &RI);
1200 void init(Value *RetVal);
1203 // ReturnInst constructors:
1204 // ReturnInst() - 'ret void' instruction
1205 // ReturnInst( null) - 'ret void' instruction
1206 // ReturnInst(Value* X) - 'ret X' instruction
1207 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1208 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1209 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1210 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1212 // NOTE: If the Value* passed is of type void then the constructor behaves as
1213 // if it was passed NULL.
1214 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1215 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1216 explicit ReturnInst(BasicBlock *InsertAtEnd);
1218 virtual ReturnInst *clone() const;
1220 // Transparently provide more efficient getOperand methods.
1221 Value *getOperand(unsigned i) const {
1222 assert(i < getNumOperands() && "getOperand() out of range!");
1225 void setOperand(unsigned i, Value *Val) {
1226 assert(i < getNumOperands() && "setOperand() out of range!");
1230 Value *getReturnValue() const { return RetVal; }
1232 unsigned getNumSuccessors() const { return 0; }
1234 // Methods for support type inquiry through isa, cast, and dyn_cast:
1235 static inline bool classof(const ReturnInst *) { return true; }
1236 static inline bool classof(const Instruction *I) {
1237 return (I->getOpcode() == Instruction::Ret);
1239 static inline bool classof(const Value *V) {
1240 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1243 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1244 virtual unsigned getNumSuccessorsV() const;
1245 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1248 //===----------------------------------------------------------------------===//
1250 //===----------------------------------------------------------------------===//
1252 //===---------------------------------------------------------------------------
1253 /// BranchInst - Conditional or Unconditional Branch instruction.
1255 class BranchInst : public TerminatorInst {
1256 /// Ops list - Branches are strange. The operands are ordered:
1257 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1258 /// they don't have to check for cond/uncond branchness.
1260 BranchInst(const BranchInst &BI);
1263 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1264 // BranchInst(BB *B) - 'br B'
1265 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1266 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1267 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1268 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1269 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1270 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1271 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1272 Instruction *InsertBefore = 0);
1273 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1274 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1275 BasicBlock *InsertAtEnd);
1277 /// Transparently provide more efficient getOperand methods.
1278 Value *getOperand(unsigned i) const {
1279 assert(i < getNumOperands() && "getOperand() out of range!");
1282 void setOperand(unsigned i, Value *Val) {
1283 assert(i < getNumOperands() && "setOperand() out of range!");
1287 virtual BranchInst *clone() const;
1289 inline bool isUnconditional() const { return getNumOperands() == 1; }
1290 inline bool isConditional() const { return getNumOperands() == 3; }
1292 inline Value *getCondition() const {
1293 assert(isConditional() && "Cannot get condition of an uncond branch!");
1294 return getOperand(2);
1297 void setCondition(Value *V) {
1298 assert(isConditional() && "Cannot set condition of unconditional branch!");
1302 // setUnconditionalDest - Change the current branch to an unconditional branch
1303 // targeting the specified block.
1304 // FIXME: Eliminate this ugly method.
1305 void setUnconditionalDest(BasicBlock *Dest) {
1306 if (isConditional()) { // Convert this to an uncond branch.
1311 setOperand(0, reinterpret_cast<Value*>(Dest));
1314 unsigned getNumSuccessors() const { return 1+isConditional(); }
1316 BasicBlock *getSuccessor(unsigned i) const {
1317 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1318 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1319 cast<BasicBlock>(getOperand(1));
1322 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1323 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1324 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1327 // Methods for support type inquiry through isa, cast, and dyn_cast:
1328 static inline bool classof(const BranchInst *) { return true; }
1329 static inline bool classof(const Instruction *I) {
1330 return (I->getOpcode() == Instruction::Br);
1332 static inline bool classof(const Value *V) {
1333 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1336 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1337 virtual unsigned getNumSuccessorsV() const;
1338 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1341 //===----------------------------------------------------------------------===//
1343 //===----------------------------------------------------------------------===//
1345 //===---------------------------------------------------------------------------
1346 /// SwitchInst - Multiway switch
1348 class SwitchInst : public TerminatorInst {
1349 unsigned ReservedSpace;
1350 // Operand[0] = Value to switch on
1351 // Operand[1] = Default basic block destination
1352 // Operand[2n ] = Value to match
1353 // Operand[2n+1] = BasicBlock to go to on match
1354 SwitchInst(const SwitchInst &RI);
1355 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1356 void resizeOperands(unsigned No);
1358 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1359 /// switch on and a default destination. The number of additional cases can
1360 /// be specified here to make memory allocation more efficient. This
1361 /// constructor can also autoinsert before another instruction.
1362 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1363 Instruction *InsertBefore = 0);
1365 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1366 /// switch on and a default destination. The number of additional cases can
1367 /// be specified here to make memory allocation more efficient. This
1368 /// constructor also autoinserts at the end of the specified BasicBlock.
1369 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1370 BasicBlock *InsertAtEnd);
1374 // Accessor Methods for Switch stmt
1375 inline Value *getCondition() const { return getOperand(0); }
1376 void setCondition(Value *V) { setOperand(0, V); }
1378 inline BasicBlock *getDefaultDest() const {
1379 return cast<BasicBlock>(getOperand(1));
1382 /// getNumCases - return the number of 'cases' in this switch instruction.
1383 /// Note that case #0 is always the default case.
1384 unsigned getNumCases() const {
1385 return getNumOperands()/2;
1388 /// getCaseValue - Return the specified case value. Note that case #0, the
1389 /// default destination, does not have a case value.
1390 ConstantInt *getCaseValue(unsigned i) {
1391 assert(i && i < getNumCases() && "Illegal case value to get!");
1392 return getSuccessorValue(i);
1395 /// getCaseValue - Return the specified case value. Note that case #0, the
1396 /// default destination, does not have a case value.
1397 const ConstantInt *getCaseValue(unsigned i) const {
1398 assert(i && i < getNumCases() && "Illegal case value to get!");
1399 return getSuccessorValue(i);
1402 /// findCaseValue - Search all of the case values for the specified constant.
1403 /// If it is explicitly handled, return the case number of it, otherwise
1404 /// return 0 to indicate that it is handled by the default handler.
1405 unsigned findCaseValue(const ConstantInt *C) const {
1406 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1407 if (getCaseValue(i) == C)
1412 /// findCaseDest - Finds the unique case value for a given successor. Returns
1413 /// null if the successor is not found, not unique, or is the default case.
1414 ConstantInt *findCaseDest(BasicBlock *BB) {
1415 if (BB == getDefaultDest()) return NULL;
1417 ConstantInt *CI = NULL;
1418 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1419 if (getSuccessor(i) == BB) {
1420 if (CI) return NULL; // Multiple cases lead to BB.
1421 else CI = getCaseValue(i);
1427 /// addCase - Add an entry to the switch instruction...
1429 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1431 /// removeCase - This method removes the specified successor from the switch
1432 /// instruction. Note that this cannot be used to remove the default
1433 /// destination (successor #0).
1435 void removeCase(unsigned idx);
1437 virtual SwitchInst *clone() const;
1439 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1440 BasicBlock *getSuccessor(unsigned idx) const {
1441 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1442 return cast<BasicBlock>(getOperand(idx*2+1));
1444 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1445 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1446 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1449 // getSuccessorValue - Return the value associated with the specified
1451 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1452 assert(idx < getNumSuccessors() && "Successor # out of range!");
1453 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1456 // Methods for support type inquiry through isa, cast, and dyn_cast:
1457 static inline bool classof(const SwitchInst *) { return true; }
1458 static inline bool classof(const Instruction *I) {
1459 return I->getOpcode() == Instruction::Switch;
1461 static inline bool classof(const Value *V) {
1462 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1465 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1466 virtual unsigned getNumSuccessorsV() const;
1467 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1470 //===----------------------------------------------------------------------===//
1472 //===----------------------------------------------------------------------===//
1474 //===---------------------------------------------------------------------------
1476 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1477 /// calling convention of the call.
1479 class InvokeInst : public TerminatorInst {
1480 ParamAttrsList *ParamAttrs;
1481 InvokeInst(const InvokeInst &BI);
1482 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1483 Value* const *Args, unsigned NumArgs);
1485 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1486 Value* const* Args, unsigned NumArgs, const std::string &Name = "",
1487 Instruction *InsertBefore = 0);
1488 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1489 Value* const* Args, unsigned NumArgs, const std::string &Name,
1490 BasicBlock *InsertAtEnd);
1493 virtual InvokeInst *clone() const;
1495 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1497 unsigned getCallingConv() const { return SubclassData; }
1498 void setCallingConv(unsigned CC) {
1502 /// Obtains a pointer to the ParamAttrsList object which holds the
1503 /// parameter attributes information, if any.
1504 /// @returns 0 if no attributes have been set.
1505 /// @brief Get the parameter attributes.
1506 ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
1508 /// Sets the parameter attributes for this InvokeInst. To construct a
1509 /// ParamAttrsList, see ParameterAttributes.h
1510 /// @brief Set the parameter attributes.
1511 void setParamAttrs(ParamAttrsList *attrs) { ParamAttrs = attrs; }
1513 /// getCalledFunction - Return the function called, or null if this is an
1514 /// indirect function invocation.
1516 Function *getCalledFunction() const {
1517 return dyn_cast<Function>(getOperand(0));
1520 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1521 inline Value *getCalledValue() const { return getOperand(0); }
1523 // get*Dest - Return the destination basic blocks...
1524 BasicBlock *getNormalDest() const {
1525 return cast<BasicBlock>(getOperand(1));
1527 BasicBlock *getUnwindDest() const {
1528 return cast<BasicBlock>(getOperand(2));
1530 void setNormalDest(BasicBlock *B) {
1531 setOperand(1, reinterpret_cast<Value*>(B));
1534 void setUnwindDest(BasicBlock *B) {
1535 setOperand(2, reinterpret_cast<Value*>(B));
1538 inline BasicBlock *getSuccessor(unsigned i) const {
1539 assert(i < 2 && "Successor # out of range for invoke!");
1540 return i == 0 ? getNormalDest() : getUnwindDest();
1543 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1544 assert(idx < 2 && "Successor # out of range for invoke!");
1545 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1548 unsigned getNumSuccessors() const { return 2; }
1550 // Methods for support type inquiry through isa, cast, and dyn_cast:
1551 static inline bool classof(const InvokeInst *) { return true; }
1552 static inline bool classof(const Instruction *I) {
1553 return (I->getOpcode() == Instruction::Invoke);
1555 static inline bool classof(const Value *V) {
1556 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1559 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1560 virtual unsigned getNumSuccessorsV() const;
1561 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1565 //===----------------------------------------------------------------------===//
1567 //===----------------------------------------------------------------------===//
1569 //===---------------------------------------------------------------------------
1570 /// UnwindInst - Immediately exit the current function, unwinding the stack
1571 /// until an invoke instruction is found.
1573 class UnwindInst : public TerminatorInst {
1575 explicit UnwindInst(Instruction *InsertBefore = 0);
1576 explicit UnwindInst(BasicBlock *InsertAtEnd);
1578 virtual UnwindInst *clone() const;
1580 unsigned getNumSuccessors() const { return 0; }
1582 // Methods for support type inquiry through isa, cast, and dyn_cast:
1583 static inline bool classof(const UnwindInst *) { return true; }
1584 static inline bool classof(const Instruction *I) {
1585 return I->getOpcode() == Instruction::Unwind;
1587 static inline bool classof(const Value *V) {
1588 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1591 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1592 virtual unsigned getNumSuccessorsV() const;
1593 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1596 //===----------------------------------------------------------------------===//
1597 // UnreachableInst Class
1598 //===----------------------------------------------------------------------===//
1600 //===---------------------------------------------------------------------------
1601 /// UnreachableInst - This function has undefined behavior. In particular, the
1602 /// presence of this instruction indicates some higher level knowledge that the
1603 /// end of the block cannot be reached.
1605 class UnreachableInst : public TerminatorInst {
1607 explicit UnreachableInst(Instruction *InsertBefore = 0);
1608 explicit UnreachableInst(BasicBlock *InsertAtEnd);
1610 virtual UnreachableInst *clone() const;
1612 unsigned getNumSuccessors() const { return 0; }
1614 // Methods for support type inquiry through isa, cast, and dyn_cast:
1615 static inline bool classof(const UnreachableInst *) { return true; }
1616 static inline bool classof(const Instruction *I) {
1617 return I->getOpcode() == Instruction::Unreachable;
1619 static inline bool classof(const Value *V) {
1620 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1623 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1624 virtual unsigned getNumSuccessorsV() const;
1625 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1628 //===----------------------------------------------------------------------===//
1630 //===----------------------------------------------------------------------===//
1632 /// @brief This class represents a truncation of integer types.
1633 class TruncInst : public CastInst {
1634 /// Private copy constructor
1635 TruncInst(const TruncInst &CI)
1636 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1639 /// @brief Constructor with insert-before-instruction semantics
1641 Value *S, ///< The value to be truncated
1642 const Type *Ty, ///< The (smaller) type to truncate to
1643 const std::string &Name = "", ///< A name for the new instruction
1644 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1647 /// @brief Constructor with insert-at-end-of-block semantics
1649 Value *S, ///< The value to be truncated
1650 const Type *Ty, ///< The (smaller) type to truncate to
1651 const std::string &Name, ///< A name for the new instruction
1652 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1655 /// @brief Clone an identical TruncInst
1656 virtual CastInst *clone() const;
1658 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1659 static inline bool classof(const TruncInst *) { return true; }
1660 static inline bool classof(const Instruction *I) {
1661 return I->getOpcode() == Trunc;
1663 static inline bool classof(const Value *V) {
1664 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1668 //===----------------------------------------------------------------------===//
1670 //===----------------------------------------------------------------------===//
1672 /// @brief This class represents zero extension of integer types.
1673 class ZExtInst : public CastInst {
1674 /// @brief Private copy constructor
1675 ZExtInst(const ZExtInst &CI)
1676 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1679 /// @brief Constructor with insert-before-instruction semantics
1681 Value *S, ///< The value to be zero extended
1682 const Type *Ty, ///< The type to zero extend to
1683 const std::string &Name = "", ///< A name for the new instruction
1684 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1687 /// @brief Constructor with insert-at-end semantics.
1689 Value *S, ///< The value to be zero extended
1690 const Type *Ty, ///< The type to zero extend to
1691 const std::string &Name, ///< A name for the new instruction
1692 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1695 /// @brief Clone an identical ZExtInst
1696 virtual CastInst *clone() const;
1698 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1699 static inline bool classof(const ZExtInst *) { return true; }
1700 static inline bool classof(const Instruction *I) {
1701 return I->getOpcode() == ZExt;
1703 static inline bool classof(const Value *V) {
1704 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1708 //===----------------------------------------------------------------------===//
1710 //===----------------------------------------------------------------------===//
1712 /// @brief This class represents a sign extension of integer types.
1713 class SExtInst : public CastInst {
1714 /// @brief Private copy constructor
1715 SExtInst(const SExtInst &CI)
1716 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1719 /// @brief Constructor with insert-before-instruction semantics
1721 Value *S, ///< The value to be sign extended
1722 const Type *Ty, ///< The type to sign extend to
1723 const std::string &Name = "", ///< A name for the new instruction
1724 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1727 /// @brief Constructor with insert-at-end-of-block semantics
1729 Value *S, ///< The value to be sign extended
1730 const Type *Ty, ///< The type to sign extend to
1731 const std::string &Name, ///< A name for the new instruction
1732 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1735 /// @brief Clone an identical SExtInst
1736 virtual CastInst *clone() const;
1738 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1739 static inline bool classof(const SExtInst *) { return true; }
1740 static inline bool classof(const Instruction *I) {
1741 return I->getOpcode() == SExt;
1743 static inline bool classof(const Value *V) {
1744 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1748 //===----------------------------------------------------------------------===//
1749 // FPTruncInst Class
1750 //===----------------------------------------------------------------------===//
1752 /// @brief This class represents a truncation of floating point types.
1753 class FPTruncInst : public CastInst {
1754 FPTruncInst(const FPTruncInst &CI)
1755 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1758 /// @brief Constructor with insert-before-instruction semantics
1760 Value *S, ///< The value to be truncated
1761 const Type *Ty, ///< The type to truncate to
1762 const std::string &Name = "", ///< A name for the new instruction
1763 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1766 /// @brief Constructor with insert-before-instruction semantics
1768 Value *S, ///< The value to be truncated
1769 const Type *Ty, ///< The type to truncate to
1770 const std::string &Name, ///< A name for the new instruction
1771 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1774 /// @brief Clone an identical FPTruncInst
1775 virtual CastInst *clone() const;
1777 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1778 static inline bool classof(const FPTruncInst *) { return true; }
1779 static inline bool classof(const Instruction *I) {
1780 return I->getOpcode() == FPTrunc;
1782 static inline bool classof(const Value *V) {
1783 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1787 //===----------------------------------------------------------------------===//
1789 //===----------------------------------------------------------------------===//
1791 /// @brief This class represents an extension of floating point types.
1792 class FPExtInst : public CastInst {
1793 FPExtInst(const FPExtInst &CI)
1794 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1797 /// @brief Constructor with insert-before-instruction semantics
1799 Value *S, ///< The value to be extended
1800 const Type *Ty, ///< The type to extend to
1801 const std::string &Name = "", ///< A name for the new instruction
1802 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1805 /// @brief Constructor with insert-at-end-of-block semantics
1807 Value *S, ///< The value to be extended
1808 const Type *Ty, ///< The type to extend to
1809 const std::string &Name, ///< A name for the new instruction
1810 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1813 /// @brief Clone an identical FPExtInst
1814 virtual CastInst *clone() const;
1816 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1817 static inline bool classof(const FPExtInst *) { return true; }
1818 static inline bool classof(const Instruction *I) {
1819 return I->getOpcode() == FPExt;
1821 static inline bool classof(const Value *V) {
1822 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1826 //===----------------------------------------------------------------------===//
1828 //===----------------------------------------------------------------------===//
1830 /// @brief This class represents a cast unsigned integer to floating point.
1831 class UIToFPInst : public CastInst {
1832 UIToFPInst(const UIToFPInst &CI)
1833 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1836 /// @brief Constructor with insert-before-instruction semantics
1838 Value *S, ///< The value to be converted
1839 const Type *Ty, ///< The type to convert to
1840 const std::string &Name = "", ///< A name for the new instruction
1841 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1844 /// @brief Constructor with insert-at-end-of-block semantics
1846 Value *S, ///< The value to be converted
1847 const Type *Ty, ///< The type to convert to
1848 const std::string &Name, ///< A name for the new instruction
1849 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1852 /// @brief Clone an identical UIToFPInst
1853 virtual CastInst *clone() const;
1855 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1856 static inline bool classof(const UIToFPInst *) { return true; }
1857 static inline bool classof(const Instruction *I) {
1858 return I->getOpcode() == UIToFP;
1860 static inline bool classof(const Value *V) {
1861 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1865 //===----------------------------------------------------------------------===//
1867 //===----------------------------------------------------------------------===//
1869 /// @brief This class represents a cast from signed integer to floating point.
1870 class SIToFPInst : public CastInst {
1871 SIToFPInst(const SIToFPInst &CI)
1872 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1875 /// @brief Constructor with insert-before-instruction semantics
1877 Value *S, ///< The value to be converted
1878 const Type *Ty, ///< The type to convert to
1879 const std::string &Name = "", ///< A name for the new instruction
1880 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1883 /// @brief Constructor with insert-at-end-of-block semantics
1885 Value *S, ///< The value to be converted
1886 const Type *Ty, ///< The type to convert to
1887 const std::string &Name, ///< A name for the new instruction
1888 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1891 /// @brief Clone an identical SIToFPInst
1892 virtual CastInst *clone() const;
1894 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1895 static inline bool classof(const SIToFPInst *) { return true; }
1896 static inline bool classof(const Instruction *I) {
1897 return I->getOpcode() == SIToFP;
1899 static inline bool classof(const Value *V) {
1900 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1904 //===----------------------------------------------------------------------===//
1906 //===----------------------------------------------------------------------===//
1908 /// @brief This class represents a cast from floating point to unsigned integer
1909 class FPToUIInst : public CastInst {
1910 FPToUIInst(const FPToUIInst &CI)
1911 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1914 /// @brief Constructor with insert-before-instruction semantics
1916 Value *S, ///< The value to be converted
1917 const Type *Ty, ///< The type to convert to
1918 const std::string &Name = "", ///< A name for the new instruction
1919 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1922 /// @brief Constructor with insert-at-end-of-block semantics
1924 Value *S, ///< The value to be converted
1925 const Type *Ty, ///< The type to convert to
1926 const std::string &Name, ///< A name for the new instruction
1927 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
1930 /// @brief Clone an identical FPToUIInst
1931 virtual CastInst *clone() const;
1933 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1934 static inline bool classof(const FPToUIInst *) { return true; }
1935 static inline bool classof(const Instruction *I) {
1936 return I->getOpcode() == FPToUI;
1938 static inline bool classof(const Value *V) {
1939 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1943 //===----------------------------------------------------------------------===//
1945 //===----------------------------------------------------------------------===//
1947 /// @brief This class represents a cast from floating point to signed integer.
1948 class FPToSIInst : public CastInst {
1949 FPToSIInst(const FPToSIInst &CI)
1950 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
1953 /// @brief Constructor with insert-before-instruction semantics
1955 Value *S, ///< The value to be converted
1956 const Type *Ty, ///< The type to convert to
1957 const std::string &Name = "", ///< A name for the new instruction
1958 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1961 /// @brief Constructor with insert-at-end-of-block semantics
1963 Value *S, ///< The value to be converted
1964 const Type *Ty, ///< The type to convert to
1965 const std::string &Name, ///< A name for the new instruction
1966 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1969 /// @brief Clone an identical FPToSIInst
1970 virtual CastInst *clone() const;
1972 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1973 static inline bool classof(const FPToSIInst *) { return true; }
1974 static inline bool classof(const Instruction *I) {
1975 return I->getOpcode() == FPToSI;
1977 static inline bool classof(const Value *V) {
1978 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1982 //===----------------------------------------------------------------------===//
1983 // IntToPtrInst Class
1984 //===----------------------------------------------------------------------===//
1986 /// @brief This class represents a cast from an integer to a pointer.
1987 class IntToPtrInst : public CastInst {
1988 IntToPtrInst(const IntToPtrInst &CI)
1989 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
1992 /// @brief Constructor with insert-before-instruction semantics
1994 Value *S, ///< The value to be converted
1995 const Type *Ty, ///< The type to convert to
1996 const std::string &Name = "", ///< A name for the new instruction
1997 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2000 /// @brief Constructor with insert-at-end-of-block semantics
2002 Value *S, ///< The value to be converted
2003 const Type *Ty, ///< The type to convert to
2004 const std::string &Name, ///< A name for the new instruction
2005 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2008 /// @brief Clone an identical IntToPtrInst
2009 virtual CastInst *clone() const;
2011 // Methods for support type inquiry through isa, cast, and dyn_cast:
2012 static inline bool classof(const IntToPtrInst *) { return true; }
2013 static inline bool classof(const Instruction *I) {
2014 return I->getOpcode() == IntToPtr;
2016 static inline bool classof(const Value *V) {
2017 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2021 //===----------------------------------------------------------------------===//
2022 // PtrToIntInst Class
2023 //===----------------------------------------------------------------------===//
2025 /// @brief This class represents a cast from a pointer to an integer
2026 class PtrToIntInst : public CastInst {
2027 PtrToIntInst(const PtrToIntInst &CI)
2028 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2031 /// @brief Constructor with insert-before-instruction semantics
2033 Value *S, ///< The value to be converted
2034 const Type *Ty, ///< The type to convert to
2035 const std::string &Name = "", ///< A name for the new instruction
2036 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2039 /// @brief Constructor with insert-at-end-of-block semantics
2041 Value *S, ///< The value to be converted
2042 const Type *Ty, ///< The type to convert to
2043 const std::string &Name, ///< A name for the new instruction
2044 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2047 /// @brief Clone an identical PtrToIntInst
2048 virtual CastInst *clone() const;
2050 // Methods for support type inquiry through isa, cast, and dyn_cast:
2051 static inline bool classof(const PtrToIntInst *) { return true; }
2052 static inline bool classof(const Instruction *I) {
2053 return I->getOpcode() == PtrToInt;
2055 static inline bool classof(const Value *V) {
2056 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2060 //===----------------------------------------------------------------------===//
2061 // BitCastInst Class
2062 //===----------------------------------------------------------------------===//
2064 /// @brief This class represents a no-op cast from one type to another.
2065 class BitCastInst : public CastInst {
2066 BitCastInst(const BitCastInst &CI)
2067 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2070 /// @brief Constructor with insert-before-instruction semantics
2072 Value *S, ///< The value to be casted
2073 const Type *Ty, ///< The type to casted to
2074 const std::string &Name = "", ///< A name for the new instruction
2075 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2078 /// @brief Constructor with insert-at-end-of-block semantics
2080 Value *S, ///< The value to be casted
2081 const Type *Ty, ///< The type to casted to
2082 const std::string &Name, ///< A name for the new instruction
2083 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2086 /// @brief Clone an identical BitCastInst
2087 virtual CastInst *clone() const;
2089 // Methods for support type inquiry through isa, cast, and dyn_cast:
2090 static inline bool classof(const BitCastInst *) { return true; }
2091 static inline bool classof(const Instruction *I) {
2092 return I->getOpcode() == BitCast;
2094 static inline bool classof(const Value *V) {
2095 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2099 } // End llvm namespace