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
446 /// @brief Constructor with insert-before-instruction semantics.
448 Predicate pred, ///< The predicate to use for the comparison
449 Value *LHS, ///< The left-hand-side of the expression
450 Value *RHS, ///< The right-hand-side of the expression
451 const std::string &Name = "", ///< Name of the instruction
452 Instruction *InsertBefore = 0 ///< Where to insert
453 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
456 /// @brief Constructor with insert-at-block-end semantics.
458 Predicate pred, ///< The predicate to use for the comparison
459 Value *LHS, ///< The left-hand-side of the expression
460 Value *RHS, ///< The right-hand-side of the expression
461 const std::string &Name, ///< Name of the instruction
462 BasicBlock *InsertAtEnd ///< Block to insert into.
463 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
466 /// @brief Return the predicate for this instruction.
467 Predicate getPredicate() const { return Predicate(SubclassData); }
469 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
470 /// @returns the inverse predicate for the instruction's current predicate.
471 /// @brief Return the inverse of the instruction's predicate.
472 Predicate getInversePredicate() const {
473 return getInversePredicate(getPredicate());
476 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
477 /// @returns the inverse predicate for predicate provided in \p pred.
478 /// @brief Return the inverse of a given predicate
479 static Predicate getInversePredicate(Predicate pred);
481 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
482 /// @returns the predicate that would be the result of exchanging the two
483 /// operands of the ICmpInst instruction without changing the result
485 /// @brief Return the predicate as if the operands were swapped
486 Predicate getSwappedPredicate() const {
487 return getSwappedPredicate(getPredicate());
490 /// This is a static version that you can use without an instruction
492 /// @brief Return the predicate as if the operands were swapped.
493 static Predicate getSwappedPredicate(Predicate Opcode);
495 /// This also tests for commutativity. If isEquality() returns true then
496 /// the predicate is also commutative. Only the equality predicates are
498 /// @returns true if the predicate of this instruction is EQ or NE.
499 /// @brief Determine if this is an equality predicate.
500 bool isEquality() const {
501 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
503 bool isCommutative() const { return isEquality(); }
505 /// @returns true if the predicate is relational (not EQ or NE).
506 /// @brief Determine if this a relational predicate.
507 bool isRelational() const {
508 return !isEquality();
511 /// Exchange the two operands to this instruction in such a way that it does
512 /// not modify the semantics of the instruction. The predicate value may be
513 /// changed to retain the same result if the predicate is order dependent
515 /// @brief Swap operands and adjust predicate.
516 void swapOperands() {
517 SubclassData = getSwappedPredicate();
518 std::swap(Ops[0], Ops[1]);
521 // Methods for support type inquiry through isa, cast, and dyn_cast:
522 static inline bool classof(const ICmpInst *) { return true; }
523 static inline bool classof(const Instruction *I) {
524 return I->getOpcode() == Instruction::ICmp;
526 static inline bool classof(const Value *V) {
527 return isa<Instruction>(V) && classof(cast<Instruction>(V));
531 //===----------------------------------------------------------------------===//
533 //===----------------------------------------------------------------------===//
535 /// This instruction compares its operands according to the predicate given
536 /// to the constructor. It only operates on floating point values or packed
537 /// vectors of floating point values. The operands must be identical types.
538 /// @brief Represents a floating point comparison operator.
539 class FCmpInst: public CmpInst {
541 /// This enumeration lists the possible predicates for the FCmpInst. Values
542 /// in the range 0-31 are reserved for FCmpInst.
544 // Opcode U L G E Intuitive operation
545 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
546 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
547 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
548 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
549 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
550 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
551 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
552 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
553 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
554 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
555 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
556 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
557 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
558 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
559 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
560 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
561 FIRST_FCMP_PREDICATE = FCMP_FALSE,
562 LAST_FCMP_PREDICATE = FCMP_TRUE
565 /// @brief Constructor with insert-before-instruction semantics.
567 Predicate pred, ///< The predicate to use for the comparison
568 Value *LHS, ///< The left-hand-side of the expression
569 Value *RHS, ///< The right-hand-side of the expression
570 const std::string &Name = "", ///< Name of the instruction
571 Instruction *InsertBefore = 0 ///< Where to insert
572 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
575 /// @brief Constructor with insert-at-block-end semantics.
577 Predicate pred, ///< The predicate to use for the comparison
578 Value *LHS, ///< The left-hand-side of the expression
579 Value *RHS, ///< The right-hand-side of the expression
580 const std::string &Name, ///< Name of the instruction
581 BasicBlock *InsertAtEnd ///< Block to insert into.
582 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
585 /// @brief Return the predicate for this instruction.
586 Predicate getPredicate() const { return Predicate(SubclassData); }
588 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
589 /// @returns the inverse predicate for the instructions current predicate.
590 /// @brief Return the inverse of the predicate
591 Predicate getInversePredicate() const {
592 return getInversePredicate(getPredicate());
595 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
596 /// @returns the inverse predicate for \p pred.
597 /// @brief Return the inverse of a given predicate
598 static Predicate getInversePredicate(Predicate pred);
600 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
601 /// @returns the predicate that would be the result of exchanging the two
602 /// operands of the ICmpInst instruction without changing the result
604 /// @brief Return the predicate as if the operands were swapped
605 Predicate getSwappedPredicate() const {
606 return getSwappedPredicate(getPredicate());
609 /// This is a static version that you can use without an instruction
611 /// @brief Return the predicate as if the operands were swapped.
612 static Predicate getSwappedPredicate(Predicate Opcode);
614 /// This also tests for commutativity. If isEquality() returns true then
615 /// the predicate is also commutative. Only the equality predicates are
617 /// @returns true if the predicate of this instruction is EQ or NE.
618 /// @brief Determine if this is an equality predicate.
619 bool isEquality() const {
620 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
621 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
623 bool isCommutative() const { return isEquality(); }
625 /// @returns true if the predicate is relational (not EQ or NE).
626 /// @brief Determine if this a relational predicate.
627 bool isRelational() const { return !isEquality(); }
629 /// Exchange the two operands to this instruction in such a way that it does
630 /// not modify the semantics of the instruction. The predicate value may be
631 /// changed to retain the same result if the predicate is order dependent
633 /// @brief Swap operands and adjust predicate.
634 void swapOperands() {
635 SubclassData = getSwappedPredicate();
636 std::swap(Ops[0], Ops[1]);
639 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
640 static inline bool classof(const FCmpInst *) { return true; }
641 static inline bool classof(const Instruction *I) {
642 return I->getOpcode() == Instruction::FCmp;
644 static inline bool classof(const Value *V) {
645 return isa<Instruction>(V) && classof(cast<Instruction>(V));
650 //===----------------------------------------------------------------------===//
652 //===----------------------------------------------------------------------===//
654 /// SetCondInst class - Represent a setCC operator, where CC is eq, ne, lt, gt,
657 class SetCondInst : public BinaryOperator {
659 SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
660 const std::string &Name = "", Instruction *InsertBefore = 0);
661 SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
662 const std::string &Name, BasicBlock *InsertAtEnd);
664 /// getInverseCondition - Return the inverse of the current condition opcode.
665 /// For example seteq -> setne, setgt -> setle, setlt -> setge, etc...
667 BinaryOps getInverseCondition() const {
668 return getInverseCondition(getOpcode());
671 /// getInverseCondition - Static version that you can use without an
672 /// instruction available.
674 static BinaryOps getInverseCondition(BinaryOps Opcode);
676 /// getSwappedCondition - Return the condition opcode that would be the result
677 /// of exchanging the two operands of the setcc instruction without changing
678 /// the result produced. Thus, seteq->seteq, setle->setge, setlt->setgt, etc.
680 BinaryOps getSwappedCondition() const {
681 return getSwappedCondition(getOpcode());
684 /// getSwappedCondition - Static version that you can use without an
685 /// instruction available.
687 static BinaryOps getSwappedCondition(BinaryOps Opcode);
689 /// isEquality - Return true if this comparison is an ==/!= comparison.
691 bool isEquality() const {
692 return getOpcode() == SetEQ || getOpcode() == SetNE;
695 /// isRelational - Return true if this comparison is a </>/<=/>= comparison.
697 bool isRelational() const {
698 return !isEquality();
701 // Methods for support type inquiry through isa, cast, and dyn_cast:
702 static inline bool classof(const SetCondInst *) { return true; }
703 static inline bool classof(const Instruction *I) {
704 return I->getOpcode() == SetEQ || I->getOpcode() == SetNE ||
705 I->getOpcode() == SetLE || I->getOpcode() == SetGE ||
706 I->getOpcode() == SetLT || I->getOpcode() == SetGT;
708 static inline bool classof(const Value *V) {
709 return isa<Instruction>(V) && classof(cast<Instruction>(V));
714 //===----------------------------------------------------------------------===//
716 //===----------------------------------------------------------------------===//
718 /// CallInst - This class represents a function call, abstracting a target
719 /// machine's calling convention. This class uses low bit of the SubClassData
720 /// field to indicate whether or not this is a tail call. The rest of the bits
721 /// hold the calling convention of the call.
723 class CallInst : public Instruction {
724 CallInst(const CallInst &CI);
725 void init(Value *Func, const std::vector<Value*> &Params);
726 void init(Value *Func, Value *Actual1, Value *Actual2);
727 void init(Value *Func, Value *Actual);
728 void init(Value *Func);
731 CallInst(Value *F, const std::vector<Value*> &Par,
732 const std::string &Name = "", Instruction *InsertBefore = 0);
733 CallInst(Value *F, const std::vector<Value*> &Par,
734 const std::string &Name, BasicBlock *InsertAtEnd);
736 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
737 // actuals, respectively.
738 CallInst(Value *F, Value *Actual1, Value *Actual2,
739 const std::string& Name = "", Instruction *InsertBefore = 0);
740 CallInst(Value *F, Value *Actual1, Value *Actual2,
741 const std::string& Name, BasicBlock *InsertAtEnd);
742 CallInst(Value *F, Value *Actual, const std::string& Name = "",
743 Instruction *InsertBefore = 0);
744 CallInst(Value *F, Value *Actual, const std::string& Name,
745 BasicBlock *InsertAtEnd);
746 explicit CallInst(Value *F, const std::string &Name = "",
747 Instruction *InsertBefore = 0);
748 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
751 virtual CallInst *clone() const;
752 bool mayWriteToMemory() const { return true; }
754 bool isTailCall() const { return SubclassData & 1; }
755 void setTailCall(bool isTailCall = true) {
756 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
759 /// getCallingConv/setCallingConv - Get or set the calling convention of this
761 unsigned getCallingConv() const { return SubclassData >> 1; }
762 void setCallingConv(unsigned CC) {
763 SubclassData = (SubclassData & 1) | (CC << 1);
766 /// getCalledFunction - Return the function being called by this instruction
767 /// if it is a direct call. If it is a call through a function pointer,
769 Function *getCalledFunction() const {
770 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
773 // getCalledValue - Get a pointer to a method that is invoked by this inst.
774 inline const Value *getCalledValue() const { return getOperand(0); }
775 inline Value *getCalledValue() { return getOperand(0); }
777 // Methods for support type inquiry through isa, cast, and dyn_cast:
778 static inline bool classof(const CallInst *) { return true; }
779 static inline bool classof(const Instruction *I) {
780 return I->getOpcode() == Instruction::Call;
782 static inline bool classof(const Value *V) {
783 return isa<Instruction>(V) && classof(cast<Instruction>(V));
788 //===----------------------------------------------------------------------===//
790 //===----------------------------------------------------------------------===//
792 /// ShiftInst - This class represents left and right shift instructions.
794 class ShiftInst : public Instruction {
796 ShiftInst(const ShiftInst &SI)
797 : Instruction(SI.getType(), SI.getOpcode(), Ops, 2) {
798 Ops[0].init(SI.Ops[0], this);
799 Ops[1].init(SI.Ops[1], this);
801 void init(OtherOps Opcode, Value *S, Value *SA) {
802 assert((Opcode == Shl || Opcode == LShr || Opcode == AShr) &&
803 "ShiftInst Opcode invalid!");
804 Ops[0].init(S, this);
805 Ops[1].init(SA, this);
809 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
810 Instruction *InsertBefore = 0)
811 : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertBefore) {
814 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
815 BasicBlock *InsertAtEnd)
816 : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertAtEnd) {
820 OtherOps getOpcode() const {
821 return static_cast<OtherOps>(Instruction::getOpcode());
824 /// Transparently provide more efficient getOperand methods.
825 Value *getOperand(unsigned i) const {
826 assert(i < 2 && "getOperand() out of range!");
829 void setOperand(unsigned i, Value *Val) {
830 assert(i < 2 && "setOperand() out of range!");
833 unsigned getNumOperands() const { return 2; }
835 /// isLogicalShift - Return true if this is a logical shift left or a logical
837 bool isLogicalShift() const {
838 unsigned opcode = getOpcode();
839 return opcode == Instruction::Shl || opcode == Instruction::LShr;
843 /// isArithmeticShift - Return true if this is a sign-extending shift right
845 bool isArithmeticShift() const {
846 return !isLogicalShift();
850 virtual ShiftInst *clone() const;
852 // Methods for support type inquiry through isa, cast, and dyn_cast:
853 static inline bool classof(const ShiftInst *) { return true; }
854 static inline bool classof(const Instruction *I) {
855 return (I->getOpcode() == Instruction::LShr) |
856 (I->getOpcode() == Instruction::AShr) |
857 (I->getOpcode() == Instruction::Shl);
859 static inline bool classof(const Value *V) {
860 return isa<Instruction>(V) && classof(cast<Instruction>(V));
864 //===----------------------------------------------------------------------===//
866 //===----------------------------------------------------------------------===//
868 /// SelectInst - This class represents the LLVM 'select' instruction.
870 class SelectInst : public Instruction {
873 void init(Value *C, Value *S1, Value *S2) {
874 Ops[0].init(C, this);
875 Ops[1].init(S1, this);
876 Ops[2].init(S2, this);
879 SelectInst(const SelectInst &SI)
880 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
881 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
884 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
885 Instruction *InsertBefore = 0)
886 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
887 Name, InsertBefore) {
890 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
891 BasicBlock *InsertAtEnd)
892 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
897 Value *getCondition() const { return Ops[0]; }
898 Value *getTrueValue() const { return Ops[1]; }
899 Value *getFalseValue() const { return Ops[2]; }
901 /// Transparently provide more efficient getOperand methods.
902 Value *getOperand(unsigned i) const {
903 assert(i < 3 && "getOperand() out of range!");
906 void setOperand(unsigned i, Value *Val) {
907 assert(i < 3 && "setOperand() out of range!");
910 unsigned getNumOperands() const { return 3; }
912 OtherOps getOpcode() const {
913 return static_cast<OtherOps>(Instruction::getOpcode());
916 virtual SelectInst *clone() const;
918 // Methods for support type inquiry through isa, cast, and dyn_cast:
919 static inline bool classof(const SelectInst *) { return true; }
920 static inline bool classof(const Instruction *I) {
921 return I->getOpcode() == Instruction::Select;
923 static inline bool classof(const Value *V) {
924 return isa<Instruction>(V) && classof(cast<Instruction>(V));
928 //===----------------------------------------------------------------------===//
930 //===----------------------------------------------------------------------===//
932 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
933 /// an argument of the specified type given a va_list and increments that list
935 class VAArgInst : public UnaryInstruction {
936 VAArgInst(const VAArgInst &VAA)
937 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
939 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
940 Instruction *InsertBefore = 0)
941 : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) {
943 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
944 BasicBlock *InsertAtEnd)
945 : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) {
948 virtual VAArgInst *clone() const;
949 bool mayWriteToMemory() const { return true; }
951 // Methods for support type inquiry through isa, cast, and dyn_cast:
952 static inline bool classof(const VAArgInst *) { return true; }
953 static inline bool classof(const Instruction *I) {
954 return I->getOpcode() == VAArg;
956 static inline bool classof(const Value *V) {
957 return isa<Instruction>(V) && classof(cast<Instruction>(V));
961 //===----------------------------------------------------------------------===//
962 // ExtractElementInst Class
963 //===----------------------------------------------------------------------===//
965 /// ExtractElementInst - This instruction extracts a single (scalar)
966 /// element from a PackedType value
968 class ExtractElementInst : public Instruction {
970 ExtractElementInst(const ExtractElementInst &EE) :
971 Instruction(EE.getType(), ExtractElement, Ops, 2) {
972 Ops[0].init(EE.Ops[0], this);
973 Ops[1].init(EE.Ops[1], this);
977 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
978 Instruction *InsertBefore = 0);
979 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
980 Instruction *InsertBefore = 0);
981 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
982 BasicBlock *InsertAtEnd);
983 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
984 BasicBlock *InsertAtEnd);
986 /// isValidOperands - Return true if an extractelement instruction can be
987 /// formed with the specified operands.
988 static bool isValidOperands(const Value *Vec, const Value *Idx);
990 virtual ExtractElementInst *clone() const;
992 virtual bool mayWriteToMemory() const { return false; }
994 /// Transparently provide more efficient getOperand methods.
995 Value *getOperand(unsigned i) const {
996 assert(i < 2 && "getOperand() out of range!");
999 void setOperand(unsigned i, Value *Val) {
1000 assert(i < 2 && "setOperand() out of range!");
1003 unsigned getNumOperands() const { return 2; }
1005 // Methods for support type inquiry through isa, cast, and dyn_cast:
1006 static inline bool classof(const ExtractElementInst *) { return true; }
1007 static inline bool classof(const Instruction *I) {
1008 return I->getOpcode() == Instruction::ExtractElement;
1010 static inline bool classof(const Value *V) {
1011 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1015 //===----------------------------------------------------------------------===//
1016 // InsertElementInst Class
1017 //===----------------------------------------------------------------------===//
1019 /// InsertElementInst - This instruction inserts a single (scalar)
1020 /// element into a PackedType value
1022 class InsertElementInst : public Instruction {
1024 InsertElementInst(const InsertElementInst &IE);
1026 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1027 const std::string &Name = "",Instruction *InsertBefore = 0);
1028 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1029 const std::string &Name = "",Instruction *InsertBefore = 0);
1030 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1031 const std::string &Name, BasicBlock *InsertAtEnd);
1032 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1033 const std::string &Name, BasicBlock *InsertAtEnd);
1035 /// isValidOperands - Return true if an insertelement instruction can be
1036 /// formed with the specified operands.
1037 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1040 virtual InsertElementInst *clone() const;
1042 virtual bool mayWriteToMemory() const { return false; }
1044 /// getType - Overload to return most specific packed type.
1046 inline const PackedType *getType() const {
1047 return reinterpret_cast<const PackedType*>(Instruction::getType());
1050 /// Transparently provide more efficient getOperand methods.
1051 Value *getOperand(unsigned i) const {
1052 assert(i < 3 && "getOperand() out of range!");
1055 void setOperand(unsigned i, Value *Val) {
1056 assert(i < 3 && "setOperand() out of range!");
1059 unsigned getNumOperands() const { return 3; }
1061 // Methods for support type inquiry through isa, cast, and dyn_cast:
1062 static inline bool classof(const InsertElementInst *) { return true; }
1063 static inline bool classof(const Instruction *I) {
1064 return I->getOpcode() == Instruction::InsertElement;
1066 static inline bool classof(const Value *V) {
1067 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1071 //===----------------------------------------------------------------------===//
1072 // ShuffleVectorInst Class
1073 //===----------------------------------------------------------------------===//
1075 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1078 class ShuffleVectorInst : public Instruction {
1080 ShuffleVectorInst(const ShuffleVectorInst &IE);
1082 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1083 const std::string &Name = "", Instruction *InsertBefor = 0);
1084 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1085 const std::string &Name, BasicBlock *InsertAtEnd);
1087 /// isValidOperands - Return true if a shufflevector instruction can be
1088 /// formed with the specified operands.
1089 static bool isValidOperands(const Value *V1, const Value *V2,
1092 virtual ShuffleVectorInst *clone() const;
1094 virtual bool mayWriteToMemory() const { return false; }
1096 /// getType - Overload to return most specific packed type.
1098 inline const PackedType *getType() const {
1099 return reinterpret_cast<const PackedType*>(Instruction::getType());
1102 /// Transparently provide more efficient getOperand methods.
1103 Value *getOperand(unsigned i) const {
1104 assert(i < 3 && "getOperand() out of range!");
1107 void setOperand(unsigned i, Value *Val) {
1108 assert(i < 3 && "setOperand() out of range!");
1111 unsigned getNumOperands() const { return 3; }
1113 // Methods for support type inquiry through isa, cast, and dyn_cast:
1114 static inline bool classof(const ShuffleVectorInst *) { return true; }
1115 static inline bool classof(const Instruction *I) {
1116 return I->getOpcode() == Instruction::ShuffleVector;
1118 static inline bool classof(const Value *V) {
1119 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1124 //===----------------------------------------------------------------------===//
1126 //===----------------------------------------------------------------------===//
1128 // PHINode - The PHINode class is used to represent the magical mystical PHI
1129 // node, that can not exist in nature, but can be synthesized in a computer
1130 // scientist's overactive imagination.
1132 class PHINode : public Instruction {
1133 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1134 /// the number actually in use.
1135 unsigned ReservedSpace;
1136 PHINode(const PHINode &PN);
1138 explicit PHINode(const Type *Ty, const std::string &Name = "",
1139 Instruction *InsertBefore = 0)
1140 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore),
1144 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1145 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
1151 /// reserveOperandSpace - This method can be used to avoid repeated
1152 /// reallocation of PHI operand lists by reserving space for the correct
1153 /// number of operands before adding them. Unlike normal vector reserves,
1154 /// this method can also be used to trim the operand space.
1155 void reserveOperandSpace(unsigned NumValues) {
1156 resizeOperands(NumValues*2);
1159 virtual PHINode *clone() const;
1161 /// getNumIncomingValues - Return the number of incoming edges
1163 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1165 /// getIncomingValue - Return incoming value number x
1167 Value *getIncomingValue(unsigned i) const {
1168 assert(i*2 < getNumOperands() && "Invalid value number!");
1169 return getOperand(i*2);
1171 void setIncomingValue(unsigned i, Value *V) {
1172 assert(i*2 < getNumOperands() && "Invalid value number!");
1175 unsigned getOperandNumForIncomingValue(unsigned i) {
1179 /// getIncomingBlock - Return incoming basic block number x
1181 BasicBlock *getIncomingBlock(unsigned i) const {
1182 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1184 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1185 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1187 unsigned getOperandNumForIncomingBlock(unsigned i) {
1191 /// addIncoming - Add an incoming value to the end of the PHI list
1193 void addIncoming(Value *V, BasicBlock *BB) {
1194 assert(getType() == V->getType() &&
1195 "All operands to PHI node must be the same type as the PHI node!");
1196 unsigned OpNo = NumOperands;
1197 if (OpNo+2 > ReservedSpace)
1198 resizeOperands(0); // Get more space!
1199 // Initialize some new operands.
1200 NumOperands = OpNo+2;
1201 OperandList[OpNo].init(V, this);
1202 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1205 /// removeIncomingValue - Remove an incoming value. This is useful if a
1206 /// predecessor basic block is deleted. The value removed is returned.
1208 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1209 /// is true), the PHI node is destroyed and any uses of it are replaced with
1210 /// dummy values. The only time there should be zero incoming values to a PHI
1211 /// node is when the block is dead, so this strategy is sound.
1213 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1215 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1216 int Idx = getBasicBlockIndex(BB);
1217 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1218 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1221 /// getBasicBlockIndex - Return the first index of the specified basic
1222 /// block in the value list for this PHI. Returns -1 if no instance.
1224 int getBasicBlockIndex(const BasicBlock *BB) const {
1225 Use *OL = OperandList;
1226 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1227 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1231 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1232 return getIncomingValue(getBasicBlockIndex(BB));
1235 /// hasConstantValue - If the specified PHI node always merges together the
1236 /// same value, return the value, otherwise return null.
1238 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1240 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1241 static inline bool classof(const PHINode *) { return true; }
1242 static inline bool classof(const Instruction *I) {
1243 return I->getOpcode() == Instruction::PHI;
1245 static inline bool classof(const Value *V) {
1246 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1249 void resizeOperands(unsigned NumOperands);
1252 //===----------------------------------------------------------------------===//
1254 //===----------------------------------------------------------------------===//
1256 //===---------------------------------------------------------------------------
1257 /// ReturnInst - Return a value (possibly void), from a function. Execution
1258 /// does not continue in this function any longer.
1260 class ReturnInst : public TerminatorInst {
1261 Use RetVal; // Possibly null retval.
1262 ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
1263 RI.getNumOperands()) {
1264 if (RI.getNumOperands())
1265 RetVal.init(RI.RetVal, this);
1268 void init(Value *RetVal);
1271 // ReturnInst constructors:
1272 // ReturnInst() - 'ret void' instruction
1273 // ReturnInst( null) - 'ret void' instruction
1274 // ReturnInst(Value* X) - 'ret X' instruction
1275 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1276 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1277 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1278 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1280 // NOTE: If the Value* passed is of type void then the constructor behaves as
1281 // if it was passed NULL.
1282 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
1283 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
1286 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
1287 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1290 explicit ReturnInst(BasicBlock *InsertAtEnd)
1291 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1294 virtual ReturnInst *clone() const;
1296 // Transparently provide more efficient getOperand methods.
1297 Value *getOperand(unsigned i) const {
1298 assert(i < getNumOperands() && "getOperand() out of range!");
1301 void setOperand(unsigned i, Value *Val) {
1302 assert(i < getNumOperands() && "setOperand() out of range!");
1306 Value *getReturnValue() const { return RetVal; }
1308 unsigned getNumSuccessors() const { return 0; }
1310 // Methods for support type inquiry through isa, cast, and dyn_cast:
1311 static inline bool classof(const ReturnInst *) { return true; }
1312 static inline bool classof(const Instruction *I) {
1313 return (I->getOpcode() == Instruction::Ret);
1315 static inline bool classof(const Value *V) {
1316 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1319 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1320 virtual unsigned getNumSuccessorsV() const;
1321 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1324 //===----------------------------------------------------------------------===//
1326 //===----------------------------------------------------------------------===//
1328 //===---------------------------------------------------------------------------
1329 /// BranchInst - Conditional or Unconditional Branch instruction.
1331 class BranchInst : public TerminatorInst {
1332 /// Ops list - Branches are strange. The operands are ordered:
1333 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1334 /// they don't have to check for cond/uncond branchness.
1336 BranchInst(const BranchInst &BI);
1339 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1340 // BranchInst(BB *B) - 'br B'
1341 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1342 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1343 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1344 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1345 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1346 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
1347 : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
1348 assert(IfTrue != 0 && "Branch destination may not be null!");
1349 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1351 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1352 Instruction *InsertBefore = 0)
1353 : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
1354 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1355 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1356 Ops[2].init(Cond, this);
1362 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
1363 : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
1364 assert(IfTrue != 0 && "Branch destination may not be null!");
1365 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1368 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1369 BasicBlock *InsertAtEnd)
1370 : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
1371 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1372 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1373 Ops[2].init(Cond, this);
1380 /// Transparently provide more efficient getOperand methods.
1381 Value *getOperand(unsigned i) const {
1382 assert(i < getNumOperands() && "getOperand() out of range!");
1385 void setOperand(unsigned i, Value *Val) {
1386 assert(i < getNumOperands() && "setOperand() out of range!");
1390 virtual BranchInst *clone() const;
1392 inline bool isUnconditional() const { return getNumOperands() == 1; }
1393 inline bool isConditional() const { return getNumOperands() == 3; }
1395 inline Value *getCondition() const {
1396 assert(isConditional() && "Cannot get condition of an uncond branch!");
1397 return getOperand(2);
1400 void setCondition(Value *V) {
1401 assert(isConditional() && "Cannot set condition of unconditional branch!");
1405 // setUnconditionalDest - Change the current branch to an unconditional branch
1406 // targeting the specified block.
1407 // FIXME: Eliminate this ugly method.
1408 void setUnconditionalDest(BasicBlock *Dest) {
1409 if (isConditional()) { // Convert this to an uncond branch.
1414 setOperand(0, reinterpret_cast<Value*>(Dest));
1417 unsigned getNumSuccessors() const { return 1+isConditional(); }
1419 BasicBlock *getSuccessor(unsigned i) const {
1420 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1421 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1422 cast<BasicBlock>(getOperand(1));
1425 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1426 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1427 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1430 // Methods for support type inquiry through isa, cast, and dyn_cast:
1431 static inline bool classof(const BranchInst *) { return true; }
1432 static inline bool classof(const Instruction *I) {
1433 return (I->getOpcode() == Instruction::Br);
1435 static inline bool classof(const Value *V) {
1436 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1439 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1440 virtual unsigned getNumSuccessorsV() const;
1441 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1444 //===----------------------------------------------------------------------===//
1446 //===----------------------------------------------------------------------===//
1448 //===---------------------------------------------------------------------------
1449 /// SwitchInst - Multiway switch
1451 class SwitchInst : public TerminatorInst {
1452 unsigned ReservedSpace;
1453 // Operand[0] = Value to switch on
1454 // Operand[1] = Default basic block destination
1455 // Operand[2n ] = Value to match
1456 // Operand[2n+1] = BasicBlock to go to on match
1457 SwitchInst(const SwitchInst &RI);
1458 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1459 void resizeOperands(unsigned No);
1461 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1462 /// switch on and a default destination. The number of additional cases can
1463 /// be specified here to make memory allocation more efficient. This
1464 /// constructor can also autoinsert before another instruction.
1465 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1466 Instruction *InsertBefore = 0)
1467 : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1468 init(Value, Default, NumCases);
1471 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1472 /// switch on and a default destination. The number of additional cases can
1473 /// be specified here to make memory allocation more efficient. This
1474 /// constructor also autoinserts at the end of the specified BasicBlock.
1475 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1476 BasicBlock *InsertAtEnd)
1477 : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1478 init(Value, Default, NumCases);
1483 // Accessor Methods for Switch stmt
1484 inline Value *getCondition() const { return getOperand(0); }
1485 void setCondition(Value *V) { setOperand(0, V); }
1487 inline BasicBlock *getDefaultDest() const {
1488 return cast<BasicBlock>(getOperand(1));
1491 /// getNumCases - return the number of 'cases' in this switch instruction.
1492 /// Note that case #0 is always the default case.
1493 unsigned getNumCases() const {
1494 return getNumOperands()/2;
1497 /// getCaseValue - Return the specified case value. Note that case #0, the
1498 /// default destination, does not have a case value.
1499 ConstantInt *getCaseValue(unsigned i) {
1500 assert(i && i < getNumCases() && "Illegal case value to get!");
1501 return getSuccessorValue(i);
1504 /// getCaseValue - Return the specified case value. Note that case #0, the
1505 /// default destination, does not have a case value.
1506 const ConstantInt *getCaseValue(unsigned i) const {
1507 assert(i && i < getNumCases() && "Illegal case value to get!");
1508 return getSuccessorValue(i);
1511 /// findCaseValue - Search all of the case values for the specified constant.
1512 /// If it is explicitly handled, return the case number of it, otherwise
1513 /// return 0 to indicate that it is handled by the default handler.
1514 unsigned findCaseValue(const ConstantInt *C) const {
1515 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1516 if (getCaseValue(i) == C)
1521 /// findCaseDest - Finds the unique case value for a given successor. Returns
1522 /// null if the successor is not found, not unique, or is the default case.
1523 ConstantInt *findCaseDest(BasicBlock *BB) {
1524 if (BB == getDefaultDest()) return NULL;
1526 ConstantInt *CI = NULL;
1527 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1528 if (getSuccessor(i) == BB) {
1529 if (CI) return NULL; // Multiple cases lead to BB.
1530 else CI = getCaseValue(i);
1536 /// addCase - Add an entry to the switch instruction...
1538 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1540 /// removeCase - This method removes the specified successor from the switch
1541 /// instruction. Note that this cannot be used to remove the default
1542 /// destination (successor #0).
1544 void removeCase(unsigned idx);
1546 virtual SwitchInst *clone() const;
1548 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1549 BasicBlock *getSuccessor(unsigned idx) const {
1550 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1551 return cast<BasicBlock>(getOperand(idx*2+1));
1553 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1554 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1555 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1558 // getSuccessorValue - Return the value associated with the specified
1560 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1561 assert(idx < getNumSuccessors() && "Successor # out of range!");
1562 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1565 // Methods for support type inquiry through isa, cast, and dyn_cast:
1566 static inline bool classof(const SwitchInst *) { return true; }
1567 static inline bool classof(const Instruction *I) {
1568 return I->getOpcode() == Instruction::Switch;
1570 static inline bool classof(const Value *V) {
1571 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1574 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1575 virtual unsigned getNumSuccessorsV() const;
1576 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1579 //===----------------------------------------------------------------------===//
1581 //===----------------------------------------------------------------------===//
1583 //===---------------------------------------------------------------------------
1585 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1586 /// calling convention of the call.
1588 class InvokeInst : public TerminatorInst {
1589 InvokeInst(const InvokeInst &BI);
1590 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1591 const std::vector<Value*> &Params);
1593 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1594 const std::vector<Value*> &Params, const std::string &Name = "",
1595 Instruction *InsertBefore = 0);
1596 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1597 const std::vector<Value*> &Params, const std::string &Name,
1598 BasicBlock *InsertAtEnd);
1601 virtual InvokeInst *clone() const;
1603 bool mayWriteToMemory() const { return true; }
1605 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1607 unsigned getCallingConv() const { return SubclassData; }
1608 void setCallingConv(unsigned CC) {
1612 /// getCalledFunction - Return the function called, or null if this is an
1613 /// indirect function invocation.
1615 Function *getCalledFunction() const {
1616 return dyn_cast<Function>(getOperand(0));
1619 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1620 inline Value *getCalledValue() const { return getOperand(0); }
1622 // get*Dest - Return the destination basic blocks...
1623 BasicBlock *getNormalDest() const {
1624 return cast<BasicBlock>(getOperand(1));
1626 BasicBlock *getUnwindDest() const {
1627 return cast<BasicBlock>(getOperand(2));
1629 void setNormalDest(BasicBlock *B) {
1630 setOperand(1, reinterpret_cast<Value*>(B));
1633 void setUnwindDest(BasicBlock *B) {
1634 setOperand(2, reinterpret_cast<Value*>(B));
1637 inline BasicBlock *getSuccessor(unsigned i) const {
1638 assert(i < 2 && "Successor # out of range for invoke!");
1639 return i == 0 ? getNormalDest() : getUnwindDest();
1642 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1643 assert(idx < 2 && "Successor # out of range for invoke!");
1644 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1647 unsigned getNumSuccessors() const { return 2; }
1649 // Methods for support type inquiry through isa, cast, and dyn_cast:
1650 static inline bool classof(const InvokeInst *) { return true; }
1651 static inline bool classof(const Instruction *I) {
1652 return (I->getOpcode() == Instruction::Invoke);
1654 static inline bool classof(const Value *V) {
1655 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1658 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1659 virtual unsigned getNumSuccessorsV() const;
1660 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1664 //===----------------------------------------------------------------------===//
1666 //===----------------------------------------------------------------------===//
1668 //===---------------------------------------------------------------------------
1669 /// UnwindInst - Immediately exit the current function, unwinding the stack
1670 /// until an invoke instruction is found.
1672 class UnwindInst : public TerminatorInst {
1674 explicit UnwindInst(Instruction *InsertBefore = 0)
1675 : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
1677 explicit UnwindInst(BasicBlock *InsertAtEnd)
1678 : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
1681 virtual UnwindInst *clone() const;
1683 unsigned getNumSuccessors() const { return 0; }
1685 // Methods for support type inquiry through isa, cast, and dyn_cast:
1686 static inline bool classof(const UnwindInst *) { return true; }
1687 static inline bool classof(const Instruction *I) {
1688 return I->getOpcode() == Instruction::Unwind;
1690 static inline bool classof(const Value *V) {
1691 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1694 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1695 virtual unsigned getNumSuccessorsV() const;
1696 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1699 //===----------------------------------------------------------------------===//
1700 // UnreachableInst Class
1701 //===----------------------------------------------------------------------===//
1703 //===---------------------------------------------------------------------------
1704 /// UnreachableInst - This function has undefined behavior. In particular, the
1705 /// presence of this instruction indicates some higher level knowledge that the
1706 /// end of the block cannot be reached.
1708 class UnreachableInst : public TerminatorInst {
1710 explicit UnreachableInst(Instruction *InsertBefore = 0)
1711 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
1713 explicit UnreachableInst(BasicBlock *InsertAtEnd)
1714 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
1717 virtual UnreachableInst *clone() const;
1719 unsigned getNumSuccessors() const { return 0; }
1721 // Methods for support type inquiry through isa, cast, and dyn_cast:
1722 static inline bool classof(const UnreachableInst *) { return true; }
1723 static inline bool classof(const Instruction *I) {
1724 return I->getOpcode() == Instruction::Unreachable;
1726 static inline bool classof(const Value *V) {
1727 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1730 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1731 virtual unsigned getNumSuccessorsV() const;
1732 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1735 //===----------------------------------------------------------------------===//
1737 //===----------------------------------------------------------------------===//
1739 /// @brief This class represents a truncation of integer types.
1740 class TruncInst : public CastInst {
1741 /// Private copy constructor
1742 TruncInst(const TruncInst &CI)
1743 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1746 /// @brief Constructor with insert-before-instruction semantics
1748 Value *S, ///< The value to be truncated
1749 const Type *Ty, ///< The (smaller) type to truncate to
1750 const std::string &Name = "", ///< A name for the new instruction
1751 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1754 /// @brief Constructor with insert-at-end-of-block semantics
1756 Value *S, ///< The value to be truncated
1757 const Type *Ty, ///< The (smaller) type to truncate to
1758 const std::string &Name, ///< A name for the new instruction
1759 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1762 /// @brief Clone an identical TruncInst
1763 virtual CastInst *clone() const;
1765 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1766 static inline bool classof(const TruncInst *) { return true; }
1767 static inline bool classof(const Instruction *I) {
1768 return I->getOpcode() == Trunc;
1770 static inline bool classof(const Value *V) {
1771 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1775 //===----------------------------------------------------------------------===//
1777 //===----------------------------------------------------------------------===//
1779 /// @brief This class represents zero extension of integer types.
1780 class ZExtInst : public CastInst {
1781 /// @brief Private copy constructor
1782 ZExtInst(const ZExtInst &CI)
1783 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1786 /// @brief Constructor with insert-before-instruction semantics
1788 Value *S, ///< The value to be zero extended
1789 const Type *Ty, ///< The type to zero extend to
1790 const std::string &Name = "", ///< A name for the new instruction
1791 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1794 /// @brief Constructor with insert-at-end semantics.
1796 Value *S, ///< The value to be zero extended
1797 const Type *Ty, ///< The type to zero extend to
1798 const std::string &Name, ///< A name for the new instruction
1799 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1802 /// @brief Clone an identical ZExtInst
1803 virtual CastInst *clone() const;
1805 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1806 static inline bool classof(const ZExtInst *) { return true; }
1807 static inline bool classof(const Instruction *I) {
1808 return I->getOpcode() == ZExt;
1810 static inline bool classof(const Value *V) {
1811 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1815 //===----------------------------------------------------------------------===//
1817 //===----------------------------------------------------------------------===//
1819 /// @brief This class represents a sign extension of integer types.
1820 class SExtInst : public CastInst {
1821 /// @brief Private copy constructor
1822 SExtInst(const SExtInst &CI)
1823 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1826 /// @brief Constructor with insert-before-instruction semantics
1828 Value *S, ///< The value to be sign extended
1829 const Type *Ty, ///< The type to sign extend to
1830 const std::string &Name = "", ///< A name for the new instruction
1831 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1834 /// @brief Constructor with insert-at-end-of-block semantics
1836 Value *S, ///< The value to be sign extended
1837 const Type *Ty, ///< The type to sign extend to
1838 const std::string &Name, ///< A name for the new instruction
1839 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1842 /// @brief Clone an identical SExtInst
1843 virtual CastInst *clone() const;
1845 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1846 static inline bool classof(const SExtInst *) { return true; }
1847 static inline bool classof(const Instruction *I) {
1848 return I->getOpcode() == SExt;
1850 static inline bool classof(const Value *V) {
1851 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1855 //===----------------------------------------------------------------------===//
1856 // FPTruncInst Class
1857 //===----------------------------------------------------------------------===//
1859 /// @brief This class represents a truncation of floating point types.
1860 class FPTruncInst : public CastInst {
1861 FPTruncInst(const FPTruncInst &CI)
1862 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1865 /// @brief Constructor with insert-before-instruction semantics
1867 Value *S, ///< The value to be truncated
1868 const Type *Ty, ///< The type to truncate to
1869 const std::string &Name = "", ///< A name for the new instruction
1870 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1873 /// @brief Constructor with insert-before-instruction semantics
1875 Value *S, ///< The value to be truncated
1876 const Type *Ty, ///< The type to truncate to
1877 const std::string &Name, ///< A name for the new instruction
1878 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1881 /// @brief Clone an identical FPTruncInst
1882 virtual CastInst *clone() const;
1884 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1885 static inline bool classof(const FPTruncInst *) { return true; }
1886 static inline bool classof(const Instruction *I) {
1887 return I->getOpcode() == FPTrunc;
1889 static inline bool classof(const Value *V) {
1890 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1894 //===----------------------------------------------------------------------===//
1896 //===----------------------------------------------------------------------===//
1898 /// @brief This class represents an extension of floating point types.
1899 class FPExtInst : public CastInst {
1900 FPExtInst(const FPExtInst &CI)
1901 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1904 /// @brief Constructor with insert-before-instruction semantics
1906 Value *S, ///< The value to be extended
1907 const Type *Ty, ///< The type to extend to
1908 const std::string &Name = "", ///< A name for the new instruction
1909 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1912 /// @brief Constructor with insert-at-end-of-block semantics
1914 Value *S, ///< The value to be extended
1915 const Type *Ty, ///< The type to extend to
1916 const std::string &Name, ///< A name for the new instruction
1917 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1920 /// @brief Clone an identical FPExtInst
1921 virtual CastInst *clone() const;
1923 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1924 static inline bool classof(const FPExtInst *) { return true; }
1925 static inline bool classof(const Instruction *I) {
1926 return I->getOpcode() == FPExt;
1928 static inline bool classof(const Value *V) {
1929 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1933 //===----------------------------------------------------------------------===//
1935 //===----------------------------------------------------------------------===//
1937 /// @brief This class represents a cast unsigned integer to floating point.
1938 class UIToFPInst : public CastInst {
1939 UIToFPInst(const UIToFPInst &CI)
1940 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1943 /// @brief Constructor with insert-before-instruction semantics
1945 Value *S, ///< The value to be converted
1946 const Type *Ty, ///< The type to convert to
1947 const std::string &Name = "", ///< A name for the new instruction
1948 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1951 /// @brief Constructor with insert-at-end-of-block semantics
1953 Value *S, ///< The value to be converted
1954 const Type *Ty, ///< The type to convert to
1955 const std::string &Name, ///< A name for the new instruction
1956 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1959 /// @brief Clone an identical UIToFPInst
1960 virtual CastInst *clone() const;
1962 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1963 static inline bool classof(const UIToFPInst *) { return true; }
1964 static inline bool classof(const Instruction *I) {
1965 return I->getOpcode() == UIToFP;
1967 static inline bool classof(const Value *V) {
1968 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1972 //===----------------------------------------------------------------------===//
1974 //===----------------------------------------------------------------------===//
1976 /// @brief This class represents a cast from signed integer to floating point.
1977 class SIToFPInst : public CastInst {
1978 SIToFPInst(const SIToFPInst &CI)
1979 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1982 /// @brief Constructor with insert-before-instruction semantics
1984 Value *S, ///< The value to be converted
1985 const Type *Ty, ///< The type to convert to
1986 const std::string &Name = "", ///< A name for the new instruction
1987 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1990 /// @brief Constructor with insert-at-end-of-block semantics
1992 Value *S, ///< The value to be converted
1993 const Type *Ty, ///< The type to convert to
1994 const std::string &Name, ///< A name for the new instruction
1995 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1998 /// @brief Clone an identical SIToFPInst
1999 virtual CastInst *clone() const;
2001 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2002 static inline bool classof(const SIToFPInst *) { return true; }
2003 static inline bool classof(const Instruction *I) {
2004 return I->getOpcode() == SIToFP;
2006 static inline bool classof(const Value *V) {
2007 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2011 //===----------------------------------------------------------------------===//
2013 //===----------------------------------------------------------------------===//
2015 /// @brief This class represents a cast from floating point to unsigned integer
2016 class FPToUIInst : public CastInst {
2017 FPToUIInst(const FPToUIInst &CI)
2018 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
2021 /// @brief Constructor with insert-before-instruction semantics
2023 Value *S, ///< The value to be converted
2024 const Type *Ty, ///< The type to convert to
2025 const std::string &Name = "", ///< A name for the new instruction
2026 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2029 /// @brief Constructor with insert-at-end-of-block semantics
2031 Value *S, ///< The value to be converted
2032 const Type *Ty, ///< The type to convert to
2033 const std::string &Name, ///< A name for the new instruction
2034 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
2037 /// @brief Clone an identical FPToUIInst
2038 virtual CastInst *clone() const;
2040 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2041 static inline bool classof(const FPToUIInst *) { return true; }
2042 static inline bool classof(const Instruction *I) {
2043 return I->getOpcode() == FPToUI;
2045 static inline bool classof(const Value *V) {
2046 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2050 //===----------------------------------------------------------------------===//
2052 //===----------------------------------------------------------------------===//
2054 /// @brief This class represents a cast from floating point to signed integer.
2055 class FPToSIInst : public CastInst {
2056 FPToSIInst(const FPToSIInst &CI)
2057 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2060 /// @brief Constructor with insert-before-instruction semantics
2062 Value *S, ///< The value to be converted
2063 const Type *Ty, ///< The type to convert to
2064 const std::string &Name = "", ///< A name for the new instruction
2065 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2068 /// @brief Constructor with insert-at-end-of-block semantics
2070 Value *S, ///< The value to be converted
2071 const Type *Ty, ///< The type to convert to
2072 const std::string &Name, ///< A name for the new instruction
2073 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2076 /// @brief Clone an identical FPToSIInst
2077 virtual CastInst *clone() const;
2079 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2080 static inline bool classof(const FPToSIInst *) { return true; }
2081 static inline bool classof(const Instruction *I) {
2082 return I->getOpcode() == FPToSI;
2084 static inline bool classof(const Value *V) {
2085 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2089 //===----------------------------------------------------------------------===//
2090 // IntToPtrInst Class
2091 //===----------------------------------------------------------------------===//
2093 /// @brief This class represents a cast from an integer to a pointer.
2094 class IntToPtrInst : public CastInst {
2095 IntToPtrInst(const IntToPtrInst &CI)
2096 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2099 /// @brief Constructor with insert-before-instruction semantics
2101 Value *S, ///< The value to be converted
2102 const Type *Ty, ///< The type to convert to
2103 const std::string &Name = "", ///< A name for the new instruction
2104 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2107 /// @brief Constructor with insert-at-end-of-block semantics
2109 Value *S, ///< The value to be converted
2110 const Type *Ty, ///< The type to convert to
2111 const std::string &Name, ///< A name for the new instruction
2112 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2115 /// @brief Clone an identical IntToPtrInst
2116 virtual CastInst *clone() const;
2118 // Methods for support type inquiry through isa, cast, and dyn_cast:
2119 static inline bool classof(const IntToPtrInst *) { return true; }
2120 static inline bool classof(const Instruction *I) {
2121 return I->getOpcode() == IntToPtr;
2123 static inline bool classof(const Value *V) {
2124 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2128 //===----------------------------------------------------------------------===//
2129 // PtrToIntInst Class
2130 //===----------------------------------------------------------------------===//
2132 /// @brief This class represents a cast from a pointer to an integer
2133 class PtrToIntInst : public CastInst {
2134 PtrToIntInst(const PtrToIntInst &CI)
2135 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2138 /// @brief Constructor with insert-before-instruction semantics
2140 Value *S, ///< The value to be converted
2141 const Type *Ty, ///< The type to convert to
2142 const std::string &Name = "", ///< A name for the new instruction
2143 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2146 /// @brief Constructor with insert-at-end-of-block semantics
2148 Value *S, ///< The value to be converted
2149 const Type *Ty, ///< The type to convert to
2150 const std::string &Name, ///< A name for the new instruction
2151 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2154 /// @brief Clone an identical PtrToIntInst
2155 virtual CastInst *clone() const;
2157 // Methods for support type inquiry through isa, cast, and dyn_cast:
2158 static inline bool classof(const PtrToIntInst *) { return true; }
2159 static inline bool classof(const Instruction *I) {
2160 return I->getOpcode() == PtrToInt;
2162 static inline bool classof(const Value *V) {
2163 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2167 //===----------------------------------------------------------------------===//
2168 // BitCastInst Class
2169 //===----------------------------------------------------------------------===//
2171 /// @brief This class represents a no-op cast from one type to another.
2172 class BitCastInst : public CastInst {
2173 BitCastInst(const BitCastInst &CI)
2174 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2177 /// @brief Constructor with insert-before-instruction semantics
2179 Value *S, ///< The value to be casted
2180 const Type *Ty, ///< The type to casted to
2181 const std::string &Name = "", ///< A name for the new instruction
2182 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2185 /// @brief Constructor with insert-at-end-of-block semantics
2187 Value *S, ///< The value to be casted
2188 const Type *Ty, ///< The type to casted to
2189 const std::string &Name, ///< A name for the new instruction
2190 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2193 /// @brief Clone an identical BitCastInst
2194 virtual CastInst *clone() const;
2196 // Methods for support type inquiry through isa, cast, and dyn_cast:
2197 static inline bool classof(const BitCastInst *) { return true; }
2198 static inline bool classof(const Instruction *I) {
2199 return I->getOpcode() == BitCast;
2201 static inline bool classof(const Value *V) {
2202 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2206 } // End llvm namespace