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
21 #include "llvm/InstrTypes.h"
22 #include "llvm/DerivedTypes.h"
34 //===----------------------------------------------------------------------===//
35 // AllocationInst Class
36 //===----------------------------------------------------------------------===//
38 /// AllocationInst - This class is the common base class of MallocInst and
41 class AllocationInst : public UnaryInstruction {
44 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
45 const std::string &Name = "", Instruction *InsertBefore = 0);
46 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
47 const std::string &Name, BasicBlock *InsertAtEnd);
49 // Out of line virtual method, so the vtable, etc has a home.
50 virtual ~AllocationInst();
52 /// isArrayAllocation - Return true if there is an allocation size parameter
53 /// to the allocation instruction that is not 1.
55 bool isArrayAllocation() const;
57 /// getArraySize - Get the number of element allocated, for a simple
58 /// allocation of a single element, this will return a constant 1 value.
60 inline const Value *getArraySize() const { return getOperand(0); }
61 inline Value *getArraySize() { return getOperand(0); }
63 /// getType - Overload to return most specific pointer type
65 inline const PointerType *getType() const {
66 return reinterpret_cast<const PointerType*>(Instruction::getType());
69 /// getAllocatedType - Return the type that is being allocated by the
72 const Type *getAllocatedType() const;
74 /// getAlignment - Return the alignment of the memory that is being allocated
75 /// by the instruction.
77 unsigned getAlignment() const { return Alignment; }
78 void setAlignment(unsigned Align) {
79 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
83 virtual Instruction *clone() const = 0;
85 // Methods for support type inquiry through isa, cast, and dyn_cast:
86 static inline bool classof(const AllocationInst *) { return true; }
87 static inline bool classof(const Instruction *I) {
88 return I->getOpcode() == Instruction::Alloca ||
89 I->getOpcode() == Instruction::Malloc;
91 static inline bool classof(const Value *V) {
92 return isa<Instruction>(V) && classof(cast<Instruction>(V));
97 //===----------------------------------------------------------------------===//
99 //===----------------------------------------------------------------------===//
101 /// MallocInst - an instruction to allocated memory on the heap
103 class MallocInst : public AllocationInst {
104 MallocInst(const MallocInst &MI);
106 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
107 const std::string &Name = "",
108 Instruction *InsertBefore = 0)
109 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
110 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
111 BasicBlock *InsertAtEnd)
112 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
114 MallocInst(const Type *Ty, const std::string &Name,
115 Instruction *InsertBefore = 0)
116 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
117 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
118 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
120 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
121 const std::string &Name, BasicBlock *InsertAtEnd)
122 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
123 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
124 const std::string &Name = "",
125 Instruction *InsertBefore = 0)
126 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
128 virtual MallocInst *clone() const;
130 // Methods for support type inquiry through isa, cast, and dyn_cast:
131 static inline bool classof(const MallocInst *) { return true; }
132 static inline bool classof(const Instruction *I) {
133 return (I->getOpcode() == Instruction::Malloc);
135 static inline bool classof(const Value *V) {
136 return isa<Instruction>(V) && classof(cast<Instruction>(V));
141 //===----------------------------------------------------------------------===//
143 //===----------------------------------------------------------------------===//
145 /// AllocaInst - an instruction to allocate memory on the stack
147 class AllocaInst : public AllocationInst {
148 AllocaInst(const AllocaInst &);
150 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
151 const std::string &Name = "",
152 Instruction *InsertBefore = 0)
153 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
154 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
155 BasicBlock *InsertAtEnd)
156 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
158 AllocaInst(const Type *Ty, const std::string &Name,
159 Instruction *InsertBefore = 0)
160 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
161 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
162 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
164 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
165 const std::string &Name = "", Instruction *InsertBefore = 0)
166 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
167 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
168 const std::string &Name, BasicBlock *InsertAtEnd)
169 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
171 virtual AllocaInst *clone() const;
173 // Methods for support type inquiry through isa, cast, and dyn_cast:
174 static inline bool classof(const AllocaInst *) { return true; }
175 static inline bool classof(const Instruction *I) {
176 return (I->getOpcode() == Instruction::Alloca);
178 static inline bool classof(const Value *V) {
179 return isa<Instruction>(V) && classof(cast<Instruction>(V));
184 //===----------------------------------------------------------------------===//
186 //===----------------------------------------------------------------------===//
188 /// FreeInst - an instruction to deallocate memory
190 class FreeInst : public UnaryInstruction {
193 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
194 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
196 virtual FreeInst *clone() const;
198 // Accessor methods for consistency with other memory operations
199 Value *getPointerOperand() { return getOperand(0); }
200 const Value *getPointerOperand() const { return getOperand(0); }
202 // Methods for support type inquiry through isa, cast, and dyn_cast:
203 static inline bool classof(const FreeInst *) { return true; }
204 static inline bool classof(const Instruction *I) {
205 return (I->getOpcode() == Instruction::Free);
207 static inline bool classof(const Value *V) {
208 return isa<Instruction>(V) && classof(cast<Instruction>(V));
213 //===----------------------------------------------------------------------===//
215 //===----------------------------------------------------------------------===//
217 /// LoadInst - an instruction for reading from memory. This uses the
218 /// SubclassData field in Value to store whether or not the load is volatile.
220 class LoadInst : public UnaryInstruction {
222 LoadInst(const LoadInst &LI)
223 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
224 setVolatile(LI.isVolatile());
225 setAlignment(LI.getAlignment());
233 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
234 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
235 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false,
236 Instruction *InsertBefore = 0);
237 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
238 Instruction *InsertBefore = 0);
239 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
240 BasicBlock *InsertAtEnd);
241 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
242 BasicBlock *InsertAtEnd);
244 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
245 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
246 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
247 Instruction *InsertBefore = 0);
248 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
249 BasicBlock *InsertAtEnd);
251 /// isVolatile - Return true if this is a load from a volatile memory
254 bool isVolatile() const { return SubclassData & 1; }
256 /// setVolatile - Specify whether this is a volatile load or not.
258 void setVolatile(bool V) {
259 SubclassData = (SubclassData & ~1) | V;
262 virtual LoadInst *clone() const;
264 /// getAlignment - Return the alignment of the access that is being performed
266 unsigned getAlignment() const {
267 return (1 << (SubclassData>>1)) >> 1;
270 void setAlignment(unsigned Align);
272 Value *getPointerOperand() { return getOperand(0); }
273 const Value *getPointerOperand() const { return getOperand(0); }
274 static unsigned getPointerOperandIndex() { return 0U; }
276 // Methods for support type inquiry through isa, cast, and dyn_cast:
277 static inline bool classof(const LoadInst *) { return true; }
278 static inline bool classof(const Instruction *I) {
279 return I->getOpcode() == Instruction::Load;
281 static inline bool classof(const Value *V) {
282 return isa<Instruction>(V) && classof(cast<Instruction>(V));
287 //===----------------------------------------------------------------------===//
289 //===----------------------------------------------------------------------===//
291 /// StoreInst - an instruction for storing to memory
293 class StoreInst : public Instruction {
296 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
297 Ops[0].init(SI.Ops[0], this);
298 Ops[1].init(SI.Ops[1], this);
299 setVolatile(SI.isVolatile());
300 setAlignment(SI.getAlignment());
308 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
309 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
310 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
311 Instruction *InsertBefore = 0);
312 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
313 unsigned Align, Instruction *InsertBefore = 0);
314 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
315 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
316 unsigned Align, BasicBlock *InsertAtEnd);
319 /// isVolatile - Return true if this is a load from a volatile memory
322 bool isVolatile() const { return SubclassData & 1; }
324 /// setVolatile - Specify whether this is a volatile load or not.
326 void setVolatile(bool V) {
327 SubclassData = (SubclassData & ~1) | V;
330 /// Transparently provide more efficient getOperand methods.
331 Value *getOperand(unsigned i) const {
332 assert(i < 2 && "getOperand() out of range!");
335 void setOperand(unsigned i, Value *Val) {
336 assert(i < 2 && "setOperand() out of range!");
339 unsigned getNumOperands() const { return 2; }
341 /// getAlignment - Return the alignment of the access that is being performed
343 unsigned getAlignment() const {
344 return (1 << (SubclassData>>1)) >> 1;
347 void setAlignment(unsigned Align);
349 virtual StoreInst *clone() const;
351 Value *getPointerOperand() { return getOperand(1); }
352 const Value *getPointerOperand() const { return getOperand(1); }
353 static unsigned getPointerOperandIndex() { return 1U; }
355 // Methods for support type inquiry through isa, cast, and dyn_cast:
356 static inline bool classof(const StoreInst *) { return true; }
357 static inline bool classof(const Instruction *I) {
358 return I->getOpcode() == Instruction::Store;
360 static inline bool classof(const Value *V) {
361 return isa<Instruction>(V) && classof(cast<Instruction>(V));
366 //===----------------------------------------------------------------------===//
367 // GetElementPtrInst Class
368 //===----------------------------------------------------------------------===//
370 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
371 /// access elements of arrays and structs
373 class GetElementPtrInst : public Instruction {
374 GetElementPtrInst(const GetElementPtrInst &GEPI)
375 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
376 0, GEPI.getNumOperands()) {
377 Use *OL = OperandList = new Use[NumOperands];
378 Use *GEPIOL = GEPI.OperandList;
379 for (unsigned i = 0, E = NumOperands; i != E; ++i)
380 OL[i].init(GEPIOL[i], this);
382 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
383 void init(Value *Ptr, Value *Idx0, Value *Idx1);
384 void init(Value *Ptr, Value *Idx);
386 /// Constructors - Create a getelementptr instruction with a base pointer an
387 /// list of indices. The first ctor can optionally insert before an existing
388 /// instruction, the second appends the new instruction to the specified
390 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
391 const std::string &Name = "", Instruction *InsertBefore =0);
392 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
393 const std::string &Name, BasicBlock *InsertAtEnd);
395 /// Constructors - These two constructors are convenience methods because one
396 /// and two index getelementptr instructions are so common.
397 GetElementPtrInst(Value *Ptr, Value *Idx,
398 const std::string &Name = "", Instruction *InsertBefore =0);
399 GetElementPtrInst(Value *Ptr, Value *Idx,
400 const std::string &Name, BasicBlock *InsertAtEnd);
401 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
402 const std::string &Name = "", Instruction *InsertBefore =0);
403 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
404 const std::string &Name, BasicBlock *InsertAtEnd);
405 ~GetElementPtrInst();
407 virtual GetElementPtrInst *clone() const;
409 // getType - Overload to return most specific pointer type...
410 inline const PointerType *getType() const {
411 return reinterpret_cast<const PointerType*>(Instruction::getType());
414 /// getIndexedType - Returns the type of the element that would be loaded with
415 /// a load instruction with the specified parameters.
417 /// A null type is returned if the indices are invalid for the specified
420 static const Type *getIndexedType(const Type *Ptr,
421 Value* const *Idx, unsigned NumIdx,
422 bool AllowStructLeaf = false);
424 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
425 bool AllowStructLeaf = false);
426 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
428 inline op_iterator idx_begin() { return op_begin()+1; }
429 inline const_op_iterator idx_begin() const { return op_begin()+1; }
430 inline op_iterator idx_end() { return op_end(); }
431 inline const_op_iterator idx_end() const { return op_end(); }
433 Value *getPointerOperand() {
434 return getOperand(0);
436 const Value *getPointerOperand() const {
437 return getOperand(0);
439 static unsigned getPointerOperandIndex() {
440 return 0U; // get index for modifying correct operand
443 inline unsigned getNumIndices() const { // Note: always non-negative
444 return getNumOperands() - 1;
447 inline bool hasIndices() const {
448 return getNumOperands() > 1;
451 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
452 /// zeros. If so, the result pointer and the first operand have the same
453 /// value, just potentially different types.
454 bool hasAllZeroIndices() const;
456 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
457 /// constant integers. If so, the result pointer and the first operand have
458 /// a constant offset between them.
459 bool hasAllConstantIndices() const;
462 // Methods for support type inquiry through isa, cast, and dyn_cast:
463 static inline bool classof(const GetElementPtrInst *) { return true; }
464 static inline bool classof(const Instruction *I) {
465 return (I->getOpcode() == Instruction::GetElementPtr);
467 static inline bool classof(const Value *V) {
468 return isa<Instruction>(V) && classof(cast<Instruction>(V));
472 //===----------------------------------------------------------------------===//
474 //===----------------------------------------------------------------------===//
476 /// This instruction compares its operands according to the predicate given
477 /// to the constructor. It only operates on integers, pointers, or packed
478 /// vectors of integrals. The two operands must be the same type.
479 /// @brief Represent an integer comparison operator.
480 class ICmpInst: public CmpInst {
482 /// This enumeration lists the possible predicates for the ICmpInst. The
483 /// values in the range 0-31 are reserved for FCmpInst while values in the
484 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
485 /// predicate values are not overlapping between the classes.
487 ICMP_EQ = 32, ///< equal
488 ICMP_NE = 33, ///< not equal
489 ICMP_UGT = 34, ///< unsigned greater than
490 ICMP_UGE = 35, ///< unsigned greater or equal
491 ICMP_ULT = 36, ///< unsigned less than
492 ICMP_ULE = 37, ///< unsigned less or equal
493 ICMP_SGT = 38, ///< signed greater than
494 ICMP_SGE = 39, ///< signed greater or equal
495 ICMP_SLT = 40, ///< signed less than
496 ICMP_SLE = 41, ///< signed less or equal
497 FIRST_ICMP_PREDICATE = ICMP_EQ,
498 LAST_ICMP_PREDICATE = ICMP_SLE,
499 BAD_ICMP_PREDICATE = ICMP_SLE + 1
502 /// @brief Constructor with insert-before-instruction semantics.
504 Predicate pred, ///< The predicate to use for the comparison
505 Value *LHS, ///< The left-hand-side of the expression
506 Value *RHS, ///< The right-hand-side of the expression
507 const std::string &Name = "", ///< Name of the instruction
508 Instruction *InsertBefore = 0 ///< Where to insert
509 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
512 /// @brief Constructor with insert-at-block-end semantics.
514 Predicate pred, ///< The predicate to use for the comparison
515 Value *LHS, ///< The left-hand-side of the expression
516 Value *RHS, ///< The right-hand-side of the expression
517 const std::string &Name, ///< Name of the instruction
518 BasicBlock *InsertAtEnd ///< Block to insert into.
519 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
522 /// @brief Return the predicate for this instruction.
523 Predicate getPredicate() const { return Predicate(SubclassData); }
525 /// @brief Set the predicate for this instruction to the specified value.
526 void setPredicate(Predicate P) { SubclassData = P; }
528 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
529 /// @returns the inverse predicate for the instruction's current predicate.
530 /// @brief Return the inverse of the instruction's predicate.
531 Predicate getInversePredicate() const {
532 return getInversePredicate(getPredicate());
535 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
536 /// @returns the inverse predicate for predicate provided in \p pred.
537 /// @brief Return the inverse of a given predicate
538 static Predicate getInversePredicate(Predicate pred);
540 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
541 /// @returns the predicate that would be the result of exchanging the two
542 /// operands of the ICmpInst instruction without changing the result
544 /// @brief Return the predicate as if the operands were swapped
545 Predicate getSwappedPredicate() const {
546 return getSwappedPredicate(getPredicate());
549 /// This is a static version that you can use without an instruction
551 /// @brief Return the predicate as if the operands were swapped.
552 static Predicate getSwappedPredicate(Predicate pred);
554 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
555 /// @returns the predicate that would be the result if the operand were
556 /// regarded as signed.
557 /// @brief Return the signed version of the predicate
558 Predicate getSignedPredicate() const {
559 return getSignedPredicate(getPredicate());
562 /// This is a static version that you can use without an instruction.
563 /// @brief Return the signed version of the predicate.
564 static Predicate getSignedPredicate(Predicate pred);
566 /// This also tests for commutativity. If isEquality() returns true then
567 /// the predicate is also commutative.
568 /// @returns true if the predicate of this instruction is EQ or NE.
569 /// @brief Determine if this is an equality predicate.
570 bool isEquality() const {
571 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
574 /// @returns true if the predicate of this ICmpInst is commutative
575 /// @brief Determine if this relation is commutative.
576 bool isCommutative() const { return isEquality(); }
578 /// @returns true if the predicate is relational (not EQ or NE).
579 /// @brief Determine if this a relational predicate.
580 bool isRelational() const {
581 return !isEquality();
584 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
585 /// @brief Determine if this instruction's predicate is signed.
586 bool isSignedPredicate() { return isSignedPredicate(getPredicate()); }
588 /// @returns true if the predicate provided is signed, false otherwise
589 /// @brief Determine if the predicate is signed.
590 static bool isSignedPredicate(Predicate pred);
592 /// Initialize a set of values that all satisfy the predicate with C.
593 /// @brief Make a ConstantRange for a relation with a constant value.
594 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
596 /// Exchange the two operands to this instruction in such a way that it does
597 /// not modify the semantics of the instruction. The predicate value may be
598 /// changed to retain the same result if the predicate is order dependent
600 /// @brief Swap operands and adjust predicate.
601 void swapOperands() {
602 SubclassData = getSwappedPredicate();
603 std::swap(Ops[0], Ops[1]);
606 // Methods for support type inquiry through isa, cast, and dyn_cast:
607 static inline bool classof(const ICmpInst *) { return true; }
608 static inline bool classof(const Instruction *I) {
609 return I->getOpcode() == Instruction::ICmp;
611 static inline bool classof(const Value *V) {
612 return isa<Instruction>(V) && classof(cast<Instruction>(V));
616 //===----------------------------------------------------------------------===//
618 //===----------------------------------------------------------------------===//
620 /// This instruction compares its operands according to the predicate given
621 /// to the constructor. It only operates on floating point values or packed
622 /// vectors of floating point values. The operands must be identical types.
623 /// @brief Represents a floating point comparison operator.
624 class FCmpInst: public CmpInst {
626 /// This enumeration lists the possible predicates for the FCmpInst. Values
627 /// in the range 0-31 are reserved for FCmpInst.
629 // Opcode U L G E Intuitive operation
630 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
631 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
632 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
633 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
634 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
635 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
636 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
637 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
638 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
639 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
640 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
641 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
642 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
643 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
644 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
645 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
646 FIRST_FCMP_PREDICATE = FCMP_FALSE,
647 LAST_FCMP_PREDICATE = FCMP_TRUE,
648 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
651 /// @brief Constructor with insert-before-instruction semantics.
653 Predicate pred, ///< The predicate to use for the comparison
654 Value *LHS, ///< The left-hand-side of the expression
655 Value *RHS, ///< The right-hand-side of the expression
656 const std::string &Name = "", ///< Name of the instruction
657 Instruction *InsertBefore = 0 ///< Where to insert
658 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
661 /// @brief Constructor with insert-at-block-end semantics.
663 Predicate pred, ///< The predicate to use for the comparison
664 Value *LHS, ///< The left-hand-side of the expression
665 Value *RHS, ///< The right-hand-side of the expression
666 const std::string &Name, ///< Name of the instruction
667 BasicBlock *InsertAtEnd ///< Block to insert into.
668 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
671 /// @brief Return the predicate for this instruction.
672 Predicate getPredicate() const { return Predicate(SubclassData); }
674 /// @brief Set the predicate for this instruction to the specified value.
675 void setPredicate(Predicate P) { SubclassData = P; }
677 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
678 /// @returns the inverse predicate for the instructions current predicate.
679 /// @brief Return the inverse of the predicate
680 Predicate getInversePredicate() const {
681 return getInversePredicate(getPredicate());
684 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
685 /// @returns the inverse predicate for \p pred.
686 /// @brief Return the inverse of a given predicate
687 static Predicate getInversePredicate(Predicate pred);
689 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
690 /// @returns the predicate that would be the result of exchanging the two
691 /// operands of the ICmpInst instruction without changing the result
693 /// @brief Return the predicate as if the operands were swapped
694 Predicate getSwappedPredicate() const {
695 return getSwappedPredicate(getPredicate());
698 /// This is a static version that you can use without an instruction
700 /// @brief Return the predicate as if the operands were swapped.
701 static Predicate getSwappedPredicate(Predicate Opcode);
703 /// This also tests for commutativity. If isEquality() returns true then
704 /// the predicate is also commutative. Only the equality predicates are
706 /// @returns true if the predicate of this instruction is EQ or NE.
707 /// @brief Determine if this is an equality predicate.
708 bool isEquality() const {
709 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
710 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
712 bool isCommutative() const { return isEquality(); }
714 /// @returns true if the predicate is relational (not EQ or NE).
715 /// @brief Determine if this a relational predicate.
716 bool isRelational() const { return !isEquality(); }
718 /// Exchange the two operands to this instruction in such a way that it does
719 /// not modify the semantics of the instruction. The predicate value may be
720 /// changed to retain the same result if the predicate is order dependent
722 /// @brief Swap operands and adjust predicate.
723 void swapOperands() {
724 SubclassData = getSwappedPredicate();
725 std::swap(Ops[0], Ops[1]);
728 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
729 static inline bool classof(const FCmpInst *) { return true; }
730 static inline bool classof(const Instruction *I) {
731 return I->getOpcode() == Instruction::FCmp;
733 static inline bool classof(const Value *V) {
734 return isa<Instruction>(V) && classof(cast<Instruction>(V));
738 //===----------------------------------------------------------------------===//
740 //===----------------------------------------------------------------------===//
741 /// CallInst - This class represents a function call, abstracting a target
742 /// machine's calling convention. This class uses low bit of the SubClassData
743 /// field to indicate whether or not this is a tail call. The rest of the bits
744 /// hold the calling convention of the call.
747 class CallInst : public Instruction {
748 ParamAttrsList *ParamAttrs; ///< parameter attributes for call
749 CallInst(const CallInst &CI);
750 void init(Value *Func, Value* const *Params, unsigned NumParams);
751 void init(Value *Func, Value *Actual1, Value *Actual2);
752 void init(Value *Func, Value *Actual);
753 void init(Value *Func);
755 template<typename InputIterator>
756 void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
757 const std::string &Name,
758 // This argument ensures that we have an iterator we can
759 // do arithmetic on in constant time
760 std::random_access_iterator_tag) {
761 typename std::iterator_traits<InputIterator>::difference_type NumArgs =
762 std::distance(ArgBegin, ArgEnd);
765 // This requires that the iterator points to contiguous memory.
766 init(Func, &*ArgBegin, NumArgs);
769 init(Func, 0, NumArgs);
776 /// Construct a CallInst given a range of arguments. InputIterator
777 /// must be a random-access iterator pointing to contiguous storage
778 /// (e.g. a std::vector<>::iterator). Checks are made for
779 /// random-accessness but not for contiguous storage as that would
780 /// incur runtime overhead.
781 /// @brief Construct a CallInst from a range of arguments
782 template<typename InputIterator>
783 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
784 const std::string &Name = "", Instruction *InsertBefore = 0)
785 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
786 ->getElementType())->getReturnType(),
787 Instruction::Call, 0, 0, InsertBefore) {
788 init(Func, ArgBegin, ArgEnd, Name,
789 typename std::iterator_traits<InputIterator>::iterator_category());
792 /// Construct a CallInst given a range of arguments. InputIterator
793 /// must be a random-access iterator pointing to contiguous storage
794 /// (e.g. a std::vector<>::iterator). Checks are made for
795 /// random-accessness but not for contiguous storage as that would
796 /// incur runtime overhead.
797 /// @brief Construct a CallInst from a range of arguments
798 template<typename InputIterator>
799 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
800 const std::string &Name, BasicBlock *InsertAtEnd)
801 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
802 ->getElementType())->getReturnType(),
803 Instruction::Call, 0, 0, InsertAtEnd) {
804 init(Func, ArgBegin, ArgEnd, Name,
805 typename std::iterator_traits<InputIterator>::iterator_category());
808 CallInst(Value *F, Value *Actual, const std::string& Name = "",
809 Instruction *InsertBefore = 0);
810 CallInst(Value *F, Value *Actual, const std::string& Name,
811 BasicBlock *InsertAtEnd);
812 explicit CallInst(Value *F, const std::string &Name = "",
813 Instruction *InsertBefore = 0);
814 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
817 virtual CallInst *clone() const;
819 bool isTailCall() const { return SubclassData & 1; }
820 void setTailCall(bool isTailCall = true) {
821 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
824 /// getCallingConv/setCallingConv - Get or set the calling convention of this
826 unsigned getCallingConv() const { return SubclassData >> 1; }
827 void setCallingConv(unsigned CC) {
828 SubclassData = (SubclassData & 1) | (CC << 1);
831 /// Obtains a pointer to the ParamAttrsList object which holds the
832 /// parameter attributes information, if any.
833 /// @returns 0 if no attributes have been set.
834 /// @brief Get the parameter attributes.
835 ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
837 /// Sets the parameter attributes for this CallInst. To construct a
838 /// ParamAttrsList, see ParameterAttributes.h
839 /// @brief Set the parameter attributes.
840 void setParamAttrs(ParamAttrsList *attrs);
842 /// getCalledFunction - Return the function being called by this instruction
843 /// if it is a direct call. If it is a call through a function pointer,
845 Function *getCalledFunction() const {
846 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
849 /// getCalledValue - Get a pointer to the function that is invoked by this
851 inline const Value *getCalledValue() const { return getOperand(0); }
852 inline Value *getCalledValue() { return getOperand(0); }
854 // Methods for support type inquiry through isa, cast, and dyn_cast:
855 static inline bool classof(const CallInst *) { return true; }
856 static inline bool classof(const Instruction *I) {
857 return I->getOpcode() == Instruction::Call;
859 static inline bool classof(const Value *V) {
860 return isa<Instruction>(V) && classof(cast<Instruction>(V));
864 //===----------------------------------------------------------------------===//
866 //===----------------------------------------------------------------------===//
868 /// SelectInst - This class represents the LLVM 'select' instruction.
870 class SelectInst : public Instruction {
873 void init(Value *C, Value *S1, Value *S2) {
874 Ops[0].init(C, this);
875 Ops[1].init(S1, this);
876 Ops[2].init(S2, this);
879 SelectInst(const SelectInst &SI)
880 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
881 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
884 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
885 Instruction *InsertBefore = 0)
886 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
890 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
891 BasicBlock *InsertAtEnd)
892 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
897 Value *getCondition() const { return Ops[0]; }
898 Value *getTrueValue() const { return Ops[1]; }
899 Value *getFalseValue() const { return Ops[2]; }
901 /// Transparently provide more efficient getOperand methods.
902 Value *getOperand(unsigned i) const {
903 assert(i < 3 && "getOperand() out of range!");
906 void setOperand(unsigned i, Value *Val) {
907 assert(i < 3 && "setOperand() out of range!");
910 unsigned getNumOperands() const { return 3; }
912 OtherOps getOpcode() const {
913 return static_cast<OtherOps>(Instruction::getOpcode());
916 virtual SelectInst *clone() const;
918 // Methods for support type inquiry through isa, cast, and dyn_cast:
919 static inline bool classof(const SelectInst *) { return true; }
920 static inline bool classof(const Instruction *I) {
921 return I->getOpcode() == Instruction::Select;
923 static inline bool classof(const Value *V) {
924 return isa<Instruction>(V) && classof(cast<Instruction>(V));
928 //===----------------------------------------------------------------------===//
930 //===----------------------------------------------------------------------===//
932 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
933 /// an argument of the specified type given a va_list and increments that list
935 class VAArgInst : public UnaryInstruction {
936 VAArgInst(const VAArgInst &VAA)
937 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
939 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
940 Instruction *InsertBefore = 0)
941 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
944 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
945 BasicBlock *InsertAtEnd)
946 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
950 virtual VAArgInst *clone() const;
952 // Methods for support type inquiry through isa, cast, and dyn_cast:
953 static inline bool classof(const VAArgInst *) { return true; }
954 static inline bool classof(const Instruction *I) {
955 return I->getOpcode() == VAArg;
957 static inline bool classof(const Value *V) {
958 return isa<Instruction>(V) && classof(cast<Instruction>(V));
962 //===----------------------------------------------------------------------===//
963 // ExtractElementInst Class
964 //===----------------------------------------------------------------------===//
966 /// ExtractElementInst - This instruction extracts a single (scalar)
967 /// element from a VectorType value
969 class ExtractElementInst : public Instruction {
971 ExtractElementInst(const ExtractElementInst &EE) :
972 Instruction(EE.getType(), ExtractElement, Ops, 2) {
973 Ops[0].init(EE.Ops[0], this);
974 Ops[1].init(EE.Ops[1], this);
978 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
979 Instruction *InsertBefore = 0);
980 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
981 Instruction *InsertBefore = 0);
982 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
983 BasicBlock *InsertAtEnd);
984 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
985 BasicBlock *InsertAtEnd);
987 /// isValidOperands - Return true if an extractelement instruction can be
988 /// formed with the specified operands.
989 static bool isValidOperands(const Value *Vec, const Value *Idx);
991 virtual ExtractElementInst *clone() const;
993 /// Transparently provide more efficient getOperand methods.
994 Value *getOperand(unsigned i) const {
995 assert(i < 2 && "getOperand() out of range!");
998 void setOperand(unsigned i, Value *Val) {
999 assert(i < 2 && "setOperand() out of range!");
1002 unsigned getNumOperands() const { return 2; }
1004 // Methods for support type inquiry through isa, cast, and dyn_cast:
1005 static inline bool classof(const ExtractElementInst *) { return true; }
1006 static inline bool classof(const Instruction *I) {
1007 return I->getOpcode() == Instruction::ExtractElement;
1009 static inline bool classof(const Value *V) {
1010 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1014 //===----------------------------------------------------------------------===//
1015 // InsertElementInst Class
1016 //===----------------------------------------------------------------------===//
1018 /// InsertElementInst - This instruction inserts a single (scalar)
1019 /// element into a VectorType value
1021 class InsertElementInst : public Instruction {
1023 InsertElementInst(const InsertElementInst &IE);
1025 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1026 const std::string &Name = "",Instruction *InsertBefore = 0);
1027 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1028 const std::string &Name = "",Instruction *InsertBefore = 0);
1029 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1030 const std::string &Name, BasicBlock *InsertAtEnd);
1031 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1032 const std::string &Name, BasicBlock *InsertAtEnd);
1034 /// isValidOperands - Return true if an insertelement instruction can be
1035 /// formed with the specified operands.
1036 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1039 virtual InsertElementInst *clone() const;
1041 /// getType - Overload to return most specific vector type.
1043 inline const VectorType *getType() const {
1044 return reinterpret_cast<const VectorType*>(Instruction::getType());
1047 /// Transparently provide more efficient getOperand methods.
1048 Value *getOperand(unsigned i) const {
1049 assert(i < 3 && "getOperand() out of range!");
1052 void setOperand(unsigned i, Value *Val) {
1053 assert(i < 3 && "setOperand() out of range!");
1056 unsigned getNumOperands() const { return 3; }
1058 // Methods for support type inquiry through isa, cast, and dyn_cast:
1059 static inline bool classof(const InsertElementInst *) { return true; }
1060 static inline bool classof(const Instruction *I) {
1061 return I->getOpcode() == Instruction::InsertElement;
1063 static inline bool classof(const Value *V) {
1064 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1068 //===----------------------------------------------------------------------===//
1069 // ShuffleVectorInst Class
1070 //===----------------------------------------------------------------------===//
1072 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1075 class ShuffleVectorInst : public Instruction {
1077 ShuffleVectorInst(const ShuffleVectorInst &IE);
1079 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1080 const std::string &Name = "", Instruction *InsertBefor = 0);
1081 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1082 const std::string &Name, BasicBlock *InsertAtEnd);
1084 /// isValidOperands - Return true if a shufflevector instruction can be
1085 /// formed with the specified operands.
1086 static bool isValidOperands(const Value *V1, const Value *V2,
1089 virtual ShuffleVectorInst *clone() const;
1091 /// getType - Overload to return most specific vector type.
1093 inline const VectorType *getType() const {
1094 return reinterpret_cast<const VectorType*>(Instruction::getType());
1097 /// Transparently provide more efficient getOperand methods.
1098 Value *getOperand(unsigned i) const {
1099 assert(i < 3 && "getOperand() out of range!");
1102 void setOperand(unsigned i, Value *Val) {
1103 assert(i < 3 && "setOperand() out of range!");
1106 unsigned getNumOperands() const { return 3; }
1108 // Methods for support type inquiry through isa, cast, and dyn_cast:
1109 static inline bool classof(const ShuffleVectorInst *) { return true; }
1110 static inline bool classof(const Instruction *I) {
1111 return I->getOpcode() == Instruction::ShuffleVector;
1113 static inline bool classof(const Value *V) {
1114 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1119 //===----------------------------------------------------------------------===//
1121 //===----------------------------------------------------------------------===//
1123 // PHINode - The PHINode class is used to represent the magical mystical PHI
1124 // node, that can not exist in nature, but can be synthesized in a computer
1125 // scientist's overactive imagination.
1127 class PHINode : public Instruction {
1128 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1129 /// the number actually in use.
1130 unsigned ReservedSpace;
1131 PHINode(const PHINode &PN);
1133 explicit PHINode(const Type *Ty, const std::string &Name = "",
1134 Instruction *InsertBefore = 0)
1135 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1140 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1141 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1148 /// reserveOperandSpace - This method can be used to avoid repeated
1149 /// reallocation of PHI operand lists by reserving space for the correct
1150 /// number of operands before adding them. Unlike normal vector reserves,
1151 /// this method can also be used to trim the operand space.
1152 void reserveOperandSpace(unsigned NumValues) {
1153 resizeOperands(NumValues*2);
1156 virtual PHINode *clone() const;
1158 /// getNumIncomingValues - Return the number of incoming edges
1160 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1162 /// getIncomingValue - Return incoming value number x
1164 Value *getIncomingValue(unsigned i) const {
1165 assert(i*2 < getNumOperands() && "Invalid value number!");
1166 return getOperand(i*2);
1168 void setIncomingValue(unsigned i, Value *V) {
1169 assert(i*2 < getNumOperands() && "Invalid value number!");
1172 unsigned getOperandNumForIncomingValue(unsigned i) {
1176 /// getIncomingBlock - Return incoming basic block number x
1178 BasicBlock *getIncomingBlock(unsigned i) const {
1179 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1181 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1182 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1184 unsigned getOperandNumForIncomingBlock(unsigned i) {
1188 /// addIncoming - Add an incoming value to the end of the PHI list
1190 void addIncoming(Value *V, BasicBlock *BB) {
1191 assert(getType() == V->getType() &&
1192 "All operands to PHI node must be the same type as the PHI node!");
1193 unsigned OpNo = NumOperands;
1194 if (OpNo+2 > ReservedSpace)
1195 resizeOperands(0); // Get more space!
1196 // Initialize some new operands.
1197 NumOperands = OpNo+2;
1198 OperandList[OpNo].init(V, this);
1199 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1202 /// removeIncomingValue - Remove an incoming value. This is useful if a
1203 /// predecessor basic block is deleted. The value removed is returned.
1205 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1206 /// is true), the PHI node is destroyed and any uses of it are replaced with
1207 /// dummy values. The only time there should be zero incoming values to a PHI
1208 /// node is when the block is dead, so this strategy is sound.
1210 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1212 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1213 int Idx = getBasicBlockIndex(BB);
1214 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1215 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1218 /// getBasicBlockIndex - Return the first index of the specified basic
1219 /// block in the value list for this PHI. Returns -1 if no instance.
1221 int getBasicBlockIndex(const BasicBlock *BB) const {
1222 Use *OL = OperandList;
1223 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1224 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1228 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1229 return getIncomingValue(getBasicBlockIndex(BB));
1232 /// hasConstantValue - If the specified PHI node always merges together the
1233 /// same value, return the value, otherwise return null.
1235 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1237 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1238 static inline bool classof(const PHINode *) { return true; }
1239 static inline bool classof(const Instruction *I) {
1240 return I->getOpcode() == Instruction::PHI;
1242 static inline bool classof(const Value *V) {
1243 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1246 void resizeOperands(unsigned NumOperands);
1249 //===----------------------------------------------------------------------===//
1251 //===----------------------------------------------------------------------===//
1253 //===---------------------------------------------------------------------------
1254 /// ReturnInst - Return a value (possibly void), from a function. Execution
1255 /// does not continue in this function any longer.
1257 class ReturnInst : public TerminatorInst {
1258 Use RetVal; // Return Value: null if 'void'.
1259 ReturnInst(const ReturnInst &RI);
1260 void init(Value *RetVal);
1263 // ReturnInst constructors:
1264 // ReturnInst() - 'ret void' instruction
1265 // ReturnInst( null) - 'ret void' instruction
1266 // ReturnInst(Value* X) - 'ret X' instruction
1267 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1268 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1269 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1270 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1272 // NOTE: If the Value* passed is of type void then the constructor behaves as
1273 // if it was passed NULL.
1274 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1275 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1276 explicit ReturnInst(BasicBlock *InsertAtEnd);
1278 virtual ReturnInst *clone() const;
1280 // Transparently provide more efficient getOperand methods.
1281 Value *getOperand(unsigned i) const {
1282 assert(i < getNumOperands() && "getOperand() out of range!");
1285 void setOperand(unsigned i, Value *Val) {
1286 assert(i < getNumOperands() && "setOperand() out of range!");
1290 Value *getReturnValue() const { return RetVal; }
1292 unsigned getNumSuccessors() const { return 0; }
1294 // Methods for support type inquiry through isa, cast, and dyn_cast:
1295 static inline bool classof(const ReturnInst *) { return true; }
1296 static inline bool classof(const Instruction *I) {
1297 return (I->getOpcode() == Instruction::Ret);
1299 static inline bool classof(const Value *V) {
1300 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1303 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1304 virtual unsigned getNumSuccessorsV() const;
1305 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1308 //===----------------------------------------------------------------------===//
1310 //===----------------------------------------------------------------------===//
1312 //===---------------------------------------------------------------------------
1313 /// BranchInst - Conditional or Unconditional Branch instruction.
1315 class BranchInst : public TerminatorInst {
1316 /// Ops list - Branches are strange. The operands are ordered:
1317 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1318 /// they don't have to check for cond/uncond branchness.
1320 BranchInst(const BranchInst &BI);
1323 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1324 // BranchInst(BB *B) - 'br B'
1325 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1326 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1327 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1328 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1329 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1330 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1331 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1332 Instruction *InsertBefore = 0);
1333 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1334 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1335 BasicBlock *InsertAtEnd);
1337 /// Transparently provide more efficient getOperand methods.
1338 Value *getOperand(unsigned i) const {
1339 assert(i < getNumOperands() && "getOperand() out of range!");
1342 void setOperand(unsigned i, Value *Val) {
1343 assert(i < getNumOperands() && "setOperand() out of range!");
1347 virtual BranchInst *clone() const;
1349 inline bool isUnconditional() const { return getNumOperands() == 1; }
1350 inline bool isConditional() const { return getNumOperands() == 3; }
1352 inline Value *getCondition() const {
1353 assert(isConditional() && "Cannot get condition of an uncond branch!");
1354 return getOperand(2);
1357 void setCondition(Value *V) {
1358 assert(isConditional() && "Cannot set condition of unconditional branch!");
1362 // setUnconditionalDest - Change the current branch to an unconditional branch
1363 // targeting the specified block.
1364 // FIXME: Eliminate this ugly method.
1365 void setUnconditionalDest(BasicBlock *Dest) {
1366 if (isConditional()) { // Convert this to an uncond branch.
1371 setOperand(0, reinterpret_cast<Value*>(Dest));
1374 unsigned getNumSuccessors() const { return 1+isConditional(); }
1376 BasicBlock *getSuccessor(unsigned i) const {
1377 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1378 return cast<BasicBlock>(getOperand(i));
1381 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1382 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1383 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1386 // Methods for support type inquiry through isa, cast, and dyn_cast:
1387 static inline bool classof(const BranchInst *) { return true; }
1388 static inline bool classof(const Instruction *I) {
1389 return (I->getOpcode() == Instruction::Br);
1391 static inline bool classof(const Value *V) {
1392 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1395 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1396 virtual unsigned getNumSuccessorsV() const;
1397 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1400 //===----------------------------------------------------------------------===//
1402 //===----------------------------------------------------------------------===//
1404 //===---------------------------------------------------------------------------
1405 /// SwitchInst - Multiway switch
1407 class SwitchInst : public TerminatorInst {
1408 unsigned ReservedSpace;
1409 // Operand[0] = Value to switch on
1410 // Operand[1] = Default basic block destination
1411 // Operand[2n ] = Value to match
1412 // Operand[2n+1] = BasicBlock to go to on match
1413 SwitchInst(const SwitchInst &RI);
1414 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1415 void resizeOperands(unsigned No);
1417 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1418 /// switch on and a default destination. The number of additional cases can
1419 /// be specified here to make memory allocation more efficient. This
1420 /// constructor can also autoinsert before another instruction.
1421 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1422 Instruction *InsertBefore = 0);
1424 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1425 /// switch on and a default destination. The number of additional cases can
1426 /// be specified here to make memory allocation more efficient. This
1427 /// constructor also autoinserts at the end of the specified BasicBlock.
1428 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1429 BasicBlock *InsertAtEnd);
1433 // Accessor Methods for Switch stmt
1434 inline Value *getCondition() const { return getOperand(0); }
1435 void setCondition(Value *V) { setOperand(0, V); }
1437 inline BasicBlock *getDefaultDest() const {
1438 return cast<BasicBlock>(getOperand(1));
1441 /// getNumCases - return the number of 'cases' in this switch instruction.
1442 /// Note that case #0 is always the default case.
1443 unsigned getNumCases() const {
1444 return getNumOperands()/2;
1447 /// getCaseValue - Return the specified case value. Note that case #0, the
1448 /// default destination, does not have a case value.
1449 ConstantInt *getCaseValue(unsigned i) {
1450 assert(i && i < getNumCases() && "Illegal case value to get!");
1451 return getSuccessorValue(i);
1454 /// getCaseValue - Return the specified case value. Note that case #0, the
1455 /// default destination, does not have a case value.
1456 const ConstantInt *getCaseValue(unsigned i) const {
1457 assert(i && i < getNumCases() && "Illegal case value to get!");
1458 return getSuccessorValue(i);
1461 /// findCaseValue - Search all of the case values for the specified constant.
1462 /// If it is explicitly handled, return the case number of it, otherwise
1463 /// return 0 to indicate that it is handled by the default handler.
1464 unsigned findCaseValue(const ConstantInt *C) const {
1465 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1466 if (getCaseValue(i) == C)
1471 /// findCaseDest - Finds the unique case value for a given successor. Returns
1472 /// null if the successor is not found, not unique, or is the default case.
1473 ConstantInt *findCaseDest(BasicBlock *BB) {
1474 if (BB == getDefaultDest()) return NULL;
1476 ConstantInt *CI = NULL;
1477 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1478 if (getSuccessor(i) == BB) {
1479 if (CI) return NULL; // Multiple cases lead to BB.
1480 else CI = getCaseValue(i);
1486 /// addCase - Add an entry to the switch instruction...
1488 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1490 /// removeCase - This method removes the specified successor from the switch
1491 /// instruction. Note that this cannot be used to remove the default
1492 /// destination (successor #0).
1494 void removeCase(unsigned idx);
1496 virtual SwitchInst *clone() const;
1498 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1499 BasicBlock *getSuccessor(unsigned idx) const {
1500 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1501 return cast<BasicBlock>(getOperand(idx*2+1));
1503 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1504 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1505 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1508 // getSuccessorValue - Return the value associated with the specified
1510 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1511 assert(idx < getNumSuccessors() && "Successor # out of range!");
1512 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1515 // Methods for support type inquiry through isa, cast, and dyn_cast:
1516 static inline bool classof(const SwitchInst *) { return true; }
1517 static inline bool classof(const Instruction *I) {
1518 return I->getOpcode() == Instruction::Switch;
1520 static inline bool classof(const Value *V) {
1521 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1524 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1525 virtual unsigned getNumSuccessorsV() const;
1526 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1529 //===----------------------------------------------------------------------===//
1531 //===----------------------------------------------------------------------===//
1533 //===---------------------------------------------------------------------------
1535 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1536 /// calling convention of the call.
1538 class InvokeInst : public TerminatorInst {
1539 ParamAttrsList *ParamAttrs;
1540 InvokeInst(const InvokeInst &BI);
1541 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1542 Value* const *Args, unsigned NumArgs);
1544 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1545 Value* const* Args, unsigned NumArgs, const std::string &Name = "",
1546 Instruction *InsertBefore = 0);
1547 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1548 Value* const* Args, unsigned NumArgs, const std::string &Name,
1549 BasicBlock *InsertAtEnd);
1552 virtual InvokeInst *clone() const;
1554 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1556 unsigned getCallingConv() const { return SubclassData; }
1557 void setCallingConv(unsigned CC) {
1561 /// Obtains a pointer to the ParamAttrsList object which holds the
1562 /// parameter attributes information, if any.
1563 /// @returns 0 if no attributes have been set.
1564 /// @brief Get the parameter attributes.
1565 ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
1567 /// Sets the parameter attributes for this InvokeInst. To construct a
1568 /// ParamAttrsList, see ParameterAttributes.h
1569 /// @brief Set the parameter attributes.
1570 void setParamAttrs(ParamAttrsList *attrs);
1572 /// getCalledFunction - Return the function called, or null if this is an
1573 /// indirect function invocation.
1575 Function *getCalledFunction() const {
1576 return dyn_cast<Function>(getOperand(0));
1579 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1580 inline Value *getCalledValue() const { return getOperand(0); }
1582 // get*Dest - Return the destination basic blocks...
1583 BasicBlock *getNormalDest() const {
1584 return cast<BasicBlock>(getOperand(1));
1586 BasicBlock *getUnwindDest() const {
1587 return cast<BasicBlock>(getOperand(2));
1589 void setNormalDest(BasicBlock *B) {
1590 setOperand(1, reinterpret_cast<Value*>(B));
1593 void setUnwindDest(BasicBlock *B) {
1594 setOperand(2, reinterpret_cast<Value*>(B));
1597 inline BasicBlock *getSuccessor(unsigned i) const {
1598 assert(i < 2 && "Successor # out of range for invoke!");
1599 return i == 0 ? getNormalDest() : getUnwindDest();
1602 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1603 assert(idx < 2 && "Successor # out of range for invoke!");
1604 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1607 unsigned getNumSuccessors() const { return 2; }
1609 // Methods for support type inquiry through isa, cast, and dyn_cast:
1610 static inline bool classof(const InvokeInst *) { return true; }
1611 static inline bool classof(const Instruction *I) {
1612 return (I->getOpcode() == Instruction::Invoke);
1614 static inline bool classof(const Value *V) {
1615 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1618 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1619 virtual unsigned getNumSuccessorsV() const;
1620 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1624 //===----------------------------------------------------------------------===//
1626 //===----------------------------------------------------------------------===//
1628 //===---------------------------------------------------------------------------
1629 /// UnwindInst - Immediately exit the current function, unwinding the stack
1630 /// until an invoke instruction is found.
1632 class UnwindInst : public TerminatorInst {
1634 explicit UnwindInst(Instruction *InsertBefore = 0);
1635 explicit UnwindInst(BasicBlock *InsertAtEnd);
1637 virtual UnwindInst *clone() const;
1639 unsigned getNumSuccessors() const { return 0; }
1641 // Methods for support type inquiry through isa, cast, and dyn_cast:
1642 static inline bool classof(const UnwindInst *) { return true; }
1643 static inline bool classof(const Instruction *I) {
1644 return I->getOpcode() == Instruction::Unwind;
1646 static inline bool classof(const Value *V) {
1647 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1650 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1651 virtual unsigned getNumSuccessorsV() const;
1652 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1655 //===----------------------------------------------------------------------===//
1656 // UnreachableInst Class
1657 //===----------------------------------------------------------------------===//
1659 //===---------------------------------------------------------------------------
1660 /// UnreachableInst - This function has undefined behavior. In particular, the
1661 /// presence of this instruction indicates some higher level knowledge that the
1662 /// end of the block cannot be reached.
1664 class UnreachableInst : public TerminatorInst {
1666 explicit UnreachableInst(Instruction *InsertBefore = 0);
1667 explicit UnreachableInst(BasicBlock *InsertAtEnd);
1669 virtual UnreachableInst *clone() const;
1671 unsigned getNumSuccessors() const { return 0; }
1673 // Methods for support type inquiry through isa, cast, and dyn_cast:
1674 static inline bool classof(const UnreachableInst *) { return true; }
1675 static inline bool classof(const Instruction *I) {
1676 return I->getOpcode() == Instruction::Unreachable;
1678 static inline bool classof(const Value *V) {
1679 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1682 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1683 virtual unsigned getNumSuccessorsV() const;
1684 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1687 //===----------------------------------------------------------------------===//
1689 //===----------------------------------------------------------------------===//
1691 /// @brief This class represents a truncation of integer types.
1692 class TruncInst : public CastInst {
1693 /// Private copy constructor
1694 TruncInst(const TruncInst &CI)
1695 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1698 /// @brief Constructor with insert-before-instruction semantics
1700 Value *S, ///< The value to be truncated
1701 const Type *Ty, ///< The (smaller) type to truncate to
1702 const std::string &Name = "", ///< A name for the new instruction
1703 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1706 /// @brief Constructor with insert-at-end-of-block semantics
1708 Value *S, ///< The value to be truncated
1709 const Type *Ty, ///< The (smaller) type to truncate to
1710 const std::string &Name, ///< A name for the new instruction
1711 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1714 /// @brief Clone an identical TruncInst
1715 virtual CastInst *clone() const;
1717 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1718 static inline bool classof(const TruncInst *) { return true; }
1719 static inline bool classof(const Instruction *I) {
1720 return I->getOpcode() == Trunc;
1722 static inline bool classof(const Value *V) {
1723 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1727 //===----------------------------------------------------------------------===//
1729 //===----------------------------------------------------------------------===//
1731 /// @brief This class represents zero extension of integer types.
1732 class ZExtInst : public CastInst {
1733 /// @brief Private copy constructor
1734 ZExtInst(const ZExtInst &CI)
1735 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1738 /// @brief Constructor with insert-before-instruction semantics
1740 Value *S, ///< The value to be zero extended
1741 const Type *Ty, ///< The type to zero extend to
1742 const std::string &Name = "", ///< A name for the new instruction
1743 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1746 /// @brief Constructor with insert-at-end semantics.
1748 Value *S, ///< The value to be zero extended
1749 const Type *Ty, ///< The type to zero extend to
1750 const std::string &Name, ///< A name for the new instruction
1751 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1754 /// @brief Clone an identical ZExtInst
1755 virtual CastInst *clone() const;
1757 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1758 static inline bool classof(const ZExtInst *) { return true; }
1759 static inline bool classof(const Instruction *I) {
1760 return I->getOpcode() == ZExt;
1762 static inline bool classof(const Value *V) {
1763 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1767 //===----------------------------------------------------------------------===//
1769 //===----------------------------------------------------------------------===//
1771 /// @brief This class represents a sign extension of integer types.
1772 class SExtInst : public CastInst {
1773 /// @brief Private copy constructor
1774 SExtInst(const SExtInst &CI)
1775 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1778 /// @brief Constructor with insert-before-instruction semantics
1780 Value *S, ///< The value to be sign extended
1781 const Type *Ty, ///< The type to sign extend to
1782 const std::string &Name = "", ///< A name for the new instruction
1783 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1786 /// @brief Constructor with insert-at-end-of-block semantics
1788 Value *S, ///< The value to be sign extended
1789 const Type *Ty, ///< The type to sign extend to
1790 const std::string &Name, ///< A name for the new instruction
1791 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1794 /// @brief Clone an identical SExtInst
1795 virtual CastInst *clone() const;
1797 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1798 static inline bool classof(const SExtInst *) { return true; }
1799 static inline bool classof(const Instruction *I) {
1800 return I->getOpcode() == SExt;
1802 static inline bool classof(const Value *V) {
1803 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1807 //===----------------------------------------------------------------------===//
1808 // FPTruncInst Class
1809 //===----------------------------------------------------------------------===//
1811 /// @brief This class represents a truncation of floating point types.
1812 class FPTruncInst : public CastInst {
1813 FPTruncInst(const FPTruncInst &CI)
1814 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1817 /// @brief Constructor with insert-before-instruction semantics
1819 Value *S, ///< The value to be truncated
1820 const Type *Ty, ///< The type to truncate to
1821 const std::string &Name = "", ///< A name for the new instruction
1822 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1825 /// @brief Constructor with insert-before-instruction semantics
1827 Value *S, ///< The value to be truncated
1828 const Type *Ty, ///< The type to truncate to
1829 const std::string &Name, ///< A name for the new instruction
1830 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1833 /// @brief Clone an identical FPTruncInst
1834 virtual CastInst *clone() const;
1836 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1837 static inline bool classof(const FPTruncInst *) { return true; }
1838 static inline bool classof(const Instruction *I) {
1839 return I->getOpcode() == FPTrunc;
1841 static inline bool classof(const Value *V) {
1842 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1846 //===----------------------------------------------------------------------===//
1848 //===----------------------------------------------------------------------===//
1850 /// @brief This class represents an extension of floating point types.
1851 class FPExtInst : public CastInst {
1852 FPExtInst(const FPExtInst &CI)
1853 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1856 /// @brief Constructor with insert-before-instruction semantics
1858 Value *S, ///< The value to be extended
1859 const Type *Ty, ///< The type to extend to
1860 const std::string &Name = "", ///< A name for the new instruction
1861 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1864 /// @brief Constructor with insert-at-end-of-block semantics
1866 Value *S, ///< The value to be extended
1867 const Type *Ty, ///< The type to extend to
1868 const std::string &Name, ///< A name for the new instruction
1869 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1872 /// @brief Clone an identical FPExtInst
1873 virtual CastInst *clone() const;
1875 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1876 static inline bool classof(const FPExtInst *) { return true; }
1877 static inline bool classof(const Instruction *I) {
1878 return I->getOpcode() == FPExt;
1880 static inline bool classof(const Value *V) {
1881 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1885 //===----------------------------------------------------------------------===//
1887 //===----------------------------------------------------------------------===//
1889 /// @brief This class represents a cast unsigned integer to floating point.
1890 class UIToFPInst : public CastInst {
1891 UIToFPInst(const UIToFPInst &CI)
1892 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1895 /// @brief Constructor with insert-before-instruction semantics
1897 Value *S, ///< The value to be converted
1898 const Type *Ty, ///< The type to convert to
1899 const std::string &Name = "", ///< A name for the new instruction
1900 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1903 /// @brief Constructor with insert-at-end-of-block semantics
1905 Value *S, ///< The value to be converted
1906 const Type *Ty, ///< The type to convert to
1907 const std::string &Name, ///< A name for the new instruction
1908 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1911 /// @brief Clone an identical UIToFPInst
1912 virtual CastInst *clone() const;
1914 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1915 static inline bool classof(const UIToFPInst *) { return true; }
1916 static inline bool classof(const Instruction *I) {
1917 return I->getOpcode() == UIToFP;
1919 static inline bool classof(const Value *V) {
1920 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1924 //===----------------------------------------------------------------------===//
1926 //===----------------------------------------------------------------------===//
1928 /// @brief This class represents a cast from signed integer to floating point.
1929 class SIToFPInst : public CastInst {
1930 SIToFPInst(const SIToFPInst &CI)
1931 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1934 /// @brief Constructor with insert-before-instruction semantics
1936 Value *S, ///< The value to be converted
1937 const Type *Ty, ///< The type to convert to
1938 const std::string &Name = "", ///< A name for the new instruction
1939 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1942 /// @brief Constructor with insert-at-end-of-block semantics
1944 Value *S, ///< The value to be converted
1945 const Type *Ty, ///< The type to convert to
1946 const std::string &Name, ///< A name for the new instruction
1947 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1950 /// @brief Clone an identical SIToFPInst
1951 virtual CastInst *clone() const;
1953 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1954 static inline bool classof(const SIToFPInst *) { return true; }
1955 static inline bool classof(const Instruction *I) {
1956 return I->getOpcode() == SIToFP;
1958 static inline bool classof(const Value *V) {
1959 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1963 //===----------------------------------------------------------------------===//
1965 //===----------------------------------------------------------------------===//
1967 /// @brief This class represents a cast from floating point to unsigned integer
1968 class FPToUIInst : public CastInst {
1969 FPToUIInst(const FPToUIInst &CI)
1970 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1973 /// @brief Constructor with insert-before-instruction semantics
1975 Value *S, ///< The value to be converted
1976 const Type *Ty, ///< The type to convert to
1977 const std::string &Name = "", ///< A name for the new instruction
1978 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1981 /// @brief Constructor with insert-at-end-of-block semantics
1983 Value *S, ///< The value to be converted
1984 const Type *Ty, ///< The type to convert to
1985 const std::string &Name, ///< A name for the new instruction
1986 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
1989 /// @brief Clone an identical FPToUIInst
1990 virtual CastInst *clone() const;
1992 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1993 static inline bool classof(const FPToUIInst *) { return true; }
1994 static inline bool classof(const Instruction *I) {
1995 return I->getOpcode() == FPToUI;
1997 static inline bool classof(const Value *V) {
1998 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2002 //===----------------------------------------------------------------------===//
2004 //===----------------------------------------------------------------------===//
2006 /// @brief This class represents a cast from floating point to signed integer.
2007 class FPToSIInst : public CastInst {
2008 FPToSIInst(const FPToSIInst &CI)
2009 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2012 /// @brief Constructor with insert-before-instruction semantics
2014 Value *S, ///< The value to be converted
2015 const Type *Ty, ///< The type to convert to
2016 const std::string &Name = "", ///< A name for the new instruction
2017 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2020 /// @brief Constructor with insert-at-end-of-block semantics
2022 Value *S, ///< The value to be converted
2023 const Type *Ty, ///< The type to convert to
2024 const std::string &Name, ///< A name for the new instruction
2025 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2028 /// @brief Clone an identical FPToSIInst
2029 virtual CastInst *clone() const;
2031 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2032 static inline bool classof(const FPToSIInst *) { return true; }
2033 static inline bool classof(const Instruction *I) {
2034 return I->getOpcode() == FPToSI;
2036 static inline bool classof(const Value *V) {
2037 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2041 //===----------------------------------------------------------------------===//
2042 // IntToPtrInst Class
2043 //===----------------------------------------------------------------------===//
2045 /// @brief This class represents a cast from an integer to a pointer.
2046 class IntToPtrInst : public CastInst {
2047 IntToPtrInst(const IntToPtrInst &CI)
2048 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2051 /// @brief Constructor with insert-before-instruction semantics
2053 Value *S, ///< The value to be converted
2054 const Type *Ty, ///< The type to convert to
2055 const std::string &Name = "", ///< A name for the new instruction
2056 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2059 /// @brief Constructor with insert-at-end-of-block semantics
2061 Value *S, ///< The value to be converted
2062 const Type *Ty, ///< The type to convert to
2063 const std::string &Name, ///< A name for the new instruction
2064 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2067 /// @brief Clone an identical IntToPtrInst
2068 virtual CastInst *clone() const;
2070 // Methods for support type inquiry through isa, cast, and dyn_cast:
2071 static inline bool classof(const IntToPtrInst *) { return true; }
2072 static inline bool classof(const Instruction *I) {
2073 return I->getOpcode() == IntToPtr;
2075 static inline bool classof(const Value *V) {
2076 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2080 //===----------------------------------------------------------------------===//
2081 // PtrToIntInst Class
2082 //===----------------------------------------------------------------------===//
2084 /// @brief This class represents a cast from a pointer to an integer
2085 class PtrToIntInst : public CastInst {
2086 PtrToIntInst(const PtrToIntInst &CI)
2087 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2090 /// @brief Constructor with insert-before-instruction semantics
2092 Value *S, ///< The value to be converted
2093 const Type *Ty, ///< The type to convert to
2094 const std::string &Name = "", ///< A name for the new instruction
2095 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2098 /// @brief Constructor with insert-at-end-of-block semantics
2100 Value *S, ///< The value to be converted
2101 const Type *Ty, ///< The type to convert to
2102 const std::string &Name, ///< A name for the new instruction
2103 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2106 /// @brief Clone an identical PtrToIntInst
2107 virtual CastInst *clone() const;
2109 // Methods for support type inquiry through isa, cast, and dyn_cast:
2110 static inline bool classof(const PtrToIntInst *) { return true; }
2111 static inline bool classof(const Instruction *I) {
2112 return I->getOpcode() == PtrToInt;
2114 static inline bool classof(const Value *V) {
2115 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2119 //===----------------------------------------------------------------------===//
2120 // BitCastInst Class
2121 //===----------------------------------------------------------------------===//
2123 /// @brief This class represents a no-op cast from one type to another.
2124 class BitCastInst : public CastInst {
2125 BitCastInst(const BitCastInst &CI)
2126 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2129 /// @brief Constructor with insert-before-instruction semantics
2131 Value *S, ///< The value to be casted
2132 const Type *Ty, ///< The type to casted to
2133 const std::string &Name = "", ///< A name for the new instruction
2134 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2137 /// @brief Constructor with insert-at-end-of-block semantics
2139 Value *S, ///< The value to be casted
2140 const Type *Ty, ///< The type to casted to
2141 const std::string &Name, ///< A name for the new instruction
2142 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2145 /// @brief Clone an identical BitCastInst
2146 virtual CastInst *clone() const;
2148 // Methods for support type inquiry through isa, cast, and dyn_cast:
2149 static inline bool classof(const BitCastInst *) { return true; }
2150 static inline bool classof(const Instruction *I) {
2151 return I->getOpcode() == BitCast;
2153 static inline bool classof(const Value *V) {
2154 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2158 } // End llvm namespace