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 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
471 /// @returns the inverse predicate for the instruction's current predicate.
472 /// @brief Return the inverse of the instruction's predicate.
473 Predicate getInversePredicate() const {
474 return getInversePredicate(getPredicate());
477 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
478 /// @returns the inverse predicate for predicate provided in \p pred.
479 /// @brief Return the inverse of a given predicate
480 static Predicate getInversePredicate(Predicate pred);
482 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
483 /// @returns the predicate that would be the result of exchanging the two
484 /// operands of the ICmpInst instruction without changing the result
486 /// @brief Return the predicate as if the operands were swapped
487 Predicate getSwappedPredicate() const {
488 return getSwappedPredicate(getPredicate());
491 /// This is a static version that you can use without an instruction
493 /// @brief Return the predicate as if the operands were swapped.
494 static Predicate getSwappedPredicate(Predicate pred);
496 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
497 /// @returns the predicate that would be the result if the operand were
498 /// regarded as signed.
499 /// @brief Return the signed version of the predicate
500 Predicate getSignedPredicate() const {
501 return getSignedPredicate(getPredicate());
504 /// This is a static version that you can use without an instruction.
505 /// @brief Return the signed version of the predicate.
506 static Predicate getSignedPredicate(Predicate pred);
508 /// This also tests for commutativity. If isEquality() returns true then
509 /// the predicate is also commutative.
510 /// @returns true if the predicate of this instruction is EQ or NE.
511 /// @brief Determine if this is an equality predicate.
512 bool isEquality() const {
513 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
516 /// @returns true if the predicate of this ICmpInst is commutative
517 /// @brief Determine if this relation is commutative.
518 bool isCommutative() const { return isEquality(); }
520 /// @returns true if the predicate is relational (not EQ or NE).
521 /// @brief Determine if this a relational predicate.
522 bool isRelational() const {
523 return !isEquality();
526 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
527 /// @brief Determine if this instruction's predicate is signed.
528 bool isSignedPredicate() { return isSignedPredicate(getPredicate()); }
530 /// @returns true if the predicate provided is signed, false otherwise
531 /// @brief Determine if the predicate is signed.
532 static bool isSignedPredicate(Predicate pred);
534 /// Exchange the two operands to this instruction in such a way that it does
535 /// not modify the semantics of the instruction. The predicate value may be
536 /// changed to retain the same result if the predicate is order dependent
538 /// @brief Swap operands and adjust predicate.
539 void swapOperands() {
540 SubclassData = getSwappedPredicate();
541 std::swap(Ops[0], Ops[1]);
544 // Methods for support type inquiry through isa, cast, and dyn_cast:
545 static inline bool classof(const ICmpInst *) { return true; }
546 static inline bool classof(const Instruction *I) {
547 return I->getOpcode() == Instruction::ICmp;
549 static inline bool classof(const Value *V) {
550 return isa<Instruction>(V) && classof(cast<Instruction>(V));
554 //===----------------------------------------------------------------------===//
556 //===----------------------------------------------------------------------===//
558 /// This instruction compares its operands according to the predicate given
559 /// to the constructor. It only operates on floating point values or packed
560 /// vectors of floating point values. The operands must be identical types.
561 /// @brief Represents a floating point comparison operator.
562 class FCmpInst: public CmpInst {
564 /// This enumeration lists the possible predicates for the FCmpInst. Values
565 /// in the range 0-31 are reserved for FCmpInst.
567 // Opcode U L G E Intuitive operation
568 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
569 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
570 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
571 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
572 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
573 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
574 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
575 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
576 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
577 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
578 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
579 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
580 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
581 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
582 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
583 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
584 FIRST_FCMP_PREDICATE = FCMP_FALSE,
585 LAST_FCMP_PREDICATE = FCMP_TRUE,
586 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
589 /// @brief Constructor with insert-before-instruction semantics.
591 Predicate pred, ///< The predicate to use for the comparison
592 Value *LHS, ///< The left-hand-side of the expression
593 Value *RHS, ///< The right-hand-side of the expression
594 const std::string &Name = "", ///< Name of the instruction
595 Instruction *InsertBefore = 0 ///< Where to insert
596 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
599 /// @brief Constructor with insert-at-block-end semantics.
601 Predicate pred, ///< The predicate to use for the comparison
602 Value *LHS, ///< The left-hand-side of the expression
603 Value *RHS, ///< The right-hand-side of the expression
604 const std::string &Name, ///< Name of the instruction
605 BasicBlock *InsertAtEnd ///< Block to insert into.
606 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
609 /// @brief Return the predicate for this instruction.
610 Predicate getPredicate() const { return Predicate(SubclassData); }
612 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
613 /// @returns the inverse predicate for the instructions current predicate.
614 /// @brief Return the inverse of the predicate
615 Predicate getInversePredicate() const {
616 return getInversePredicate(getPredicate());
619 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
620 /// @returns the inverse predicate for \p pred.
621 /// @brief Return the inverse of a given predicate
622 static Predicate getInversePredicate(Predicate pred);
624 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
625 /// @returns the predicate that would be the result of exchanging the two
626 /// operands of the ICmpInst instruction without changing the result
628 /// @brief Return the predicate as if the operands were swapped
629 Predicate getSwappedPredicate() const {
630 return getSwappedPredicate(getPredicate());
633 /// This is a static version that you can use without an instruction
635 /// @brief Return the predicate as if the operands were swapped.
636 static Predicate getSwappedPredicate(Predicate Opcode);
638 /// This also tests for commutativity. If isEquality() returns true then
639 /// the predicate is also commutative. Only the equality predicates are
641 /// @returns true if the predicate of this instruction is EQ or NE.
642 /// @brief Determine if this is an equality predicate.
643 bool isEquality() const {
644 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
645 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
647 bool isCommutative() const { return isEquality(); }
649 /// @returns true if the predicate is relational (not EQ or NE).
650 /// @brief Determine if this a relational predicate.
651 bool isRelational() const { return !isEquality(); }
653 /// Exchange the two operands to this instruction in such a way that it does
654 /// not modify the semantics of the instruction. The predicate value may be
655 /// changed to retain the same result if the predicate is order dependent
657 /// @brief Swap operands and adjust predicate.
658 void swapOperands() {
659 SubclassData = getSwappedPredicate();
660 std::swap(Ops[0], Ops[1]);
663 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
664 static inline bool classof(const FCmpInst *) { return true; }
665 static inline bool classof(const Instruction *I) {
666 return I->getOpcode() == Instruction::FCmp;
668 static inline bool classof(const Value *V) {
669 return isa<Instruction>(V) && classof(cast<Instruction>(V));
673 //===----------------------------------------------------------------------===//
675 //===----------------------------------------------------------------------===//
677 /// CallInst - This class represents a function call, abstracting a target
678 /// machine's calling convention. This class uses low bit of the SubClassData
679 /// field to indicate whether or not this is a tail call. The rest of the bits
680 /// hold the calling convention of the call.
682 class CallInst : public Instruction {
683 CallInst(const CallInst &CI);
684 void init(Value *Func, const std::vector<Value*> &Params);
685 void init(Value *Func, Value *Actual1, Value *Actual2);
686 void init(Value *Func, Value *Actual);
687 void init(Value *Func);
690 CallInst(Value *F, const std::vector<Value*> &Par,
691 const std::string &Name = "", Instruction *InsertBefore = 0);
692 CallInst(Value *F, const std::vector<Value*> &Par,
693 const std::string &Name, BasicBlock *InsertAtEnd);
695 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
696 // actuals, respectively.
697 CallInst(Value *F, Value *Actual1, Value *Actual2,
698 const std::string& Name = "", Instruction *InsertBefore = 0);
699 CallInst(Value *F, Value *Actual1, Value *Actual2,
700 const std::string& Name, BasicBlock *InsertAtEnd);
701 CallInst(Value *F, Value *Actual, const std::string& Name = "",
702 Instruction *InsertBefore = 0);
703 CallInst(Value *F, Value *Actual, const std::string& Name,
704 BasicBlock *InsertAtEnd);
705 explicit CallInst(Value *F, const std::string &Name = "",
706 Instruction *InsertBefore = 0);
707 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
710 virtual CallInst *clone() const;
711 bool mayWriteToMemory() const { return true; }
713 bool isTailCall() const { return SubclassData & 1; }
714 void setTailCall(bool isTailCall = true) {
715 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
718 /// getCallingConv/setCallingConv - Get or set the calling convention of this
720 unsigned getCallingConv() const { return SubclassData >> 1; }
721 void setCallingConv(unsigned CC) {
722 SubclassData = (SubclassData & 1) | (CC << 1);
725 /// getCalledFunction - Return the function being called by this instruction
726 /// if it is a direct call. If it is a call through a function pointer,
728 Function *getCalledFunction() const {
729 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
732 /// getCalledValue - Get a pointer to the function that is invoked by this
734 inline const Value *getCalledValue() const { return getOperand(0); }
735 inline Value *getCalledValue() { return getOperand(0); }
737 // Methods for support type inquiry through isa, cast, and dyn_cast:
738 static inline bool classof(const CallInst *) { return true; }
739 static inline bool classof(const Instruction *I) {
740 return I->getOpcode() == Instruction::Call;
742 static inline bool classof(const Value *V) {
743 return isa<Instruction>(V) && classof(cast<Instruction>(V));
748 //===----------------------------------------------------------------------===//
750 //===----------------------------------------------------------------------===//
752 /// ShiftInst - This class represents left and right shift instructions.
754 class ShiftInst : public Instruction {
756 ShiftInst(const ShiftInst &SI)
757 : Instruction(SI.getType(), SI.getOpcode(), Ops, 2) {
758 Ops[0].init(SI.Ops[0], this);
759 Ops[1].init(SI.Ops[1], this);
761 void init(OtherOps Opcode, Value *S, Value *SA) {
762 assert((Opcode == Shl || Opcode == LShr || Opcode == AShr) &&
763 "ShiftInst Opcode invalid!");
764 Ops[0].init(S, this);
765 Ops[1].init(SA, this);
769 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
770 Instruction *InsertBefore = 0)
771 : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertBefore) {
774 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
775 BasicBlock *InsertAtEnd)
776 : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertAtEnd) {
780 OtherOps getOpcode() const {
781 return static_cast<OtherOps>(Instruction::getOpcode());
784 /// Transparently provide more efficient getOperand methods.
785 Value *getOperand(unsigned i) const {
786 assert(i < 2 && "getOperand() out of range!");
789 void setOperand(unsigned i, Value *Val) {
790 assert(i < 2 && "setOperand() out of range!");
793 unsigned getNumOperands() const { return 2; }
795 /// isLogicalShift - Return true if this is a logical shift left or a logical
797 bool isLogicalShift() const {
798 unsigned opcode = getOpcode();
799 return opcode == Instruction::Shl || opcode == Instruction::LShr;
803 /// isArithmeticShift - Return true if this is a sign-extending shift right
805 bool isArithmeticShift() const {
806 return !isLogicalShift();
810 virtual ShiftInst *clone() const;
812 // Methods for support type inquiry through isa, cast, and dyn_cast:
813 static inline bool classof(const ShiftInst *) { return true; }
814 static inline bool classof(const Instruction *I) {
815 return (I->getOpcode() == Instruction::LShr) |
816 (I->getOpcode() == Instruction::AShr) |
817 (I->getOpcode() == Instruction::Shl);
819 static inline bool classof(const Value *V) {
820 return isa<Instruction>(V) && classof(cast<Instruction>(V));
824 //===----------------------------------------------------------------------===//
826 //===----------------------------------------------------------------------===//
828 /// SelectInst - This class represents the LLVM 'select' instruction.
830 class SelectInst : public Instruction {
833 void init(Value *C, Value *S1, Value *S2) {
834 Ops[0].init(C, this);
835 Ops[1].init(S1, this);
836 Ops[2].init(S2, this);
839 SelectInst(const SelectInst &SI)
840 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
841 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
844 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
845 Instruction *InsertBefore = 0)
846 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
847 Name, InsertBefore) {
850 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
851 BasicBlock *InsertAtEnd)
852 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
857 Value *getCondition() const { return Ops[0]; }
858 Value *getTrueValue() const { return Ops[1]; }
859 Value *getFalseValue() const { return Ops[2]; }
861 /// Transparently provide more efficient getOperand methods.
862 Value *getOperand(unsigned i) const {
863 assert(i < 3 && "getOperand() out of range!");
866 void setOperand(unsigned i, Value *Val) {
867 assert(i < 3 && "setOperand() out of range!");
870 unsigned getNumOperands() const { return 3; }
872 OtherOps getOpcode() const {
873 return static_cast<OtherOps>(Instruction::getOpcode());
876 virtual SelectInst *clone() const;
878 // Methods for support type inquiry through isa, cast, and dyn_cast:
879 static inline bool classof(const SelectInst *) { return true; }
880 static inline bool classof(const Instruction *I) {
881 return I->getOpcode() == Instruction::Select;
883 static inline bool classof(const Value *V) {
884 return isa<Instruction>(V) && classof(cast<Instruction>(V));
888 //===----------------------------------------------------------------------===//
890 //===----------------------------------------------------------------------===//
892 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
893 /// an argument of the specified type given a va_list and increments that list
895 class VAArgInst : public UnaryInstruction {
896 VAArgInst(const VAArgInst &VAA)
897 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
899 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
900 Instruction *InsertBefore = 0)
901 : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) {
903 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
904 BasicBlock *InsertAtEnd)
905 : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) {
908 virtual VAArgInst *clone() const;
909 bool mayWriteToMemory() const { return true; }
911 // Methods for support type inquiry through isa, cast, and dyn_cast:
912 static inline bool classof(const VAArgInst *) { return true; }
913 static inline bool classof(const Instruction *I) {
914 return I->getOpcode() == VAArg;
916 static inline bool classof(const Value *V) {
917 return isa<Instruction>(V) && classof(cast<Instruction>(V));
921 //===----------------------------------------------------------------------===//
922 // ExtractElementInst Class
923 //===----------------------------------------------------------------------===//
925 /// ExtractElementInst - This instruction extracts a single (scalar)
926 /// element from a PackedType value
928 class ExtractElementInst : public Instruction {
930 ExtractElementInst(const ExtractElementInst &EE) :
931 Instruction(EE.getType(), ExtractElement, Ops, 2) {
932 Ops[0].init(EE.Ops[0], this);
933 Ops[1].init(EE.Ops[1], this);
937 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
938 Instruction *InsertBefore = 0);
939 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
940 Instruction *InsertBefore = 0);
941 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
942 BasicBlock *InsertAtEnd);
943 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
944 BasicBlock *InsertAtEnd);
946 /// isValidOperands - Return true if an extractelement instruction can be
947 /// formed with the specified operands.
948 static bool isValidOperands(const Value *Vec, const Value *Idx);
950 virtual ExtractElementInst *clone() const;
952 virtual bool mayWriteToMemory() const { return false; }
954 /// Transparently provide more efficient getOperand methods.
955 Value *getOperand(unsigned i) const {
956 assert(i < 2 && "getOperand() out of range!");
959 void setOperand(unsigned i, Value *Val) {
960 assert(i < 2 && "setOperand() out of range!");
963 unsigned getNumOperands() const { return 2; }
965 // Methods for support type inquiry through isa, cast, and dyn_cast:
966 static inline bool classof(const ExtractElementInst *) { return true; }
967 static inline bool classof(const Instruction *I) {
968 return I->getOpcode() == Instruction::ExtractElement;
970 static inline bool classof(const Value *V) {
971 return isa<Instruction>(V) && classof(cast<Instruction>(V));
975 //===----------------------------------------------------------------------===//
976 // InsertElementInst Class
977 //===----------------------------------------------------------------------===//
979 /// InsertElementInst - This instruction inserts a single (scalar)
980 /// element into a PackedType value
982 class InsertElementInst : public Instruction {
984 InsertElementInst(const InsertElementInst &IE);
986 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
987 const std::string &Name = "",Instruction *InsertBefore = 0);
988 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
989 const std::string &Name = "",Instruction *InsertBefore = 0);
990 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
991 const std::string &Name, BasicBlock *InsertAtEnd);
992 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
993 const std::string &Name, BasicBlock *InsertAtEnd);
995 /// isValidOperands - Return true if an insertelement instruction can be
996 /// formed with the specified operands.
997 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1000 virtual InsertElementInst *clone() const;
1002 virtual bool mayWriteToMemory() const { return false; }
1004 /// getType - Overload to return most specific packed type.
1006 inline const PackedType *getType() const {
1007 return reinterpret_cast<const PackedType*>(Instruction::getType());
1010 /// Transparently provide more efficient getOperand methods.
1011 Value *getOperand(unsigned i) const {
1012 assert(i < 3 && "getOperand() out of range!");
1015 void setOperand(unsigned i, Value *Val) {
1016 assert(i < 3 && "setOperand() out of range!");
1019 unsigned getNumOperands() const { return 3; }
1021 // Methods for support type inquiry through isa, cast, and dyn_cast:
1022 static inline bool classof(const InsertElementInst *) { return true; }
1023 static inline bool classof(const Instruction *I) {
1024 return I->getOpcode() == Instruction::InsertElement;
1026 static inline bool classof(const Value *V) {
1027 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1031 //===----------------------------------------------------------------------===//
1032 // ShuffleVectorInst Class
1033 //===----------------------------------------------------------------------===//
1035 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1038 class ShuffleVectorInst : public Instruction {
1040 ShuffleVectorInst(const ShuffleVectorInst &IE);
1042 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1043 const std::string &Name = "", Instruction *InsertBefor = 0);
1044 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1045 const std::string &Name, BasicBlock *InsertAtEnd);
1047 /// isValidOperands - Return true if a shufflevector instruction can be
1048 /// formed with the specified operands.
1049 static bool isValidOperands(const Value *V1, const Value *V2,
1052 virtual ShuffleVectorInst *clone() const;
1054 virtual bool mayWriteToMemory() const { return false; }
1056 /// getType - Overload to return most specific packed type.
1058 inline const PackedType *getType() const {
1059 return reinterpret_cast<const PackedType*>(Instruction::getType());
1062 /// Transparently provide more efficient getOperand methods.
1063 Value *getOperand(unsigned i) const {
1064 assert(i < 3 && "getOperand() out of range!");
1067 void setOperand(unsigned i, Value *Val) {
1068 assert(i < 3 && "setOperand() out of range!");
1071 unsigned getNumOperands() const { return 3; }
1073 // Methods for support type inquiry through isa, cast, and dyn_cast:
1074 static inline bool classof(const ShuffleVectorInst *) { return true; }
1075 static inline bool classof(const Instruction *I) {
1076 return I->getOpcode() == Instruction::ShuffleVector;
1078 static inline bool classof(const Value *V) {
1079 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1084 //===----------------------------------------------------------------------===//
1086 //===----------------------------------------------------------------------===//
1088 // PHINode - The PHINode class is used to represent the magical mystical PHI
1089 // node, that can not exist in nature, but can be synthesized in a computer
1090 // scientist's overactive imagination.
1092 class PHINode : public Instruction {
1093 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1094 /// the number actually in use.
1095 unsigned ReservedSpace;
1096 PHINode(const PHINode &PN);
1098 explicit PHINode(const Type *Ty, const std::string &Name = "",
1099 Instruction *InsertBefore = 0)
1100 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore),
1104 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1105 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
1111 /// reserveOperandSpace - This method can be used to avoid repeated
1112 /// reallocation of PHI operand lists by reserving space for the correct
1113 /// number of operands before adding them. Unlike normal vector reserves,
1114 /// this method can also be used to trim the operand space.
1115 void reserveOperandSpace(unsigned NumValues) {
1116 resizeOperands(NumValues*2);
1119 virtual PHINode *clone() const;
1121 /// getNumIncomingValues - Return the number of incoming edges
1123 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1125 /// getIncomingValue - Return incoming value number x
1127 Value *getIncomingValue(unsigned i) const {
1128 assert(i*2 < getNumOperands() && "Invalid value number!");
1129 return getOperand(i*2);
1131 void setIncomingValue(unsigned i, Value *V) {
1132 assert(i*2 < getNumOperands() && "Invalid value number!");
1135 unsigned getOperandNumForIncomingValue(unsigned i) {
1139 /// getIncomingBlock - Return incoming basic block number x
1141 BasicBlock *getIncomingBlock(unsigned i) const {
1142 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1144 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1145 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1147 unsigned getOperandNumForIncomingBlock(unsigned i) {
1151 /// addIncoming - Add an incoming value to the end of the PHI list
1153 void addIncoming(Value *V, BasicBlock *BB) {
1154 assert(getType() == V->getType() &&
1155 "All operands to PHI node must be the same type as the PHI node!");
1156 unsigned OpNo = NumOperands;
1157 if (OpNo+2 > ReservedSpace)
1158 resizeOperands(0); // Get more space!
1159 // Initialize some new operands.
1160 NumOperands = OpNo+2;
1161 OperandList[OpNo].init(V, this);
1162 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1165 /// removeIncomingValue - Remove an incoming value. This is useful if a
1166 /// predecessor basic block is deleted. The value removed is returned.
1168 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1169 /// is true), the PHI node is destroyed and any uses of it are replaced with
1170 /// dummy values. The only time there should be zero incoming values to a PHI
1171 /// node is when the block is dead, so this strategy is sound.
1173 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1175 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1176 int Idx = getBasicBlockIndex(BB);
1177 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1178 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1181 /// getBasicBlockIndex - Return the first index of the specified basic
1182 /// block in the value list for this PHI. Returns -1 if no instance.
1184 int getBasicBlockIndex(const BasicBlock *BB) const {
1185 Use *OL = OperandList;
1186 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1187 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1191 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1192 return getIncomingValue(getBasicBlockIndex(BB));
1195 /// hasConstantValue - If the specified PHI node always merges together the
1196 /// same value, return the value, otherwise return null.
1198 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1200 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1201 static inline bool classof(const PHINode *) { return true; }
1202 static inline bool classof(const Instruction *I) {
1203 return I->getOpcode() == Instruction::PHI;
1205 static inline bool classof(const Value *V) {
1206 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1209 void resizeOperands(unsigned NumOperands);
1212 //===----------------------------------------------------------------------===//
1214 //===----------------------------------------------------------------------===//
1216 //===---------------------------------------------------------------------------
1217 /// ReturnInst - Return a value (possibly void), from a function. Execution
1218 /// does not continue in this function any longer.
1220 class ReturnInst : public TerminatorInst {
1221 Use RetVal; // Possibly null retval.
1222 ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
1223 RI.getNumOperands()) {
1224 if (RI.getNumOperands())
1225 RetVal.init(RI.RetVal, this);
1228 void init(Value *RetVal);
1231 // ReturnInst constructors:
1232 // ReturnInst() - 'ret void' instruction
1233 // ReturnInst( null) - 'ret void' instruction
1234 // ReturnInst(Value* X) - 'ret X' instruction
1235 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1236 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1237 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1238 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1240 // NOTE: If the Value* passed is of type void then the constructor behaves as
1241 // if it was passed NULL.
1242 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
1243 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
1246 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
1247 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1250 explicit ReturnInst(BasicBlock *InsertAtEnd)
1251 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1254 virtual ReturnInst *clone() const;
1256 // Transparently provide more efficient getOperand methods.
1257 Value *getOperand(unsigned i) const {
1258 assert(i < getNumOperands() && "getOperand() out of range!");
1261 void setOperand(unsigned i, Value *Val) {
1262 assert(i < getNumOperands() && "setOperand() out of range!");
1266 Value *getReturnValue() const { return RetVal; }
1268 unsigned getNumSuccessors() const { return 0; }
1270 // Methods for support type inquiry through isa, cast, and dyn_cast:
1271 static inline bool classof(const ReturnInst *) { return true; }
1272 static inline bool classof(const Instruction *I) {
1273 return (I->getOpcode() == Instruction::Ret);
1275 static inline bool classof(const Value *V) {
1276 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1279 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1280 virtual unsigned getNumSuccessorsV() const;
1281 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1284 //===----------------------------------------------------------------------===//
1286 //===----------------------------------------------------------------------===//
1288 //===---------------------------------------------------------------------------
1289 /// BranchInst - Conditional or Unconditional Branch instruction.
1291 class BranchInst : public TerminatorInst {
1292 /// Ops list - Branches are strange. The operands are ordered:
1293 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1294 /// they don't have to check for cond/uncond branchness.
1296 BranchInst(const BranchInst &BI);
1299 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1300 // BranchInst(BB *B) - 'br B'
1301 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1302 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1303 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1304 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1305 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1306 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
1307 : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
1308 assert(IfTrue != 0 && "Branch destination may not be null!");
1309 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1311 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1312 Instruction *InsertBefore = 0)
1313 : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
1314 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1315 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1316 Ops[2].init(Cond, this);
1322 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
1323 : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
1324 assert(IfTrue != 0 && "Branch destination may not be null!");
1325 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1328 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1329 BasicBlock *InsertAtEnd)
1330 : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
1331 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1332 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1333 Ops[2].init(Cond, this);
1340 /// Transparently provide more efficient getOperand methods.
1341 Value *getOperand(unsigned i) const {
1342 assert(i < getNumOperands() && "getOperand() out of range!");
1345 void setOperand(unsigned i, Value *Val) {
1346 assert(i < getNumOperands() && "setOperand() out of range!");
1350 virtual BranchInst *clone() const;
1352 inline bool isUnconditional() const { return getNumOperands() == 1; }
1353 inline bool isConditional() const { return getNumOperands() == 3; }
1355 inline Value *getCondition() const {
1356 assert(isConditional() && "Cannot get condition of an uncond branch!");
1357 return getOperand(2);
1360 void setCondition(Value *V) {
1361 assert(isConditional() && "Cannot set condition of unconditional branch!");
1365 // setUnconditionalDest - Change the current branch to an unconditional branch
1366 // targeting the specified block.
1367 // FIXME: Eliminate this ugly method.
1368 void setUnconditionalDest(BasicBlock *Dest) {
1369 if (isConditional()) { // Convert this to an uncond branch.
1374 setOperand(0, reinterpret_cast<Value*>(Dest));
1377 unsigned getNumSuccessors() const { return 1+isConditional(); }
1379 BasicBlock *getSuccessor(unsigned i) const {
1380 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1381 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1382 cast<BasicBlock>(getOperand(1));
1385 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1386 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1387 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1390 // Methods for support type inquiry through isa, cast, and dyn_cast:
1391 static inline bool classof(const BranchInst *) { return true; }
1392 static inline bool classof(const Instruction *I) {
1393 return (I->getOpcode() == Instruction::Br);
1395 static inline bool classof(const Value *V) {
1396 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1399 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1400 virtual unsigned getNumSuccessorsV() const;
1401 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1404 //===----------------------------------------------------------------------===//
1406 //===----------------------------------------------------------------------===//
1408 //===---------------------------------------------------------------------------
1409 /// SwitchInst - Multiway switch
1411 class SwitchInst : public TerminatorInst {
1412 unsigned ReservedSpace;
1413 // Operand[0] = Value to switch on
1414 // Operand[1] = Default basic block destination
1415 // Operand[2n ] = Value to match
1416 // Operand[2n+1] = BasicBlock to go to on match
1417 SwitchInst(const SwitchInst &RI);
1418 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1419 void resizeOperands(unsigned No);
1421 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1422 /// switch on and a default destination. The number of additional cases can
1423 /// be specified here to make memory allocation more efficient. This
1424 /// constructor can also autoinsert before another instruction.
1425 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1426 Instruction *InsertBefore = 0)
1427 : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1428 init(Value, Default, NumCases);
1431 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1432 /// switch on and a default destination. The number of additional cases can
1433 /// be specified here to make memory allocation more efficient. This
1434 /// constructor also autoinserts at the end of the specified BasicBlock.
1435 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1436 BasicBlock *InsertAtEnd)
1437 : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1438 init(Value, Default, NumCases);
1443 // Accessor Methods for Switch stmt
1444 inline Value *getCondition() const { return getOperand(0); }
1445 void setCondition(Value *V) { setOperand(0, V); }
1447 inline BasicBlock *getDefaultDest() const {
1448 return cast<BasicBlock>(getOperand(1));
1451 /// getNumCases - return the number of 'cases' in this switch instruction.
1452 /// Note that case #0 is always the default case.
1453 unsigned getNumCases() const {
1454 return getNumOperands()/2;
1457 /// getCaseValue - Return the specified case value. Note that case #0, the
1458 /// default destination, does not have a case value.
1459 ConstantInt *getCaseValue(unsigned i) {
1460 assert(i && i < getNumCases() && "Illegal case value to get!");
1461 return getSuccessorValue(i);
1464 /// getCaseValue - Return the specified case value. Note that case #0, the
1465 /// default destination, does not have a case value.
1466 const ConstantInt *getCaseValue(unsigned i) const {
1467 assert(i && i < getNumCases() && "Illegal case value to get!");
1468 return getSuccessorValue(i);
1471 /// findCaseValue - Search all of the case values for the specified constant.
1472 /// If it is explicitly handled, return the case number of it, otherwise
1473 /// return 0 to indicate that it is handled by the default handler.
1474 unsigned findCaseValue(const ConstantInt *C) const {
1475 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1476 if (getCaseValue(i) == C)
1481 /// findCaseDest - Finds the unique case value for a given successor. Returns
1482 /// null if the successor is not found, not unique, or is the default case.
1483 ConstantInt *findCaseDest(BasicBlock *BB) {
1484 if (BB == getDefaultDest()) return NULL;
1486 ConstantInt *CI = NULL;
1487 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1488 if (getSuccessor(i) == BB) {
1489 if (CI) return NULL; // Multiple cases lead to BB.
1490 else CI = getCaseValue(i);
1496 /// addCase - Add an entry to the switch instruction...
1498 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1500 /// removeCase - This method removes the specified successor from the switch
1501 /// instruction. Note that this cannot be used to remove the default
1502 /// destination (successor #0).
1504 void removeCase(unsigned idx);
1506 virtual SwitchInst *clone() const;
1508 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1509 BasicBlock *getSuccessor(unsigned idx) const {
1510 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1511 return cast<BasicBlock>(getOperand(idx*2+1));
1513 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1514 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1515 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1518 // getSuccessorValue - Return the value associated with the specified
1520 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1521 assert(idx < getNumSuccessors() && "Successor # out of range!");
1522 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1525 // Methods for support type inquiry through isa, cast, and dyn_cast:
1526 static inline bool classof(const SwitchInst *) { return true; }
1527 static inline bool classof(const Instruction *I) {
1528 return I->getOpcode() == Instruction::Switch;
1530 static inline bool classof(const Value *V) {
1531 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1534 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1535 virtual unsigned getNumSuccessorsV() const;
1536 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1539 //===----------------------------------------------------------------------===//
1541 //===----------------------------------------------------------------------===//
1543 //===---------------------------------------------------------------------------
1545 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1546 /// calling convention of the call.
1548 class InvokeInst : public TerminatorInst {
1549 InvokeInst(const InvokeInst &BI);
1550 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1551 const std::vector<Value*> &Params);
1553 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1554 const std::vector<Value*> &Params, const std::string &Name = "",
1555 Instruction *InsertBefore = 0);
1556 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1557 const std::vector<Value*> &Params, const std::string &Name,
1558 BasicBlock *InsertAtEnd);
1561 virtual InvokeInst *clone() const;
1563 bool mayWriteToMemory() const { return true; }
1565 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1567 unsigned getCallingConv() const { return SubclassData; }
1568 void setCallingConv(unsigned CC) {
1572 /// getCalledFunction - Return the function called, or null if this is an
1573 /// indirect function invocation.
1575 Function *getCalledFunction() const {
1576 return dyn_cast<Function>(getOperand(0));
1579 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1580 inline Value *getCalledValue() const { return getOperand(0); }
1582 // get*Dest - Return the destination basic blocks...
1583 BasicBlock *getNormalDest() const {
1584 return cast<BasicBlock>(getOperand(1));
1586 BasicBlock *getUnwindDest() const {
1587 return cast<BasicBlock>(getOperand(2));
1589 void setNormalDest(BasicBlock *B) {
1590 setOperand(1, reinterpret_cast<Value*>(B));
1593 void setUnwindDest(BasicBlock *B) {
1594 setOperand(2, reinterpret_cast<Value*>(B));
1597 inline BasicBlock *getSuccessor(unsigned i) const {
1598 assert(i < 2 && "Successor # out of range for invoke!");
1599 return i == 0 ? getNormalDest() : getUnwindDest();
1602 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1603 assert(idx < 2 && "Successor # out of range for invoke!");
1604 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1607 unsigned getNumSuccessors() const { return 2; }
1609 // Methods for support type inquiry through isa, cast, and dyn_cast:
1610 static inline bool classof(const InvokeInst *) { return true; }
1611 static inline bool classof(const Instruction *I) {
1612 return (I->getOpcode() == Instruction::Invoke);
1614 static inline bool classof(const Value *V) {
1615 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1618 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1619 virtual unsigned getNumSuccessorsV() const;
1620 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1624 //===----------------------------------------------------------------------===//
1626 //===----------------------------------------------------------------------===//
1628 //===---------------------------------------------------------------------------
1629 /// UnwindInst - Immediately exit the current function, unwinding the stack
1630 /// until an invoke instruction is found.
1632 class UnwindInst : public TerminatorInst {
1634 explicit UnwindInst(Instruction *InsertBefore = 0)
1635 : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
1637 explicit UnwindInst(BasicBlock *InsertAtEnd)
1638 : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
1641 virtual UnwindInst *clone() const;
1643 unsigned getNumSuccessors() const { return 0; }
1645 // Methods for support type inquiry through isa, cast, and dyn_cast:
1646 static inline bool classof(const UnwindInst *) { return true; }
1647 static inline bool classof(const Instruction *I) {
1648 return I->getOpcode() == Instruction::Unwind;
1650 static inline bool classof(const Value *V) {
1651 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1654 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1655 virtual unsigned getNumSuccessorsV() const;
1656 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1659 //===----------------------------------------------------------------------===//
1660 // UnreachableInst Class
1661 //===----------------------------------------------------------------------===//
1663 //===---------------------------------------------------------------------------
1664 /// UnreachableInst - This function has undefined behavior. In particular, the
1665 /// presence of this instruction indicates some higher level knowledge that the
1666 /// end of the block cannot be reached.
1668 class UnreachableInst : public TerminatorInst {
1670 explicit UnreachableInst(Instruction *InsertBefore = 0)
1671 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
1673 explicit UnreachableInst(BasicBlock *InsertAtEnd)
1674 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
1677 virtual UnreachableInst *clone() const;
1679 unsigned getNumSuccessors() const { return 0; }
1681 // Methods for support type inquiry through isa, cast, and dyn_cast:
1682 static inline bool classof(const UnreachableInst *) { return true; }
1683 static inline bool classof(const Instruction *I) {
1684 return I->getOpcode() == Instruction::Unreachable;
1686 static inline bool classof(const Value *V) {
1687 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1690 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1691 virtual unsigned getNumSuccessorsV() const;
1692 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1695 //===----------------------------------------------------------------------===//
1697 //===----------------------------------------------------------------------===//
1699 /// @brief This class represents a truncation of integer types.
1700 class TruncInst : public CastInst {
1701 /// Private copy constructor
1702 TruncInst(const TruncInst &CI)
1703 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1706 /// @brief Constructor with insert-before-instruction semantics
1708 Value *S, ///< The value to be truncated
1709 const Type *Ty, ///< The (smaller) type to truncate to
1710 const std::string &Name = "", ///< A name for the new instruction
1711 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1714 /// @brief Constructor with insert-at-end-of-block semantics
1716 Value *S, ///< The value to be truncated
1717 const Type *Ty, ///< The (smaller) type to truncate to
1718 const std::string &Name, ///< A name for the new instruction
1719 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1722 /// @brief Clone an identical TruncInst
1723 virtual CastInst *clone() const;
1725 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1726 static inline bool classof(const TruncInst *) { return true; }
1727 static inline bool classof(const Instruction *I) {
1728 return I->getOpcode() == Trunc;
1730 static inline bool classof(const Value *V) {
1731 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1735 //===----------------------------------------------------------------------===//
1737 //===----------------------------------------------------------------------===//
1739 /// @brief This class represents zero extension of integer types.
1740 class ZExtInst : public CastInst {
1741 /// @brief Private copy constructor
1742 ZExtInst(const ZExtInst &CI)
1743 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1746 /// @brief Constructor with insert-before-instruction semantics
1748 Value *S, ///< The value to be zero extended
1749 const Type *Ty, ///< The type to zero extend to
1750 const std::string &Name = "", ///< A name for the new instruction
1751 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1754 /// @brief Constructor with insert-at-end semantics.
1756 Value *S, ///< The value to be zero extended
1757 const Type *Ty, ///< The type to zero extend 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 ZExtInst
1763 virtual CastInst *clone() const;
1765 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1766 static inline bool classof(const ZExtInst *) { return true; }
1767 static inline bool classof(const Instruction *I) {
1768 return I->getOpcode() == ZExt;
1770 static inline bool classof(const Value *V) {
1771 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1775 //===----------------------------------------------------------------------===//
1777 //===----------------------------------------------------------------------===//
1779 /// @brief This class represents a sign extension of integer types.
1780 class SExtInst : public CastInst {
1781 /// @brief Private copy constructor
1782 SExtInst(const SExtInst &CI)
1783 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1786 /// @brief Constructor with insert-before-instruction semantics
1788 Value *S, ///< The value to be sign extended
1789 const Type *Ty, ///< The type to sign extend to
1790 const std::string &Name = "", ///< A name for the new instruction
1791 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1794 /// @brief Constructor with insert-at-end-of-block semantics
1796 Value *S, ///< The value to be sign extended
1797 const Type *Ty, ///< The type to sign 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 SExtInst
1803 virtual CastInst *clone() const;
1805 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1806 static inline bool classof(const SExtInst *) { return true; }
1807 static inline bool classof(const Instruction *I) {
1808 return I->getOpcode() == SExt;
1810 static inline bool classof(const Value *V) {
1811 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1815 //===----------------------------------------------------------------------===//
1816 // FPTruncInst Class
1817 //===----------------------------------------------------------------------===//
1819 /// @brief This class represents a truncation of floating point types.
1820 class FPTruncInst : public CastInst {
1821 FPTruncInst(const FPTruncInst &CI)
1822 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1825 /// @brief Constructor with insert-before-instruction semantics
1827 Value *S, ///< The value to be truncated
1828 const Type *Ty, ///< The type to truncate to
1829 const std::string &Name = "", ///< A name for the new instruction
1830 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1833 /// @brief Constructor with insert-before-instruction semantics
1835 Value *S, ///< The value to be truncated
1836 const Type *Ty, ///< The type to truncate to
1837 const std::string &Name, ///< A name for the new instruction
1838 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1841 /// @brief Clone an identical FPTruncInst
1842 virtual CastInst *clone() const;
1844 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1845 static inline bool classof(const FPTruncInst *) { return true; }
1846 static inline bool classof(const Instruction *I) {
1847 return I->getOpcode() == FPTrunc;
1849 static inline bool classof(const Value *V) {
1850 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1854 //===----------------------------------------------------------------------===//
1856 //===----------------------------------------------------------------------===//
1858 /// @brief This class represents an extension of floating point types.
1859 class FPExtInst : public CastInst {
1860 FPExtInst(const FPExtInst &CI)
1861 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1864 /// @brief Constructor with insert-before-instruction semantics
1866 Value *S, ///< The value to be extended
1867 const Type *Ty, ///< The type to extend to
1868 const std::string &Name = "", ///< A name for the new instruction
1869 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1872 /// @brief Constructor with insert-at-end-of-block semantics
1874 Value *S, ///< The value to be extended
1875 const Type *Ty, ///< The type to extend to
1876 const std::string &Name, ///< A name for the new instruction
1877 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1880 /// @brief Clone an identical FPExtInst
1881 virtual CastInst *clone() const;
1883 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1884 static inline bool classof(const FPExtInst *) { return true; }
1885 static inline bool classof(const Instruction *I) {
1886 return I->getOpcode() == FPExt;
1888 static inline bool classof(const Value *V) {
1889 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1893 //===----------------------------------------------------------------------===//
1895 //===----------------------------------------------------------------------===//
1897 /// @brief This class represents a cast unsigned integer to floating point.
1898 class UIToFPInst : public CastInst {
1899 UIToFPInst(const UIToFPInst &CI)
1900 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1903 /// @brief Constructor with insert-before-instruction semantics
1905 Value *S, ///< The value to be converted
1906 const Type *Ty, ///< The type to convert to
1907 const std::string &Name = "", ///< A name for the new instruction
1908 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1911 /// @brief Constructor with insert-at-end-of-block semantics
1913 Value *S, ///< The value to be converted
1914 const Type *Ty, ///< The type to convert to
1915 const std::string &Name, ///< A name for the new instruction
1916 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1919 /// @brief Clone an identical UIToFPInst
1920 virtual CastInst *clone() const;
1922 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1923 static inline bool classof(const UIToFPInst *) { return true; }
1924 static inline bool classof(const Instruction *I) {
1925 return I->getOpcode() == UIToFP;
1927 static inline bool classof(const Value *V) {
1928 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1932 //===----------------------------------------------------------------------===//
1934 //===----------------------------------------------------------------------===//
1936 /// @brief This class represents a cast from signed integer to floating point.
1937 class SIToFPInst : public CastInst {
1938 SIToFPInst(const SIToFPInst &CI)
1939 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1942 /// @brief Constructor with insert-before-instruction semantics
1944 Value *S, ///< The value to be converted
1945 const Type *Ty, ///< The type to convert to
1946 const std::string &Name = "", ///< A name for the new instruction
1947 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1950 /// @brief Constructor with insert-at-end-of-block semantics
1952 Value *S, ///< The value to be converted
1953 const Type *Ty, ///< The type to convert to
1954 const std::string &Name, ///< A name for the new instruction
1955 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1958 /// @brief Clone an identical SIToFPInst
1959 virtual CastInst *clone() const;
1961 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1962 static inline bool classof(const SIToFPInst *) { return true; }
1963 static inline bool classof(const Instruction *I) {
1964 return I->getOpcode() == SIToFP;
1966 static inline bool classof(const Value *V) {
1967 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1971 //===----------------------------------------------------------------------===//
1973 //===----------------------------------------------------------------------===//
1975 /// @brief This class represents a cast from floating point to unsigned integer
1976 class FPToUIInst : public CastInst {
1977 FPToUIInst(const FPToUIInst &CI)
1978 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1981 /// @brief Constructor with insert-before-instruction semantics
1983 Value *S, ///< The value to be converted
1984 const Type *Ty, ///< The type to convert to
1985 const std::string &Name = "", ///< A name for the new instruction
1986 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1989 /// @brief Constructor with insert-at-end-of-block semantics
1991 Value *S, ///< The value to be converted
1992 const Type *Ty, ///< The type to convert to
1993 const std::string &Name, ///< A name for the new instruction
1994 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
1997 /// @brief Clone an identical FPToUIInst
1998 virtual CastInst *clone() const;
2000 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2001 static inline bool classof(const FPToUIInst *) { return true; }
2002 static inline bool classof(const Instruction *I) {
2003 return I->getOpcode() == FPToUI;
2005 static inline bool classof(const Value *V) {
2006 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2010 //===----------------------------------------------------------------------===//
2012 //===----------------------------------------------------------------------===//
2014 /// @brief This class represents a cast from floating point to signed integer.
2015 class FPToSIInst : public CastInst {
2016 FPToSIInst(const FPToSIInst &CI)
2017 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2020 /// @brief Constructor with insert-before-instruction semantics
2022 Value *S, ///< The value to be converted
2023 const Type *Ty, ///< The type to convert to
2024 const std::string &Name = "", ///< A name for the new instruction
2025 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2028 /// @brief Constructor with insert-at-end-of-block semantics
2030 Value *S, ///< The value to be converted
2031 const Type *Ty, ///< The type to convert to
2032 const std::string &Name, ///< A name for the new instruction
2033 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2036 /// @brief Clone an identical FPToSIInst
2037 virtual CastInst *clone() const;
2039 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2040 static inline bool classof(const FPToSIInst *) { return true; }
2041 static inline bool classof(const Instruction *I) {
2042 return I->getOpcode() == FPToSI;
2044 static inline bool classof(const Value *V) {
2045 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2049 //===----------------------------------------------------------------------===//
2050 // IntToPtrInst Class
2051 //===----------------------------------------------------------------------===//
2053 /// @brief This class represents a cast from an integer to a pointer.
2054 class IntToPtrInst : public CastInst {
2055 IntToPtrInst(const IntToPtrInst &CI)
2056 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2059 /// @brief Constructor with insert-before-instruction semantics
2061 Value *S, ///< The value to be converted
2062 const Type *Ty, ///< The type to convert to
2063 const std::string &Name = "", ///< A name for the new instruction
2064 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2067 /// @brief Constructor with insert-at-end-of-block semantics
2069 Value *S, ///< The value to be converted
2070 const Type *Ty, ///< The type to convert to
2071 const std::string &Name, ///< A name for the new instruction
2072 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2075 /// @brief Clone an identical IntToPtrInst
2076 virtual CastInst *clone() const;
2078 // Methods for support type inquiry through isa, cast, and dyn_cast:
2079 static inline bool classof(const IntToPtrInst *) { return true; }
2080 static inline bool classof(const Instruction *I) {
2081 return I->getOpcode() == IntToPtr;
2083 static inline bool classof(const Value *V) {
2084 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2088 //===----------------------------------------------------------------------===//
2089 // PtrToIntInst Class
2090 //===----------------------------------------------------------------------===//
2092 /// @brief This class represents a cast from a pointer to an integer
2093 class PtrToIntInst : public CastInst {
2094 PtrToIntInst(const PtrToIntInst &CI)
2095 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2098 /// @brief Constructor with insert-before-instruction semantics
2100 Value *S, ///< The value to be converted
2101 const Type *Ty, ///< The type to convert to
2102 const std::string &Name = "", ///< A name for the new instruction
2103 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2106 /// @brief Constructor with insert-at-end-of-block semantics
2108 Value *S, ///< The value to be converted
2109 const Type *Ty, ///< The type to convert to
2110 const std::string &Name, ///< A name for the new instruction
2111 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2114 /// @brief Clone an identical PtrToIntInst
2115 virtual CastInst *clone() const;
2117 // Methods for support type inquiry through isa, cast, and dyn_cast:
2118 static inline bool classof(const PtrToIntInst *) { return true; }
2119 static inline bool classof(const Instruction *I) {
2120 return I->getOpcode() == PtrToInt;
2122 static inline bool classof(const Value *V) {
2123 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2127 //===----------------------------------------------------------------------===//
2128 // BitCastInst Class
2129 //===----------------------------------------------------------------------===//
2131 /// @brief This class represents a no-op cast from one type to another.
2132 class BitCastInst : public CastInst {
2133 BitCastInst(const BitCastInst &CI)
2134 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2137 /// @brief Constructor with insert-before-instruction semantics
2139 Value *S, ///< The value to be casted
2140 const Type *Ty, ///< The type to casted to
2141 const std::string &Name = "", ///< A name for the new instruction
2142 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2145 /// @brief Constructor with insert-at-end-of-block semantics
2147 Value *S, ///< The value to be casted
2148 const Type *Ty, ///< The type to casted to
2149 const std::string &Name, ///< A name for the new instruction
2150 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2153 /// @brief Clone an identical BitCastInst
2154 virtual CastInst *clone() const;
2156 // Methods for support type inquiry through isa, cast, and dyn_cast:
2157 static inline bool classof(const BitCastInst *) { return true; }
2158 static inline bool classof(const Instruction *I) {
2159 return I->getOpcode() == BitCast;
2161 static inline bool classof(const Value *V) {
2162 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2166 } // End llvm namespace