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"
28 //===----------------------------------------------------------------------===//
29 // AllocationInst Class
30 //===----------------------------------------------------------------------===//
32 /// AllocationInst - This class is the common base class of MallocInst and
35 class AllocationInst : public UnaryInstruction {
38 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
39 const std::string &Name = "", Instruction *InsertBefore = 0);
40 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
41 const std::string &Name, BasicBlock *InsertAtEnd);
43 // Out of line virtual method, so the vtable, etc has a home.
44 virtual ~AllocationInst();
46 /// isArrayAllocation - Return true if there is an allocation size parameter
47 /// to the allocation instruction that is not 1.
49 bool isArrayAllocation() const;
51 /// getArraySize - Get the number of element allocated, for a simple
52 /// allocation of a single element, this will return a constant 1 value.
54 inline const Value *getArraySize() const { return getOperand(0); }
55 inline Value *getArraySize() { return getOperand(0); }
57 /// getType - Overload to return most specific pointer type
59 inline const PointerType *getType() const {
60 return reinterpret_cast<const PointerType*>(Instruction::getType());
63 /// getAllocatedType - Return the type that is being allocated by the
66 const Type *getAllocatedType() const;
68 /// getAlignment - Return the alignment of the memory that is being allocated
69 /// by the instruction.
71 unsigned getAlignment() const { return Alignment; }
72 void setAlignment(unsigned Align) {
73 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
77 virtual Instruction *clone() const = 0;
79 // Methods for support type inquiry through isa, cast, and dyn_cast:
80 static inline bool classof(const AllocationInst *) { return true; }
81 static inline bool classof(const Instruction *I) {
82 return I->getOpcode() == Instruction::Alloca ||
83 I->getOpcode() == Instruction::Malloc;
85 static inline bool classof(const Value *V) {
86 return isa<Instruction>(V) && classof(cast<Instruction>(V));
91 //===----------------------------------------------------------------------===//
93 //===----------------------------------------------------------------------===//
95 /// MallocInst - an instruction to allocated memory on the heap
97 class MallocInst : public AllocationInst {
98 MallocInst(const MallocInst &MI);
100 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
101 const std::string &Name = "",
102 Instruction *InsertBefore = 0)
103 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
104 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
105 BasicBlock *InsertAtEnd)
106 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
108 MallocInst(const Type *Ty, const std::string &Name,
109 Instruction *InsertBefore = 0)
110 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
111 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
112 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
114 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
115 const std::string &Name, BasicBlock *InsertAtEnd)
116 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
117 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
118 const std::string &Name = "",
119 Instruction *InsertBefore = 0)
120 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
122 virtual MallocInst *clone() const;
124 // Methods for support type inquiry through isa, cast, and dyn_cast:
125 static inline bool classof(const MallocInst *) { return true; }
126 static inline bool classof(const Instruction *I) {
127 return (I->getOpcode() == Instruction::Malloc);
129 static inline bool classof(const Value *V) {
130 return isa<Instruction>(V) && classof(cast<Instruction>(V));
135 //===----------------------------------------------------------------------===//
137 //===----------------------------------------------------------------------===//
139 /// AllocaInst - an instruction to allocate memory on the stack
141 class AllocaInst : public AllocationInst {
142 AllocaInst(const AllocaInst &);
144 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
145 const std::string &Name = "",
146 Instruction *InsertBefore = 0)
147 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
148 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
149 BasicBlock *InsertAtEnd)
150 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
152 AllocaInst(const Type *Ty, const std::string &Name,
153 Instruction *InsertBefore = 0)
154 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
155 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
156 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
158 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
159 const std::string &Name = "", Instruction *InsertBefore = 0)
160 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
161 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
162 const std::string &Name, BasicBlock *InsertAtEnd)
163 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
165 virtual AllocaInst *clone() const;
167 // Methods for support type inquiry through isa, cast, and dyn_cast:
168 static inline bool classof(const AllocaInst *) { return true; }
169 static inline bool classof(const Instruction *I) {
170 return (I->getOpcode() == Instruction::Alloca);
172 static inline bool classof(const Value *V) {
173 return isa<Instruction>(V) && classof(cast<Instruction>(V));
178 //===----------------------------------------------------------------------===//
180 //===----------------------------------------------------------------------===//
182 /// FreeInst - an instruction to deallocate memory
184 class FreeInst : public UnaryInstruction {
187 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
188 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
190 virtual FreeInst *clone() const;
192 // Methods for support type inquiry through isa, cast, and dyn_cast:
193 static inline bool classof(const FreeInst *) { return true; }
194 static inline bool classof(const Instruction *I) {
195 return (I->getOpcode() == Instruction::Free);
197 static inline bool classof(const Value *V) {
198 return isa<Instruction>(V) && classof(cast<Instruction>(V));
203 //===----------------------------------------------------------------------===//
205 //===----------------------------------------------------------------------===//
207 /// LoadInst - an instruction for reading from memory. This uses the
208 /// SubclassData field in Value to store whether or not the load is volatile.
210 class LoadInst : public UnaryInstruction {
211 LoadInst(const LoadInst &LI)
212 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
213 setVolatile(LI.isVolatile());
221 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
222 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
223 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false,
224 Instruction *InsertBefore = 0);
225 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
226 BasicBlock *InsertAtEnd);
228 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
229 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
230 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
231 Instruction *InsertBefore = 0);
232 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
233 BasicBlock *InsertAtEnd);
235 /// isVolatile - Return true if this is a load from a volatile memory
238 bool isVolatile() const { return SubclassData; }
240 /// setVolatile - Specify whether this is a volatile load or not.
242 void setVolatile(bool V) { SubclassData = V; }
244 virtual LoadInst *clone() const;
246 Value *getPointerOperand() { return getOperand(0); }
247 const Value *getPointerOperand() const { return getOperand(0); }
248 static unsigned getPointerOperandIndex() { return 0U; }
250 // Methods for support type inquiry through isa, cast, and dyn_cast:
251 static inline bool classof(const LoadInst *) { return true; }
252 static inline bool classof(const Instruction *I) {
253 return I->getOpcode() == Instruction::Load;
255 static inline bool classof(const Value *V) {
256 return isa<Instruction>(V) && classof(cast<Instruction>(V));
261 //===----------------------------------------------------------------------===//
263 //===----------------------------------------------------------------------===//
265 /// StoreInst - an instruction for storing to memory
267 class StoreInst : public Instruction {
269 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
270 Ops[0].init(SI.Ops[0], this);
271 Ops[1].init(SI.Ops[1], this);
272 setVolatile(SI.isVolatile());
279 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
280 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
281 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
282 Instruction *InsertBefore = 0);
283 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
286 /// isVolatile - Return true if this is a load from a volatile memory
289 bool isVolatile() const { return SubclassData; }
291 /// setVolatile - Specify whether this is a volatile load or not.
293 void setVolatile(bool V) { SubclassData = V; }
295 /// Transparently provide more efficient getOperand methods.
296 Value *getOperand(unsigned i) const {
297 assert(i < 2 && "getOperand() out of range!");
300 void setOperand(unsigned i, Value *Val) {
301 assert(i < 2 && "setOperand() out of range!");
304 unsigned getNumOperands() const { return 2; }
307 virtual StoreInst *clone() const;
309 Value *getPointerOperand() { return getOperand(1); }
310 const Value *getPointerOperand() const { return getOperand(1); }
311 static unsigned getPointerOperandIndex() { return 1U; }
313 // Methods for support type inquiry through isa, cast, and dyn_cast:
314 static inline bool classof(const StoreInst *) { return true; }
315 static inline bool classof(const Instruction *I) {
316 return I->getOpcode() == Instruction::Store;
318 static inline bool classof(const Value *V) {
319 return isa<Instruction>(V) && classof(cast<Instruction>(V));
324 //===----------------------------------------------------------------------===//
325 // GetElementPtrInst Class
326 //===----------------------------------------------------------------------===//
328 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
329 /// access elements of arrays and structs
331 class GetElementPtrInst : public Instruction {
332 GetElementPtrInst(const GetElementPtrInst &GEPI)
333 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
334 0, GEPI.getNumOperands()) {
335 Use *OL = OperandList = new Use[NumOperands];
336 Use *GEPIOL = GEPI.OperandList;
337 for (unsigned i = 0, E = NumOperands; i != E; ++i)
338 OL[i].init(GEPIOL[i], this);
340 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
341 void init(Value *Ptr, Value *Idx0, Value *Idx1);
342 void init(Value *Ptr, Value *Idx);
344 /// Constructors - Create a getelementptr instruction with a base pointer an
345 /// list of indices. The first ctor can optionally insert before an existing
346 /// instruction, the second appends the new instruction to the specified
348 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
349 const std::string &Name = "", Instruction *InsertBefore =0);
350 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
351 const std::string &Name, BasicBlock *InsertAtEnd);
353 /// Constructors - These two constructors are convenience methods because one
354 /// and two index getelementptr instructions are so common.
355 GetElementPtrInst(Value *Ptr, Value *Idx,
356 const std::string &Name = "", Instruction *InsertBefore =0);
357 GetElementPtrInst(Value *Ptr, Value *Idx,
358 const std::string &Name, BasicBlock *InsertAtEnd);
359 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
360 const std::string &Name = "", Instruction *InsertBefore =0);
361 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
362 const std::string &Name, BasicBlock *InsertAtEnd);
363 ~GetElementPtrInst();
365 virtual GetElementPtrInst *clone() const;
367 // getType - Overload to return most specific pointer type...
368 inline const PointerType *getType() const {
369 return reinterpret_cast<const PointerType*>(Instruction::getType());
372 /// getIndexedType - Returns the type of the element that would be loaded with
373 /// a load instruction with the specified parameters.
375 /// A null type is returned if the indices are invalid for the specified
378 static const Type *getIndexedType(const Type *Ptr,
379 Value* const *Idx, unsigned NumIdx,
380 bool AllowStructLeaf = false);
382 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
383 bool AllowStructLeaf = false);
384 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
386 inline op_iterator idx_begin() { return op_begin()+1; }
387 inline const_op_iterator idx_begin() const { return op_begin()+1; }
388 inline op_iterator idx_end() { return op_end(); }
389 inline const_op_iterator idx_end() const { return op_end(); }
391 Value *getPointerOperand() {
392 return getOperand(0);
394 const Value *getPointerOperand() const {
395 return getOperand(0);
397 static unsigned getPointerOperandIndex() {
398 return 0U; // get index for modifying correct operand
401 inline unsigned getNumIndices() const { // Note: always non-negative
402 return getNumOperands() - 1;
405 inline bool hasIndices() const {
406 return getNumOperands() > 1;
409 // Methods for support type inquiry through isa, cast, and dyn_cast:
410 static inline bool classof(const GetElementPtrInst *) { return true; }
411 static inline bool classof(const Instruction *I) {
412 return (I->getOpcode() == Instruction::GetElementPtr);
414 static inline bool classof(const Value *V) {
415 return isa<Instruction>(V) && classof(cast<Instruction>(V));
419 //===----------------------------------------------------------------------===//
421 //===----------------------------------------------------------------------===//
423 /// This instruction compares its operands according to the predicate given
424 /// to the constructor. It only operates on integers, pointers, or packed
425 /// vectors of integrals. The two operands must be the same type.
426 /// @brief Represent an integer comparison operator.
427 class ICmpInst: public CmpInst {
429 /// This enumeration lists the possible predicates for the ICmpInst. The
430 /// values in the range 0-31 are reserved for FCmpInst while values in the
431 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
432 /// predicate values are not overlapping between the classes.
434 ICMP_EQ = 32, ///< equal
435 ICMP_NE = 33, ///< not equal
436 ICMP_UGT = 34, ///< unsigned greater than
437 ICMP_UGE = 35, ///< unsigned greater or equal
438 ICMP_ULT = 36, ///< unsigned less than
439 ICMP_ULE = 37, ///< unsigned less or equal
440 ICMP_SGT = 38, ///< signed greater than
441 ICMP_SGE = 39, ///< signed greater or equal
442 ICMP_SLT = 40, ///< signed less than
443 ICMP_SLE = 41, ///< signed less or equal
444 FIRST_ICMP_PREDICATE = ICMP_EQ,
445 LAST_ICMP_PREDICATE = ICMP_SLE,
446 BAD_ICMP_PREDICATE = ICMP_SLE + 1
449 /// @brief Constructor with insert-before-instruction semantics.
451 Predicate pred, ///< The predicate to use for the comparison
452 Value *LHS, ///< The left-hand-side of the expression
453 Value *RHS, ///< The right-hand-side of the expression
454 const std::string &Name = "", ///< Name of the instruction
455 Instruction *InsertBefore = 0 ///< Where to insert
456 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
459 /// @brief Constructor with insert-at-block-end semantics.
461 Predicate pred, ///< The predicate to use for the comparison
462 Value *LHS, ///< The left-hand-side of the expression
463 Value *RHS, ///< The right-hand-side of the expression
464 const std::string &Name, ///< Name of the instruction
465 BasicBlock *InsertAtEnd ///< Block to insert into.
466 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
469 /// @brief Return the predicate for this instruction.
470 Predicate getPredicate() const { return Predicate(SubclassData); }
472 /// @brief Set the predicate for this instruction to the specified value.
473 void setPredicate(Predicate P) { SubclassData = P; }
475 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
476 /// @returns the inverse predicate for the instruction's current predicate.
477 /// @brief Return the inverse of the instruction's predicate.
478 Predicate getInversePredicate() const {
479 return getInversePredicate(getPredicate());
482 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
483 /// @returns the inverse predicate for predicate provided in \p pred.
484 /// @brief Return the inverse of a given predicate
485 static Predicate getInversePredicate(Predicate pred);
487 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
488 /// @returns the predicate that would be the result of exchanging the two
489 /// operands of the ICmpInst instruction without changing the result
491 /// @brief Return the predicate as if the operands were swapped
492 Predicate getSwappedPredicate() const {
493 return getSwappedPredicate(getPredicate());
496 /// This is a static version that you can use without an instruction
498 /// @brief Return the predicate as if the operands were swapped.
499 static Predicate getSwappedPredicate(Predicate pred);
501 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
502 /// @returns the predicate that would be the result if the operand were
503 /// regarded as signed.
504 /// @brief Return the signed version of the predicate
505 Predicate getSignedPredicate() const {
506 return getSignedPredicate(getPredicate());
509 /// This is a static version that you can use without an instruction.
510 /// @brief Return the signed version of the predicate.
511 static Predicate getSignedPredicate(Predicate pred);
513 /// This also tests for commutativity. If isEquality() returns true then
514 /// the predicate is also commutative.
515 /// @returns true if the predicate of this instruction is EQ or NE.
516 /// @brief Determine if this is an equality predicate.
517 bool isEquality() const {
518 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
521 /// @returns true if the predicate of this ICmpInst is commutative
522 /// @brief Determine if this relation is commutative.
523 bool isCommutative() const { return isEquality(); }
525 /// @returns true if the predicate is relational (not EQ or NE).
526 /// @brief Determine if this a relational predicate.
527 bool isRelational() const {
528 return !isEquality();
531 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
532 /// @brief Determine if this instruction's predicate is signed.
533 bool isSignedPredicate() { return isSignedPredicate(getPredicate()); }
535 /// @returns true if the predicate provided is signed, false otherwise
536 /// @brief Determine if the predicate is signed.
537 static bool isSignedPredicate(Predicate pred);
539 /// Exchange the two operands to this instruction in such a way that it does
540 /// not modify the semantics of the instruction. The predicate value may be
541 /// changed to retain the same result if the predicate is order dependent
543 /// @brief Swap operands and adjust predicate.
544 void swapOperands() {
545 SubclassData = getSwappedPredicate();
546 std::swap(Ops[0], Ops[1]);
549 // Methods for support type inquiry through isa, cast, and dyn_cast:
550 static inline bool classof(const ICmpInst *) { return true; }
551 static inline bool classof(const Instruction *I) {
552 return I->getOpcode() == Instruction::ICmp;
554 static inline bool classof(const Value *V) {
555 return isa<Instruction>(V) && classof(cast<Instruction>(V));
559 //===----------------------------------------------------------------------===//
561 //===----------------------------------------------------------------------===//
563 /// This instruction compares its operands according to the predicate given
564 /// to the constructor. It only operates on floating point values or packed
565 /// vectors of floating point values. The operands must be identical types.
566 /// @brief Represents a floating point comparison operator.
567 class FCmpInst: public CmpInst {
569 /// This enumeration lists the possible predicates for the FCmpInst. Values
570 /// in the range 0-31 are reserved for FCmpInst.
572 // Opcode U L G E Intuitive operation
573 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
574 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
575 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
576 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
577 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
578 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
579 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
580 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
581 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
582 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
583 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
584 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
585 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
586 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
587 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
588 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
589 FIRST_FCMP_PREDICATE = FCMP_FALSE,
590 LAST_FCMP_PREDICATE = FCMP_TRUE,
591 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
594 /// @brief Constructor with insert-before-instruction semantics.
596 Predicate pred, ///< The predicate to use for the comparison
597 Value *LHS, ///< The left-hand-side of the expression
598 Value *RHS, ///< The right-hand-side of the expression
599 const std::string &Name = "", ///< Name of the instruction
600 Instruction *InsertBefore = 0 ///< Where to insert
601 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
604 /// @brief Constructor with insert-at-block-end semantics.
606 Predicate pred, ///< The predicate to use for the comparison
607 Value *LHS, ///< The left-hand-side of the expression
608 Value *RHS, ///< The right-hand-side of the expression
609 const std::string &Name, ///< Name of the instruction
610 BasicBlock *InsertAtEnd ///< Block to insert into.
611 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
614 /// @brief Return the predicate for this instruction.
615 Predicate getPredicate() const { return Predicate(SubclassData); }
617 /// @brief Set the predicate for this instruction to the specified value.
618 void setPredicate(Predicate P) { SubclassData = P; }
620 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
621 /// @returns the inverse predicate for the instructions current predicate.
622 /// @brief Return the inverse of the predicate
623 Predicate getInversePredicate() const {
624 return getInversePredicate(getPredicate());
627 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
628 /// @returns the inverse predicate for \p pred.
629 /// @brief Return the inverse of a given predicate
630 static Predicate getInversePredicate(Predicate pred);
632 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
633 /// @returns the predicate that would be the result of exchanging the two
634 /// operands of the ICmpInst instruction without changing the result
636 /// @brief Return the predicate as if the operands were swapped
637 Predicate getSwappedPredicate() const {
638 return getSwappedPredicate(getPredicate());
641 /// This is a static version that you can use without an instruction
643 /// @brief Return the predicate as if the operands were swapped.
644 static Predicate getSwappedPredicate(Predicate Opcode);
646 /// This also tests for commutativity. If isEquality() returns true then
647 /// the predicate is also commutative. Only the equality predicates are
649 /// @returns true if the predicate of this instruction is EQ or NE.
650 /// @brief Determine if this is an equality predicate.
651 bool isEquality() const {
652 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
653 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
655 bool isCommutative() const { return isEquality(); }
657 /// @returns true if the predicate is relational (not EQ or NE).
658 /// @brief Determine if this a relational predicate.
659 bool isRelational() const { return !isEquality(); }
661 /// Exchange the two operands to this instruction in such a way that it does
662 /// not modify the semantics of the instruction. The predicate value may be
663 /// changed to retain the same result if the predicate is order dependent
665 /// @brief Swap operands and adjust predicate.
666 void swapOperands() {
667 SubclassData = getSwappedPredicate();
668 std::swap(Ops[0], Ops[1]);
671 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
672 static inline bool classof(const FCmpInst *) { return true; }
673 static inline bool classof(const Instruction *I) {
674 return I->getOpcode() == Instruction::FCmp;
676 static inline bool classof(const Value *V) {
677 return isa<Instruction>(V) && classof(cast<Instruction>(V));
681 //===----------------------------------------------------------------------===//
683 //===----------------------------------------------------------------------===//
685 /// CallInst - This class represents a function call, abstracting a target
686 /// machine's calling convention. This class uses low bit of the SubClassData
687 /// field to indicate whether or not this is a tail call. The rest of the bits
688 /// hold the calling convention of the call.
690 class CallInst : public Instruction {
691 CallInst(const CallInst &CI);
692 void init(Value *Func, Value* const *Params, unsigned NumParams);
693 void init(Value *Func, Value *Actual1, Value *Actual2);
694 void init(Value *Func, Value *Actual);
695 void init(Value *Func);
698 CallInst(Value *F, Value* const *Args, unsigned NumArgs,
699 const std::string &Name = "", Instruction *InsertBefore = 0);
700 CallInst(Value *F, Value *const *Args, unsigned NumArgs,
701 const std::string &Name, BasicBlock *InsertAtEnd);
703 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
704 // actuals, respectively.
705 CallInst(Value *F, Value *Actual1, Value *Actual2,
706 const std::string& Name = "", Instruction *InsertBefore = 0);
707 CallInst(Value *F, Value *Actual1, Value *Actual2,
708 const std::string& Name, BasicBlock *InsertAtEnd);
709 CallInst(Value *F, Value *Actual, const std::string& Name = "",
710 Instruction *InsertBefore = 0);
711 CallInst(Value *F, Value *Actual, const std::string& Name,
712 BasicBlock *InsertAtEnd);
713 explicit CallInst(Value *F, const std::string &Name = "",
714 Instruction *InsertBefore = 0);
715 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
718 virtual CallInst *clone() const;
720 bool isTailCall() const { return SubclassData & 1; }
721 void setTailCall(bool isTailCall = true) {
722 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
725 /// getCallingConv/setCallingConv - Get or set the calling convention of this
727 unsigned getCallingConv() const { return SubclassData >> 1; }
728 void setCallingConv(unsigned CC) {
729 SubclassData = (SubclassData & 1) | (CC << 1);
732 /// getCalledFunction - Return the function being called by this instruction
733 /// if it is a direct call. If it is a call through a function pointer,
735 Function *getCalledFunction() const {
736 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
739 /// getCalledValue - Get a pointer to the function that is invoked by this
741 inline const Value *getCalledValue() const { return getOperand(0); }
742 inline Value *getCalledValue() { return getOperand(0); }
744 // Methods for support type inquiry through isa, cast, and dyn_cast:
745 static inline bool classof(const CallInst *) { return true; }
746 static inline bool classof(const Instruction *I) {
747 return I->getOpcode() == Instruction::Call;
749 static inline bool classof(const Value *V) {
750 return isa<Instruction>(V) && classof(cast<Instruction>(V));
754 //===----------------------------------------------------------------------===//
756 //===----------------------------------------------------------------------===//
758 /// SelectInst - This class represents the LLVM 'select' instruction.
760 class SelectInst : public Instruction {
763 void init(Value *C, Value *S1, Value *S2) {
764 Ops[0].init(C, this);
765 Ops[1].init(S1, this);
766 Ops[2].init(S2, this);
769 SelectInst(const SelectInst &SI)
770 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
771 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
774 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
775 Instruction *InsertBefore = 0)
776 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
780 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
781 BasicBlock *InsertAtEnd)
782 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
787 Value *getCondition() const { return Ops[0]; }
788 Value *getTrueValue() const { return Ops[1]; }
789 Value *getFalseValue() const { return Ops[2]; }
791 /// Transparently provide more efficient getOperand methods.
792 Value *getOperand(unsigned i) const {
793 assert(i < 3 && "getOperand() out of range!");
796 void setOperand(unsigned i, Value *Val) {
797 assert(i < 3 && "setOperand() out of range!");
800 unsigned getNumOperands() const { return 3; }
802 OtherOps getOpcode() const {
803 return static_cast<OtherOps>(Instruction::getOpcode());
806 virtual SelectInst *clone() const;
808 // Methods for support type inquiry through isa, cast, and dyn_cast:
809 static inline bool classof(const SelectInst *) { return true; }
810 static inline bool classof(const Instruction *I) {
811 return I->getOpcode() == Instruction::Select;
813 static inline bool classof(const Value *V) {
814 return isa<Instruction>(V) && classof(cast<Instruction>(V));
818 //===----------------------------------------------------------------------===//
820 //===----------------------------------------------------------------------===//
822 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
823 /// an argument of the specified type given a va_list and increments that list
825 class VAArgInst : public UnaryInstruction {
826 VAArgInst(const VAArgInst &VAA)
827 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
829 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
830 Instruction *InsertBefore = 0)
831 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
834 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
835 BasicBlock *InsertAtEnd)
836 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
840 virtual VAArgInst *clone() const;
842 // Methods for support type inquiry through isa, cast, and dyn_cast:
843 static inline bool classof(const VAArgInst *) { return true; }
844 static inline bool classof(const Instruction *I) {
845 return I->getOpcode() == VAArg;
847 static inline bool classof(const Value *V) {
848 return isa<Instruction>(V) && classof(cast<Instruction>(V));
852 //===----------------------------------------------------------------------===//
853 // ExtractElementInst Class
854 //===----------------------------------------------------------------------===//
856 /// ExtractElementInst - This instruction extracts a single (scalar)
857 /// element from a VectorType value
859 class ExtractElementInst : public Instruction {
861 ExtractElementInst(const ExtractElementInst &EE) :
862 Instruction(EE.getType(), ExtractElement, Ops, 2) {
863 Ops[0].init(EE.Ops[0], this);
864 Ops[1].init(EE.Ops[1], this);
868 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
869 Instruction *InsertBefore = 0);
870 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
871 Instruction *InsertBefore = 0);
872 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
873 BasicBlock *InsertAtEnd);
874 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
875 BasicBlock *InsertAtEnd);
877 /// isValidOperands - Return true if an extractelement instruction can be
878 /// formed with the specified operands.
879 static bool isValidOperands(const Value *Vec, const Value *Idx);
881 virtual ExtractElementInst *clone() const;
883 /// Transparently provide more efficient getOperand methods.
884 Value *getOperand(unsigned i) const {
885 assert(i < 2 && "getOperand() out of range!");
888 void setOperand(unsigned i, Value *Val) {
889 assert(i < 2 && "setOperand() out of range!");
892 unsigned getNumOperands() const { return 2; }
894 // Methods for support type inquiry through isa, cast, and dyn_cast:
895 static inline bool classof(const ExtractElementInst *) { return true; }
896 static inline bool classof(const Instruction *I) {
897 return I->getOpcode() == Instruction::ExtractElement;
899 static inline bool classof(const Value *V) {
900 return isa<Instruction>(V) && classof(cast<Instruction>(V));
904 //===----------------------------------------------------------------------===//
905 // InsertElementInst Class
906 //===----------------------------------------------------------------------===//
908 /// InsertElementInst - This instruction inserts a single (scalar)
909 /// element into a VectorType value
911 class InsertElementInst : public Instruction {
913 InsertElementInst(const InsertElementInst &IE);
915 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
916 const std::string &Name = "",Instruction *InsertBefore = 0);
917 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
918 const std::string &Name = "",Instruction *InsertBefore = 0);
919 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
920 const std::string &Name, BasicBlock *InsertAtEnd);
921 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
922 const std::string &Name, BasicBlock *InsertAtEnd);
924 /// isValidOperands - Return true if an insertelement instruction can be
925 /// formed with the specified operands.
926 static bool isValidOperands(const Value *Vec, const Value *NewElt,
929 virtual InsertElementInst *clone() const;
931 /// getType - Overload to return most specific vector type.
933 inline const VectorType *getType() const {
934 return reinterpret_cast<const VectorType*>(Instruction::getType());
937 /// Transparently provide more efficient getOperand methods.
938 Value *getOperand(unsigned i) const {
939 assert(i < 3 && "getOperand() out of range!");
942 void setOperand(unsigned i, Value *Val) {
943 assert(i < 3 && "setOperand() out of range!");
946 unsigned getNumOperands() const { return 3; }
948 // Methods for support type inquiry through isa, cast, and dyn_cast:
949 static inline bool classof(const InsertElementInst *) { return true; }
950 static inline bool classof(const Instruction *I) {
951 return I->getOpcode() == Instruction::InsertElement;
953 static inline bool classof(const Value *V) {
954 return isa<Instruction>(V) && classof(cast<Instruction>(V));
958 //===----------------------------------------------------------------------===//
959 // ShuffleVectorInst Class
960 //===----------------------------------------------------------------------===//
962 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
965 class ShuffleVectorInst : public Instruction {
967 ShuffleVectorInst(const ShuffleVectorInst &IE);
969 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
970 const std::string &Name = "", Instruction *InsertBefor = 0);
971 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
972 const std::string &Name, BasicBlock *InsertAtEnd);
974 /// isValidOperands - Return true if a shufflevector instruction can be
975 /// formed with the specified operands.
976 static bool isValidOperands(const Value *V1, const Value *V2,
979 virtual ShuffleVectorInst *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 ShuffleVectorInst *) { return true; }
1000 static inline bool classof(const Instruction *I) {
1001 return I->getOpcode() == Instruction::ShuffleVector;
1003 static inline bool classof(const Value *V) {
1004 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1009 //===----------------------------------------------------------------------===//
1011 //===----------------------------------------------------------------------===//
1013 // PHINode - The PHINode class is used to represent the magical mystical PHI
1014 // node, that can not exist in nature, but can be synthesized in a computer
1015 // scientist's overactive imagination.
1017 class PHINode : public Instruction {
1018 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1019 /// the number actually in use.
1020 unsigned ReservedSpace;
1021 PHINode(const PHINode &PN);
1023 explicit PHINode(const Type *Ty, const std::string &Name = "",
1024 Instruction *InsertBefore = 0)
1025 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1030 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1031 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1038 /// reserveOperandSpace - This method can be used to avoid repeated
1039 /// reallocation of PHI operand lists by reserving space for the correct
1040 /// number of operands before adding them. Unlike normal vector reserves,
1041 /// this method can also be used to trim the operand space.
1042 void reserveOperandSpace(unsigned NumValues) {
1043 resizeOperands(NumValues*2);
1046 virtual PHINode *clone() const;
1048 /// getNumIncomingValues - Return the number of incoming edges
1050 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1052 /// getIncomingValue - Return incoming value number x
1054 Value *getIncomingValue(unsigned i) const {
1055 assert(i*2 < getNumOperands() && "Invalid value number!");
1056 return getOperand(i*2);
1058 void setIncomingValue(unsigned i, Value *V) {
1059 assert(i*2 < getNumOperands() && "Invalid value number!");
1062 unsigned getOperandNumForIncomingValue(unsigned i) {
1066 /// getIncomingBlock - Return incoming basic block number x
1068 BasicBlock *getIncomingBlock(unsigned i) const {
1069 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1071 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1072 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1074 unsigned getOperandNumForIncomingBlock(unsigned i) {
1078 /// addIncoming - Add an incoming value to the end of the PHI list
1080 void addIncoming(Value *V, BasicBlock *BB) {
1081 assert(getType() == V->getType() &&
1082 "All operands to PHI node must be the same type as the PHI node!");
1083 unsigned OpNo = NumOperands;
1084 if (OpNo+2 > ReservedSpace)
1085 resizeOperands(0); // Get more space!
1086 // Initialize some new operands.
1087 NumOperands = OpNo+2;
1088 OperandList[OpNo].init(V, this);
1089 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1092 /// removeIncomingValue - Remove an incoming value. This is useful if a
1093 /// predecessor basic block is deleted. The value removed is returned.
1095 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1096 /// is true), the PHI node is destroyed and any uses of it are replaced with
1097 /// dummy values. The only time there should be zero incoming values to a PHI
1098 /// node is when the block is dead, so this strategy is sound.
1100 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1102 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1103 int Idx = getBasicBlockIndex(BB);
1104 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1105 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1108 /// getBasicBlockIndex - Return the first index of the specified basic
1109 /// block in the value list for this PHI. Returns -1 if no instance.
1111 int getBasicBlockIndex(const BasicBlock *BB) const {
1112 Use *OL = OperandList;
1113 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1114 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1118 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1119 return getIncomingValue(getBasicBlockIndex(BB));
1122 /// hasConstantValue - If the specified PHI node always merges together the
1123 /// same value, return the value, otherwise return null.
1125 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1127 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1128 static inline bool classof(const PHINode *) { return true; }
1129 static inline bool classof(const Instruction *I) {
1130 return I->getOpcode() == Instruction::PHI;
1132 static inline bool classof(const Value *V) {
1133 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1136 void resizeOperands(unsigned NumOperands);
1139 //===----------------------------------------------------------------------===//
1141 //===----------------------------------------------------------------------===//
1143 //===---------------------------------------------------------------------------
1144 /// ReturnInst - Return a value (possibly void), from a function. Execution
1145 /// does not continue in this function any longer.
1147 class ReturnInst : public TerminatorInst {
1148 Use RetVal; // Return Value: null if 'void'.
1149 ReturnInst(const ReturnInst &RI);
1150 void init(Value *RetVal);
1153 // ReturnInst constructors:
1154 // ReturnInst() - 'ret void' instruction
1155 // ReturnInst( null) - 'ret void' instruction
1156 // ReturnInst(Value* X) - 'ret X' instruction
1157 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1158 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1159 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1160 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1162 // NOTE: If the Value* passed is of type void then the constructor behaves as
1163 // if it was passed NULL.
1164 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1165 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1166 explicit ReturnInst(BasicBlock *InsertAtEnd);
1168 virtual ReturnInst *clone() const;
1170 // Transparently provide more efficient getOperand methods.
1171 Value *getOperand(unsigned i) const {
1172 assert(i < getNumOperands() && "getOperand() out of range!");
1175 void setOperand(unsigned i, Value *Val) {
1176 assert(i < getNumOperands() && "setOperand() out of range!");
1180 Value *getReturnValue() const { return RetVal; }
1182 unsigned getNumSuccessors() const { return 0; }
1184 // Methods for support type inquiry through isa, cast, and dyn_cast:
1185 static inline bool classof(const ReturnInst *) { return true; }
1186 static inline bool classof(const Instruction *I) {
1187 return (I->getOpcode() == Instruction::Ret);
1189 static inline bool classof(const Value *V) {
1190 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1193 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1194 virtual unsigned getNumSuccessorsV() const;
1195 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1198 //===----------------------------------------------------------------------===//
1200 //===----------------------------------------------------------------------===//
1202 //===---------------------------------------------------------------------------
1203 /// BranchInst - Conditional or Unconditional Branch instruction.
1205 class BranchInst : public TerminatorInst {
1206 /// Ops list - Branches are strange. The operands are ordered:
1207 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1208 /// they don't have to check for cond/uncond branchness.
1210 BranchInst(const BranchInst &BI);
1213 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1214 // BranchInst(BB *B) - 'br B'
1215 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1216 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1217 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1218 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1219 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1220 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1221 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1222 Instruction *InsertBefore = 0);
1223 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1224 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1225 BasicBlock *InsertAtEnd);
1227 /// Transparently provide more efficient getOperand methods.
1228 Value *getOperand(unsigned i) const {
1229 assert(i < getNumOperands() && "getOperand() out of range!");
1232 void setOperand(unsigned i, Value *Val) {
1233 assert(i < getNumOperands() && "setOperand() out of range!");
1237 virtual BranchInst *clone() const;
1239 inline bool isUnconditional() const { return getNumOperands() == 1; }
1240 inline bool isConditional() const { return getNumOperands() == 3; }
1242 inline Value *getCondition() const {
1243 assert(isConditional() && "Cannot get condition of an uncond branch!");
1244 return getOperand(2);
1247 void setCondition(Value *V) {
1248 assert(isConditional() && "Cannot set condition of unconditional branch!");
1252 // setUnconditionalDest - Change the current branch to an unconditional branch
1253 // targeting the specified block.
1254 // FIXME: Eliminate this ugly method.
1255 void setUnconditionalDest(BasicBlock *Dest) {
1256 if (isConditional()) { // Convert this to an uncond branch.
1261 setOperand(0, reinterpret_cast<Value*>(Dest));
1264 unsigned getNumSuccessors() const { return 1+isConditional(); }
1266 BasicBlock *getSuccessor(unsigned i) const {
1267 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1268 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1269 cast<BasicBlock>(getOperand(1));
1272 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1273 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1274 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1277 // Methods for support type inquiry through isa, cast, and dyn_cast:
1278 static inline bool classof(const BranchInst *) { return true; }
1279 static inline bool classof(const Instruction *I) {
1280 return (I->getOpcode() == Instruction::Br);
1282 static inline bool classof(const Value *V) {
1283 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1286 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1287 virtual unsigned getNumSuccessorsV() const;
1288 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1291 //===----------------------------------------------------------------------===//
1293 //===----------------------------------------------------------------------===//
1295 //===---------------------------------------------------------------------------
1296 /// SwitchInst - Multiway switch
1298 class SwitchInst : public TerminatorInst {
1299 unsigned ReservedSpace;
1300 // Operand[0] = Value to switch on
1301 // Operand[1] = Default basic block destination
1302 // Operand[2n ] = Value to match
1303 // Operand[2n+1] = BasicBlock to go to on match
1304 SwitchInst(const SwitchInst &RI);
1305 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1306 void resizeOperands(unsigned No);
1308 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1309 /// switch on and a default destination. The number of additional cases can
1310 /// be specified here to make memory allocation more efficient. This
1311 /// constructor can also autoinsert before another instruction.
1312 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1313 Instruction *InsertBefore = 0);
1315 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1316 /// switch on and a default destination. The number of additional cases can
1317 /// be specified here to make memory allocation more efficient. This
1318 /// constructor also autoinserts at the end of the specified BasicBlock.
1319 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1320 BasicBlock *InsertAtEnd);
1324 // Accessor Methods for Switch stmt
1325 inline Value *getCondition() const { return getOperand(0); }
1326 void setCondition(Value *V) { setOperand(0, V); }
1328 inline BasicBlock *getDefaultDest() const {
1329 return cast<BasicBlock>(getOperand(1));
1332 /// getNumCases - return the number of 'cases' in this switch instruction.
1333 /// Note that case #0 is always the default case.
1334 unsigned getNumCases() const {
1335 return getNumOperands()/2;
1338 /// getCaseValue - Return the specified case value. Note that case #0, the
1339 /// default destination, does not have a case value.
1340 ConstantInt *getCaseValue(unsigned i) {
1341 assert(i && i < getNumCases() && "Illegal case value to get!");
1342 return getSuccessorValue(i);
1345 /// getCaseValue - Return the specified case value. Note that case #0, the
1346 /// default destination, does not have a case value.
1347 const ConstantInt *getCaseValue(unsigned i) const {
1348 assert(i && i < getNumCases() && "Illegal case value to get!");
1349 return getSuccessorValue(i);
1352 /// findCaseValue - Search all of the case values for the specified constant.
1353 /// If it is explicitly handled, return the case number of it, otherwise
1354 /// return 0 to indicate that it is handled by the default handler.
1355 unsigned findCaseValue(const ConstantInt *C) const {
1356 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1357 if (getCaseValue(i) == C)
1362 /// findCaseDest - Finds the unique case value for a given successor. Returns
1363 /// null if the successor is not found, not unique, or is the default case.
1364 ConstantInt *findCaseDest(BasicBlock *BB) {
1365 if (BB == getDefaultDest()) return NULL;
1367 ConstantInt *CI = NULL;
1368 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1369 if (getSuccessor(i) == BB) {
1370 if (CI) return NULL; // Multiple cases lead to BB.
1371 else CI = getCaseValue(i);
1377 /// addCase - Add an entry to the switch instruction...
1379 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1381 /// removeCase - This method removes the specified successor from the switch
1382 /// instruction. Note that this cannot be used to remove the default
1383 /// destination (successor #0).
1385 void removeCase(unsigned idx);
1387 virtual SwitchInst *clone() const;
1389 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1390 BasicBlock *getSuccessor(unsigned idx) const {
1391 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1392 return cast<BasicBlock>(getOperand(idx*2+1));
1394 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1395 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1396 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1399 // getSuccessorValue - Return the value associated with the specified
1401 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1402 assert(idx < getNumSuccessors() && "Successor # out of range!");
1403 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1406 // Methods for support type inquiry through isa, cast, and dyn_cast:
1407 static inline bool classof(const SwitchInst *) { return true; }
1408 static inline bool classof(const Instruction *I) {
1409 return I->getOpcode() == Instruction::Switch;
1411 static inline bool classof(const Value *V) {
1412 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1415 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1416 virtual unsigned getNumSuccessorsV() const;
1417 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1420 //===----------------------------------------------------------------------===//
1422 //===----------------------------------------------------------------------===//
1424 //===---------------------------------------------------------------------------
1426 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1427 /// calling convention of the call.
1429 class InvokeInst : public TerminatorInst {
1430 InvokeInst(const InvokeInst &BI);
1431 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1432 Value* const *Args, unsigned NumArgs);
1434 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1435 Value* const* Args, unsigned NumArgs, const std::string &Name = "",
1436 Instruction *InsertBefore = 0);
1437 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1438 Value* const* Args, unsigned NumArgs, const std::string &Name,
1439 BasicBlock *InsertAtEnd);
1442 virtual InvokeInst *clone() const;
1444 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1446 unsigned getCallingConv() const { return SubclassData; }
1447 void setCallingConv(unsigned CC) {
1451 /// getCalledFunction - Return the function called, or null if this is an
1452 /// indirect function invocation.
1454 Function *getCalledFunction() const {
1455 return dyn_cast<Function>(getOperand(0));
1458 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1459 inline Value *getCalledValue() const { return getOperand(0); }
1461 // get*Dest - Return the destination basic blocks...
1462 BasicBlock *getNormalDest() const {
1463 return cast<BasicBlock>(getOperand(1));
1465 BasicBlock *getUnwindDest() const {
1466 return cast<BasicBlock>(getOperand(2));
1468 void setNormalDest(BasicBlock *B) {
1469 setOperand(1, reinterpret_cast<Value*>(B));
1472 void setUnwindDest(BasicBlock *B) {
1473 setOperand(2, reinterpret_cast<Value*>(B));
1476 inline BasicBlock *getSuccessor(unsigned i) const {
1477 assert(i < 2 && "Successor # out of range for invoke!");
1478 return i == 0 ? getNormalDest() : getUnwindDest();
1481 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1482 assert(idx < 2 && "Successor # out of range for invoke!");
1483 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1486 unsigned getNumSuccessors() const { return 2; }
1488 // Methods for support type inquiry through isa, cast, and dyn_cast:
1489 static inline bool classof(const InvokeInst *) { return true; }
1490 static inline bool classof(const Instruction *I) {
1491 return (I->getOpcode() == Instruction::Invoke);
1493 static inline bool classof(const Value *V) {
1494 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1497 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1498 virtual unsigned getNumSuccessorsV() const;
1499 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1503 //===----------------------------------------------------------------------===//
1505 //===----------------------------------------------------------------------===//
1507 //===---------------------------------------------------------------------------
1508 /// UnwindInst - Immediately exit the current function, unwinding the stack
1509 /// until an invoke instruction is found.
1511 class UnwindInst : public TerminatorInst {
1513 explicit UnwindInst(Instruction *InsertBefore = 0);
1514 explicit UnwindInst(BasicBlock *InsertAtEnd);
1516 virtual UnwindInst *clone() const;
1518 unsigned getNumSuccessors() const { return 0; }
1520 // Methods for support type inquiry through isa, cast, and dyn_cast:
1521 static inline bool classof(const UnwindInst *) { return true; }
1522 static inline bool classof(const Instruction *I) {
1523 return I->getOpcode() == Instruction::Unwind;
1525 static inline bool classof(const Value *V) {
1526 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1529 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1530 virtual unsigned getNumSuccessorsV() const;
1531 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1534 //===----------------------------------------------------------------------===//
1535 // UnreachableInst Class
1536 //===----------------------------------------------------------------------===//
1538 //===---------------------------------------------------------------------------
1539 /// UnreachableInst - This function has undefined behavior. In particular, the
1540 /// presence of this instruction indicates some higher level knowledge that the
1541 /// end of the block cannot be reached.
1543 class UnreachableInst : public TerminatorInst {
1545 explicit UnreachableInst(Instruction *InsertBefore = 0);
1546 explicit UnreachableInst(BasicBlock *InsertAtEnd);
1548 virtual UnreachableInst *clone() const;
1550 unsigned getNumSuccessors() const { return 0; }
1552 // Methods for support type inquiry through isa, cast, and dyn_cast:
1553 static inline bool classof(const UnreachableInst *) { return true; }
1554 static inline bool classof(const Instruction *I) {
1555 return I->getOpcode() == Instruction::Unreachable;
1557 static inline bool classof(const Value *V) {
1558 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1561 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1562 virtual unsigned getNumSuccessorsV() const;
1563 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1566 //===----------------------------------------------------------------------===//
1568 //===----------------------------------------------------------------------===//
1570 /// @brief This class represents a truncation of integer types.
1571 class TruncInst : public CastInst {
1572 /// Private copy constructor
1573 TruncInst(const TruncInst &CI)
1574 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1577 /// @brief Constructor with insert-before-instruction semantics
1579 Value *S, ///< The value to be truncated
1580 const Type *Ty, ///< The (smaller) type to truncate to
1581 const std::string &Name = "", ///< A name for the new instruction
1582 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1585 /// @brief Constructor with insert-at-end-of-block semantics
1587 Value *S, ///< The value to be truncated
1588 const Type *Ty, ///< The (smaller) type to truncate to
1589 const std::string &Name, ///< A name for the new instruction
1590 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1593 /// @brief Clone an identical TruncInst
1594 virtual CastInst *clone() const;
1596 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1597 static inline bool classof(const TruncInst *) { return true; }
1598 static inline bool classof(const Instruction *I) {
1599 return I->getOpcode() == Trunc;
1601 static inline bool classof(const Value *V) {
1602 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1606 //===----------------------------------------------------------------------===//
1608 //===----------------------------------------------------------------------===//
1610 /// @brief This class represents zero extension of integer types.
1611 class ZExtInst : public CastInst {
1612 /// @brief Private copy constructor
1613 ZExtInst(const ZExtInst &CI)
1614 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1617 /// @brief Constructor with insert-before-instruction semantics
1619 Value *S, ///< The value to be zero extended
1620 const Type *Ty, ///< The type to zero extend to
1621 const std::string &Name = "", ///< A name for the new instruction
1622 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1625 /// @brief Constructor with insert-at-end semantics.
1627 Value *S, ///< The value to be zero extended
1628 const Type *Ty, ///< The type to zero extend to
1629 const std::string &Name, ///< A name for the new instruction
1630 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1633 /// @brief Clone an identical ZExtInst
1634 virtual CastInst *clone() const;
1636 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1637 static inline bool classof(const ZExtInst *) { return true; }
1638 static inline bool classof(const Instruction *I) {
1639 return I->getOpcode() == ZExt;
1641 static inline bool classof(const Value *V) {
1642 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1646 //===----------------------------------------------------------------------===//
1648 //===----------------------------------------------------------------------===//
1650 /// @brief This class represents a sign extension of integer types.
1651 class SExtInst : public CastInst {
1652 /// @brief Private copy constructor
1653 SExtInst(const SExtInst &CI)
1654 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1657 /// @brief Constructor with insert-before-instruction semantics
1659 Value *S, ///< The value to be sign extended
1660 const Type *Ty, ///< The type to sign extend to
1661 const std::string &Name = "", ///< A name for the new instruction
1662 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1665 /// @brief Constructor with insert-at-end-of-block semantics
1667 Value *S, ///< The value to be sign extended
1668 const Type *Ty, ///< The type to sign extend to
1669 const std::string &Name, ///< A name for the new instruction
1670 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1673 /// @brief Clone an identical SExtInst
1674 virtual CastInst *clone() const;
1676 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1677 static inline bool classof(const SExtInst *) { return true; }
1678 static inline bool classof(const Instruction *I) {
1679 return I->getOpcode() == SExt;
1681 static inline bool classof(const Value *V) {
1682 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1686 //===----------------------------------------------------------------------===//
1687 // FPTruncInst Class
1688 //===----------------------------------------------------------------------===//
1690 /// @brief This class represents a truncation of floating point types.
1691 class FPTruncInst : public CastInst {
1692 FPTruncInst(const FPTruncInst &CI)
1693 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1696 /// @brief Constructor with insert-before-instruction semantics
1698 Value *S, ///< The value to be truncated
1699 const Type *Ty, ///< The type to truncate to
1700 const std::string &Name = "", ///< A name for the new instruction
1701 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1704 /// @brief Constructor with insert-before-instruction semantics
1706 Value *S, ///< The value to be truncated
1707 const Type *Ty, ///< The type to truncate to
1708 const std::string &Name, ///< A name for the new instruction
1709 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1712 /// @brief Clone an identical FPTruncInst
1713 virtual CastInst *clone() const;
1715 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1716 static inline bool classof(const FPTruncInst *) { return true; }
1717 static inline bool classof(const Instruction *I) {
1718 return I->getOpcode() == FPTrunc;
1720 static inline bool classof(const Value *V) {
1721 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1725 //===----------------------------------------------------------------------===//
1727 //===----------------------------------------------------------------------===//
1729 /// @brief This class represents an extension of floating point types.
1730 class FPExtInst : public CastInst {
1731 FPExtInst(const FPExtInst &CI)
1732 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1735 /// @brief Constructor with insert-before-instruction semantics
1737 Value *S, ///< The value to be extended
1738 const Type *Ty, ///< The type to extend to
1739 const std::string &Name = "", ///< A name for the new instruction
1740 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1743 /// @brief Constructor with insert-at-end-of-block semantics
1745 Value *S, ///< The value to be extended
1746 const Type *Ty, ///< The type to extend to
1747 const std::string &Name, ///< A name for the new instruction
1748 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1751 /// @brief Clone an identical FPExtInst
1752 virtual CastInst *clone() const;
1754 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1755 static inline bool classof(const FPExtInst *) { return true; }
1756 static inline bool classof(const Instruction *I) {
1757 return I->getOpcode() == FPExt;
1759 static inline bool classof(const Value *V) {
1760 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1764 //===----------------------------------------------------------------------===//
1766 //===----------------------------------------------------------------------===//
1768 /// @brief This class represents a cast unsigned integer to floating point.
1769 class UIToFPInst : public CastInst {
1770 UIToFPInst(const UIToFPInst &CI)
1771 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1774 /// @brief Constructor with insert-before-instruction semantics
1776 Value *S, ///< The value to be converted
1777 const Type *Ty, ///< The type to convert to
1778 const std::string &Name = "", ///< A name for the new instruction
1779 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1782 /// @brief Constructor with insert-at-end-of-block semantics
1784 Value *S, ///< The value to be converted
1785 const Type *Ty, ///< The type to convert to
1786 const std::string &Name, ///< A name for the new instruction
1787 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1790 /// @brief Clone an identical UIToFPInst
1791 virtual CastInst *clone() const;
1793 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1794 static inline bool classof(const UIToFPInst *) { return true; }
1795 static inline bool classof(const Instruction *I) {
1796 return I->getOpcode() == UIToFP;
1798 static inline bool classof(const Value *V) {
1799 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1803 //===----------------------------------------------------------------------===//
1805 //===----------------------------------------------------------------------===//
1807 /// @brief This class represents a cast from signed integer to floating point.
1808 class SIToFPInst : public CastInst {
1809 SIToFPInst(const SIToFPInst &CI)
1810 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1813 /// @brief Constructor with insert-before-instruction semantics
1815 Value *S, ///< The value to be converted
1816 const Type *Ty, ///< The type to convert to
1817 const std::string &Name = "", ///< A name for the new instruction
1818 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1821 /// @brief Constructor with insert-at-end-of-block semantics
1823 Value *S, ///< The value to be converted
1824 const Type *Ty, ///< The type to convert to
1825 const std::string &Name, ///< A name for the new instruction
1826 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1829 /// @brief Clone an identical SIToFPInst
1830 virtual CastInst *clone() const;
1832 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1833 static inline bool classof(const SIToFPInst *) { return true; }
1834 static inline bool classof(const Instruction *I) {
1835 return I->getOpcode() == SIToFP;
1837 static inline bool classof(const Value *V) {
1838 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1842 //===----------------------------------------------------------------------===//
1844 //===----------------------------------------------------------------------===//
1846 /// @brief This class represents a cast from floating point to unsigned integer
1847 class FPToUIInst : public CastInst {
1848 FPToUIInst(const FPToUIInst &CI)
1849 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1852 /// @brief Constructor with insert-before-instruction semantics
1854 Value *S, ///< The value to be converted
1855 const Type *Ty, ///< The type to convert to
1856 const std::string &Name = "", ///< A name for the new instruction
1857 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1860 /// @brief Constructor with insert-at-end-of-block semantics
1862 Value *S, ///< The value to be converted
1863 const Type *Ty, ///< The type to convert to
1864 const std::string &Name, ///< A name for the new instruction
1865 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
1868 /// @brief Clone an identical FPToUIInst
1869 virtual CastInst *clone() const;
1871 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1872 static inline bool classof(const FPToUIInst *) { return true; }
1873 static inline bool classof(const Instruction *I) {
1874 return I->getOpcode() == FPToUI;
1876 static inline bool classof(const Value *V) {
1877 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1881 //===----------------------------------------------------------------------===//
1883 //===----------------------------------------------------------------------===//
1885 /// @brief This class represents a cast from floating point to signed integer.
1886 class FPToSIInst : public CastInst {
1887 FPToSIInst(const FPToSIInst &CI)
1888 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
1891 /// @brief Constructor with insert-before-instruction semantics
1893 Value *S, ///< The value to be converted
1894 const Type *Ty, ///< The type to convert to
1895 const std::string &Name = "", ///< A name for the new instruction
1896 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1899 /// @brief Constructor with insert-at-end-of-block semantics
1901 Value *S, ///< The value to be converted
1902 const Type *Ty, ///< The type to convert to
1903 const std::string &Name, ///< A name for the new instruction
1904 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1907 /// @brief Clone an identical FPToSIInst
1908 virtual CastInst *clone() const;
1910 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1911 static inline bool classof(const FPToSIInst *) { return true; }
1912 static inline bool classof(const Instruction *I) {
1913 return I->getOpcode() == FPToSI;
1915 static inline bool classof(const Value *V) {
1916 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1920 //===----------------------------------------------------------------------===//
1921 // IntToPtrInst Class
1922 //===----------------------------------------------------------------------===//
1924 /// @brief This class represents a cast from an integer to a pointer.
1925 class IntToPtrInst : public CastInst {
1926 IntToPtrInst(const IntToPtrInst &CI)
1927 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
1930 /// @brief Constructor with insert-before-instruction semantics
1932 Value *S, ///< The value to be converted
1933 const Type *Ty, ///< The type to convert to
1934 const std::string &Name = "", ///< A name for the new instruction
1935 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1938 /// @brief Constructor with insert-at-end-of-block semantics
1940 Value *S, ///< The value to be converted
1941 const Type *Ty, ///< The type to convert to
1942 const std::string &Name, ///< A name for the new instruction
1943 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1946 /// @brief Clone an identical IntToPtrInst
1947 virtual CastInst *clone() const;
1949 // Methods for support type inquiry through isa, cast, and dyn_cast:
1950 static inline bool classof(const IntToPtrInst *) { return true; }
1951 static inline bool classof(const Instruction *I) {
1952 return I->getOpcode() == IntToPtr;
1954 static inline bool classof(const Value *V) {
1955 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1959 //===----------------------------------------------------------------------===//
1960 // PtrToIntInst Class
1961 //===----------------------------------------------------------------------===//
1963 /// @brief This class represents a cast from a pointer to an integer
1964 class PtrToIntInst : public CastInst {
1965 PtrToIntInst(const PtrToIntInst &CI)
1966 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
1969 /// @brief Constructor with insert-before-instruction semantics
1971 Value *S, ///< The value to be converted
1972 const Type *Ty, ///< The type to convert to
1973 const std::string &Name = "", ///< A name for the new instruction
1974 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1977 /// @brief Constructor with insert-at-end-of-block semantics
1979 Value *S, ///< The value to be converted
1980 const Type *Ty, ///< The type to convert to
1981 const std::string &Name, ///< A name for the new instruction
1982 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1985 /// @brief Clone an identical PtrToIntInst
1986 virtual CastInst *clone() const;
1988 // Methods for support type inquiry through isa, cast, and dyn_cast:
1989 static inline bool classof(const PtrToIntInst *) { return true; }
1990 static inline bool classof(const Instruction *I) {
1991 return I->getOpcode() == PtrToInt;
1993 static inline bool classof(const Value *V) {
1994 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1998 //===----------------------------------------------------------------------===//
1999 // BitCastInst Class
2000 //===----------------------------------------------------------------------===//
2002 /// @brief This class represents a no-op cast from one type to another.
2003 class BitCastInst : public CastInst {
2004 BitCastInst(const BitCastInst &CI)
2005 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2008 /// @brief Constructor with insert-before-instruction semantics
2010 Value *S, ///< The value to be casted
2011 const Type *Ty, ///< The type to casted to
2012 const std::string &Name = "", ///< A name for the new instruction
2013 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2016 /// @brief Constructor with insert-at-end-of-block semantics
2018 Value *S, ///< The value to be casted
2019 const Type *Ty, ///< The type to casted to
2020 const std::string &Name, ///< A name for the new instruction
2021 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2024 /// @brief Clone an identical BitCastInst
2025 virtual CastInst *clone() const;
2027 // Methods for support type inquiry through isa, cast, and dyn_cast:
2028 static inline bool classof(const BitCastInst *) { return true; }
2029 static inline bool classof(const Instruction *I) {
2030 return I->getOpcode() == BitCast;
2032 static inline bool classof(const Value *V) {
2033 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2037 } // End llvm namespace