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 virtual bool mayWriteToMemory() const { return true; }
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 explicit LoadInst(Value *Ptr, const std::string &Name = "",
226 bool isVolatile = false, Instruction *InsertBefore = 0);
227 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
228 BasicBlock *InsertAtEnd);
230 /// isVolatile - Return true if this is a load from a volatile memory
233 bool isVolatile() const { return SubclassData; }
235 /// setVolatile - Specify whether this is a volatile load or not.
237 void setVolatile(bool V) { SubclassData = V; }
239 virtual LoadInst *clone() const;
241 virtual bool mayWriteToMemory() const { return isVolatile(); }
243 Value *getPointerOperand() { return getOperand(0); }
244 const Value *getPointerOperand() const { return getOperand(0); }
245 static unsigned getPointerOperandIndex() { return 0U; }
247 // Methods for support type inquiry through isa, cast, and dyn_cast:
248 static inline bool classof(const LoadInst *) { return true; }
249 static inline bool classof(const Instruction *I) {
250 return I->getOpcode() == Instruction::Load;
252 static inline bool classof(const Value *V) {
253 return isa<Instruction>(V) && classof(cast<Instruction>(V));
258 //===----------------------------------------------------------------------===//
260 //===----------------------------------------------------------------------===//
262 /// StoreInst - an instruction for storing to memory
264 class StoreInst : public Instruction {
266 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
267 Ops[0].init(SI.Ops[0], this);
268 Ops[1].init(SI.Ops[1], this);
269 setVolatile(SI.isVolatile());
276 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
277 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
278 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
279 Instruction *InsertBefore = 0);
280 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
283 /// isVolatile - Return true if this is a load from a volatile memory
286 bool isVolatile() const { return SubclassData; }
288 /// setVolatile - Specify whether this is a volatile load or not.
290 void setVolatile(bool V) { SubclassData = V; }
292 /// Transparently provide more efficient getOperand methods.
293 Value *getOperand(unsigned i) const {
294 assert(i < 2 && "getOperand() out of range!");
297 void setOperand(unsigned i, Value *Val) {
298 assert(i < 2 && "setOperand() out of range!");
301 unsigned getNumOperands() const { return 2; }
304 virtual StoreInst *clone() const;
306 virtual bool mayWriteToMemory() const { return true; }
308 Value *getPointerOperand() { return getOperand(1); }
309 const Value *getPointerOperand() const { return getOperand(1); }
310 static unsigned getPointerOperandIndex() { return 1U; }
312 // Methods for support type inquiry through isa, cast, and dyn_cast:
313 static inline bool classof(const StoreInst *) { return true; }
314 static inline bool classof(const Instruction *I) {
315 return I->getOpcode() == Instruction::Store;
317 static inline bool classof(const Value *V) {
318 return isa<Instruction>(V) && classof(cast<Instruction>(V));
323 //===----------------------------------------------------------------------===//
324 // GetElementPtrInst Class
325 //===----------------------------------------------------------------------===//
327 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
328 /// access elements of arrays and structs
330 class GetElementPtrInst : public Instruction {
331 GetElementPtrInst(const GetElementPtrInst &GEPI)
332 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
333 0, GEPI.getNumOperands()) {
334 Use *OL = OperandList = new Use[NumOperands];
335 Use *GEPIOL = GEPI.OperandList;
336 for (unsigned i = 0, E = NumOperands; i != E; ++i)
337 OL[i].init(GEPIOL[i], this);
339 void init(Value *Ptr, const std::vector<Value*> &Idx);
340 void init(Value *Ptr, Value *Idx0, Value *Idx1);
341 void init(Value *Ptr, Value *Idx);
343 /// Constructors - Create a getelementptr instruction with a base pointer an
344 /// list of indices. The first ctor can optionally insert before an existing
345 /// instruction, the second appends the new instruction to the specified
347 GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
348 const std::string &Name = "", Instruction *InsertBefore =0);
349 GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
350 const std::string &Name, BasicBlock *InsertAtEnd);
352 /// Constructors - These two constructors are convenience methods because one
353 /// and two index getelementptr instructions are so common.
354 GetElementPtrInst(Value *Ptr, Value *Idx,
355 const std::string &Name = "", Instruction *InsertBefore =0);
356 GetElementPtrInst(Value *Ptr, Value *Idx,
357 const std::string &Name, BasicBlock *InsertAtEnd);
358 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
359 const std::string &Name = "", Instruction *InsertBefore =0);
360 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
361 const std::string &Name, BasicBlock *InsertAtEnd);
362 ~GetElementPtrInst();
364 virtual GetElementPtrInst *clone() const;
366 // getType - Overload to return most specific pointer type...
367 inline const PointerType *getType() const {
368 return reinterpret_cast<const PointerType*>(Instruction::getType());
371 /// getIndexedType - Returns the type of the element that would be loaded with
372 /// a load instruction with the specified parameters.
374 /// A null type is returned if the indices are invalid for the specified
377 static const Type *getIndexedType(const Type *Ptr,
378 const std::vector<Value*> &Indices,
379 bool AllowStructLeaf = false);
380 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
381 bool AllowStructLeaf = false);
382 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
384 inline op_iterator idx_begin() { return op_begin()+1; }
385 inline const_op_iterator idx_begin() const { return op_begin()+1; }
386 inline op_iterator idx_end() { return op_end(); }
387 inline const_op_iterator idx_end() const { return op_end(); }
389 Value *getPointerOperand() {
390 return getOperand(0);
392 const Value *getPointerOperand() const {
393 return getOperand(0);
395 static unsigned getPointerOperandIndex() {
396 return 0U; // get index for modifying correct operand
399 inline unsigned getNumIndices() const { // Note: always non-negative
400 return getNumOperands() - 1;
403 inline bool hasIndices() const {
404 return getNumOperands() > 1;
407 // Methods for support type inquiry through isa, cast, and dyn_cast:
408 static inline bool classof(const GetElementPtrInst *) { return true; }
409 static inline bool classof(const Instruction *I) {
410 return (I->getOpcode() == Instruction::GetElementPtr);
412 static inline bool classof(const Value *V) {
413 return isa<Instruction>(V) && classof(cast<Instruction>(V));
417 //===----------------------------------------------------------------------===//
419 //===----------------------------------------------------------------------===//
421 /// This instruction compares its operands according to the predicate given
422 /// to the constructor. It only operates on integers, pointers, or packed
423 /// vectors of integrals. The two operands must be the same type.
424 /// @brief Represent an integer comparison operator.
425 class ICmpInst: public CmpInst {
427 /// This enumeration lists the possible predicates for the ICmpInst. The
428 /// values in the range 0-31 are reserved for FCmpInst while values in the
429 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
430 /// predicate values are not overlapping between the classes.
432 ICMP_EQ = 32, ///< equal
433 ICMP_NE = 33, ///< not equal
434 ICMP_UGT = 34, ///< unsigned greater than
435 ICMP_UGE = 35, ///< unsigned greater or equal
436 ICMP_ULT = 36, ///< unsigned less than
437 ICMP_ULE = 37, ///< unsigned less or equal
438 ICMP_SGT = 38, ///< signed greater than
439 ICMP_SGE = 39, ///< signed greater or equal
440 ICMP_SLT = 40, ///< signed less than
441 ICMP_SLE = 41, ///< signed less or equal
442 FIRST_ICMP_PREDICATE = ICMP_EQ,
443 LAST_ICMP_PREDICATE = ICMP_SLE,
444 BAD_ICMP_PREDICATE = ICMP_SLE + 1
447 /// @brief Constructor with insert-before-instruction semantics.
449 Predicate pred, ///< The predicate to use for the comparison
450 Value *LHS, ///< The left-hand-side of the expression
451 Value *RHS, ///< The right-hand-side of the expression
452 const std::string &Name = "", ///< Name of the instruction
453 Instruction *InsertBefore = 0 ///< Where to insert
454 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
457 /// @brief Constructor with insert-at-block-end semantics.
459 Predicate pred, ///< The predicate to use for the comparison
460 Value *LHS, ///< The left-hand-side of the expression
461 Value *RHS, ///< The right-hand-side of the expression
462 const std::string &Name, ///< Name of the instruction
463 BasicBlock *InsertAtEnd ///< Block to insert into.
464 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
467 /// @brief Return the predicate for this instruction.
468 Predicate getPredicate() const { return Predicate(SubclassData); }
470 /// @brief Set the predicate for this instruction to the specified value.
471 void setPredicate(Predicate P) { SubclassData = P; }
473 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
474 /// @returns the inverse predicate for the instruction's current predicate.
475 /// @brief Return the inverse of the instruction's predicate.
476 Predicate getInversePredicate() const {
477 return getInversePredicate(getPredicate());
480 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
481 /// @returns the inverse predicate for predicate provided in \p pred.
482 /// @brief Return the inverse of a given predicate
483 static Predicate getInversePredicate(Predicate pred);
485 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
486 /// @returns the predicate that would be the result of exchanging the two
487 /// operands of the ICmpInst instruction without changing the result
489 /// @brief Return the predicate as if the operands were swapped
490 Predicate getSwappedPredicate() const {
491 return getSwappedPredicate(getPredicate());
494 /// This is a static version that you can use without an instruction
496 /// @brief Return the predicate as if the operands were swapped.
497 static Predicate getSwappedPredicate(Predicate pred);
499 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
500 /// @returns the predicate that would be the result if the operand were
501 /// regarded as signed.
502 /// @brief Return the signed version of the predicate
503 Predicate getSignedPredicate() const {
504 return getSignedPredicate(getPredicate());
507 /// This is a static version that you can use without an instruction.
508 /// @brief Return the signed version of the predicate.
509 static Predicate getSignedPredicate(Predicate pred);
511 /// This also tests for commutativity. If isEquality() returns true then
512 /// the predicate is also commutative.
513 /// @returns true if the predicate of this instruction is EQ or NE.
514 /// @brief Determine if this is an equality predicate.
515 bool isEquality() const {
516 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
519 /// @returns true if the predicate of this ICmpInst is commutative
520 /// @brief Determine if this relation is commutative.
521 bool isCommutative() const { return isEquality(); }
523 /// @returns true if the predicate is relational (not EQ or NE).
524 /// @brief Determine if this a relational predicate.
525 bool isRelational() const {
526 return !isEquality();
529 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
530 /// @brief Determine if this instruction's predicate is signed.
531 bool isSignedPredicate() { return isSignedPredicate(getPredicate()); }
533 /// @returns true if the predicate provided is signed, false otherwise
534 /// @brief Determine if the predicate is signed.
535 static bool isSignedPredicate(Predicate pred);
537 /// Exchange the two operands to this instruction in such a way that it does
538 /// not modify the semantics of the instruction. The predicate value may be
539 /// changed to retain the same result if the predicate is order dependent
541 /// @brief Swap operands and adjust predicate.
542 void swapOperands() {
543 SubclassData = getSwappedPredicate();
544 std::swap(Ops[0], Ops[1]);
547 // Methods for support type inquiry through isa, cast, and dyn_cast:
548 static inline bool classof(const ICmpInst *) { return true; }
549 static inline bool classof(const Instruction *I) {
550 return I->getOpcode() == Instruction::ICmp;
552 static inline bool classof(const Value *V) {
553 return isa<Instruction>(V) && classof(cast<Instruction>(V));
557 //===----------------------------------------------------------------------===//
559 //===----------------------------------------------------------------------===//
561 /// This instruction compares its operands according to the predicate given
562 /// to the constructor. It only operates on floating point values or packed
563 /// vectors of floating point values. The operands must be identical types.
564 /// @brief Represents a floating point comparison operator.
565 class FCmpInst: public CmpInst {
567 /// This enumeration lists the possible predicates for the FCmpInst. Values
568 /// in the range 0-31 are reserved for FCmpInst.
570 // Opcode U L G E Intuitive operation
571 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
572 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
573 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
574 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
575 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
576 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
577 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
578 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
579 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
580 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
581 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
582 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
583 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
584 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
585 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
586 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
587 FIRST_FCMP_PREDICATE = FCMP_FALSE,
588 LAST_FCMP_PREDICATE = FCMP_TRUE,
589 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
592 /// @brief Constructor with insert-before-instruction semantics.
594 Predicate pred, ///< The predicate to use for the comparison
595 Value *LHS, ///< The left-hand-side of the expression
596 Value *RHS, ///< The right-hand-side of the expression
597 const std::string &Name = "", ///< Name of the instruction
598 Instruction *InsertBefore = 0 ///< Where to insert
599 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
602 /// @brief Constructor with insert-at-block-end semantics.
604 Predicate pred, ///< The predicate to use for the comparison
605 Value *LHS, ///< The left-hand-side of the expression
606 Value *RHS, ///< The right-hand-side of the expression
607 const std::string &Name, ///< Name of the instruction
608 BasicBlock *InsertAtEnd ///< Block to insert into.
609 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
612 /// @brief Return the predicate for this instruction.
613 Predicate getPredicate() const { return Predicate(SubclassData); }
615 /// @brief Set the predicate for this instruction to the specified value.
616 void setPredicate(Predicate P) { SubclassData = P; }
618 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
619 /// @returns the inverse predicate for the instructions current predicate.
620 /// @brief Return the inverse of the predicate
621 Predicate getInversePredicate() const {
622 return getInversePredicate(getPredicate());
625 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
626 /// @returns the inverse predicate for \p pred.
627 /// @brief Return the inverse of a given predicate
628 static Predicate getInversePredicate(Predicate pred);
630 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
631 /// @returns the predicate that would be the result of exchanging the two
632 /// operands of the ICmpInst instruction without changing the result
634 /// @brief Return the predicate as if the operands were swapped
635 Predicate getSwappedPredicate() const {
636 return getSwappedPredicate(getPredicate());
639 /// This is a static version that you can use without an instruction
641 /// @brief Return the predicate as if the operands were swapped.
642 static Predicate getSwappedPredicate(Predicate Opcode);
644 /// This also tests for commutativity. If isEquality() returns true then
645 /// the predicate is also commutative. Only the equality predicates are
647 /// @returns true if the predicate of this instruction is EQ or NE.
648 /// @brief Determine if this is an equality predicate.
649 bool isEquality() const {
650 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
651 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
653 bool isCommutative() const { return isEquality(); }
655 /// @returns true if the predicate is relational (not EQ or NE).
656 /// @brief Determine if this a relational predicate.
657 bool isRelational() const { return !isEquality(); }
659 /// Exchange the two operands to this instruction in such a way that it does
660 /// not modify the semantics of the instruction. The predicate value may be
661 /// changed to retain the same result if the predicate is order dependent
663 /// @brief Swap operands and adjust predicate.
664 void swapOperands() {
665 SubclassData = getSwappedPredicate();
666 std::swap(Ops[0], Ops[1]);
669 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
670 static inline bool classof(const FCmpInst *) { return true; }
671 static inline bool classof(const Instruction *I) {
672 return I->getOpcode() == Instruction::FCmp;
674 static inline bool classof(const Value *V) {
675 return isa<Instruction>(V) && classof(cast<Instruction>(V));
679 //===----------------------------------------------------------------------===//
681 //===----------------------------------------------------------------------===//
683 /// CallInst - This class represents a function call, abstracting a target
684 /// machine's calling convention. This class uses low bit of the SubClassData
685 /// field to indicate whether or not this is a tail call. The rest of the bits
686 /// hold the calling convention of the call.
688 class CallInst : public Instruction {
689 CallInst(const CallInst &CI);
690 void init(Value *Func, const std::vector<Value*> &Params);
691 void init(Value *Func, Value *Actual1, Value *Actual2);
692 void init(Value *Func, Value *Actual);
693 void init(Value *Func);
696 CallInst(Value *F, const std::vector<Value*> &Par,
697 const std::string &Name = "", Instruction *InsertBefore = 0);
698 CallInst(Value *F, const std::vector<Value*> &Par,
699 const std::string &Name, BasicBlock *InsertAtEnd);
701 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
702 // actuals, respectively.
703 CallInst(Value *F, Value *Actual1, Value *Actual2,
704 const std::string& Name = "", Instruction *InsertBefore = 0);
705 CallInst(Value *F, Value *Actual1, Value *Actual2,
706 const std::string& Name, BasicBlock *InsertAtEnd);
707 CallInst(Value *F, Value *Actual, const std::string& Name = "",
708 Instruction *InsertBefore = 0);
709 CallInst(Value *F, Value *Actual, const std::string& Name,
710 BasicBlock *InsertAtEnd);
711 explicit CallInst(Value *F, const std::string &Name = "",
712 Instruction *InsertBefore = 0);
713 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
716 virtual CallInst *clone() const;
717 bool mayWriteToMemory() const { return true; }
719 bool isTailCall() const { return SubclassData & 1; }
720 void setTailCall(bool isTailCall = true) {
721 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
724 /// getCallingConv/setCallingConv - Get or set the calling convention of this
726 unsigned getCallingConv() const { return SubclassData >> 1; }
727 void setCallingConv(unsigned CC) {
728 SubclassData = (SubclassData & 1) | (CC << 1);
731 /// getCalledFunction - Return the function being called by this instruction
732 /// if it is a direct call. If it is a call through a function pointer,
734 Function *getCalledFunction() const {
735 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
738 /// getCalledValue - Get a pointer to the function that is invoked by this
740 inline const Value *getCalledValue() const { return getOperand(0); }
741 inline Value *getCalledValue() { return getOperand(0); }
743 // Methods for support type inquiry through isa, cast, and dyn_cast:
744 static inline bool classof(const CallInst *) { return true; }
745 static inline bool classof(const Instruction *I) {
746 return I->getOpcode() == Instruction::Call;
748 static inline bool classof(const Value *V) {
749 return isa<Instruction>(V) && classof(cast<Instruction>(V));
754 //===----------------------------------------------------------------------===//
756 //===----------------------------------------------------------------------===//
758 /// ShiftInst - This class represents left and right shift instructions.
760 class ShiftInst : public Instruction {
762 ShiftInst(const ShiftInst &SI)
763 : Instruction(SI.getType(), SI.getOpcode(), Ops, 2) {
764 Ops[0].init(SI.Ops[0], this);
765 Ops[1].init(SI.Ops[1], this);
767 void init(OtherOps Opcode, Value *S, Value *SA) {
768 assert((Opcode == Shl || Opcode == LShr || Opcode == AShr) &&
769 "ShiftInst Opcode invalid!");
770 Ops[0].init(S, this);
771 Ops[1].init(SA, this);
775 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
776 Instruction *InsertBefore = 0)
777 : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertBefore) {
780 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
781 BasicBlock *InsertAtEnd)
782 : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertAtEnd) {
786 OtherOps getOpcode() const {
787 return static_cast<OtherOps>(Instruction::getOpcode());
790 /// Transparently provide more efficient getOperand methods.
791 Value *getOperand(unsigned i) const {
792 assert(i < 2 && "getOperand() out of range!");
795 void setOperand(unsigned i, Value *Val) {
796 assert(i < 2 && "setOperand() out of range!");
799 unsigned getNumOperands() const { return 2; }
801 /// isLogicalShift - Return true if this is a logical shift left or a logical
803 bool isLogicalShift() const {
804 unsigned opcode = getOpcode();
805 return opcode == Instruction::Shl || opcode == Instruction::LShr;
809 /// isArithmeticShift - Return true if this is a sign-extending shift right
811 bool isArithmeticShift() const {
812 return !isLogicalShift();
816 virtual ShiftInst *clone() const;
818 // Methods for support type inquiry through isa, cast, and dyn_cast:
819 static inline bool classof(const ShiftInst *) { return true; }
820 static inline bool classof(const Instruction *I) {
821 return (I->getOpcode() == Instruction::LShr) |
822 (I->getOpcode() == Instruction::AShr) |
823 (I->getOpcode() == Instruction::Shl);
825 static inline bool classof(const Value *V) {
826 return isa<Instruction>(V) && classof(cast<Instruction>(V));
830 //===----------------------------------------------------------------------===//
832 //===----------------------------------------------------------------------===//
834 /// SelectInst - This class represents the LLVM 'select' instruction.
836 class SelectInst : public Instruction {
839 void init(Value *C, Value *S1, Value *S2) {
840 Ops[0].init(C, this);
841 Ops[1].init(S1, this);
842 Ops[2].init(S2, this);
845 SelectInst(const SelectInst &SI)
846 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
847 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
850 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
851 Instruction *InsertBefore = 0)
852 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
853 Name, InsertBefore) {
856 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
857 BasicBlock *InsertAtEnd)
858 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
863 Value *getCondition() const { return Ops[0]; }
864 Value *getTrueValue() const { return Ops[1]; }
865 Value *getFalseValue() const { return Ops[2]; }
867 /// Transparently provide more efficient getOperand methods.
868 Value *getOperand(unsigned i) const {
869 assert(i < 3 && "getOperand() out of range!");
872 void setOperand(unsigned i, Value *Val) {
873 assert(i < 3 && "setOperand() out of range!");
876 unsigned getNumOperands() const { return 3; }
878 OtherOps getOpcode() const {
879 return static_cast<OtherOps>(Instruction::getOpcode());
882 virtual SelectInst *clone() const;
884 // Methods for support type inquiry through isa, cast, and dyn_cast:
885 static inline bool classof(const SelectInst *) { return true; }
886 static inline bool classof(const Instruction *I) {
887 return I->getOpcode() == Instruction::Select;
889 static inline bool classof(const Value *V) {
890 return isa<Instruction>(V) && classof(cast<Instruction>(V));
894 //===----------------------------------------------------------------------===//
896 //===----------------------------------------------------------------------===//
898 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
899 /// an argument of the specified type given a va_list and increments that list
901 class VAArgInst : public UnaryInstruction {
902 VAArgInst(const VAArgInst &VAA)
903 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
905 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
906 Instruction *InsertBefore = 0)
907 : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) {
909 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
910 BasicBlock *InsertAtEnd)
911 : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) {
914 virtual VAArgInst *clone() const;
915 bool mayWriteToMemory() const { return true; }
917 // Methods for support type inquiry through isa, cast, and dyn_cast:
918 static inline bool classof(const VAArgInst *) { return true; }
919 static inline bool classof(const Instruction *I) {
920 return I->getOpcode() == VAArg;
922 static inline bool classof(const Value *V) {
923 return isa<Instruction>(V) && classof(cast<Instruction>(V));
927 //===----------------------------------------------------------------------===//
928 // ExtractElementInst Class
929 //===----------------------------------------------------------------------===//
931 /// ExtractElementInst - This instruction extracts a single (scalar)
932 /// element from a PackedType value
934 class ExtractElementInst : public Instruction {
936 ExtractElementInst(const ExtractElementInst &EE) :
937 Instruction(EE.getType(), ExtractElement, Ops, 2) {
938 Ops[0].init(EE.Ops[0], this);
939 Ops[1].init(EE.Ops[1], this);
943 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
944 Instruction *InsertBefore = 0);
945 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
946 Instruction *InsertBefore = 0);
947 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
948 BasicBlock *InsertAtEnd);
949 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
950 BasicBlock *InsertAtEnd);
952 /// isValidOperands - Return true if an extractelement instruction can be
953 /// formed with the specified operands.
954 static bool isValidOperands(const Value *Vec, const Value *Idx);
956 virtual ExtractElementInst *clone() const;
958 virtual bool mayWriteToMemory() const { return false; }
960 /// Transparently provide more efficient getOperand methods.
961 Value *getOperand(unsigned i) const {
962 assert(i < 2 && "getOperand() out of range!");
965 void setOperand(unsigned i, Value *Val) {
966 assert(i < 2 && "setOperand() out of range!");
969 unsigned getNumOperands() const { return 2; }
971 // Methods for support type inquiry through isa, cast, and dyn_cast:
972 static inline bool classof(const ExtractElementInst *) { return true; }
973 static inline bool classof(const Instruction *I) {
974 return I->getOpcode() == Instruction::ExtractElement;
976 static inline bool classof(const Value *V) {
977 return isa<Instruction>(V) && classof(cast<Instruction>(V));
981 //===----------------------------------------------------------------------===//
982 // InsertElementInst Class
983 //===----------------------------------------------------------------------===//
985 /// InsertElementInst - This instruction inserts a single (scalar)
986 /// element into a PackedType value
988 class InsertElementInst : public Instruction {
990 InsertElementInst(const InsertElementInst &IE);
992 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
993 const std::string &Name = "",Instruction *InsertBefore = 0);
994 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
995 const std::string &Name = "",Instruction *InsertBefore = 0);
996 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
997 const std::string &Name, BasicBlock *InsertAtEnd);
998 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
999 const std::string &Name, BasicBlock *InsertAtEnd);
1001 /// isValidOperands - Return true if an insertelement instruction can be
1002 /// formed with the specified operands.
1003 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1006 virtual InsertElementInst *clone() const;
1008 virtual bool mayWriteToMemory() const { return false; }
1010 /// getType - Overload to return most specific packed type.
1012 inline const PackedType *getType() const {
1013 return reinterpret_cast<const PackedType*>(Instruction::getType());
1016 /// Transparently provide more efficient getOperand methods.
1017 Value *getOperand(unsigned i) const {
1018 assert(i < 3 && "getOperand() out of range!");
1021 void setOperand(unsigned i, Value *Val) {
1022 assert(i < 3 && "setOperand() out of range!");
1025 unsigned getNumOperands() const { return 3; }
1027 // Methods for support type inquiry through isa, cast, and dyn_cast:
1028 static inline bool classof(const InsertElementInst *) { return true; }
1029 static inline bool classof(const Instruction *I) {
1030 return I->getOpcode() == Instruction::InsertElement;
1032 static inline bool classof(const Value *V) {
1033 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1037 //===----------------------------------------------------------------------===//
1038 // ShuffleVectorInst Class
1039 //===----------------------------------------------------------------------===//
1041 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1044 class ShuffleVectorInst : public Instruction {
1046 ShuffleVectorInst(const ShuffleVectorInst &IE);
1048 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1049 const std::string &Name = "", Instruction *InsertBefor = 0);
1050 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1051 const std::string &Name, BasicBlock *InsertAtEnd);
1053 /// isValidOperands - Return true if a shufflevector instruction can be
1054 /// formed with the specified operands.
1055 static bool isValidOperands(const Value *V1, const Value *V2,
1058 virtual ShuffleVectorInst *clone() const;
1060 virtual bool mayWriteToMemory() const { return false; }
1062 /// getType - Overload to return most specific packed type.
1064 inline const PackedType *getType() const {
1065 return reinterpret_cast<const PackedType*>(Instruction::getType());
1068 /// Transparently provide more efficient getOperand methods.
1069 Value *getOperand(unsigned i) const {
1070 assert(i < 3 && "getOperand() out of range!");
1073 void setOperand(unsigned i, Value *Val) {
1074 assert(i < 3 && "setOperand() out of range!");
1077 unsigned getNumOperands() const { return 3; }
1079 // Methods for support type inquiry through isa, cast, and dyn_cast:
1080 static inline bool classof(const ShuffleVectorInst *) { return true; }
1081 static inline bool classof(const Instruction *I) {
1082 return I->getOpcode() == Instruction::ShuffleVector;
1084 static inline bool classof(const Value *V) {
1085 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1090 //===----------------------------------------------------------------------===//
1092 //===----------------------------------------------------------------------===//
1094 // PHINode - The PHINode class is used to represent the magical mystical PHI
1095 // node, that can not exist in nature, but can be synthesized in a computer
1096 // scientist's overactive imagination.
1098 class PHINode : public Instruction {
1099 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1100 /// the number actually in use.
1101 unsigned ReservedSpace;
1102 PHINode(const PHINode &PN);
1104 explicit PHINode(const Type *Ty, const std::string &Name = "",
1105 Instruction *InsertBefore = 0)
1106 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore),
1110 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1111 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
1117 /// reserveOperandSpace - This method can be used to avoid repeated
1118 /// reallocation of PHI operand lists by reserving space for the correct
1119 /// number of operands before adding them. Unlike normal vector reserves,
1120 /// this method can also be used to trim the operand space.
1121 void reserveOperandSpace(unsigned NumValues) {
1122 resizeOperands(NumValues*2);
1125 virtual PHINode *clone() const;
1127 /// getNumIncomingValues - Return the number of incoming edges
1129 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1131 /// getIncomingValue - Return incoming value number x
1133 Value *getIncomingValue(unsigned i) const {
1134 assert(i*2 < getNumOperands() && "Invalid value number!");
1135 return getOperand(i*2);
1137 void setIncomingValue(unsigned i, Value *V) {
1138 assert(i*2 < getNumOperands() && "Invalid value number!");
1141 unsigned getOperandNumForIncomingValue(unsigned i) {
1145 /// getIncomingBlock - Return incoming basic block number x
1147 BasicBlock *getIncomingBlock(unsigned i) const {
1148 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1150 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1151 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1153 unsigned getOperandNumForIncomingBlock(unsigned i) {
1157 /// addIncoming - Add an incoming value to the end of the PHI list
1159 void addIncoming(Value *V, BasicBlock *BB) {
1160 assert(getType() == V->getType() &&
1161 "All operands to PHI node must be the same type as the PHI node!");
1162 unsigned OpNo = NumOperands;
1163 if (OpNo+2 > ReservedSpace)
1164 resizeOperands(0); // Get more space!
1165 // Initialize some new operands.
1166 NumOperands = OpNo+2;
1167 OperandList[OpNo].init(V, this);
1168 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1171 /// removeIncomingValue - Remove an incoming value. This is useful if a
1172 /// predecessor basic block is deleted. The value removed is returned.
1174 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1175 /// is true), the PHI node is destroyed and any uses of it are replaced with
1176 /// dummy values. The only time there should be zero incoming values to a PHI
1177 /// node is when the block is dead, so this strategy is sound.
1179 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1181 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1182 int Idx = getBasicBlockIndex(BB);
1183 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1184 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1187 /// getBasicBlockIndex - Return the first index of the specified basic
1188 /// block in the value list for this PHI. Returns -1 if no instance.
1190 int getBasicBlockIndex(const BasicBlock *BB) const {
1191 Use *OL = OperandList;
1192 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1193 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1197 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1198 return getIncomingValue(getBasicBlockIndex(BB));
1201 /// hasConstantValue - If the specified PHI node always merges together the
1202 /// same value, return the value, otherwise return null.
1204 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1206 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1207 static inline bool classof(const PHINode *) { return true; }
1208 static inline bool classof(const Instruction *I) {
1209 return I->getOpcode() == Instruction::PHI;
1211 static inline bool classof(const Value *V) {
1212 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1215 void resizeOperands(unsigned NumOperands);
1218 //===----------------------------------------------------------------------===//
1220 //===----------------------------------------------------------------------===//
1222 //===---------------------------------------------------------------------------
1223 /// ReturnInst - Return a value (possibly void), from a function. Execution
1224 /// does not continue in this function any longer.
1226 class ReturnInst : public TerminatorInst {
1227 Use RetVal; // Possibly null retval.
1228 ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
1229 RI.getNumOperands()) {
1230 if (RI.getNumOperands())
1231 RetVal.init(RI.RetVal, this);
1234 void init(Value *RetVal);
1237 // ReturnInst constructors:
1238 // ReturnInst() - 'ret void' instruction
1239 // ReturnInst( null) - 'ret void' instruction
1240 // ReturnInst(Value* X) - 'ret X' instruction
1241 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1242 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1243 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1244 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1246 // NOTE: If the Value* passed is of type void then the constructor behaves as
1247 // if it was passed NULL.
1248 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
1249 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
1252 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
1253 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1256 explicit ReturnInst(BasicBlock *InsertAtEnd)
1257 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1260 virtual ReturnInst *clone() const;
1262 // Transparently provide more efficient getOperand methods.
1263 Value *getOperand(unsigned i) const {
1264 assert(i < getNumOperands() && "getOperand() out of range!");
1267 void setOperand(unsigned i, Value *Val) {
1268 assert(i < getNumOperands() && "setOperand() out of range!");
1272 Value *getReturnValue() const { return RetVal; }
1274 unsigned getNumSuccessors() const { return 0; }
1276 // Methods for support type inquiry through isa, cast, and dyn_cast:
1277 static inline bool classof(const ReturnInst *) { return true; }
1278 static inline bool classof(const Instruction *I) {
1279 return (I->getOpcode() == Instruction::Ret);
1281 static inline bool classof(const Value *V) {
1282 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1285 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1286 virtual unsigned getNumSuccessorsV() const;
1287 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1290 //===----------------------------------------------------------------------===//
1292 //===----------------------------------------------------------------------===//
1294 //===---------------------------------------------------------------------------
1295 /// BranchInst - Conditional or Unconditional Branch instruction.
1297 class BranchInst : public TerminatorInst {
1298 /// Ops list - Branches are strange. The operands are ordered:
1299 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1300 /// they don't have to check for cond/uncond branchness.
1302 BranchInst(const BranchInst &BI);
1305 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1306 // BranchInst(BB *B) - 'br B'
1307 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1308 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1309 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1310 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1311 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1312 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
1313 : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
1314 assert(IfTrue != 0 && "Branch destination may not be null!");
1315 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1317 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1318 Instruction *InsertBefore = 0)
1319 : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
1320 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1321 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1322 Ops[2].init(Cond, this);
1328 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
1329 : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
1330 assert(IfTrue != 0 && "Branch destination may not be null!");
1331 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1334 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1335 BasicBlock *InsertAtEnd)
1336 : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
1337 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1338 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1339 Ops[2].init(Cond, this);
1346 /// Transparently provide more efficient getOperand methods.
1347 Value *getOperand(unsigned i) const {
1348 assert(i < getNumOperands() && "getOperand() out of range!");
1351 void setOperand(unsigned i, Value *Val) {
1352 assert(i < getNumOperands() && "setOperand() out of range!");
1356 virtual BranchInst *clone() const;
1358 inline bool isUnconditional() const { return getNumOperands() == 1; }
1359 inline bool isConditional() const { return getNumOperands() == 3; }
1361 inline Value *getCondition() const {
1362 assert(isConditional() && "Cannot get condition of an uncond branch!");
1363 return getOperand(2);
1366 void setCondition(Value *V) {
1367 assert(isConditional() && "Cannot set condition of unconditional branch!");
1371 // setUnconditionalDest - Change the current branch to an unconditional branch
1372 // targeting the specified block.
1373 // FIXME: Eliminate this ugly method.
1374 void setUnconditionalDest(BasicBlock *Dest) {
1375 if (isConditional()) { // Convert this to an uncond branch.
1380 setOperand(0, reinterpret_cast<Value*>(Dest));
1383 unsigned getNumSuccessors() const { return 1+isConditional(); }
1385 BasicBlock *getSuccessor(unsigned i) const {
1386 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1387 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1388 cast<BasicBlock>(getOperand(1));
1391 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1392 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1393 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1396 // Methods for support type inquiry through isa, cast, and dyn_cast:
1397 static inline bool classof(const BranchInst *) { return true; }
1398 static inline bool classof(const Instruction *I) {
1399 return (I->getOpcode() == Instruction::Br);
1401 static inline bool classof(const Value *V) {
1402 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1405 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1406 virtual unsigned getNumSuccessorsV() const;
1407 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1410 //===----------------------------------------------------------------------===//
1412 //===----------------------------------------------------------------------===//
1414 //===---------------------------------------------------------------------------
1415 /// SwitchInst - Multiway switch
1417 class SwitchInst : public TerminatorInst {
1418 unsigned ReservedSpace;
1419 // Operand[0] = Value to switch on
1420 // Operand[1] = Default basic block destination
1421 // Operand[2n ] = Value to match
1422 // Operand[2n+1] = BasicBlock to go to on match
1423 SwitchInst(const SwitchInst &RI);
1424 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1425 void resizeOperands(unsigned No);
1427 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1428 /// switch on and a default destination. The number of additional cases can
1429 /// be specified here to make memory allocation more efficient. This
1430 /// constructor can also autoinsert before another instruction.
1431 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1432 Instruction *InsertBefore = 0)
1433 : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1434 init(Value, Default, NumCases);
1437 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1438 /// switch on and a default destination. The number of additional cases can
1439 /// be specified here to make memory allocation more efficient. This
1440 /// constructor also autoinserts at the end of the specified BasicBlock.
1441 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1442 BasicBlock *InsertAtEnd)
1443 : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1444 init(Value, Default, NumCases);
1449 // Accessor Methods for Switch stmt
1450 inline Value *getCondition() const { return getOperand(0); }
1451 void setCondition(Value *V) { setOperand(0, V); }
1453 inline BasicBlock *getDefaultDest() const {
1454 return cast<BasicBlock>(getOperand(1));
1457 /// getNumCases - return the number of 'cases' in this switch instruction.
1458 /// Note that case #0 is always the default case.
1459 unsigned getNumCases() const {
1460 return getNumOperands()/2;
1463 /// getCaseValue - Return the specified case value. Note that case #0, the
1464 /// default destination, does not have a case value.
1465 ConstantInt *getCaseValue(unsigned i) {
1466 assert(i && i < getNumCases() && "Illegal case value to get!");
1467 return getSuccessorValue(i);
1470 /// getCaseValue - Return the specified case value. Note that case #0, the
1471 /// default destination, does not have a case value.
1472 const ConstantInt *getCaseValue(unsigned i) const {
1473 assert(i && i < getNumCases() && "Illegal case value to get!");
1474 return getSuccessorValue(i);
1477 /// findCaseValue - Search all of the case values for the specified constant.
1478 /// If it is explicitly handled, return the case number of it, otherwise
1479 /// return 0 to indicate that it is handled by the default handler.
1480 unsigned findCaseValue(const ConstantInt *C) const {
1481 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1482 if (getCaseValue(i) == C)
1487 /// findCaseDest - Finds the unique case value for a given successor. Returns
1488 /// null if the successor is not found, not unique, or is the default case.
1489 ConstantInt *findCaseDest(BasicBlock *BB) {
1490 if (BB == getDefaultDest()) return NULL;
1492 ConstantInt *CI = NULL;
1493 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1494 if (getSuccessor(i) == BB) {
1495 if (CI) return NULL; // Multiple cases lead to BB.
1496 else CI = getCaseValue(i);
1502 /// addCase - Add an entry to the switch instruction...
1504 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1506 /// removeCase - This method removes the specified successor from the switch
1507 /// instruction. Note that this cannot be used to remove the default
1508 /// destination (successor #0).
1510 void removeCase(unsigned idx);
1512 virtual SwitchInst *clone() const;
1514 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1515 BasicBlock *getSuccessor(unsigned idx) const {
1516 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1517 return cast<BasicBlock>(getOperand(idx*2+1));
1519 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1520 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1521 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1524 // getSuccessorValue - Return the value associated with the specified
1526 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1527 assert(idx < getNumSuccessors() && "Successor # out of range!");
1528 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1531 // Methods for support type inquiry through isa, cast, and dyn_cast:
1532 static inline bool classof(const SwitchInst *) { return true; }
1533 static inline bool classof(const Instruction *I) {
1534 return I->getOpcode() == Instruction::Switch;
1536 static inline bool classof(const Value *V) {
1537 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1540 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1541 virtual unsigned getNumSuccessorsV() const;
1542 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1545 //===----------------------------------------------------------------------===//
1547 //===----------------------------------------------------------------------===//
1549 //===---------------------------------------------------------------------------
1551 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1552 /// calling convention of the call.
1554 class InvokeInst : public TerminatorInst {
1555 InvokeInst(const InvokeInst &BI);
1556 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1557 const std::vector<Value*> &Params);
1559 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1560 const std::vector<Value*> &Params, const std::string &Name = "",
1561 Instruction *InsertBefore = 0);
1562 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1563 const std::vector<Value*> &Params, const std::string &Name,
1564 BasicBlock *InsertAtEnd);
1567 virtual InvokeInst *clone() const;
1569 bool mayWriteToMemory() const { return true; }
1571 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1573 unsigned getCallingConv() const { return SubclassData; }
1574 void setCallingConv(unsigned CC) {
1578 /// getCalledFunction - Return the function called, or null if this is an
1579 /// indirect function invocation.
1581 Function *getCalledFunction() const {
1582 return dyn_cast<Function>(getOperand(0));
1585 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1586 inline Value *getCalledValue() const { return getOperand(0); }
1588 // get*Dest - Return the destination basic blocks...
1589 BasicBlock *getNormalDest() const {
1590 return cast<BasicBlock>(getOperand(1));
1592 BasicBlock *getUnwindDest() const {
1593 return cast<BasicBlock>(getOperand(2));
1595 void setNormalDest(BasicBlock *B) {
1596 setOperand(1, reinterpret_cast<Value*>(B));
1599 void setUnwindDest(BasicBlock *B) {
1600 setOperand(2, reinterpret_cast<Value*>(B));
1603 inline BasicBlock *getSuccessor(unsigned i) const {
1604 assert(i < 2 && "Successor # out of range for invoke!");
1605 return i == 0 ? getNormalDest() : getUnwindDest();
1608 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1609 assert(idx < 2 && "Successor # out of range for invoke!");
1610 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1613 unsigned getNumSuccessors() const { return 2; }
1615 // Methods for support type inquiry through isa, cast, and dyn_cast:
1616 static inline bool classof(const InvokeInst *) { return true; }
1617 static inline bool classof(const Instruction *I) {
1618 return (I->getOpcode() == Instruction::Invoke);
1620 static inline bool classof(const Value *V) {
1621 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1624 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1625 virtual unsigned getNumSuccessorsV() const;
1626 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1630 //===----------------------------------------------------------------------===//
1632 //===----------------------------------------------------------------------===//
1634 //===---------------------------------------------------------------------------
1635 /// UnwindInst - Immediately exit the current function, unwinding the stack
1636 /// until an invoke instruction is found.
1638 class UnwindInst : public TerminatorInst {
1640 explicit UnwindInst(Instruction *InsertBefore = 0)
1641 : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
1643 explicit UnwindInst(BasicBlock *InsertAtEnd)
1644 : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
1647 virtual UnwindInst *clone() const;
1649 unsigned getNumSuccessors() const { return 0; }
1651 // Methods for support type inquiry through isa, cast, and dyn_cast:
1652 static inline bool classof(const UnwindInst *) { return true; }
1653 static inline bool classof(const Instruction *I) {
1654 return I->getOpcode() == Instruction::Unwind;
1656 static inline bool classof(const Value *V) {
1657 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1660 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1661 virtual unsigned getNumSuccessorsV() const;
1662 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1665 //===----------------------------------------------------------------------===//
1666 // UnreachableInst Class
1667 //===----------------------------------------------------------------------===//
1669 //===---------------------------------------------------------------------------
1670 /// UnreachableInst - This function has undefined behavior. In particular, the
1671 /// presence of this instruction indicates some higher level knowledge that the
1672 /// end of the block cannot be reached.
1674 class UnreachableInst : public TerminatorInst {
1676 explicit UnreachableInst(Instruction *InsertBefore = 0)
1677 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
1679 explicit UnreachableInst(BasicBlock *InsertAtEnd)
1680 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
1683 virtual UnreachableInst *clone() const;
1685 unsigned getNumSuccessors() const { return 0; }
1687 // Methods for support type inquiry through isa, cast, and dyn_cast:
1688 static inline bool classof(const UnreachableInst *) { return true; }
1689 static inline bool classof(const Instruction *I) {
1690 return I->getOpcode() == Instruction::Unreachable;
1692 static inline bool classof(const Value *V) {
1693 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1696 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1697 virtual unsigned getNumSuccessorsV() const;
1698 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1701 //===----------------------------------------------------------------------===//
1703 //===----------------------------------------------------------------------===//
1705 /// @brief This class represents a truncation of integer types.
1706 class TruncInst : public CastInst {
1707 /// Private copy constructor
1708 TruncInst(const TruncInst &CI)
1709 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1712 /// @brief Constructor with insert-before-instruction semantics
1714 Value *S, ///< The value to be truncated
1715 const Type *Ty, ///< The (smaller) type to truncate to
1716 const std::string &Name = "", ///< A name for the new instruction
1717 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1720 /// @brief Constructor with insert-at-end-of-block semantics
1722 Value *S, ///< The value to be truncated
1723 const Type *Ty, ///< The (smaller) type to truncate to
1724 const std::string &Name, ///< A name for the new instruction
1725 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1728 /// @brief Clone an identical TruncInst
1729 virtual CastInst *clone() const;
1731 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1732 static inline bool classof(const TruncInst *) { return true; }
1733 static inline bool classof(const Instruction *I) {
1734 return I->getOpcode() == Trunc;
1736 static inline bool classof(const Value *V) {
1737 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1741 //===----------------------------------------------------------------------===//
1743 //===----------------------------------------------------------------------===//
1745 /// @brief This class represents zero extension of integer types.
1746 class ZExtInst : public CastInst {
1747 /// @brief Private copy constructor
1748 ZExtInst(const ZExtInst &CI)
1749 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1752 /// @brief Constructor with insert-before-instruction semantics
1754 Value *S, ///< The value to be zero extended
1755 const Type *Ty, ///< The type to zero extend to
1756 const std::string &Name = "", ///< A name for the new instruction
1757 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1760 /// @brief Constructor with insert-at-end semantics.
1762 Value *S, ///< The value to be zero extended
1763 const Type *Ty, ///< The type to zero extend to
1764 const std::string &Name, ///< A name for the new instruction
1765 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1768 /// @brief Clone an identical ZExtInst
1769 virtual CastInst *clone() const;
1771 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1772 static inline bool classof(const ZExtInst *) { return true; }
1773 static inline bool classof(const Instruction *I) {
1774 return I->getOpcode() == ZExt;
1776 static inline bool classof(const Value *V) {
1777 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1781 //===----------------------------------------------------------------------===//
1783 //===----------------------------------------------------------------------===//
1785 /// @brief This class represents a sign extension of integer types.
1786 class SExtInst : public CastInst {
1787 /// @brief Private copy constructor
1788 SExtInst(const SExtInst &CI)
1789 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1792 /// @brief Constructor with insert-before-instruction semantics
1794 Value *S, ///< The value to be sign extended
1795 const Type *Ty, ///< The type to sign extend to
1796 const std::string &Name = "", ///< A name for the new instruction
1797 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1800 /// @brief Constructor with insert-at-end-of-block semantics
1802 Value *S, ///< The value to be sign extended
1803 const Type *Ty, ///< The type to sign extend to
1804 const std::string &Name, ///< A name for the new instruction
1805 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1808 /// @brief Clone an identical SExtInst
1809 virtual CastInst *clone() const;
1811 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1812 static inline bool classof(const SExtInst *) { return true; }
1813 static inline bool classof(const Instruction *I) {
1814 return I->getOpcode() == SExt;
1816 static inline bool classof(const Value *V) {
1817 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1821 //===----------------------------------------------------------------------===//
1822 // FPTruncInst Class
1823 //===----------------------------------------------------------------------===//
1825 /// @brief This class represents a truncation of floating point types.
1826 class FPTruncInst : public CastInst {
1827 FPTruncInst(const FPTruncInst &CI)
1828 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1831 /// @brief Constructor with insert-before-instruction semantics
1833 Value *S, ///< The value to be truncated
1834 const Type *Ty, ///< The type to truncate to
1835 const std::string &Name = "", ///< A name for the new instruction
1836 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1839 /// @brief Constructor with insert-before-instruction semantics
1841 Value *S, ///< The value to be truncated
1842 const Type *Ty, ///< The type to truncate to
1843 const std::string &Name, ///< A name for the new instruction
1844 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1847 /// @brief Clone an identical FPTruncInst
1848 virtual CastInst *clone() const;
1850 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1851 static inline bool classof(const FPTruncInst *) { return true; }
1852 static inline bool classof(const Instruction *I) {
1853 return I->getOpcode() == FPTrunc;
1855 static inline bool classof(const Value *V) {
1856 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1860 //===----------------------------------------------------------------------===//
1862 //===----------------------------------------------------------------------===//
1864 /// @brief This class represents an extension of floating point types.
1865 class FPExtInst : public CastInst {
1866 FPExtInst(const FPExtInst &CI)
1867 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1870 /// @brief Constructor with insert-before-instruction semantics
1872 Value *S, ///< The value to be extended
1873 const Type *Ty, ///< The type to extend to
1874 const std::string &Name = "", ///< A name for the new instruction
1875 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1878 /// @brief Constructor with insert-at-end-of-block semantics
1880 Value *S, ///< The value to be extended
1881 const Type *Ty, ///< The type to extend to
1882 const std::string &Name, ///< A name for the new instruction
1883 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1886 /// @brief Clone an identical FPExtInst
1887 virtual CastInst *clone() const;
1889 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1890 static inline bool classof(const FPExtInst *) { return true; }
1891 static inline bool classof(const Instruction *I) {
1892 return I->getOpcode() == FPExt;
1894 static inline bool classof(const Value *V) {
1895 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1899 //===----------------------------------------------------------------------===//
1901 //===----------------------------------------------------------------------===//
1903 /// @brief This class represents a cast unsigned integer to floating point.
1904 class UIToFPInst : public CastInst {
1905 UIToFPInst(const UIToFPInst &CI)
1906 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1909 /// @brief Constructor with insert-before-instruction semantics
1911 Value *S, ///< The value to be converted
1912 const Type *Ty, ///< The type to convert to
1913 const std::string &Name = "", ///< A name for the new instruction
1914 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1917 /// @brief Constructor with insert-at-end-of-block semantics
1919 Value *S, ///< The value to be converted
1920 const Type *Ty, ///< The type to convert to
1921 const std::string &Name, ///< A name for the new instruction
1922 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1925 /// @brief Clone an identical UIToFPInst
1926 virtual CastInst *clone() const;
1928 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1929 static inline bool classof(const UIToFPInst *) { return true; }
1930 static inline bool classof(const Instruction *I) {
1931 return I->getOpcode() == UIToFP;
1933 static inline bool classof(const Value *V) {
1934 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1938 //===----------------------------------------------------------------------===//
1940 //===----------------------------------------------------------------------===//
1942 /// @brief This class represents a cast from signed integer to floating point.
1943 class SIToFPInst : public CastInst {
1944 SIToFPInst(const SIToFPInst &CI)
1945 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1948 /// @brief Constructor with insert-before-instruction semantics
1950 Value *S, ///< The value to be converted
1951 const Type *Ty, ///< The type to convert to
1952 const std::string &Name = "", ///< A name for the new instruction
1953 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1956 /// @brief Constructor with insert-at-end-of-block semantics
1958 Value *S, ///< The value to be converted
1959 const Type *Ty, ///< The type to convert to
1960 const std::string &Name, ///< A name for the new instruction
1961 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1964 /// @brief Clone an identical SIToFPInst
1965 virtual CastInst *clone() const;
1967 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1968 static inline bool classof(const SIToFPInst *) { return true; }
1969 static inline bool classof(const Instruction *I) {
1970 return I->getOpcode() == SIToFP;
1972 static inline bool classof(const Value *V) {
1973 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1977 //===----------------------------------------------------------------------===//
1979 //===----------------------------------------------------------------------===//
1981 /// @brief This class represents a cast from floating point to unsigned integer
1982 class FPToUIInst : public CastInst {
1983 FPToUIInst(const FPToUIInst &CI)
1984 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1987 /// @brief Constructor with insert-before-instruction semantics
1989 Value *S, ///< The value to be converted
1990 const Type *Ty, ///< The type to convert to
1991 const std::string &Name = "", ///< A name for the new instruction
1992 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1995 /// @brief Constructor with insert-at-end-of-block semantics
1997 Value *S, ///< The value to be converted
1998 const Type *Ty, ///< The type to convert to
1999 const std::string &Name, ///< A name for the new instruction
2000 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
2003 /// @brief Clone an identical FPToUIInst
2004 virtual CastInst *clone() const;
2006 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2007 static inline bool classof(const FPToUIInst *) { return true; }
2008 static inline bool classof(const Instruction *I) {
2009 return I->getOpcode() == FPToUI;
2011 static inline bool classof(const Value *V) {
2012 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2016 //===----------------------------------------------------------------------===//
2018 //===----------------------------------------------------------------------===//
2020 /// @brief This class represents a cast from floating point to signed integer.
2021 class FPToSIInst : public CastInst {
2022 FPToSIInst(const FPToSIInst &CI)
2023 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2026 /// @brief Constructor with insert-before-instruction semantics
2028 Value *S, ///< The value to be converted
2029 const Type *Ty, ///< The type to convert to
2030 const std::string &Name = "", ///< A name for the new instruction
2031 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2034 /// @brief Constructor with insert-at-end-of-block semantics
2036 Value *S, ///< The value to be converted
2037 const Type *Ty, ///< The type to convert to
2038 const std::string &Name, ///< A name for the new instruction
2039 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2042 /// @brief Clone an identical FPToSIInst
2043 virtual CastInst *clone() const;
2045 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2046 static inline bool classof(const FPToSIInst *) { return true; }
2047 static inline bool classof(const Instruction *I) {
2048 return I->getOpcode() == FPToSI;
2050 static inline bool classof(const Value *V) {
2051 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2055 //===----------------------------------------------------------------------===//
2056 // IntToPtrInst Class
2057 //===----------------------------------------------------------------------===//
2059 /// @brief This class represents a cast from an integer to a pointer.
2060 class IntToPtrInst : public CastInst {
2061 IntToPtrInst(const IntToPtrInst &CI)
2062 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2065 /// @brief Constructor with insert-before-instruction semantics
2067 Value *S, ///< The value to be converted
2068 const Type *Ty, ///< The type to convert to
2069 const std::string &Name = "", ///< A name for the new instruction
2070 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2073 /// @brief Constructor with insert-at-end-of-block semantics
2075 Value *S, ///< The value to be converted
2076 const Type *Ty, ///< The type to convert to
2077 const std::string &Name, ///< A name for the new instruction
2078 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2081 /// @brief Clone an identical IntToPtrInst
2082 virtual CastInst *clone() const;
2084 // Methods for support type inquiry through isa, cast, and dyn_cast:
2085 static inline bool classof(const IntToPtrInst *) { return true; }
2086 static inline bool classof(const Instruction *I) {
2087 return I->getOpcode() == IntToPtr;
2089 static inline bool classof(const Value *V) {
2090 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2094 //===----------------------------------------------------------------------===//
2095 // PtrToIntInst Class
2096 //===----------------------------------------------------------------------===//
2098 /// @brief This class represents a cast from a pointer to an integer
2099 class PtrToIntInst : public CastInst {
2100 PtrToIntInst(const PtrToIntInst &CI)
2101 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2104 /// @brief Constructor with insert-before-instruction semantics
2106 Value *S, ///< The value to be converted
2107 const Type *Ty, ///< The type to convert to
2108 const std::string &Name = "", ///< A name for the new instruction
2109 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2112 /// @brief Constructor with insert-at-end-of-block semantics
2114 Value *S, ///< The value to be converted
2115 const Type *Ty, ///< The type to convert to
2116 const std::string &Name, ///< A name for the new instruction
2117 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2120 /// @brief Clone an identical PtrToIntInst
2121 virtual CastInst *clone() const;
2123 // Methods for support type inquiry through isa, cast, and dyn_cast:
2124 static inline bool classof(const PtrToIntInst *) { return true; }
2125 static inline bool classof(const Instruction *I) {
2126 return I->getOpcode() == PtrToInt;
2128 static inline bool classof(const Value *V) {
2129 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2133 //===----------------------------------------------------------------------===//
2134 // BitCastInst Class
2135 //===----------------------------------------------------------------------===//
2137 /// @brief This class represents a no-op cast from one type to another.
2138 class BitCastInst : public CastInst {
2139 BitCastInst(const BitCastInst &CI)
2140 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2143 /// @brief Constructor with insert-before-instruction semantics
2145 Value *S, ///< The value to be casted
2146 const Type *Ty, ///< The type to casted to
2147 const std::string &Name = "", ///< A name for the new instruction
2148 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2151 /// @brief Constructor with insert-at-end-of-block semantics
2153 Value *S, ///< The value to be casted
2154 const Type *Ty, ///< The type to casted to
2155 const std::string &Name, ///< A name for the new instruction
2156 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2159 /// @brief Clone an identical BitCastInst
2160 virtual CastInst *clone() const;
2162 // Methods for support type inquiry through isa, cast, and dyn_cast:
2163 static inline bool classof(const BitCastInst *) { return true; }
2164 static inline bool classof(const Instruction *I) {
2165 return I->getOpcode() == BitCast;
2167 static inline bool classof(const Value *V) {
2168 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2172 } // End llvm namespace