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"
30 //===----------------------------------------------------------------------===//
31 // AllocationInst Class
32 //===----------------------------------------------------------------------===//
34 /// AllocationInst - This class is the common base class of MallocInst and
37 class AllocationInst : public UnaryInstruction {
40 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
41 const std::string &Name = "", Instruction *InsertBefore = 0);
42 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
43 const std::string &Name, BasicBlock *InsertAtEnd);
45 // Out of line virtual method, so the vtable, etc has a home.
46 virtual ~AllocationInst();
48 /// isArrayAllocation - Return true if there is an allocation size parameter
49 /// to the allocation instruction that is not 1.
51 bool isArrayAllocation() const;
53 /// getArraySize - Get the number of element allocated, for a simple
54 /// allocation of a single element, this will return a constant 1 value.
56 inline const Value *getArraySize() const { return getOperand(0); }
57 inline Value *getArraySize() { return getOperand(0); }
59 /// getType - Overload to return most specific pointer type
61 inline const PointerType *getType() const {
62 return reinterpret_cast<const PointerType*>(Instruction::getType());
65 /// getAllocatedType - Return the type that is being allocated by the
68 const Type *getAllocatedType() const;
70 /// getAlignment - Return the alignment of the memory that is being allocated
71 /// by the instruction.
73 unsigned getAlignment() const { return Alignment; }
74 void setAlignment(unsigned Align) {
75 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
79 virtual Instruction *clone() const = 0;
81 // Methods for support type inquiry through isa, cast, and dyn_cast:
82 static inline bool classof(const AllocationInst *) { return true; }
83 static inline bool classof(const Instruction *I) {
84 return I->getOpcode() == Instruction::Alloca ||
85 I->getOpcode() == Instruction::Malloc;
87 static inline bool classof(const Value *V) {
88 return isa<Instruction>(V) && classof(cast<Instruction>(V));
93 //===----------------------------------------------------------------------===//
95 //===----------------------------------------------------------------------===//
97 /// MallocInst - an instruction to allocated memory on the heap
99 class MallocInst : public AllocationInst {
100 MallocInst(const MallocInst &MI);
102 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
103 const std::string &Name = "",
104 Instruction *InsertBefore = 0)
105 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
106 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
107 BasicBlock *InsertAtEnd)
108 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
110 MallocInst(const Type *Ty, const std::string &Name,
111 Instruction *InsertBefore = 0)
112 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
113 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
114 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
116 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
117 const std::string &Name, BasicBlock *InsertAtEnd)
118 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
119 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
120 const std::string &Name = "",
121 Instruction *InsertBefore = 0)
122 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
124 virtual MallocInst *clone() const;
126 // Methods for support type inquiry through isa, cast, and dyn_cast:
127 static inline bool classof(const MallocInst *) { return true; }
128 static inline bool classof(const Instruction *I) {
129 return (I->getOpcode() == Instruction::Malloc);
131 static inline bool classof(const Value *V) {
132 return isa<Instruction>(V) && classof(cast<Instruction>(V));
137 //===----------------------------------------------------------------------===//
139 //===----------------------------------------------------------------------===//
141 /// AllocaInst - an instruction to allocate memory on the stack
143 class AllocaInst : public AllocationInst {
144 AllocaInst(const AllocaInst &);
146 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
147 const std::string &Name = "",
148 Instruction *InsertBefore = 0)
149 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
150 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
151 BasicBlock *InsertAtEnd)
152 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
154 AllocaInst(const Type *Ty, const std::string &Name,
155 Instruction *InsertBefore = 0)
156 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
157 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
158 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
160 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
161 const std::string &Name = "", Instruction *InsertBefore = 0)
162 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
163 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
164 const std::string &Name, BasicBlock *InsertAtEnd)
165 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
167 virtual AllocaInst *clone() const;
169 // Methods for support type inquiry through isa, cast, and dyn_cast:
170 static inline bool classof(const AllocaInst *) { return true; }
171 static inline bool classof(const Instruction *I) {
172 return (I->getOpcode() == Instruction::Alloca);
174 static inline bool classof(const Value *V) {
175 return isa<Instruction>(V) && classof(cast<Instruction>(V));
180 //===----------------------------------------------------------------------===//
182 //===----------------------------------------------------------------------===//
184 /// FreeInst - an instruction to deallocate memory
186 class FreeInst : public UnaryInstruction {
189 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
190 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
192 virtual FreeInst *clone() const;
194 // Methods for support type inquiry through isa, cast, and dyn_cast:
195 static inline bool classof(const FreeInst *) { return true; }
196 static inline bool classof(const Instruction *I) {
197 return (I->getOpcode() == Instruction::Free);
199 static inline bool classof(const Value *V) {
200 return isa<Instruction>(V) && classof(cast<Instruction>(V));
205 //===----------------------------------------------------------------------===//
207 //===----------------------------------------------------------------------===//
209 /// LoadInst - an instruction for reading from memory. This uses the
210 /// SubclassData field in Value to store whether or not the load is volatile.
212 class LoadInst : public UnaryInstruction {
213 LoadInst(const LoadInst &LI)
214 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
215 setVolatile(LI.isVolatile());
223 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
224 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
225 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false,
226 Instruction *InsertBefore = 0);
227 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
228 BasicBlock *InsertAtEnd);
230 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
231 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
232 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
233 Instruction *InsertBefore = 0);
234 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
235 BasicBlock *InsertAtEnd);
237 /// isVolatile - Return true if this is a load from a volatile memory
240 bool isVolatile() const { return SubclassData; }
242 /// setVolatile - Specify whether this is a volatile load or not.
244 void setVolatile(bool V) { SubclassData = V; }
246 virtual LoadInst *clone() const;
248 Value *getPointerOperand() { return getOperand(0); }
249 const Value *getPointerOperand() const { return getOperand(0); }
250 static unsigned getPointerOperandIndex() { return 0U; }
252 // Methods for support type inquiry through isa, cast, and dyn_cast:
253 static inline bool classof(const LoadInst *) { return true; }
254 static inline bool classof(const Instruction *I) {
255 return I->getOpcode() == Instruction::Load;
257 static inline bool classof(const Value *V) {
258 return isa<Instruction>(V) && classof(cast<Instruction>(V));
263 //===----------------------------------------------------------------------===//
265 //===----------------------------------------------------------------------===//
267 /// StoreInst - an instruction for storing to memory
269 class StoreInst : public Instruction {
271 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
272 Ops[0].init(SI.Ops[0], this);
273 Ops[1].init(SI.Ops[1], this);
274 setVolatile(SI.isVolatile());
281 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
282 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
283 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
284 Instruction *InsertBefore = 0);
285 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
288 /// isVolatile - Return true if this is a load from a volatile memory
291 bool isVolatile() const { return SubclassData; }
293 /// setVolatile - Specify whether this is a volatile load or not.
295 void setVolatile(bool V) { SubclassData = V; }
297 /// Transparently provide more efficient getOperand methods.
298 Value *getOperand(unsigned i) const {
299 assert(i < 2 && "getOperand() out of range!");
302 void setOperand(unsigned i, Value *Val) {
303 assert(i < 2 && "setOperand() out of range!");
306 unsigned getNumOperands() const { return 2; }
309 virtual StoreInst *clone() const;
311 Value *getPointerOperand() { return getOperand(1); }
312 const Value *getPointerOperand() const { return getOperand(1); }
313 static unsigned getPointerOperandIndex() { return 1U; }
315 // Methods for support type inquiry through isa, cast, and dyn_cast:
316 static inline bool classof(const StoreInst *) { return true; }
317 static inline bool classof(const Instruction *I) {
318 return I->getOpcode() == Instruction::Store;
320 static inline bool classof(const Value *V) {
321 return isa<Instruction>(V) && classof(cast<Instruction>(V));
326 //===----------------------------------------------------------------------===//
327 // GetElementPtrInst Class
328 //===----------------------------------------------------------------------===//
330 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
331 /// access elements of arrays and structs
333 class GetElementPtrInst : public Instruction {
334 GetElementPtrInst(const GetElementPtrInst &GEPI)
335 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
336 0, GEPI.getNumOperands()) {
337 Use *OL = OperandList = new Use[NumOperands];
338 Use *GEPIOL = GEPI.OperandList;
339 for (unsigned i = 0, E = NumOperands; i != E; ++i)
340 OL[i].init(GEPIOL[i], this);
342 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
343 void init(Value *Ptr, Value *Idx0, Value *Idx1);
344 void init(Value *Ptr, Value *Idx);
346 /// Constructors - Create a getelementptr instruction with a base pointer an
347 /// list of indices. The first ctor can optionally insert before an existing
348 /// instruction, the second appends the new instruction to the specified
350 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
351 const std::string &Name = "", Instruction *InsertBefore =0);
352 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
353 const std::string &Name, BasicBlock *InsertAtEnd);
355 /// Constructors - These two constructors are convenience methods because one
356 /// and two index getelementptr instructions are so common.
357 GetElementPtrInst(Value *Ptr, Value *Idx,
358 const std::string &Name = "", Instruction *InsertBefore =0);
359 GetElementPtrInst(Value *Ptr, Value *Idx,
360 const std::string &Name, BasicBlock *InsertAtEnd);
361 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
362 const std::string &Name = "", Instruction *InsertBefore =0);
363 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
364 const std::string &Name, BasicBlock *InsertAtEnd);
365 ~GetElementPtrInst();
367 virtual GetElementPtrInst *clone() const;
369 // getType - Overload to return most specific pointer type...
370 inline const PointerType *getType() const {
371 return reinterpret_cast<const PointerType*>(Instruction::getType());
374 /// getIndexedType - Returns the type of the element that would be loaded with
375 /// a load instruction with the specified parameters.
377 /// A null type is returned if the indices are invalid for the specified
380 static const Type *getIndexedType(const Type *Ptr,
381 Value* const *Idx, unsigned NumIdx,
382 bool AllowStructLeaf = false);
384 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
385 bool AllowStructLeaf = false);
386 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
388 inline op_iterator idx_begin() { return op_begin()+1; }
389 inline const_op_iterator idx_begin() const { return op_begin()+1; }
390 inline op_iterator idx_end() { return op_end(); }
391 inline const_op_iterator idx_end() const { return op_end(); }
393 Value *getPointerOperand() {
394 return getOperand(0);
396 const Value *getPointerOperand() const {
397 return getOperand(0);
399 static unsigned getPointerOperandIndex() {
400 return 0U; // get index for modifying correct operand
403 inline unsigned getNumIndices() const { // Note: always non-negative
404 return getNumOperands() - 1;
407 inline bool hasIndices() const {
408 return getNumOperands() > 1;
411 // Methods for support type inquiry through isa, cast, and dyn_cast:
412 static inline bool classof(const GetElementPtrInst *) { return true; }
413 static inline bool classof(const Instruction *I) {
414 return (I->getOpcode() == Instruction::GetElementPtr);
416 static inline bool classof(const Value *V) {
417 return isa<Instruction>(V) && classof(cast<Instruction>(V));
421 //===----------------------------------------------------------------------===//
423 //===----------------------------------------------------------------------===//
425 /// This instruction compares its operands according to the predicate given
426 /// to the constructor. It only operates on integers, pointers, or packed
427 /// vectors of integrals. The two operands must be the same type.
428 /// @brief Represent an integer comparison operator.
429 class ICmpInst: public CmpInst {
431 /// This enumeration lists the possible predicates for the ICmpInst. The
432 /// values in the range 0-31 are reserved for FCmpInst while values in the
433 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
434 /// predicate values are not overlapping between the classes.
436 ICMP_EQ = 32, ///< equal
437 ICMP_NE = 33, ///< not equal
438 ICMP_UGT = 34, ///< unsigned greater than
439 ICMP_UGE = 35, ///< unsigned greater or equal
440 ICMP_ULT = 36, ///< unsigned less than
441 ICMP_ULE = 37, ///< unsigned less or equal
442 ICMP_SGT = 38, ///< signed greater than
443 ICMP_SGE = 39, ///< signed greater or equal
444 ICMP_SLT = 40, ///< signed less than
445 ICMP_SLE = 41, ///< signed less or equal
446 FIRST_ICMP_PREDICATE = ICMP_EQ,
447 LAST_ICMP_PREDICATE = ICMP_SLE,
448 BAD_ICMP_PREDICATE = ICMP_SLE + 1
451 /// @brief Constructor with insert-before-instruction semantics.
453 Predicate pred, ///< The predicate to use for the comparison
454 Value *LHS, ///< The left-hand-side of the expression
455 Value *RHS, ///< The right-hand-side of the expression
456 const std::string &Name = "", ///< Name of the instruction
457 Instruction *InsertBefore = 0 ///< Where to insert
458 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
461 /// @brief Constructor with insert-at-block-end semantics.
463 Predicate pred, ///< The predicate to use for the comparison
464 Value *LHS, ///< The left-hand-side of the expression
465 Value *RHS, ///< The right-hand-side of the expression
466 const std::string &Name, ///< Name of the instruction
467 BasicBlock *InsertAtEnd ///< Block to insert into.
468 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
471 /// @brief Return the predicate for this instruction.
472 Predicate getPredicate() const { return Predicate(SubclassData); }
474 /// @brief Set the predicate for this instruction to the specified value.
475 void setPredicate(Predicate P) { SubclassData = P; }
477 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
478 /// @returns the inverse predicate for the instruction's current predicate.
479 /// @brief Return the inverse of the instruction's predicate.
480 Predicate getInversePredicate() const {
481 return getInversePredicate(getPredicate());
484 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
485 /// @returns the inverse predicate for predicate provided in \p pred.
486 /// @brief Return the inverse of a given predicate
487 static Predicate getInversePredicate(Predicate pred);
489 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
490 /// @returns the predicate that would be the result of exchanging the two
491 /// operands of the ICmpInst instruction without changing the result
493 /// @brief Return the predicate as if the operands were swapped
494 Predicate getSwappedPredicate() const {
495 return getSwappedPredicate(getPredicate());
498 /// This is a static version that you can use without an instruction
500 /// @brief Return the predicate as if the operands were swapped.
501 static Predicate getSwappedPredicate(Predicate pred);
503 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
504 /// @returns the predicate that would be the result if the operand were
505 /// regarded as signed.
506 /// @brief Return the signed version of the predicate
507 Predicate getSignedPredicate() const {
508 return getSignedPredicate(getPredicate());
511 /// This is a static version that you can use without an instruction.
512 /// @brief Return the signed version of the predicate.
513 static Predicate getSignedPredicate(Predicate pred);
515 /// This also tests for commutativity. If isEquality() returns true then
516 /// the predicate is also commutative.
517 /// @returns true if the predicate of this instruction is EQ or NE.
518 /// @brief Determine if this is an equality predicate.
519 bool isEquality() const {
520 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
523 /// @returns true if the predicate of this ICmpInst is commutative
524 /// @brief Determine if this relation is commutative.
525 bool isCommutative() const { return isEquality(); }
527 /// @returns true if the predicate is relational (not EQ or NE).
528 /// @brief Determine if this a relational predicate.
529 bool isRelational() const {
530 return !isEquality();
533 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
534 /// @brief Determine if this instruction's predicate is signed.
535 bool isSignedPredicate() { return isSignedPredicate(getPredicate()); }
537 /// @returns true if the predicate provided is signed, false otherwise
538 /// @brief Determine if the predicate is signed.
539 static bool isSignedPredicate(Predicate pred);
541 /// Initialize a set of values that all satisfy the predicate with C.
542 /// @brief Make a ConstantRange for a relation with a constant value.
543 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
545 /// Exchange the two operands to this instruction in such a way that it does
546 /// not modify the semantics of the instruction. The predicate value may be
547 /// changed to retain the same result if the predicate is order dependent
549 /// @brief Swap operands and adjust predicate.
550 void swapOperands() {
551 SubclassData = getSwappedPredicate();
552 std::swap(Ops[0], Ops[1]);
555 // Methods for support type inquiry through isa, cast, and dyn_cast:
556 static inline bool classof(const ICmpInst *) { return true; }
557 static inline bool classof(const Instruction *I) {
558 return I->getOpcode() == Instruction::ICmp;
560 static inline bool classof(const Value *V) {
561 return isa<Instruction>(V) && classof(cast<Instruction>(V));
565 //===----------------------------------------------------------------------===//
567 //===----------------------------------------------------------------------===//
569 /// This instruction compares its operands according to the predicate given
570 /// to the constructor. It only operates on floating point values or packed
571 /// vectors of floating point values. The operands must be identical types.
572 /// @brief Represents a floating point comparison operator.
573 class FCmpInst: public CmpInst {
575 /// This enumeration lists the possible predicates for the FCmpInst. Values
576 /// in the range 0-31 are reserved for FCmpInst.
578 // Opcode U L G E Intuitive operation
579 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
580 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
581 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
582 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
583 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
584 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
585 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
586 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
587 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
588 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
589 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
590 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
591 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
592 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
593 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
594 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
595 FIRST_FCMP_PREDICATE = FCMP_FALSE,
596 LAST_FCMP_PREDICATE = FCMP_TRUE,
597 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
600 /// @brief Constructor with insert-before-instruction semantics.
602 Predicate pred, ///< The predicate to use for the comparison
603 Value *LHS, ///< The left-hand-side of the expression
604 Value *RHS, ///< The right-hand-side of the expression
605 const std::string &Name = "", ///< Name of the instruction
606 Instruction *InsertBefore = 0 ///< Where to insert
607 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
610 /// @brief Constructor with insert-at-block-end semantics.
612 Predicate pred, ///< The predicate to use for the comparison
613 Value *LHS, ///< The left-hand-side of the expression
614 Value *RHS, ///< The right-hand-side of the expression
615 const std::string &Name, ///< Name of the instruction
616 BasicBlock *InsertAtEnd ///< Block to insert into.
617 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
620 /// @brief Return the predicate for this instruction.
621 Predicate getPredicate() const { return Predicate(SubclassData); }
623 /// @brief Set the predicate for this instruction to the specified value.
624 void setPredicate(Predicate P) { SubclassData = P; }
626 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
627 /// @returns the inverse predicate for the instructions current predicate.
628 /// @brief Return the inverse of the predicate
629 Predicate getInversePredicate() const {
630 return getInversePredicate(getPredicate());
633 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
634 /// @returns the inverse predicate for \p pred.
635 /// @brief Return the inverse of a given predicate
636 static Predicate getInversePredicate(Predicate pred);
638 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
639 /// @returns the predicate that would be the result of exchanging the two
640 /// operands of the ICmpInst instruction without changing the result
642 /// @brief Return the predicate as if the operands were swapped
643 Predicate getSwappedPredicate() const {
644 return getSwappedPredicate(getPredicate());
647 /// This is a static version that you can use without an instruction
649 /// @brief Return the predicate as if the operands were swapped.
650 static Predicate getSwappedPredicate(Predicate Opcode);
652 /// This also tests for commutativity. If isEquality() returns true then
653 /// the predicate is also commutative. Only the equality predicates are
655 /// @returns true if the predicate of this instruction is EQ or NE.
656 /// @brief Determine if this is an equality predicate.
657 bool isEquality() const {
658 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
659 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
661 bool isCommutative() const { return isEquality(); }
663 /// @returns true if the predicate is relational (not EQ or NE).
664 /// @brief Determine if this a relational predicate.
665 bool isRelational() const { return !isEquality(); }
667 /// Exchange the two operands to this instruction in such a way that it does
668 /// not modify the semantics of the instruction. The predicate value may be
669 /// changed to retain the same result if the predicate is order dependent
671 /// @brief Swap operands and adjust predicate.
672 void swapOperands() {
673 SubclassData = getSwappedPredicate();
674 std::swap(Ops[0], Ops[1]);
677 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
678 static inline bool classof(const FCmpInst *) { return true; }
679 static inline bool classof(const Instruction *I) {
680 return I->getOpcode() == Instruction::FCmp;
682 static inline bool classof(const Value *V) {
683 return isa<Instruction>(V) && classof(cast<Instruction>(V));
687 //===----------------------------------------------------------------------===//
689 //===----------------------------------------------------------------------===//
691 /// CallInst - This class represents a function call, abstracting a target
692 /// machine's calling convention. This class uses low bit of the SubClassData
693 /// field to indicate whether or not this is a tail call. The rest of the bits
694 /// hold the calling convention of the call.
696 class CallInst : public Instruction {
697 CallInst(const CallInst &CI);
698 void init(Value *Func, Value* const *Params, unsigned NumParams);
699 void init(Value *Func, Value *Actual1, Value *Actual2);
700 void init(Value *Func, Value *Actual);
701 void init(Value *Func);
704 CallInst(Value *F, Value* const *Args, unsigned NumArgs,
705 const std::string &Name = "", Instruction *InsertBefore = 0);
706 CallInst(Value *F, Value *const *Args, unsigned NumArgs,
707 const std::string &Name, BasicBlock *InsertAtEnd);
709 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
710 // actuals, respectively.
711 CallInst(Value *F, Value *Actual1, Value *Actual2,
712 const std::string& Name = "", Instruction *InsertBefore = 0);
713 CallInst(Value *F, Value *Actual1, Value *Actual2,
714 const std::string& Name, BasicBlock *InsertAtEnd);
715 CallInst(Value *F, Value *Actual, const std::string& Name = "",
716 Instruction *InsertBefore = 0);
717 CallInst(Value *F, Value *Actual, const std::string& Name,
718 BasicBlock *InsertAtEnd);
719 explicit CallInst(Value *F, const std::string &Name = "",
720 Instruction *InsertBefore = 0);
721 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
724 virtual CallInst *clone() const;
726 bool isTailCall() const { return SubclassData & 1; }
727 void setTailCall(bool isTailCall = true) {
728 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
731 /// getCallingConv/setCallingConv - Get or set the calling convention of this
733 unsigned getCallingConv() const { return SubclassData >> 1; }
734 void setCallingConv(unsigned CC) {
735 SubclassData = (SubclassData & 1) | (CC << 1);
738 /// getCalledFunction - Return the function being called by this instruction
739 /// if it is a direct call. If it is a call through a function pointer,
741 Function *getCalledFunction() const {
742 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
745 /// getCalledValue - Get a pointer to the function that is invoked by this
747 inline const Value *getCalledValue() const { return getOperand(0); }
748 inline Value *getCalledValue() { return getOperand(0); }
750 // Methods for support type inquiry through isa, cast, and dyn_cast:
751 static inline bool classof(const CallInst *) { return true; }
752 static inline bool classof(const Instruction *I) {
753 return I->getOpcode() == Instruction::Call;
755 static inline bool classof(const Value *V) {
756 return isa<Instruction>(V) && classof(cast<Instruction>(V));
760 //===----------------------------------------------------------------------===//
762 //===----------------------------------------------------------------------===//
764 /// SelectInst - This class represents the LLVM 'select' instruction.
766 class SelectInst : public Instruction {
769 void init(Value *C, Value *S1, Value *S2) {
770 Ops[0].init(C, this);
771 Ops[1].init(S1, this);
772 Ops[2].init(S2, this);
775 SelectInst(const SelectInst &SI)
776 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
777 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
780 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
781 Instruction *InsertBefore = 0)
782 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
786 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
787 BasicBlock *InsertAtEnd)
788 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
793 Value *getCondition() const { return Ops[0]; }
794 Value *getTrueValue() const { return Ops[1]; }
795 Value *getFalseValue() const { return Ops[2]; }
797 /// Transparently provide more efficient getOperand methods.
798 Value *getOperand(unsigned i) const {
799 assert(i < 3 && "getOperand() out of range!");
802 void setOperand(unsigned i, Value *Val) {
803 assert(i < 3 && "setOperand() out of range!");
806 unsigned getNumOperands() const { return 3; }
808 OtherOps getOpcode() const {
809 return static_cast<OtherOps>(Instruction::getOpcode());
812 virtual SelectInst *clone() const;
814 // Methods for support type inquiry through isa, cast, and dyn_cast:
815 static inline bool classof(const SelectInst *) { return true; }
816 static inline bool classof(const Instruction *I) {
817 return I->getOpcode() == Instruction::Select;
819 static inline bool classof(const Value *V) {
820 return isa<Instruction>(V) && classof(cast<Instruction>(V));
824 //===----------------------------------------------------------------------===//
826 //===----------------------------------------------------------------------===//
828 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
829 /// an argument of the specified type given a va_list and increments that list
831 class VAArgInst : public UnaryInstruction {
832 VAArgInst(const VAArgInst &VAA)
833 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
835 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
836 Instruction *InsertBefore = 0)
837 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
840 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
841 BasicBlock *InsertAtEnd)
842 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
846 virtual VAArgInst *clone() const;
848 // Methods for support type inquiry through isa, cast, and dyn_cast:
849 static inline bool classof(const VAArgInst *) { return true; }
850 static inline bool classof(const Instruction *I) {
851 return I->getOpcode() == VAArg;
853 static inline bool classof(const Value *V) {
854 return isa<Instruction>(V) && classof(cast<Instruction>(V));
858 //===----------------------------------------------------------------------===//
859 // ExtractElementInst Class
860 //===----------------------------------------------------------------------===//
862 /// ExtractElementInst - This instruction extracts a single (scalar)
863 /// element from a VectorType value
865 class ExtractElementInst : public Instruction {
867 ExtractElementInst(const ExtractElementInst &EE) :
868 Instruction(EE.getType(), ExtractElement, Ops, 2) {
869 Ops[0].init(EE.Ops[0], this);
870 Ops[1].init(EE.Ops[1], this);
874 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
875 Instruction *InsertBefore = 0);
876 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
877 Instruction *InsertBefore = 0);
878 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
879 BasicBlock *InsertAtEnd);
880 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
881 BasicBlock *InsertAtEnd);
883 /// isValidOperands - Return true if an extractelement instruction can be
884 /// formed with the specified operands.
885 static bool isValidOperands(const Value *Vec, const Value *Idx);
887 virtual ExtractElementInst *clone() const;
889 /// Transparently provide more efficient getOperand methods.
890 Value *getOperand(unsigned i) const {
891 assert(i < 2 && "getOperand() out of range!");
894 void setOperand(unsigned i, Value *Val) {
895 assert(i < 2 && "setOperand() out of range!");
898 unsigned getNumOperands() const { return 2; }
900 // Methods for support type inquiry through isa, cast, and dyn_cast:
901 static inline bool classof(const ExtractElementInst *) { return true; }
902 static inline bool classof(const Instruction *I) {
903 return I->getOpcode() == Instruction::ExtractElement;
905 static inline bool classof(const Value *V) {
906 return isa<Instruction>(V) && classof(cast<Instruction>(V));
910 //===----------------------------------------------------------------------===//
911 // InsertElementInst Class
912 //===----------------------------------------------------------------------===//
914 /// InsertElementInst - This instruction inserts a single (scalar)
915 /// element into a VectorType value
917 class InsertElementInst : public Instruction {
919 InsertElementInst(const InsertElementInst &IE);
921 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
922 const std::string &Name = "",Instruction *InsertBefore = 0);
923 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
924 const std::string &Name = "",Instruction *InsertBefore = 0);
925 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
926 const std::string &Name, BasicBlock *InsertAtEnd);
927 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
928 const std::string &Name, BasicBlock *InsertAtEnd);
930 /// isValidOperands - Return true if an insertelement instruction can be
931 /// formed with the specified operands.
932 static bool isValidOperands(const Value *Vec, const Value *NewElt,
935 virtual InsertElementInst *clone() const;
937 /// getType - Overload to return most specific vector type.
939 inline const VectorType *getType() const {
940 return reinterpret_cast<const VectorType*>(Instruction::getType());
943 /// Transparently provide more efficient getOperand methods.
944 Value *getOperand(unsigned i) const {
945 assert(i < 3 && "getOperand() out of range!");
948 void setOperand(unsigned i, Value *Val) {
949 assert(i < 3 && "setOperand() out of range!");
952 unsigned getNumOperands() const { return 3; }
954 // Methods for support type inquiry through isa, cast, and dyn_cast:
955 static inline bool classof(const InsertElementInst *) { return true; }
956 static inline bool classof(const Instruction *I) {
957 return I->getOpcode() == Instruction::InsertElement;
959 static inline bool classof(const Value *V) {
960 return isa<Instruction>(V) && classof(cast<Instruction>(V));
964 //===----------------------------------------------------------------------===//
965 // ShuffleVectorInst Class
966 //===----------------------------------------------------------------------===//
968 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
971 class ShuffleVectorInst : public Instruction {
973 ShuffleVectorInst(const ShuffleVectorInst &IE);
975 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
976 const std::string &Name = "", Instruction *InsertBefor = 0);
977 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
978 const std::string &Name, BasicBlock *InsertAtEnd);
980 /// isValidOperands - Return true if a shufflevector instruction can be
981 /// formed with the specified operands.
982 static bool isValidOperands(const Value *V1, const Value *V2,
985 virtual ShuffleVectorInst *clone() const;
987 /// getType - Overload to return most specific vector type.
989 inline const VectorType *getType() const {
990 return reinterpret_cast<const VectorType*>(Instruction::getType());
993 /// Transparently provide more efficient getOperand methods.
994 Value *getOperand(unsigned i) const {
995 assert(i < 3 && "getOperand() out of range!");
998 void setOperand(unsigned i, Value *Val) {
999 assert(i < 3 && "setOperand() out of range!");
1002 unsigned getNumOperands() const { return 3; }
1004 // Methods for support type inquiry through isa, cast, and dyn_cast:
1005 static inline bool classof(const ShuffleVectorInst *) { return true; }
1006 static inline bool classof(const Instruction *I) {
1007 return I->getOpcode() == Instruction::ShuffleVector;
1009 static inline bool classof(const Value *V) {
1010 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1015 //===----------------------------------------------------------------------===//
1017 //===----------------------------------------------------------------------===//
1019 // PHINode - The PHINode class is used to represent the magical mystical PHI
1020 // node, that can not exist in nature, but can be synthesized in a computer
1021 // scientist's overactive imagination.
1023 class PHINode : public Instruction {
1024 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1025 /// the number actually in use.
1026 unsigned ReservedSpace;
1027 PHINode(const PHINode &PN);
1029 explicit PHINode(const Type *Ty, const std::string &Name = "",
1030 Instruction *InsertBefore = 0)
1031 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1036 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1037 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1044 /// reserveOperandSpace - This method can be used to avoid repeated
1045 /// reallocation of PHI operand lists by reserving space for the correct
1046 /// number of operands before adding them. Unlike normal vector reserves,
1047 /// this method can also be used to trim the operand space.
1048 void reserveOperandSpace(unsigned NumValues) {
1049 resizeOperands(NumValues*2);
1052 virtual PHINode *clone() const;
1054 /// getNumIncomingValues - Return the number of incoming edges
1056 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1058 /// getIncomingValue - Return incoming value number x
1060 Value *getIncomingValue(unsigned i) const {
1061 assert(i*2 < getNumOperands() && "Invalid value number!");
1062 return getOperand(i*2);
1064 void setIncomingValue(unsigned i, Value *V) {
1065 assert(i*2 < getNumOperands() && "Invalid value number!");
1068 unsigned getOperandNumForIncomingValue(unsigned i) {
1072 /// getIncomingBlock - Return incoming basic block number x
1074 BasicBlock *getIncomingBlock(unsigned i) const {
1075 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1077 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1078 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1080 unsigned getOperandNumForIncomingBlock(unsigned i) {
1084 /// addIncoming - Add an incoming value to the end of the PHI list
1086 void addIncoming(Value *V, BasicBlock *BB) {
1087 assert(getType() == V->getType() &&
1088 "All operands to PHI node must be the same type as the PHI node!");
1089 unsigned OpNo = NumOperands;
1090 if (OpNo+2 > ReservedSpace)
1091 resizeOperands(0); // Get more space!
1092 // Initialize some new operands.
1093 NumOperands = OpNo+2;
1094 OperandList[OpNo].init(V, this);
1095 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1098 /// removeIncomingValue - Remove an incoming value. This is useful if a
1099 /// predecessor basic block is deleted. The value removed is returned.
1101 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1102 /// is true), the PHI node is destroyed and any uses of it are replaced with
1103 /// dummy values. The only time there should be zero incoming values to a PHI
1104 /// node is when the block is dead, so this strategy is sound.
1106 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1108 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1109 int Idx = getBasicBlockIndex(BB);
1110 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1111 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1114 /// getBasicBlockIndex - Return the first index of the specified basic
1115 /// block in the value list for this PHI. Returns -1 if no instance.
1117 int getBasicBlockIndex(const BasicBlock *BB) const {
1118 Use *OL = OperandList;
1119 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1120 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1124 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1125 return getIncomingValue(getBasicBlockIndex(BB));
1128 /// hasConstantValue - If the specified PHI node always merges together the
1129 /// same value, return the value, otherwise return null.
1131 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1133 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1134 static inline bool classof(const PHINode *) { return true; }
1135 static inline bool classof(const Instruction *I) {
1136 return I->getOpcode() == Instruction::PHI;
1138 static inline bool classof(const Value *V) {
1139 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1142 void resizeOperands(unsigned NumOperands);
1145 //===----------------------------------------------------------------------===//
1147 //===----------------------------------------------------------------------===//
1149 //===---------------------------------------------------------------------------
1150 /// ReturnInst - Return a value (possibly void), from a function. Execution
1151 /// does not continue in this function any longer.
1153 class ReturnInst : public TerminatorInst {
1154 Use RetVal; // Return Value: null if 'void'.
1155 ReturnInst(const ReturnInst &RI);
1156 void init(Value *RetVal);
1159 // ReturnInst constructors:
1160 // ReturnInst() - 'ret void' instruction
1161 // ReturnInst( null) - 'ret void' instruction
1162 // ReturnInst(Value* X) - 'ret X' instruction
1163 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1164 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1165 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1166 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1168 // NOTE: If the Value* passed is of type void then the constructor behaves as
1169 // if it was passed NULL.
1170 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1171 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1172 explicit ReturnInst(BasicBlock *InsertAtEnd);
1174 virtual ReturnInst *clone() const;
1176 // Transparently provide more efficient getOperand methods.
1177 Value *getOperand(unsigned i) const {
1178 assert(i < getNumOperands() && "getOperand() out of range!");
1181 void setOperand(unsigned i, Value *Val) {
1182 assert(i < getNumOperands() && "setOperand() out of range!");
1186 Value *getReturnValue() const { return RetVal; }
1188 unsigned getNumSuccessors() const { return 0; }
1190 // Methods for support type inquiry through isa, cast, and dyn_cast:
1191 static inline bool classof(const ReturnInst *) { return true; }
1192 static inline bool classof(const Instruction *I) {
1193 return (I->getOpcode() == Instruction::Ret);
1195 static inline bool classof(const Value *V) {
1196 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1199 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1200 virtual unsigned getNumSuccessorsV() const;
1201 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1204 //===----------------------------------------------------------------------===//
1206 //===----------------------------------------------------------------------===//
1208 //===---------------------------------------------------------------------------
1209 /// BranchInst - Conditional or Unconditional Branch instruction.
1211 class BranchInst : public TerminatorInst {
1212 /// Ops list - Branches are strange. The operands are ordered:
1213 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1214 /// they don't have to check for cond/uncond branchness.
1216 BranchInst(const BranchInst &BI);
1219 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1220 // BranchInst(BB *B) - 'br B'
1221 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1222 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1223 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1224 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1225 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1226 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1227 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1228 Instruction *InsertBefore = 0);
1229 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1230 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1231 BasicBlock *InsertAtEnd);
1233 /// Transparently provide more efficient getOperand methods.
1234 Value *getOperand(unsigned i) const {
1235 assert(i < getNumOperands() && "getOperand() out of range!");
1238 void setOperand(unsigned i, Value *Val) {
1239 assert(i < getNumOperands() && "setOperand() out of range!");
1243 virtual BranchInst *clone() const;
1245 inline bool isUnconditional() const { return getNumOperands() == 1; }
1246 inline bool isConditional() const { return getNumOperands() == 3; }
1248 inline Value *getCondition() const {
1249 assert(isConditional() && "Cannot get condition of an uncond branch!");
1250 return getOperand(2);
1253 void setCondition(Value *V) {
1254 assert(isConditional() && "Cannot set condition of unconditional branch!");
1258 // setUnconditionalDest - Change the current branch to an unconditional branch
1259 // targeting the specified block.
1260 // FIXME: Eliminate this ugly method.
1261 void setUnconditionalDest(BasicBlock *Dest) {
1262 if (isConditional()) { // Convert this to an uncond branch.
1267 setOperand(0, reinterpret_cast<Value*>(Dest));
1270 unsigned getNumSuccessors() const { return 1+isConditional(); }
1272 BasicBlock *getSuccessor(unsigned i) const {
1273 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1274 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1275 cast<BasicBlock>(getOperand(1));
1278 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1279 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1280 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1283 // Methods for support type inquiry through isa, cast, and dyn_cast:
1284 static inline bool classof(const BranchInst *) { return true; }
1285 static inline bool classof(const Instruction *I) {
1286 return (I->getOpcode() == Instruction::Br);
1288 static inline bool classof(const Value *V) {
1289 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1292 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1293 virtual unsigned getNumSuccessorsV() const;
1294 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1297 //===----------------------------------------------------------------------===//
1299 //===----------------------------------------------------------------------===//
1301 //===---------------------------------------------------------------------------
1302 /// SwitchInst - Multiway switch
1304 class SwitchInst : public TerminatorInst {
1305 unsigned ReservedSpace;
1306 // Operand[0] = Value to switch on
1307 // Operand[1] = Default basic block destination
1308 // Operand[2n ] = Value to match
1309 // Operand[2n+1] = BasicBlock to go to on match
1310 SwitchInst(const SwitchInst &RI);
1311 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1312 void resizeOperands(unsigned No);
1314 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1315 /// switch on and a default destination. The number of additional cases can
1316 /// be specified here to make memory allocation more efficient. This
1317 /// constructor can also autoinsert before another instruction.
1318 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1319 Instruction *InsertBefore = 0);
1321 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1322 /// switch on and a default destination. The number of additional cases can
1323 /// be specified here to make memory allocation more efficient. This
1324 /// constructor also autoinserts at the end of the specified BasicBlock.
1325 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1326 BasicBlock *InsertAtEnd);
1330 // Accessor Methods for Switch stmt
1331 inline Value *getCondition() const { return getOperand(0); }
1332 void setCondition(Value *V) { setOperand(0, V); }
1334 inline BasicBlock *getDefaultDest() const {
1335 return cast<BasicBlock>(getOperand(1));
1338 /// getNumCases - return the number of 'cases' in this switch instruction.
1339 /// Note that case #0 is always the default case.
1340 unsigned getNumCases() const {
1341 return getNumOperands()/2;
1344 /// getCaseValue - Return the specified case value. Note that case #0, the
1345 /// default destination, does not have a case value.
1346 ConstantInt *getCaseValue(unsigned i) {
1347 assert(i && i < getNumCases() && "Illegal case value to get!");
1348 return getSuccessorValue(i);
1351 /// getCaseValue - Return the specified case value. Note that case #0, the
1352 /// default destination, does not have a case value.
1353 const ConstantInt *getCaseValue(unsigned i) const {
1354 assert(i && i < getNumCases() && "Illegal case value to get!");
1355 return getSuccessorValue(i);
1358 /// findCaseValue - Search all of the case values for the specified constant.
1359 /// If it is explicitly handled, return the case number of it, otherwise
1360 /// return 0 to indicate that it is handled by the default handler.
1361 unsigned findCaseValue(const ConstantInt *C) const {
1362 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1363 if (getCaseValue(i) == C)
1368 /// findCaseDest - Finds the unique case value for a given successor. Returns
1369 /// null if the successor is not found, not unique, or is the default case.
1370 ConstantInt *findCaseDest(BasicBlock *BB) {
1371 if (BB == getDefaultDest()) return NULL;
1373 ConstantInt *CI = NULL;
1374 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1375 if (getSuccessor(i) == BB) {
1376 if (CI) return NULL; // Multiple cases lead to BB.
1377 else CI = getCaseValue(i);
1383 /// addCase - Add an entry to the switch instruction...
1385 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1387 /// removeCase - This method removes the specified successor from the switch
1388 /// instruction. Note that this cannot be used to remove the default
1389 /// destination (successor #0).
1391 void removeCase(unsigned idx);
1393 virtual SwitchInst *clone() const;
1395 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1396 BasicBlock *getSuccessor(unsigned idx) const {
1397 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1398 return cast<BasicBlock>(getOperand(idx*2+1));
1400 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1401 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1402 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1405 // getSuccessorValue - Return the value associated with the specified
1407 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1408 assert(idx < getNumSuccessors() && "Successor # out of range!");
1409 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1412 // Methods for support type inquiry through isa, cast, and dyn_cast:
1413 static inline bool classof(const SwitchInst *) { return true; }
1414 static inline bool classof(const Instruction *I) {
1415 return I->getOpcode() == Instruction::Switch;
1417 static inline bool classof(const Value *V) {
1418 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1421 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1422 virtual unsigned getNumSuccessorsV() const;
1423 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1426 //===----------------------------------------------------------------------===//
1428 //===----------------------------------------------------------------------===//
1430 //===---------------------------------------------------------------------------
1432 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1433 /// calling convention of the call.
1435 class InvokeInst : public TerminatorInst {
1436 InvokeInst(const InvokeInst &BI);
1437 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1438 Value* const *Args, unsigned NumArgs);
1440 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1441 Value* const* Args, unsigned NumArgs, const std::string &Name = "",
1442 Instruction *InsertBefore = 0);
1443 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1444 Value* const* Args, unsigned NumArgs, const std::string &Name,
1445 BasicBlock *InsertAtEnd);
1448 virtual InvokeInst *clone() const;
1450 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1452 unsigned getCallingConv() const { return SubclassData; }
1453 void setCallingConv(unsigned CC) {
1457 /// getCalledFunction - Return the function called, or null if this is an
1458 /// indirect function invocation.
1460 Function *getCalledFunction() const {
1461 return dyn_cast<Function>(getOperand(0));
1464 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1465 inline Value *getCalledValue() const { return getOperand(0); }
1467 // get*Dest - Return the destination basic blocks...
1468 BasicBlock *getNormalDest() const {
1469 return cast<BasicBlock>(getOperand(1));
1471 BasicBlock *getUnwindDest() const {
1472 return cast<BasicBlock>(getOperand(2));
1474 void setNormalDest(BasicBlock *B) {
1475 setOperand(1, reinterpret_cast<Value*>(B));
1478 void setUnwindDest(BasicBlock *B) {
1479 setOperand(2, reinterpret_cast<Value*>(B));
1482 inline BasicBlock *getSuccessor(unsigned i) const {
1483 assert(i < 2 && "Successor # out of range for invoke!");
1484 return i == 0 ? getNormalDest() : getUnwindDest();
1487 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1488 assert(idx < 2 && "Successor # out of range for invoke!");
1489 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1492 unsigned getNumSuccessors() const { return 2; }
1494 // Methods for support type inquiry through isa, cast, and dyn_cast:
1495 static inline bool classof(const InvokeInst *) { return true; }
1496 static inline bool classof(const Instruction *I) {
1497 return (I->getOpcode() == Instruction::Invoke);
1499 static inline bool classof(const Value *V) {
1500 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1503 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1504 virtual unsigned getNumSuccessorsV() const;
1505 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1509 //===----------------------------------------------------------------------===//
1511 //===----------------------------------------------------------------------===//
1513 //===---------------------------------------------------------------------------
1514 /// UnwindInst - Immediately exit the current function, unwinding the stack
1515 /// until an invoke instruction is found.
1517 class UnwindInst : public TerminatorInst {
1519 explicit UnwindInst(Instruction *InsertBefore = 0);
1520 explicit UnwindInst(BasicBlock *InsertAtEnd);
1522 virtual UnwindInst *clone() const;
1524 unsigned getNumSuccessors() const { return 0; }
1526 // Methods for support type inquiry through isa, cast, and dyn_cast:
1527 static inline bool classof(const UnwindInst *) { return true; }
1528 static inline bool classof(const Instruction *I) {
1529 return I->getOpcode() == Instruction::Unwind;
1531 static inline bool classof(const Value *V) {
1532 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1535 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1536 virtual unsigned getNumSuccessorsV() const;
1537 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1540 //===----------------------------------------------------------------------===//
1541 // UnreachableInst Class
1542 //===----------------------------------------------------------------------===//
1544 //===---------------------------------------------------------------------------
1545 /// UnreachableInst - This function has undefined behavior. In particular, the
1546 /// presence of this instruction indicates some higher level knowledge that the
1547 /// end of the block cannot be reached.
1549 class UnreachableInst : public TerminatorInst {
1551 explicit UnreachableInst(Instruction *InsertBefore = 0);
1552 explicit UnreachableInst(BasicBlock *InsertAtEnd);
1554 virtual UnreachableInst *clone() const;
1556 unsigned getNumSuccessors() const { return 0; }
1558 // Methods for support type inquiry through isa, cast, and dyn_cast:
1559 static inline bool classof(const UnreachableInst *) { return true; }
1560 static inline bool classof(const Instruction *I) {
1561 return I->getOpcode() == Instruction::Unreachable;
1563 static inline bool classof(const Value *V) {
1564 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1567 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1568 virtual unsigned getNumSuccessorsV() const;
1569 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1572 //===----------------------------------------------------------------------===//
1574 //===----------------------------------------------------------------------===//
1576 /// @brief This class represents a truncation of integer types.
1577 class TruncInst : public CastInst {
1578 /// Private copy constructor
1579 TruncInst(const TruncInst &CI)
1580 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1583 /// @brief Constructor with insert-before-instruction semantics
1585 Value *S, ///< The value to be truncated
1586 const Type *Ty, ///< The (smaller) type to truncate to
1587 const std::string &Name = "", ///< A name for the new instruction
1588 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1591 /// @brief Constructor with insert-at-end-of-block semantics
1593 Value *S, ///< The value to be truncated
1594 const Type *Ty, ///< The (smaller) type to truncate to
1595 const std::string &Name, ///< A name for the new instruction
1596 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1599 /// @brief Clone an identical TruncInst
1600 virtual CastInst *clone() const;
1602 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1603 static inline bool classof(const TruncInst *) { return true; }
1604 static inline bool classof(const Instruction *I) {
1605 return I->getOpcode() == Trunc;
1607 static inline bool classof(const Value *V) {
1608 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1612 //===----------------------------------------------------------------------===//
1614 //===----------------------------------------------------------------------===//
1616 /// @brief This class represents zero extension of integer types.
1617 class ZExtInst : public CastInst {
1618 /// @brief Private copy constructor
1619 ZExtInst(const ZExtInst &CI)
1620 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1623 /// @brief Constructor with insert-before-instruction semantics
1625 Value *S, ///< The value to be zero extended
1626 const Type *Ty, ///< The type to zero extend to
1627 const std::string &Name = "", ///< A name for the new instruction
1628 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1631 /// @brief Constructor with insert-at-end semantics.
1633 Value *S, ///< The value to be zero extended
1634 const Type *Ty, ///< The type to zero extend to
1635 const std::string &Name, ///< A name for the new instruction
1636 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1639 /// @brief Clone an identical ZExtInst
1640 virtual CastInst *clone() const;
1642 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1643 static inline bool classof(const ZExtInst *) { return true; }
1644 static inline bool classof(const Instruction *I) {
1645 return I->getOpcode() == ZExt;
1647 static inline bool classof(const Value *V) {
1648 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1652 //===----------------------------------------------------------------------===//
1654 //===----------------------------------------------------------------------===//
1656 /// @brief This class represents a sign extension of integer types.
1657 class SExtInst : public CastInst {
1658 /// @brief Private copy constructor
1659 SExtInst(const SExtInst &CI)
1660 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1663 /// @brief Constructor with insert-before-instruction semantics
1665 Value *S, ///< The value to be sign extended
1666 const Type *Ty, ///< The type to sign extend to
1667 const std::string &Name = "", ///< A name for the new instruction
1668 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1671 /// @brief Constructor with insert-at-end-of-block semantics
1673 Value *S, ///< The value to be sign extended
1674 const Type *Ty, ///< The type to sign extend to
1675 const std::string &Name, ///< A name for the new instruction
1676 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1679 /// @brief Clone an identical SExtInst
1680 virtual CastInst *clone() const;
1682 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1683 static inline bool classof(const SExtInst *) { return true; }
1684 static inline bool classof(const Instruction *I) {
1685 return I->getOpcode() == SExt;
1687 static inline bool classof(const Value *V) {
1688 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1692 //===----------------------------------------------------------------------===//
1693 // FPTruncInst Class
1694 //===----------------------------------------------------------------------===//
1696 /// @brief This class represents a truncation of floating point types.
1697 class FPTruncInst : public CastInst {
1698 FPTruncInst(const FPTruncInst &CI)
1699 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1702 /// @brief Constructor with insert-before-instruction semantics
1704 Value *S, ///< The value to be truncated
1705 const Type *Ty, ///< The type to truncate to
1706 const std::string &Name = "", ///< A name for the new instruction
1707 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1710 /// @brief Constructor with insert-before-instruction semantics
1712 Value *S, ///< The value to be truncated
1713 const Type *Ty, ///< The type to truncate to
1714 const std::string &Name, ///< A name for the new instruction
1715 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1718 /// @brief Clone an identical FPTruncInst
1719 virtual CastInst *clone() const;
1721 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1722 static inline bool classof(const FPTruncInst *) { return true; }
1723 static inline bool classof(const Instruction *I) {
1724 return I->getOpcode() == FPTrunc;
1726 static inline bool classof(const Value *V) {
1727 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1731 //===----------------------------------------------------------------------===//
1733 //===----------------------------------------------------------------------===//
1735 /// @brief This class represents an extension of floating point types.
1736 class FPExtInst : public CastInst {
1737 FPExtInst(const FPExtInst &CI)
1738 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1741 /// @brief Constructor with insert-before-instruction semantics
1743 Value *S, ///< The value to be extended
1744 const Type *Ty, ///< The type to extend to
1745 const std::string &Name = "", ///< A name for the new instruction
1746 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1749 /// @brief Constructor with insert-at-end-of-block semantics
1751 Value *S, ///< The value to be extended
1752 const Type *Ty, ///< The type to extend to
1753 const std::string &Name, ///< A name for the new instruction
1754 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1757 /// @brief Clone an identical FPExtInst
1758 virtual CastInst *clone() const;
1760 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1761 static inline bool classof(const FPExtInst *) { return true; }
1762 static inline bool classof(const Instruction *I) {
1763 return I->getOpcode() == FPExt;
1765 static inline bool classof(const Value *V) {
1766 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1770 //===----------------------------------------------------------------------===//
1772 //===----------------------------------------------------------------------===//
1774 /// @brief This class represents a cast unsigned integer to floating point.
1775 class UIToFPInst : public CastInst {
1776 UIToFPInst(const UIToFPInst &CI)
1777 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1780 /// @brief Constructor with insert-before-instruction semantics
1782 Value *S, ///< The value to be converted
1783 const Type *Ty, ///< The type to convert to
1784 const std::string &Name = "", ///< A name for the new instruction
1785 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1788 /// @brief Constructor with insert-at-end-of-block semantics
1790 Value *S, ///< The value to be converted
1791 const Type *Ty, ///< The type to convert to
1792 const std::string &Name, ///< A name for the new instruction
1793 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1796 /// @brief Clone an identical UIToFPInst
1797 virtual CastInst *clone() const;
1799 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1800 static inline bool classof(const UIToFPInst *) { return true; }
1801 static inline bool classof(const Instruction *I) {
1802 return I->getOpcode() == UIToFP;
1804 static inline bool classof(const Value *V) {
1805 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1809 //===----------------------------------------------------------------------===//
1811 //===----------------------------------------------------------------------===//
1813 /// @brief This class represents a cast from signed integer to floating point.
1814 class SIToFPInst : public CastInst {
1815 SIToFPInst(const SIToFPInst &CI)
1816 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1819 /// @brief Constructor with insert-before-instruction semantics
1821 Value *S, ///< The value to be converted
1822 const Type *Ty, ///< The type to convert to
1823 const std::string &Name = "", ///< A name for the new instruction
1824 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1827 /// @brief Constructor with insert-at-end-of-block semantics
1829 Value *S, ///< The value to be converted
1830 const Type *Ty, ///< The type to convert to
1831 const std::string &Name, ///< A name for the new instruction
1832 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1835 /// @brief Clone an identical SIToFPInst
1836 virtual CastInst *clone() const;
1838 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1839 static inline bool classof(const SIToFPInst *) { return true; }
1840 static inline bool classof(const Instruction *I) {
1841 return I->getOpcode() == SIToFP;
1843 static inline bool classof(const Value *V) {
1844 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1848 //===----------------------------------------------------------------------===//
1850 //===----------------------------------------------------------------------===//
1852 /// @brief This class represents a cast from floating point to unsigned integer
1853 class FPToUIInst : public CastInst {
1854 FPToUIInst(const FPToUIInst &CI)
1855 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1858 /// @brief Constructor with insert-before-instruction semantics
1860 Value *S, ///< The value to be converted
1861 const Type *Ty, ///< The type to convert to
1862 const std::string &Name = "", ///< A name for the new instruction
1863 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1866 /// @brief Constructor with insert-at-end-of-block semantics
1868 Value *S, ///< The value to be converted
1869 const Type *Ty, ///< The type to convert to
1870 const std::string &Name, ///< A name for the new instruction
1871 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
1874 /// @brief Clone an identical FPToUIInst
1875 virtual CastInst *clone() const;
1877 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1878 static inline bool classof(const FPToUIInst *) { return true; }
1879 static inline bool classof(const Instruction *I) {
1880 return I->getOpcode() == FPToUI;
1882 static inline bool classof(const Value *V) {
1883 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1887 //===----------------------------------------------------------------------===//
1889 //===----------------------------------------------------------------------===//
1891 /// @brief This class represents a cast from floating point to signed integer.
1892 class FPToSIInst : public CastInst {
1893 FPToSIInst(const FPToSIInst &CI)
1894 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
1897 /// @brief Constructor with insert-before-instruction semantics
1899 Value *S, ///< The value to be converted
1900 const Type *Ty, ///< The type to convert to
1901 const std::string &Name = "", ///< A name for the new instruction
1902 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1905 /// @brief Constructor with insert-at-end-of-block semantics
1907 Value *S, ///< The value to be converted
1908 const Type *Ty, ///< The type to convert to
1909 const std::string &Name, ///< A name for the new instruction
1910 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1913 /// @brief Clone an identical FPToSIInst
1914 virtual CastInst *clone() const;
1916 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1917 static inline bool classof(const FPToSIInst *) { return true; }
1918 static inline bool classof(const Instruction *I) {
1919 return I->getOpcode() == FPToSI;
1921 static inline bool classof(const Value *V) {
1922 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1926 //===----------------------------------------------------------------------===//
1927 // IntToPtrInst Class
1928 //===----------------------------------------------------------------------===//
1930 /// @brief This class represents a cast from an integer to a pointer.
1931 class IntToPtrInst : public CastInst {
1932 IntToPtrInst(const IntToPtrInst &CI)
1933 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
1936 /// @brief Constructor with insert-before-instruction semantics
1938 Value *S, ///< The value to be converted
1939 const Type *Ty, ///< The type to convert to
1940 const std::string &Name = "", ///< A name for the new instruction
1941 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1944 /// @brief Constructor with insert-at-end-of-block semantics
1946 Value *S, ///< The value to be converted
1947 const Type *Ty, ///< The type to convert to
1948 const std::string &Name, ///< A name for the new instruction
1949 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1952 /// @brief Clone an identical IntToPtrInst
1953 virtual CastInst *clone() const;
1955 // Methods for support type inquiry through isa, cast, and dyn_cast:
1956 static inline bool classof(const IntToPtrInst *) { return true; }
1957 static inline bool classof(const Instruction *I) {
1958 return I->getOpcode() == IntToPtr;
1960 static inline bool classof(const Value *V) {
1961 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1965 //===----------------------------------------------------------------------===//
1966 // PtrToIntInst Class
1967 //===----------------------------------------------------------------------===//
1969 /// @brief This class represents a cast from a pointer to an integer
1970 class PtrToIntInst : public CastInst {
1971 PtrToIntInst(const PtrToIntInst &CI)
1972 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
1975 /// @brief Constructor with insert-before-instruction semantics
1977 Value *S, ///< The value to be converted
1978 const Type *Ty, ///< The type to convert to
1979 const std::string &Name = "", ///< A name for the new instruction
1980 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1983 /// @brief Constructor with insert-at-end-of-block semantics
1985 Value *S, ///< The value to be converted
1986 const Type *Ty, ///< The type to convert to
1987 const std::string &Name, ///< A name for the new instruction
1988 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1991 /// @brief Clone an identical PtrToIntInst
1992 virtual CastInst *clone() const;
1994 // Methods for support type inquiry through isa, cast, and dyn_cast:
1995 static inline bool classof(const PtrToIntInst *) { return true; }
1996 static inline bool classof(const Instruction *I) {
1997 return I->getOpcode() == PtrToInt;
1999 static inline bool classof(const Value *V) {
2000 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2004 //===----------------------------------------------------------------------===//
2005 // BitCastInst Class
2006 //===----------------------------------------------------------------------===//
2008 /// @brief This class represents a no-op cast from one type to another.
2009 class BitCastInst : public CastInst {
2010 BitCastInst(const BitCastInst &CI)
2011 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2014 /// @brief Constructor with insert-before-instruction semantics
2016 Value *S, ///< The value to be casted
2017 const Type *Ty, ///< The type to casted to
2018 const std::string &Name = "", ///< A name for the new instruction
2019 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2022 /// @brief Constructor with insert-at-end-of-block semantics
2024 Value *S, ///< The value to be casted
2025 const Type *Ty, ///< The type to casted to
2026 const std::string &Name, ///< A name for the new instruction
2027 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2030 /// @brief Clone an identical BitCastInst
2031 virtual CastInst *clone() const;
2033 // Methods for support type inquiry through isa, cast, and dyn_cast:
2034 static inline bool classof(const BitCastInst *) { return true; }
2035 static inline bool classof(const Instruction *I) {
2036 return I->getOpcode() == BitCast;
2038 static inline bool classof(const Value *V) {
2039 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2043 } // End llvm namespace