1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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
21 #include "llvm/InstrTypes.h"
22 #include "llvm/DerivedTypes.h"
23 #include "llvm/ParameterAttributes.h"
34 //===----------------------------------------------------------------------===//
35 // AllocationInst Class
36 //===----------------------------------------------------------------------===//
38 /// AllocationInst - This class is the common base class of MallocInst and
41 class AllocationInst : public UnaryInstruction {
43 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
44 const std::string &Name = "", Instruction *InsertBefore = 0);
45 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
46 const std::string &Name, BasicBlock *InsertAtEnd);
48 // Out of line virtual method, so the vtable, etc. has a home.
49 virtual ~AllocationInst();
51 /// isArrayAllocation - Return true if there is an allocation size parameter
52 /// to the allocation instruction that is not 1.
54 bool isArrayAllocation() const;
56 /// getArraySize - Get the number of element allocated, for a simple
57 /// allocation of a single element, this will return a constant 1 value.
59 const Value *getArraySize() const { return getOperand(0); }
60 Value *getArraySize() { return getOperand(0); }
62 /// getType - Overload to return most specific pointer type
64 const PointerType *getType() const {
65 return reinterpret_cast<const PointerType*>(Instruction::getType());
68 /// getAllocatedType - Return the type that is being allocated by the
71 const Type *getAllocatedType() const;
73 /// getAlignment - Return the alignment of the memory that is being allocated
74 /// by the instruction.
76 unsigned getAlignment() const { return (1u << SubclassData) >> 1; }
77 void setAlignment(unsigned Align);
79 virtual Instruction *clone() const = 0;
81 // Methods for support type inquiry through isa, cast, and dyn_cast:
82 static inline bool classof(const AllocationInst *) { return true; }
83 static inline bool classof(const Instruction *I) {
84 return I->getOpcode() == Instruction::Alloca ||
85 I->getOpcode() == Instruction::Malloc;
87 static inline bool classof(const Value *V) {
88 return isa<Instruction>(V) && classof(cast<Instruction>(V));
93 //===----------------------------------------------------------------------===//
95 //===----------------------------------------------------------------------===//
97 /// MallocInst - an instruction to allocated memory on the heap
99 class MallocInst : public AllocationInst {
100 MallocInst(const MallocInst &MI);
102 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
103 const std::string &Name = "",
104 Instruction *InsertBefore = 0)
105 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
106 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
107 BasicBlock *InsertAtEnd)
108 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
110 MallocInst(const Type *Ty, const std::string &Name,
111 Instruction *InsertBefore = 0)
112 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
113 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
114 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
116 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
117 const std::string &Name, BasicBlock *InsertAtEnd)
118 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
119 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
120 const std::string &Name = "",
121 Instruction *InsertBefore = 0)
122 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
124 virtual MallocInst *clone() const;
126 // Methods for support type inquiry through isa, cast, and dyn_cast:
127 static inline bool classof(const MallocInst *) { return true; }
128 static inline bool classof(const Instruction *I) {
129 return (I->getOpcode() == Instruction::Malloc);
131 static inline bool classof(const Value *V) {
132 return isa<Instruction>(V) && classof(cast<Instruction>(V));
137 //===----------------------------------------------------------------------===//
139 //===----------------------------------------------------------------------===//
141 /// AllocaInst - an instruction to allocate memory on the stack
143 class AllocaInst : public AllocationInst {
144 AllocaInst(const AllocaInst &);
146 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
147 const std::string &Name = "",
148 Instruction *InsertBefore = 0)
149 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
150 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
151 BasicBlock *InsertAtEnd)
152 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
154 AllocaInst(const Type *Ty, const std::string &Name,
155 Instruction *InsertBefore = 0)
156 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
157 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
158 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
160 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
161 const std::string &Name = "", Instruction *InsertBefore = 0)
162 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
163 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
164 const std::string &Name, BasicBlock *InsertAtEnd)
165 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
167 virtual AllocaInst *clone() const;
169 // Methods for support type inquiry through isa, cast, and dyn_cast:
170 static inline bool classof(const AllocaInst *) { return true; }
171 static inline bool classof(const Instruction *I) {
172 return (I->getOpcode() == Instruction::Alloca);
174 static inline bool classof(const Value *V) {
175 return isa<Instruction>(V) && classof(cast<Instruction>(V));
180 //===----------------------------------------------------------------------===//
182 //===----------------------------------------------------------------------===//
184 /// FreeInst - an instruction to deallocate memory
186 class FreeInst : public UnaryInstruction {
189 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
190 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
192 virtual FreeInst *clone() const;
194 // Accessor methods for consistency with other memory operations
195 Value *getPointerOperand() { return getOperand(0); }
196 const Value *getPointerOperand() const { return getOperand(0); }
198 // Methods for support type inquiry through isa, cast, and dyn_cast:
199 static inline bool classof(const FreeInst *) { return true; }
200 static inline bool classof(const Instruction *I) {
201 return (I->getOpcode() == Instruction::Free);
203 static inline bool classof(const Value *V) {
204 return isa<Instruction>(V) && classof(cast<Instruction>(V));
209 //===----------------------------------------------------------------------===//
211 //===----------------------------------------------------------------------===//
213 /// LoadInst - an instruction for reading from memory. This uses the
214 /// SubclassData field in Value to store whether or not the load is volatile.
216 class LoadInst : public UnaryInstruction {
218 LoadInst(const LoadInst &LI)
219 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
220 setVolatile(LI.isVolatile());
221 setAlignment(LI.getAlignment());
229 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
230 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
231 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false,
232 Instruction *InsertBefore = 0);
233 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
234 Instruction *InsertBefore = 0);
235 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
236 BasicBlock *InsertAtEnd);
237 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
238 BasicBlock *InsertAtEnd);
240 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
241 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
242 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
243 Instruction *InsertBefore = 0);
244 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
245 BasicBlock *InsertAtEnd);
247 /// isVolatile - Return true if this is a load from a volatile memory
250 bool isVolatile() const { return SubclassData & 1; }
252 /// setVolatile - Specify whether this is a volatile load or not.
254 void setVolatile(bool V) {
255 SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
258 virtual LoadInst *clone() const;
260 /// getAlignment - Return the alignment of the access that is being performed
262 unsigned getAlignment() const {
263 return (1 << (SubclassData>>1)) >> 1;
266 void setAlignment(unsigned Align);
268 Value *getPointerOperand() { return getOperand(0); }
269 const Value *getPointerOperand() const { return getOperand(0); }
270 static unsigned getPointerOperandIndex() { return 0U; }
272 // Methods for support type inquiry through isa, cast, and dyn_cast:
273 static inline bool classof(const LoadInst *) { return true; }
274 static inline bool classof(const Instruction *I) {
275 return I->getOpcode() == Instruction::Load;
277 static inline bool classof(const Value *V) {
278 return isa<Instruction>(V) && classof(cast<Instruction>(V));
283 //===----------------------------------------------------------------------===//
285 //===----------------------------------------------------------------------===//
287 /// StoreInst - an instruction for storing to memory
289 class StoreInst : public Instruction {
290 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
293 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
294 Ops[0].init(SI.Ops[0], this);
295 Ops[1].init(SI.Ops[1], this);
296 setVolatile(SI.isVolatile());
297 setAlignment(SI.getAlignment());
305 // allocate space for exactly two operands
306 void *operator new(size_t s) {
307 return User::operator new(s, 2);
309 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
310 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
311 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
312 Instruction *InsertBefore = 0);
313 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
314 unsigned Align, Instruction *InsertBefore = 0);
315 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
316 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
317 unsigned Align, BasicBlock *InsertAtEnd);
320 /// isVolatile - Return true if this is a load from a volatile memory
323 bool isVolatile() const { return SubclassData & 1; }
325 /// setVolatile - Specify whether this is a volatile load or not.
327 void setVolatile(bool V) {
328 SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
331 /// Transparently provide more efficient getOperand methods.
332 Value *getOperand(unsigned i) const {
333 assert(i < 2 && "getOperand() out of range!");
336 void setOperand(unsigned i, Value *Val) {
337 assert(i < 2 && "setOperand() out of range!");
340 unsigned getNumOperands() const { return 2; }
342 /// getAlignment - Return the alignment of the access that is being performed
344 unsigned getAlignment() const {
345 return (1 << (SubclassData>>1)) >> 1;
348 void setAlignment(unsigned Align);
350 virtual StoreInst *clone() const;
352 Value *getPointerOperand() { return getOperand(1); }
353 const Value *getPointerOperand() const { return getOperand(1); }
354 static unsigned getPointerOperandIndex() { return 1U; }
356 // Methods for support type inquiry through isa, cast, and dyn_cast:
357 static inline bool classof(const StoreInst *) { return true; }
358 static inline bool classof(const Instruction *I) {
359 return I->getOpcode() == Instruction::Store;
361 static inline bool classof(const Value *V) {
362 return isa<Instruction>(V) && classof(cast<Instruction>(V));
367 //===----------------------------------------------------------------------===//
368 // GetElementPtrInst Class
369 //===----------------------------------------------------------------------===//
371 // checkType - Simple wrapper function to give a better assertion failure
372 // message on bad indexes for a gep instruction.
374 static inline const Type *checkType(const Type *Ty) {
375 assert(Ty && "Invalid GetElementPtrInst indices for type!");
379 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
380 /// access elements of arrays and structs
382 class GetElementPtrInst : public Instruction {
383 GetElementPtrInst(const GetElementPtrInst &GEPI)
384 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
385 0, GEPI.getNumOperands()) {
386 Use *OL = OperandList = new Use[NumOperands];
387 Use *GEPIOL = GEPI.OperandList;
388 for (unsigned i = 0, E = NumOperands; i != E; ++i)
389 OL[i].init(GEPIOL[i], this);
391 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
392 void init(Value *Ptr, Value *Idx);
394 template<typename InputIterator>
395 void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
396 const std::string &Name,
397 // This argument ensures that we have an iterator we can
398 // do arithmetic on in constant time
399 std::random_access_iterator_tag) {
400 typename std::iterator_traits<InputIterator>::difference_type NumIdx =
401 std::distance(IdxBegin, IdxEnd);
404 // This requires that the itoerator points to contiguous memory.
405 init(Ptr, &*IdxBegin, NumIdx);
408 init(Ptr, 0, NumIdx);
414 /// getIndexedType - Returns the type of the element that would be loaded with
415 /// a load instruction with the specified parameters.
417 /// A null type is returned if the indices are invalid for the specified
420 static const Type *getIndexedType(const Type *Ptr,
421 Value* const *Idx, unsigned NumIdx,
422 bool AllowStructLeaf = false);
424 template<typename InputIterator>
425 static const Type *getIndexedType(const Type *Ptr,
426 InputIterator IdxBegin,
427 InputIterator IdxEnd,
428 bool AllowStructLeaf,
429 // This argument ensures that we
430 // have an iterator we can do
431 // arithmetic on in constant time
432 std::random_access_iterator_tag) {
433 typename std::iterator_traits<InputIterator>::difference_type NumIdx =
434 std::distance(IdxBegin, IdxEnd);
437 // This requires that the iterator points to contiguous memory.
438 return(getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx,
442 return(getIndexedType(Ptr, (Value *const*)0, NumIdx, AllowStructLeaf));
446 /// Constructors - Create a getelementptr instruction with a base pointer an
447 /// list of indices. The first ctor can optionally insert before an existing
448 /// instruction, the second appends the new instruction to the specified
450 template<typename InputIterator>
451 GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
452 InputIterator IdxEnd,
453 const std::string &Name = "",
454 Instruction *InsertBefore = 0)
455 : Instruction(PointerType::get(
456 checkType(getIndexedType(Ptr->getType(),
457 IdxBegin, IdxEnd, true)),
458 cast<PointerType>(Ptr->getType())->getAddressSpace()),
459 GetElementPtr, 0, 0, InsertBefore) {
460 init(Ptr, IdxBegin, IdxEnd, Name,
461 typename std::iterator_traits<InputIterator>::iterator_category());
463 template<typename InputIterator>
464 GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
465 const std::string &Name, BasicBlock *InsertAtEnd)
466 : Instruction(PointerType::get(
467 checkType(getIndexedType(Ptr->getType(),
468 IdxBegin, IdxEnd, true)),
469 cast<PointerType>(Ptr->getType())->getAddressSpace()),
470 GetElementPtr, 0, 0, InsertAtEnd) {
471 init(Ptr, IdxBegin, IdxEnd, Name,
472 typename std::iterator_traits<InputIterator>::iterator_category());
475 /// Constructors - These two constructors are convenience methods because one
476 /// and two index getelementptr instructions are so common.
477 GetElementPtrInst(Value *Ptr, Value *Idx,
478 const std::string &Name = "", Instruction *InsertBefore = 0);
479 GetElementPtrInst(Value *Ptr, Value *Idx,
480 const std::string &Name, BasicBlock *InsertAtEnd);
482 template<typename InputIterator>
483 static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin,
484 InputIterator IdxEnd,
485 const std::string &Name = "",
486 Instruction *InsertBefore = 0) {
487 return new(0/*FIXME*/) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name, InsertBefore);
489 template<typename InputIterator>
490 static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
491 const std::string &Name, BasicBlock *InsertAtEnd) {
492 return new(0/*FIXME*/) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name, InsertAtEnd);
495 /// Constructors - These two constructors are convenience methods because one
496 /// and two index getelementptr instructions are so common.
497 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
498 const std::string &Name = "", Instruction *InsertBefore = 0) {
499 return new(2/*FIXME*/) GetElementPtrInst(Ptr, Idx, Name, InsertBefore);
501 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
502 const std::string &Name, BasicBlock *InsertAtEnd) {
503 return new(2/*FIXME*/) GetElementPtrInst(Ptr, Idx, Name, InsertAtEnd);
505 ~GetElementPtrInst();
507 virtual GetElementPtrInst *clone() const;
509 // getType - Overload to return most specific pointer type...
510 const PointerType *getType() const {
511 return reinterpret_cast<const PointerType*>(Instruction::getType());
514 /// getIndexedType - Returns the type of the element that would be loaded with
515 /// a load instruction with the specified parameters.
517 /// A null type is returned if the indices are invalid for the specified
520 template<typename InputIterator>
521 static const Type *getIndexedType(const Type *Ptr,
522 InputIterator IdxBegin,
523 InputIterator IdxEnd,
524 bool AllowStructLeaf = false) {
525 return(getIndexedType(Ptr, IdxBegin, IdxEnd, AllowStructLeaf,
526 typename std::iterator_traits<InputIterator>::
527 iterator_category()));
529 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
531 inline op_iterator idx_begin() { return op_begin()+1; }
532 inline const_op_iterator idx_begin() const { return op_begin()+1; }
533 inline op_iterator idx_end() { return op_end(); }
534 inline const_op_iterator idx_end() const { return op_end(); }
536 Value *getPointerOperand() {
537 return getOperand(0);
539 const Value *getPointerOperand() const {
540 return getOperand(0);
542 static unsigned getPointerOperandIndex() {
543 return 0U; // get index for modifying correct operand
546 unsigned getNumIndices() const { // Note: always non-negative
547 return getNumOperands() - 1;
550 bool hasIndices() const {
551 return getNumOperands() > 1;
554 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
555 /// zeros. If so, the result pointer and the first operand have the same
556 /// value, just potentially different types.
557 bool hasAllZeroIndices() const;
559 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
560 /// constant integers. If so, the result pointer and the first operand have
561 /// a constant offset between them.
562 bool hasAllConstantIndices() const;
565 // Methods for support type inquiry through isa, cast, and dyn_cast:
566 static inline bool classof(const GetElementPtrInst *) { return true; }
567 static inline bool classof(const Instruction *I) {
568 return (I->getOpcode() == Instruction::GetElementPtr);
570 static inline bool classof(const Value *V) {
571 return isa<Instruction>(V) && classof(cast<Instruction>(V));
575 //===----------------------------------------------------------------------===//
577 //===----------------------------------------------------------------------===//
579 /// This instruction compares its operands according to the predicate given
580 /// to the constructor. It only operates on integers, pointers, or packed
581 /// vectors of integrals. The two operands must be the same type.
582 /// @brief Represent an integer comparison operator.
583 class ICmpInst: public CmpInst {
585 /// This enumeration lists the possible predicates for the ICmpInst. The
586 /// values in the range 0-31 are reserved for FCmpInst while values in the
587 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
588 /// predicate values are not overlapping between the classes.
590 ICMP_EQ = 32, ///< equal
591 ICMP_NE = 33, ///< not equal
592 ICMP_UGT = 34, ///< unsigned greater than
593 ICMP_UGE = 35, ///< unsigned greater or equal
594 ICMP_ULT = 36, ///< unsigned less than
595 ICMP_ULE = 37, ///< unsigned less or equal
596 ICMP_SGT = 38, ///< signed greater than
597 ICMP_SGE = 39, ///< signed greater or equal
598 ICMP_SLT = 40, ///< signed less than
599 ICMP_SLE = 41, ///< signed less or equal
600 FIRST_ICMP_PREDICATE = ICMP_EQ,
601 LAST_ICMP_PREDICATE = ICMP_SLE,
602 BAD_ICMP_PREDICATE = ICMP_SLE + 1
605 /// @brief Constructor with insert-before-instruction semantics.
607 Predicate pred, ///< The predicate to use for the comparison
608 Value *LHS, ///< The left-hand-side of the expression
609 Value *RHS, ///< The right-hand-side of the expression
610 const std::string &Name = "", ///< Name of the instruction
611 Instruction *InsertBefore = 0 ///< Where to insert
612 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
615 /// @brief Constructor with insert-at-block-end semantics.
617 Predicate pred, ///< The predicate to use for the comparison
618 Value *LHS, ///< The left-hand-side of the expression
619 Value *RHS, ///< The right-hand-side of the expression
620 const std::string &Name, ///< Name of the instruction
621 BasicBlock *InsertAtEnd ///< Block to insert into.
622 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
625 /// @brief Return the predicate for this instruction.
626 Predicate getPredicate() const { return Predicate(SubclassData); }
628 /// @brief Set the predicate for this instruction to the specified value.
629 void setPredicate(Predicate P) { SubclassData = P; }
631 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
632 /// @returns the inverse predicate for the instruction's current predicate.
633 /// @brief Return the inverse of the instruction's predicate.
634 Predicate getInversePredicate() const {
635 return getInversePredicate(getPredicate());
638 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
639 /// @returns the inverse predicate for predicate provided in \p pred.
640 /// @brief Return the inverse of a given predicate
641 static Predicate getInversePredicate(Predicate pred);
643 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
644 /// @returns the predicate that would be the result of exchanging the two
645 /// operands of the ICmpInst instruction without changing the result
647 /// @brief Return the predicate as if the operands were swapped
648 Predicate getSwappedPredicate() const {
649 return getSwappedPredicate(getPredicate());
652 /// This is a static version that you can use without an instruction
654 /// @brief Return the predicate as if the operands were swapped.
655 static Predicate getSwappedPredicate(Predicate pred);
657 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
658 /// @returns the predicate that would be the result if the operand were
659 /// regarded as signed.
660 /// @brief Return the signed version of the predicate
661 Predicate getSignedPredicate() const {
662 return getSignedPredicate(getPredicate());
665 /// This is a static version that you can use without an instruction.
666 /// @brief Return the signed version of the predicate.
667 static Predicate getSignedPredicate(Predicate pred);
669 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
670 /// @returns the predicate that would be the result if the operand were
671 /// regarded as unsigned.
672 /// @brief Return the unsigned version of the predicate
673 Predicate getUnsignedPredicate() const {
674 return getUnsignedPredicate(getPredicate());
677 /// This is a static version that you can use without an instruction.
678 /// @brief Return the unsigned version of the predicate.
679 static Predicate getUnsignedPredicate(Predicate pred);
681 /// isEquality - Return true if this predicate is either EQ or NE. This also
682 /// tests for commutativity.
683 static bool isEquality(Predicate P) {
684 return P == ICMP_EQ || P == ICMP_NE;
687 /// isEquality - Return true if this predicate is either EQ or NE. This also
688 /// tests for commutativity.
689 bool isEquality() const {
690 return isEquality(getPredicate());
693 /// @returns true if the predicate of this ICmpInst is commutative
694 /// @brief Determine if this relation is commutative.
695 bool isCommutative() const { return isEquality(); }
697 /// isRelational - Return true if the predicate is relational (not EQ or NE).
699 bool isRelational() const {
700 return !isEquality();
703 /// isRelational - Return true if the predicate is relational (not EQ or NE).
705 static bool isRelational(Predicate P) {
706 return !isEquality(P);
709 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
710 /// @brief Determine if this instruction's predicate is signed.
711 bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); }
713 /// @returns true if the predicate provided is signed, false otherwise
714 /// @brief Determine if the predicate is signed.
715 static bool isSignedPredicate(Predicate pred);
717 /// Initialize a set of values that all satisfy the predicate with C.
718 /// @brief Make a ConstantRange for a relation with a constant value.
719 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
721 /// Exchange the two operands to this instruction in such a way that it does
722 /// not modify the semantics of the instruction. The predicate value may be
723 /// changed to retain the same result if the predicate is order dependent
725 /// @brief Swap operands and adjust predicate.
726 void swapOperands() {
727 SubclassData = getSwappedPredicate();
728 std::swap(Ops[0], Ops[1]);
731 virtual ICmpInst *clone() const;
733 // Methods for support type inquiry through isa, cast, and dyn_cast:
734 static inline bool classof(const ICmpInst *) { return true; }
735 static inline bool classof(const Instruction *I) {
736 return I->getOpcode() == Instruction::ICmp;
738 static inline bool classof(const Value *V) {
739 return isa<Instruction>(V) && classof(cast<Instruction>(V));
743 //===----------------------------------------------------------------------===//
745 //===----------------------------------------------------------------------===//
747 /// This instruction compares its operands according to the predicate given
748 /// to the constructor. It only operates on floating point values or packed
749 /// vectors of floating point values. The operands must be identical types.
750 /// @brief Represents a floating point comparison operator.
751 class FCmpInst: public CmpInst {
753 /// This enumeration lists the possible predicates for the FCmpInst. Values
754 /// in the range 0-31 are reserved for FCmpInst.
756 // Opcode U L G E Intuitive operation
757 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
758 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
759 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
760 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
761 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
762 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
763 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
764 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
765 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
766 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
767 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
768 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
769 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
770 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
771 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
772 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
773 FIRST_FCMP_PREDICATE = FCMP_FALSE,
774 LAST_FCMP_PREDICATE = FCMP_TRUE,
775 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
778 /// @brief Constructor with insert-before-instruction semantics.
780 Predicate pred, ///< The predicate to use for the comparison
781 Value *LHS, ///< The left-hand-side of the expression
782 Value *RHS, ///< The right-hand-side of the expression
783 const std::string &Name = "", ///< Name of the instruction
784 Instruction *InsertBefore = 0 ///< Where to insert
785 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
788 /// @brief Constructor with insert-at-block-end semantics.
790 Predicate pred, ///< The predicate to use for the comparison
791 Value *LHS, ///< The left-hand-side of the expression
792 Value *RHS, ///< The right-hand-side of the expression
793 const std::string &Name, ///< Name of the instruction
794 BasicBlock *InsertAtEnd ///< Block to insert into.
795 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
798 /// @brief Return the predicate for this instruction.
799 Predicate getPredicate() const { return Predicate(SubclassData); }
801 /// @brief Set the predicate for this instruction to the specified value.
802 void setPredicate(Predicate P) { SubclassData = P; }
804 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
805 /// @returns the inverse predicate for the instructions current predicate.
806 /// @brief Return the inverse of the predicate
807 Predicate getInversePredicate() const {
808 return getInversePredicate(getPredicate());
811 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
812 /// @returns the inverse predicate for \p pred.
813 /// @brief Return the inverse of a given predicate
814 static Predicate getInversePredicate(Predicate pred);
816 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
817 /// @returns the predicate that would be the result of exchanging the two
818 /// operands of the ICmpInst instruction without changing the result
820 /// @brief Return the predicate as if the operands were swapped
821 Predicate getSwappedPredicate() const {
822 return getSwappedPredicate(getPredicate());
825 /// This is a static version that you can use without an instruction
827 /// @brief Return the predicate as if the operands were swapped.
828 static Predicate getSwappedPredicate(Predicate Opcode);
830 /// This also tests for commutativity. If isEquality() returns true then
831 /// the predicate is also commutative. Only the equality predicates are
833 /// @returns true if the predicate of this instruction is EQ or NE.
834 /// @brief Determine if this is an equality predicate.
835 bool isEquality() const {
836 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
837 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
839 bool isCommutative() const { return isEquality(); }
841 /// @returns true if the predicate is relational (not EQ or NE).
842 /// @brief Determine if this a relational predicate.
843 bool isRelational() const { return !isEquality(); }
845 /// Exchange the two operands to this instruction in such a way that it does
846 /// not modify the semantics of the instruction. The predicate value may be
847 /// changed to retain the same result if the predicate is order dependent
849 /// @brief Swap operands and adjust predicate.
850 void swapOperands() {
851 SubclassData = getSwappedPredicate();
852 std::swap(Ops[0], Ops[1]);
855 virtual FCmpInst *clone() const;
857 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
858 static inline bool classof(const FCmpInst *) { return true; }
859 static inline bool classof(const Instruction *I) {
860 return I->getOpcode() == Instruction::FCmp;
862 static inline bool classof(const Value *V) {
863 return isa<Instruction>(V) && classof(cast<Instruction>(V));
867 //===----------------------------------------------------------------------===//
869 //===----------------------------------------------------------------------===//
870 /// CallInst - This class represents a function call, abstracting a target
871 /// machine's calling convention. This class uses low bit of the SubClassData
872 /// field to indicate whether or not this is a tail call. The rest of the bits
873 /// hold the calling convention of the call.
876 class CallInst : public Instruction {
877 PAListPtr ParamAttrs; ///< parameter attributes for call
878 CallInst(const CallInst &CI);
879 void init(Value *Func, Value* const *Params, unsigned NumParams);
880 void init(Value *Func, Value *Actual1, Value *Actual2);
881 void init(Value *Func, Value *Actual);
882 void init(Value *Func);
884 template<typename InputIterator>
885 void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
886 const std::string &Name,
887 // This argument ensures that we have an iterator we can
888 // do arithmetic on in constant time
889 std::random_access_iterator_tag) {
890 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
892 // This requires that the iterator points to contiguous memory.
893 init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
897 /// Construct a CallInst given a range of arguments. InputIterator
898 /// must be a random-access iterator pointing to contiguous storage
899 /// (e.g. a std::vector<>::iterator). Checks are made for
900 /// random-accessness but not for contiguous storage as that would
901 /// incur runtime overhead.
902 /// @brief Construct a CallInst from a range of arguments
903 template<typename InputIterator>
904 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
905 const std::string &Name = "", Instruction *InsertBefore = 0)
906 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
907 ->getElementType())->getReturnType(),
908 Instruction::Call, 0, 0, InsertBefore) {
909 init(Func, ArgBegin, ArgEnd, Name,
910 typename std::iterator_traits<InputIterator>::iterator_category());
913 /// Construct a CallInst given a range of arguments. InputIterator
914 /// must be a random-access iterator pointing to contiguous storage
915 /// (e.g. a std::vector<>::iterator). Checks are made for
916 /// random-accessness but not for contiguous storage as that would
917 /// incur runtime overhead.
918 /// @brief Construct a CallInst from a range of arguments
919 template<typename InputIterator>
920 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
921 const std::string &Name, BasicBlock *InsertAtEnd)
922 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
923 ->getElementType())->getReturnType(),
924 Instruction::Call, 0, 0, InsertAtEnd) {
925 init(Func, ArgBegin, ArgEnd, Name,
926 typename std::iterator_traits<InputIterator>::iterator_category());
929 CallInst(Value *F, Value *Actual, const std::string& Name = "",
930 Instruction *InsertBefore = 0);
931 CallInst(Value *F, Value *Actual, const std::string& Name,
932 BasicBlock *InsertAtEnd);
933 explicit CallInst(Value *F, const std::string &Name = "",
934 Instruction *InsertBefore = 0);
935 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
937 template<typename InputIterator>
938 static CallInst *Create(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
939 const std::string &Name = "", Instruction *InsertBefore = 0) {
940 return new(ArgEnd - ArgBegin + 1) CallInst(Func, ArgBegin, ArgEnd, Name, InsertBefore);
942 template<typename InputIterator>
943 static CallInst *Create(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
944 const std::string &Name, BasicBlock *InsertAtEnd) {
945 return new(ArgEnd - ArgBegin + 1) CallInst(Func, ArgBegin, ArgEnd, Name, InsertAtEnd);
947 static CallInst *Create(Value *F, Value *Actual, const std::string& Name = "",
948 Instruction *InsertBefore = 0) {
949 return new(2) CallInst(F, Actual, Name, InsertBefore);
951 static CallInst *Create(Value *F, Value *Actual, const std::string& Name,
952 BasicBlock *InsertAtEnd) {
953 return new(2) CallInst(F, Actual, Name, InsertAtEnd);
955 static CallInst *Create(Value *F, const std::string &Name = "",
956 Instruction *InsertBefore = 0) {
957 return new(1) CallInst(F, Name, InsertBefore);
959 static CallInst *Create(Value *F, const std::string &Name, BasicBlock *InsertAtEnd) {
960 return new(1) CallInst(F, Name, InsertAtEnd);
965 virtual CallInst *clone() const;
967 bool isTailCall() const { return SubclassData & 1; }
968 void setTailCall(bool isTailCall = true) {
969 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
972 /// getCallingConv/setCallingConv - Get or set the calling convention of this
974 unsigned getCallingConv() const { return SubclassData >> 1; }
975 void setCallingConv(unsigned CC) {
976 SubclassData = (SubclassData & 1) | (CC << 1);
979 /// getParamAttrs - Return the parameter attributes for this call.
981 const PAListPtr &getParamAttrs() const { return ParamAttrs; }
983 /// setParamAttrs - Sets the parameter attributes for this call.
984 void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
986 /// @brief Determine whether the call or the callee has the given attribute.
987 bool paramHasAttr(unsigned i, unsigned attr) const;
989 /// @brief Extract the alignment for a call or parameter (0=unknown).
990 unsigned getParamAlignment(unsigned i) const {
991 return ParamAttrs.getParamAlignment(i);
994 /// @brief Determine if the call does not access memory.
995 bool doesNotAccessMemory() const {
996 return paramHasAttr(0, ParamAttr::ReadNone);
999 /// @brief Determine if the call does not access or only reads memory.
1000 bool onlyReadsMemory() const {
1001 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
1004 /// @brief Determine if the call cannot return.
1005 bool doesNotReturn() const {
1006 return paramHasAttr(0, ParamAttr::NoReturn);
1009 /// @brief Determine if the call cannot unwind.
1010 bool doesNotThrow() const {
1011 return paramHasAttr(0, ParamAttr::NoUnwind);
1013 void setDoesNotThrow(bool doesNotThrow = true);
1015 /// @brief Determine if the call returns a structure through first
1016 /// pointer argument.
1017 bool hasStructRetAttr() const {
1018 // Be friendly and also check the callee.
1019 return paramHasAttr(1, ParamAttr::StructRet);
1022 /// @brief Determine if any call argument is an aggregate passed by value.
1023 bool hasByValArgument() const {
1024 return ParamAttrs.hasAttrSomewhere(ParamAttr::ByVal);
1027 /// getCalledFunction - Return the function being called by this instruction
1028 /// if it is a direct call. If it is a call through a function pointer,
1030 Function *getCalledFunction() const {
1031 return dyn_cast<Function>(getOperand(0));
1034 /// getCalledValue - Get a pointer to the function that is invoked by this
1036 const Value *getCalledValue() const { return getOperand(0); }
1037 Value *getCalledValue() { return getOperand(0); }
1039 // Methods for support type inquiry through isa, cast, and dyn_cast:
1040 static inline bool classof(const CallInst *) { return true; }
1041 static inline bool classof(const Instruction *I) {
1042 return I->getOpcode() == Instruction::Call;
1044 static inline bool classof(const Value *V) {
1045 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1049 //===----------------------------------------------------------------------===//
1051 //===----------------------------------------------------------------------===//
1053 /// SelectInst - This class represents the LLVM 'select' instruction.
1055 class SelectInst : public Instruction {
1058 void init(Value *C, Value *S1, Value *S2) {
1059 Ops[0].init(C, this);
1060 Ops[1].init(S1, this);
1061 Ops[2].init(S2, this);
1064 SelectInst(const SelectInst &SI)
1065 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
1066 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
1068 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
1069 Instruction *InsertBefore = 0)
1070 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
1074 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
1075 BasicBlock *InsertAtEnd)
1076 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
1081 static SelectInst *Create(Value *C, Value *S1, Value *S2, const std::string &Name = "",
1082 Instruction *InsertBefore = 0) {
1083 return new(3) SelectInst(C, S1, S2, Name, InsertBefore);
1085 static SelectInst *Create(Value *C, Value *S1, Value *S2, const std::string &Name,
1086 BasicBlock *InsertAtEnd) {
1087 return new(3) SelectInst(C, S1, S2, Name, InsertAtEnd);
1090 Value *getCondition() const { return Ops[0]; }
1091 Value *getTrueValue() const { return Ops[1]; }
1092 Value *getFalseValue() const { return Ops[2]; }
1094 /// Transparently provide more efficient getOperand methods.
1095 Value *getOperand(unsigned i) const {
1096 assert(i < 3 && "getOperand() out of range!");
1099 void setOperand(unsigned i, Value *Val) {
1100 assert(i < 3 && "setOperand() out of range!");
1103 unsigned getNumOperands() const { return 3; }
1105 OtherOps getOpcode() const {
1106 return static_cast<OtherOps>(Instruction::getOpcode());
1109 virtual SelectInst *clone() const;
1111 // Methods for support type inquiry through isa, cast, and dyn_cast:
1112 static inline bool classof(const SelectInst *) { return true; }
1113 static inline bool classof(const Instruction *I) {
1114 return I->getOpcode() == Instruction::Select;
1116 static inline bool classof(const Value *V) {
1117 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1121 //===----------------------------------------------------------------------===//
1123 //===----------------------------------------------------------------------===//
1125 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1126 /// an argument of the specified type given a va_list and increments that list
1128 class VAArgInst : public UnaryInstruction {
1129 VAArgInst(const VAArgInst &VAA)
1130 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
1132 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
1133 Instruction *InsertBefore = 0)
1134 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1137 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
1138 BasicBlock *InsertAtEnd)
1139 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1143 virtual VAArgInst *clone() const;
1145 // Methods for support type inquiry through isa, cast, and dyn_cast:
1146 static inline bool classof(const VAArgInst *) { return true; }
1147 static inline bool classof(const Instruction *I) {
1148 return I->getOpcode() == VAArg;
1150 static inline bool classof(const Value *V) {
1151 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1155 //===----------------------------------------------------------------------===//
1156 // ExtractElementInst Class
1157 //===----------------------------------------------------------------------===//
1159 /// ExtractElementInst - This instruction extracts a single (scalar)
1160 /// element from a VectorType value
1162 class ExtractElementInst : public Instruction {
1164 ExtractElementInst(const ExtractElementInst &EE) :
1165 Instruction(EE.getType(), ExtractElement, Ops, 2) {
1166 Ops[0].init(EE.Ops[0], this);
1167 Ops[1].init(EE.Ops[1], this);
1171 // allocate space for exactly two operands
1172 void *operator new(size_t s) {
1173 return User::operator new(s, 2); // FIXME: unsigned Idx forms of constructor?
1175 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
1176 Instruction *InsertBefore = 0);
1177 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
1178 Instruction *InsertBefore = 0);
1179 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
1180 BasicBlock *InsertAtEnd);
1181 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
1182 BasicBlock *InsertAtEnd);
1184 /// isValidOperands - Return true if an extractelement instruction can be
1185 /// formed with the specified operands.
1186 static bool isValidOperands(const Value *Vec, const Value *Idx);
1188 virtual ExtractElementInst *clone() const;
1190 /// Transparently provide more efficient getOperand methods.
1191 Value *getOperand(unsigned i) const {
1192 assert(i < 2 && "getOperand() out of range!");
1195 void setOperand(unsigned i, Value *Val) {
1196 assert(i < 2 && "setOperand() out of range!");
1199 unsigned getNumOperands() const { return 2; }
1201 // Methods for support type inquiry through isa, cast, and dyn_cast:
1202 static inline bool classof(const ExtractElementInst *) { return true; }
1203 static inline bool classof(const Instruction *I) {
1204 return I->getOpcode() == Instruction::ExtractElement;
1206 static inline bool classof(const Value *V) {
1207 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1211 //===----------------------------------------------------------------------===//
1212 // InsertElementInst Class
1213 //===----------------------------------------------------------------------===//
1215 /// InsertElementInst - This instruction inserts a single (scalar)
1216 /// element into a VectorType value
1218 class InsertElementInst : public Instruction {
1220 InsertElementInst(const InsertElementInst &IE);
1221 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1222 const std::string &Name = "",Instruction *InsertBefore = 0);
1223 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1224 const std::string &Name = "",Instruction *InsertBefore = 0);
1225 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1226 const std::string &Name, BasicBlock *InsertAtEnd);
1227 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1228 const std::string &Name, BasicBlock *InsertAtEnd);
1230 static InsertElementInst *Create(const InsertElementInst &IE) {
1231 return new(IE.getNumOperands()) InsertElementInst(IE);
1233 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1234 const std::string &Name = "",Instruction *InsertBefore = 0) {
1235 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
1237 static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
1238 const std::string &Name = "",Instruction *InsertBefore = 0) {
1239 return new(3/*FIXME*/) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
1241 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1242 const std::string &Name, BasicBlock *InsertAtEnd) {
1243 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
1245 static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
1246 const std::string &Name, BasicBlock *InsertAtEnd) {
1247 return new(3/*FIXME*/) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
1250 /// isValidOperands - Return true if an insertelement instruction can be
1251 /// formed with the specified operands.
1252 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1255 virtual InsertElementInst *clone() const;
1257 /// getType - Overload to return most specific vector type.
1259 const VectorType *getType() const {
1260 return reinterpret_cast<const VectorType*>(Instruction::getType());
1263 /// Transparently provide more efficient getOperand methods.
1264 Value *getOperand(unsigned i) const {
1265 assert(i < 3 && "getOperand() out of range!");
1268 void setOperand(unsigned i, Value *Val) {
1269 assert(i < 3 && "setOperand() out of range!");
1272 unsigned getNumOperands() const { return 3; }
1274 // Methods for support type inquiry through isa, cast, and dyn_cast:
1275 static inline bool classof(const InsertElementInst *) { return true; }
1276 static inline bool classof(const Instruction *I) {
1277 return I->getOpcode() == Instruction::InsertElement;
1279 static inline bool classof(const Value *V) {
1280 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1284 //===----------------------------------------------------------------------===//
1285 // ShuffleVectorInst Class
1286 //===----------------------------------------------------------------------===//
1288 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1291 class ShuffleVectorInst : public Instruction {
1293 ShuffleVectorInst(const ShuffleVectorInst &IE);
1295 // allocate space for exactly three operands
1296 void *operator new(size_t s) {
1297 return User::operator new(s, 3);
1299 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1300 const std::string &Name = "", Instruction *InsertBefor = 0);
1301 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1302 const std::string &Name, BasicBlock *InsertAtEnd);
1304 /// isValidOperands - Return true if a shufflevector instruction can be
1305 /// formed with the specified operands.
1306 static bool isValidOperands(const Value *V1, const Value *V2,
1309 virtual ShuffleVectorInst *clone() const;
1311 /// getType - Overload to return most specific vector type.
1313 const VectorType *getType() const {
1314 return reinterpret_cast<const VectorType*>(Instruction::getType());
1317 /// Transparently provide more efficient getOperand methods.
1318 const Value *getOperand(unsigned i) const {
1319 assert(i < 3 && "getOperand() out of range!");
1322 Value *getOperand(unsigned i) {
1323 assert(i < 3 && "getOperand() out of range!");
1326 void setOperand(unsigned i, Value *Val) {
1327 assert(i < 3 && "setOperand() out of range!");
1330 unsigned getNumOperands() const { return 3; }
1332 /// getMaskValue - Return the index from the shuffle mask for the specified
1333 /// output result. This is either -1 if the element is undef or a number less
1334 /// than 2*numelements.
1335 int getMaskValue(unsigned i) const;
1337 // Methods for support type inquiry through isa, cast, and dyn_cast:
1338 static inline bool classof(const ShuffleVectorInst *) { return true; }
1339 static inline bool classof(const Instruction *I) {
1340 return I->getOpcode() == Instruction::ShuffleVector;
1342 static inline bool classof(const Value *V) {
1343 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1348 //===----------------------------------------------------------------------===//
1350 //===----------------------------------------------------------------------===//
1352 // PHINode - The PHINode class is used to represent the magical mystical PHI
1353 // node, that can not exist in nature, but can be synthesized in a computer
1354 // scientist's overactive imagination.
1356 class PHINode : public Instruction {
1357 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1358 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1359 /// the number actually in use.
1360 unsigned ReservedSpace;
1361 PHINode(const PHINode &PN);
1362 // allocate space for exactly zero operands
1363 void *operator new(size_t s) {
1364 return User::operator new(s, 0);
1366 explicit PHINode(const Type *Ty, const std::string &Name = "",
1367 Instruction *InsertBefore = 0)
1368 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1373 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1374 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1379 static PHINode *Create(const Type *Ty, const std::string &Name = "",
1380 Instruction *InsertBefore = 0) {
1381 return new PHINode(Ty, Name, InsertBefore);
1383 static PHINode *Create(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) {
1384 return new PHINode(Ty, Name, InsertAtEnd);
1388 /// reserveOperandSpace - This method can be used to avoid repeated
1389 /// reallocation of PHI operand lists by reserving space for the correct
1390 /// number of operands before adding them. Unlike normal vector reserves,
1391 /// this method can also be used to trim the operand space.
1392 void reserveOperandSpace(unsigned NumValues) {
1393 resizeOperands(NumValues*2);
1396 virtual PHINode *clone() const;
1398 /// getNumIncomingValues - Return the number of incoming edges
1400 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1402 /// getIncomingValue - Return incoming value number x
1404 Value *getIncomingValue(unsigned i) const {
1405 assert(i*2 < getNumOperands() && "Invalid value number!");
1406 return getOperand(i*2);
1408 void setIncomingValue(unsigned i, Value *V) {
1409 assert(i*2 < getNumOperands() && "Invalid value number!");
1412 unsigned getOperandNumForIncomingValue(unsigned i) {
1416 /// getIncomingBlock - Return incoming basic block number x
1418 BasicBlock *getIncomingBlock(unsigned i) const {
1419 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1421 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1422 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1424 unsigned getOperandNumForIncomingBlock(unsigned i) {
1428 /// addIncoming - Add an incoming value to the end of the PHI list
1430 void addIncoming(Value *V, BasicBlock *BB) {
1431 assert(V && "PHI node got a null value!");
1432 assert(BB && "PHI node got a null basic block!");
1433 assert(getType() == V->getType() &&
1434 "All operands to PHI node must be the same type as the PHI node!");
1435 unsigned OpNo = NumOperands;
1436 if (OpNo+2 > ReservedSpace)
1437 resizeOperands(0); // Get more space!
1438 // Initialize some new operands.
1439 NumOperands = OpNo+2;
1440 OperandList[OpNo].init(V, this);
1441 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1444 /// removeIncomingValue - Remove an incoming value. This is useful if a
1445 /// predecessor basic block is deleted. The value removed is returned.
1447 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1448 /// is true), the PHI node is destroyed and any uses of it are replaced with
1449 /// dummy values. The only time there should be zero incoming values to a PHI
1450 /// node is when the block is dead, so this strategy is sound.
1452 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1454 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1455 int Idx = getBasicBlockIndex(BB);
1456 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1457 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1460 /// getBasicBlockIndex - Return the first index of the specified basic
1461 /// block in the value list for this PHI. Returns -1 if no instance.
1463 int getBasicBlockIndex(const BasicBlock *BB) const {
1464 Use *OL = OperandList;
1465 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1466 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1470 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1471 return getIncomingValue(getBasicBlockIndex(BB));
1474 /// hasConstantValue - If the specified PHI node always merges together the
1475 /// same value, return the value, otherwise return null.
1477 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1479 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1480 static inline bool classof(const PHINode *) { return true; }
1481 static inline bool classof(const Instruction *I) {
1482 return I->getOpcode() == Instruction::PHI;
1484 static inline bool classof(const Value *V) {
1485 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1488 void resizeOperands(unsigned NumOperands);
1491 //===----------------------------------------------------------------------===//
1493 //===----------------------------------------------------------------------===//
1495 //===---------------------------------------------------------------------------
1496 /// ReturnInst - Return a value (possibly void), from a function. Execution
1497 /// does not continue in this function any longer.
1499 class ReturnInst : public TerminatorInst {
1501 ReturnInst(const ReturnInst &RI);
1502 void init(Value * const* retVals, unsigned N);
1505 // ReturnInst constructors:
1506 // ReturnInst() - 'ret void' instruction
1507 // ReturnInst( null) - 'ret void' instruction
1508 // ReturnInst(Value* X) - 'ret X' instruction
1509 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1510 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1511 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1512 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1513 // ReturnInst(Value* X, N) - 'ret X,X+1...X+N-1' instruction
1514 // ReturnInst(Value* X, N, Inst *) - 'ret X,X+1...X+N-1', insert before I
1515 // ReturnInst(Value* X, N, BB *) - 'ret X,X+1...X+N-1', insert @ end of BB
1517 // NOTE: If the Value* passed is of type void then the constructor behaves as
1518 // if it was passed NULL.
1519 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1520 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1521 ReturnInst(Value * const* retVals, unsigned N);
1522 ReturnInst(Value * const* retVals, unsigned N, Instruction *InsertBefore);
1523 ReturnInst(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd);
1524 explicit ReturnInst(BasicBlock *InsertAtEnd);
1526 static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) {
1527 return new(!!retVal) ReturnInst(retVal, InsertBefore);
1529 static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) {
1530 return new(!!retVal) ReturnInst(retVal, InsertAtEnd);
1532 static ReturnInst* Create(Value * const* retVals, unsigned N) {
1533 return new(N) ReturnInst(retVals, N);
1535 static ReturnInst* Create(Value * const* retVals, unsigned N, Instruction *InsertBefore) {
1536 return new(N) ReturnInst(retVals, N, InsertBefore);
1538 static ReturnInst* Create(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd) {
1539 return new(N) ReturnInst(retVals, N, InsertAtEnd);
1541 static ReturnInst* Create(BasicBlock *InsertAtEnd) {
1542 return new(0) ReturnInst(InsertAtEnd);
1544 virtual ~ReturnInst();
1546 virtual ReturnInst *clone() const;
1548 Value *getOperand(unsigned n = 0) const {
1549 if (getNumOperands() > 1)
1550 return TerminatorInst::getOperand(n);
1555 Value *getReturnValue(unsigned n = 0) const {
1556 return getOperand(n);
1559 unsigned getNumSuccessors() const { return 0; }
1561 // Methods for support type inquiry through isa, cast, and dyn_cast:
1562 static inline bool classof(const ReturnInst *) { return true; }
1563 static inline bool classof(const Instruction *I) {
1564 return (I->getOpcode() == Instruction::Ret);
1566 static inline bool classof(const Value *V) {
1567 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1570 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1571 virtual unsigned getNumSuccessorsV() const;
1572 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1575 //===----------------------------------------------------------------------===//
1577 //===----------------------------------------------------------------------===//
1579 //===---------------------------------------------------------------------------
1580 /// BranchInst - Conditional or Unconditional Branch instruction.
1582 class BranchInst : public TerminatorInst {
1583 /// Ops list - Branches are strange. The operands are ordered:
1584 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1585 /// they don't have to check for cond/uncond branchness.
1587 BranchInst(const BranchInst &BI);
1589 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1590 // BranchInst(BB *B) - 'br B'
1591 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1592 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1593 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1594 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1595 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1596 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1597 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1598 Instruction *InsertBefore = 0);
1599 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1600 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1601 BasicBlock *InsertAtEnd);
1603 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
1604 return new(1) BranchInst(IfTrue, InsertBefore);
1606 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1607 Instruction *InsertBefore = 0) {
1608 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
1610 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
1611 return new(1) BranchInst(IfTrue, InsertAtEnd);
1613 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1614 BasicBlock *InsertAtEnd) {
1615 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
1618 /// Transparently provide more efficient getOperand methods.
1619 Value *getOperand(unsigned i) const {
1620 assert(i < getNumOperands() && "getOperand() out of range!");
1623 void setOperand(unsigned i, Value *Val) {
1624 assert(i < getNumOperands() && "setOperand() out of range!");
1628 virtual BranchInst *clone() const;
1630 bool isUnconditional() const { return getNumOperands() == 1; }
1631 bool isConditional() const { return getNumOperands() == 3; }
1633 Value *getCondition() const {
1634 assert(isConditional() && "Cannot get condition of an uncond branch!");
1635 return getOperand(2);
1638 void setCondition(Value *V) {
1639 assert(isConditional() && "Cannot set condition of unconditional branch!");
1643 // setUnconditionalDest - Change the current branch to an unconditional branch
1644 // targeting the specified block.
1645 // FIXME: Eliminate this ugly method.
1646 void setUnconditionalDest(BasicBlock *Dest) {
1647 if (isConditional()) { // Convert this to an uncond branch.
1652 setOperand(0, reinterpret_cast<Value*>(Dest));
1655 unsigned getNumSuccessors() const { return 1+isConditional(); }
1657 BasicBlock *getSuccessor(unsigned i) const {
1658 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1659 return cast<BasicBlock>(getOperand(i));
1662 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1663 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1664 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1667 // Methods for support type inquiry through isa, cast, and dyn_cast:
1668 static inline bool classof(const BranchInst *) { return true; }
1669 static inline bool classof(const Instruction *I) {
1670 return (I->getOpcode() == Instruction::Br);
1672 static inline bool classof(const Value *V) {
1673 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1676 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1677 virtual unsigned getNumSuccessorsV() const;
1678 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1681 //===----------------------------------------------------------------------===//
1683 //===----------------------------------------------------------------------===//
1685 //===---------------------------------------------------------------------------
1686 /// SwitchInst - Multiway switch
1688 class SwitchInst : public TerminatorInst {
1689 unsigned ReservedSpace;
1690 // Operand[0] = Value to switch on
1691 // Operand[1] = Default basic block destination
1692 // Operand[2n ] = Value to match
1693 // Operand[2n+1] = BasicBlock to go to on match
1694 SwitchInst(const SwitchInst &RI);
1695 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1696 void resizeOperands(unsigned No);
1697 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1698 /// switch on and a default destination. The number of additional cases can
1699 /// be specified here to make memory allocation more efficient. This
1700 /// constructor can also autoinsert before another instruction.
1701 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1702 Instruction *InsertBefore = 0);
1704 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1705 /// switch on and a default destination. The number of additional cases can
1706 /// be specified here to make memory allocation more efficient. This
1707 /// constructor also autoinserts at the end of the specified BasicBlock.
1708 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1709 BasicBlock *InsertAtEnd);
1711 static SwitchInst *Create(Value *Value, BasicBlock *Default, unsigned NumCases,
1712 Instruction *InsertBefore = 0) {
1713 return new(NumCases/*FIXME*/) SwitchInst(Value, Default, NumCases, InsertBefore);
1715 static SwitchInst *Create(Value *Value, BasicBlock *Default, unsigned NumCases,
1716 BasicBlock *InsertAtEnd) {
1717 return new(NumCases/*FIXME*/) SwitchInst(Value, Default, NumCases, InsertAtEnd);
1721 // Accessor Methods for Switch stmt
1722 Value *getCondition() const { return getOperand(0); }
1723 void setCondition(Value *V) { setOperand(0, V); }
1725 BasicBlock *getDefaultDest() const {
1726 return cast<BasicBlock>(getOperand(1));
1729 /// getNumCases - return the number of 'cases' in this switch instruction.
1730 /// Note that case #0 is always the default case.
1731 unsigned getNumCases() const {
1732 return getNumOperands()/2;
1735 /// getCaseValue - Return the specified case value. Note that case #0, the
1736 /// default destination, does not have a case value.
1737 ConstantInt *getCaseValue(unsigned i) {
1738 assert(i && i < getNumCases() && "Illegal case value to get!");
1739 return getSuccessorValue(i);
1742 /// getCaseValue - Return the specified case value. Note that case #0, the
1743 /// default destination, does not have a case value.
1744 const ConstantInt *getCaseValue(unsigned i) const {
1745 assert(i && i < getNumCases() && "Illegal case value to get!");
1746 return getSuccessorValue(i);
1749 /// findCaseValue - Search all of the case values for the specified constant.
1750 /// If it is explicitly handled, return the case number of it, otherwise
1751 /// return 0 to indicate that it is handled by the default handler.
1752 unsigned findCaseValue(const ConstantInt *C) const {
1753 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1754 if (getCaseValue(i) == C)
1759 /// findCaseDest - Finds the unique case value for a given successor. Returns
1760 /// null if the successor is not found, not unique, or is the default case.
1761 ConstantInt *findCaseDest(BasicBlock *BB) {
1762 if (BB == getDefaultDest()) return NULL;
1764 ConstantInt *CI = NULL;
1765 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1766 if (getSuccessor(i) == BB) {
1767 if (CI) return NULL; // Multiple cases lead to BB.
1768 else CI = getCaseValue(i);
1774 /// addCase - Add an entry to the switch instruction...
1776 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1778 /// removeCase - This method removes the specified successor from the switch
1779 /// instruction. Note that this cannot be used to remove the default
1780 /// destination (successor #0).
1782 void removeCase(unsigned idx);
1784 virtual SwitchInst *clone() const;
1786 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1787 BasicBlock *getSuccessor(unsigned idx) const {
1788 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1789 return cast<BasicBlock>(getOperand(idx*2+1));
1791 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1792 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1793 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1796 // getSuccessorValue - Return the value associated with the specified
1798 ConstantInt *getSuccessorValue(unsigned idx) const {
1799 assert(idx < getNumSuccessors() && "Successor # out of range!");
1800 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1803 // Methods for support type inquiry through isa, cast, and dyn_cast:
1804 static inline bool classof(const SwitchInst *) { return true; }
1805 static inline bool classof(const Instruction *I) {
1806 return I->getOpcode() == Instruction::Switch;
1808 static inline bool classof(const Value *V) {
1809 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1812 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1813 virtual unsigned getNumSuccessorsV() const;
1814 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1817 //===----------------------------------------------------------------------===//
1819 //===----------------------------------------------------------------------===//
1821 //===---------------------------------------------------------------------------
1823 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1824 /// calling convention of the call.
1826 class InvokeInst : public TerminatorInst {
1827 PAListPtr ParamAttrs;
1828 InvokeInst(const InvokeInst &BI);
1829 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1830 Value* const *Args, unsigned NumArgs);
1832 template<typename InputIterator>
1833 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1834 InputIterator ArgBegin, InputIterator ArgEnd,
1835 const std::string &Name,
1836 // This argument ensures that we have an iterator we can
1837 // do arithmetic on in constant time
1838 std::random_access_iterator_tag) {
1839 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
1841 // This requires that the iterator points to contiguous memory.
1842 init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
1846 /// Construct an InvokeInst given a range of arguments.
1847 /// InputIterator must be a random-access iterator pointing to
1848 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
1849 /// made for random-accessness but not for contiguous storage as
1850 /// that would incur runtime overhead.
1852 /// @brief Construct an InvokeInst from a range of arguments
1853 template<typename InputIterator>
1854 InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1855 InputIterator ArgBegin, InputIterator ArgEnd,
1856 const std::string &Name = "", Instruction *InsertBefore = 0)
1857 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
1858 ->getElementType())->getReturnType(),
1859 Instruction::Invoke, 0, 0, InsertBefore) {
1860 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
1861 typename std::iterator_traits<InputIterator>::iterator_category());
1864 /// Construct an InvokeInst given a range of arguments.
1865 /// InputIterator must be a random-access iterator pointing to
1866 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
1867 /// made for random-accessness but not for contiguous storage as
1868 /// that would incur runtime overhead.
1870 /// @brief Construct an InvokeInst from a range of arguments
1871 template<typename InputIterator>
1872 InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1873 InputIterator ArgBegin, InputIterator ArgEnd,
1874 const std::string &Name, BasicBlock *InsertAtEnd)
1875 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
1876 ->getElementType())->getReturnType(),
1877 Instruction::Invoke, 0, 0, InsertAtEnd) {
1878 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
1879 typename std::iterator_traits<InputIterator>::iterator_category());
1882 template<typename InputIterator>
1883 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1884 InputIterator ArgBegin, InputIterator ArgEnd,
1885 const std::string &Name = "", Instruction *InsertBefore = 0) {
1886 return new(ArgEnd - ArgBegin + 3) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, InsertBefore);
1888 template<typename InputIterator>
1889 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1890 InputIterator ArgBegin, InputIterator ArgEnd,
1891 const std::string &Name, BasicBlock *InsertAtEnd) {
1892 return new(ArgEnd - ArgBegin + 3) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, InsertAtEnd);
1897 virtual InvokeInst *clone() const;
1899 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1901 unsigned getCallingConv() const { return SubclassData; }
1902 void setCallingConv(unsigned CC) {
1906 /// getParamAttrs - Return the parameter attributes for this invoke.
1908 const PAListPtr &getParamAttrs() const { return ParamAttrs; }
1910 /// setParamAttrs - Set the parameter attributes for this invoke.
1912 void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
1914 /// @brief Determine whether the call or the callee has the given attribute.
1915 bool paramHasAttr(unsigned i, ParameterAttributes attr) const;
1917 /// @brief Extract the alignment for a call or parameter (0=unknown).
1918 unsigned getParamAlignment(unsigned i) const {
1919 return ParamAttrs.getParamAlignment(i);
1922 /// @brief Determine if the call does not access memory.
1923 bool doesNotAccessMemory() const {
1924 return paramHasAttr(0, ParamAttr::ReadNone);
1927 /// @brief Determine if the call does not access or only reads memory.
1928 bool onlyReadsMemory() const {
1929 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
1932 /// @brief Determine if the call cannot return.
1933 bool doesNotReturn() const {
1934 return paramHasAttr(0, ParamAttr::NoReturn);
1937 /// @brief Determine if the call cannot unwind.
1938 bool doesNotThrow() const {
1939 return paramHasAttr(0, ParamAttr::NoUnwind);
1941 void setDoesNotThrow(bool doesNotThrow = true);
1943 /// @brief Determine if the call returns a structure through first
1944 /// pointer argument.
1945 bool hasStructRetAttr() const {
1946 // Be friendly and also check the callee.
1947 return paramHasAttr(1, ParamAttr::StructRet);
1950 /// getCalledFunction - Return the function called, or null if this is an
1951 /// indirect function invocation.
1953 Function *getCalledFunction() const {
1954 return dyn_cast<Function>(getOperand(0));
1957 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1958 Value *getCalledValue() const { return getOperand(0); }
1960 // get*Dest - Return the destination basic blocks...
1961 BasicBlock *getNormalDest() const {
1962 return cast<BasicBlock>(getOperand(1));
1964 BasicBlock *getUnwindDest() const {
1965 return cast<BasicBlock>(getOperand(2));
1967 void setNormalDest(BasicBlock *B) {
1968 setOperand(1, reinterpret_cast<Value*>(B));
1971 void setUnwindDest(BasicBlock *B) {
1972 setOperand(2, reinterpret_cast<Value*>(B));
1975 BasicBlock *getSuccessor(unsigned i) const {
1976 assert(i < 2 && "Successor # out of range for invoke!");
1977 return i == 0 ? getNormalDest() : getUnwindDest();
1980 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1981 assert(idx < 2 && "Successor # out of range for invoke!");
1982 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1985 unsigned getNumSuccessors() const { return 2; }
1987 // Methods for support type inquiry through isa, cast, and dyn_cast:
1988 static inline bool classof(const InvokeInst *) { return true; }
1989 static inline bool classof(const Instruction *I) {
1990 return (I->getOpcode() == Instruction::Invoke);
1992 static inline bool classof(const Value *V) {
1993 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1996 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1997 virtual unsigned getNumSuccessorsV() const;
1998 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2002 //===----------------------------------------------------------------------===//
2004 //===----------------------------------------------------------------------===//
2006 //===---------------------------------------------------------------------------
2007 /// UnwindInst - Immediately exit the current function, unwinding the stack
2008 /// until an invoke instruction is found.
2010 class UnwindInst : public TerminatorInst {
2011 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2013 // allocate space for exactly zero operands
2014 void *operator new(size_t s) {
2015 return User::operator new(s, 0);
2017 explicit UnwindInst(Instruction *InsertBefore = 0);
2018 explicit UnwindInst(BasicBlock *InsertAtEnd);
2020 virtual UnwindInst *clone() const;
2022 unsigned getNumSuccessors() const { return 0; }
2024 // Methods for support type inquiry through isa, cast, and dyn_cast:
2025 static inline bool classof(const UnwindInst *) { return true; }
2026 static inline bool classof(const Instruction *I) {
2027 return I->getOpcode() == Instruction::Unwind;
2029 static inline bool classof(const Value *V) {
2030 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2033 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2034 virtual unsigned getNumSuccessorsV() const;
2035 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2038 //===----------------------------------------------------------------------===//
2039 // UnreachableInst Class
2040 //===----------------------------------------------------------------------===//
2042 //===---------------------------------------------------------------------------
2043 /// UnreachableInst - This function has undefined behavior. In particular, the
2044 /// presence of this instruction indicates some higher level knowledge that the
2045 /// end of the block cannot be reached.
2047 class UnreachableInst : public TerminatorInst {
2048 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2050 // allocate space for exactly zero operands
2051 void *operator new(size_t s) {
2052 return User::operator new(s, 0);
2054 explicit UnreachableInst(Instruction *InsertBefore = 0);
2055 explicit UnreachableInst(BasicBlock *InsertAtEnd);
2057 virtual UnreachableInst *clone() const;
2059 unsigned getNumSuccessors() const { return 0; }
2061 // Methods for support type inquiry through isa, cast, and dyn_cast:
2062 static inline bool classof(const UnreachableInst *) { return true; }
2063 static inline bool classof(const Instruction *I) {
2064 return I->getOpcode() == Instruction::Unreachable;
2066 static inline bool classof(const Value *V) {
2067 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2070 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2071 virtual unsigned getNumSuccessorsV() const;
2072 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2075 //===----------------------------------------------------------------------===//
2077 //===----------------------------------------------------------------------===//
2079 /// @brief This class represents a truncation of integer types.
2080 class TruncInst : public CastInst {
2081 /// Private copy constructor
2082 TruncInst(const TruncInst &CI)
2083 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
2086 /// @brief Constructor with insert-before-instruction semantics
2088 Value *S, ///< The value to be truncated
2089 const Type *Ty, ///< The (smaller) type to truncate to
2090 const std::string &Name = "", ///< A name for the new instruction
2091 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2094 /// @brief Constructor with insert-at-end-of-block semantics
2096 Value *S, ///< The value to be truncated
2097 const Type *Ty, ///< The (smaller) type to truncate to
2098 const std::string &Name, ///< A name for the new instruction
2099 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2102 /// @brief Clone an identical TruncInst
2103 virtual CastInst *clone() const;
2105 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2106 static inline bool classof(const TruncInst *) { return true; }
2107 static inline bool classof(const Instruction *I) {
2108 return I->getOpcode() == Trunc;
2110 static inline bool classof(const Value *V) {
2111 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2115 //===----------------------------------------------------------------------===//
2117 //===----------------------------------------------------------------------===//
2119 /// @brief This class represents zero extension of integer types.
2120 class ZExtInst : public CastInst {
2121 /// @brief Private copy constructor
2122 ZExtInst(const ZExtInst &CI)
2123 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
2126 /// @brief Constructor with insert-before-instruction semantics
2128 Value *S, ///< The value to be zero extended
2129 const Type *Ty, ///< The type to zero extend to
2130 const std::string &Name = "", ///< A name for the new instruction
2131 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2134 /// @brief Constructor with insert-at-end semantics.
2136 Value *S, ///< The value to be zero extended
2137 const Type *Ty, ///< The type to zero extend to
2138 const std::string &Name, ///< A name for the new instruction
2139 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2142 /// @brief Clone an identical ZExtInst
2143 virtual CastInst *clone() const;
2145 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2146 static inline bool classof(const ZExtInst *) { return true; }
2147 static inline bool classof(const Instruction *I) {
2148 return I->getOpcode() == ZExt;
2150 static inline bool classof(const Value *V) {
2151 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2155 //===----------------------------------------------------------------------===//
2157 //===----------------------------------------------------------------------===//
2159 /// @brief This class represents a sign extension of integer types.
2160 class SExtInst : public CastInst {
2161 /// @brief Private copy constructor
2162 SExtInst(const SExtInst &CI)
2163 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
2166 /// @brief Constructor with insert-before-instruction semantics
2168 Value *S, ///< The value to be sign extended
2169 const Type *Ty, ///< The type to sign extend to
2170 const std::string &Name = "", ///< A name for the new instruction
2171 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2174 /// @brief Constructor with insert-at-end-of-block semantics
2176 Value *S, ///< The value to be sign extended
2177 const Type *Ty, ///< The type to sign extend to
2178 const std::string &Name, ///< A name for the new instruction
2179 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2182 /// @brief Clone an identical SExtInst
2183 virtual CastInst *clone() const;
2185 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2186 static inline bool classof(const SExtInst *) { return true; }
2187 static inline bool classof(const Instruction *I) {
2188 return I->getOpcode() == SExt;
2190 static inline bool classof(const Value *V) {
2191 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2195 //===----------------------------------------------------------------------===//
2196 // FPTruncInst Class
2197 //===----------------------------------------------------------------------===//
2199 /// @brief This class represents a truncation of floating point types.
2200 class FPTruncInst : public CastInst {
2201 FPTruncInst(const FPTruncInst &CI)
2202 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
2205 /// @brief Constructor with insert-before-instruction semantics
2207 Value *S, ///< The value to be truncated
2208 const Type *Ty, ///< The type to truncate to
2209 const std::string &Name = "", ///< A name for the new instruction
2210 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2213 /// @brief Constructor with insert-before-instruction semantics
2215 Value *S, ///< The value to be truncated
2216 const Type *Ty, ///< The type to truncate to
2217 const std::string &Name, ///< A name for the new instruction
2218 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2221 /// @brief Clone an identical FPTruncInst
2222 virtual CastInst *clone() const;
2224 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2225 static inline bool classof(const FPTruncInst *) { return true; }
2226 static inline bool classof(const Instruction *I) {
2227 return I->getOpcode() == FPTrunc;
2229 static inline bool classof(const Value *V) {
2230 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2234 //===----------------------------------------------------------------------===//
2236 //===----------------------------------------------------------------------===//
2238 /// @brief This class represents an extension of floating point types.
2239 class FPExtInst : public CastInst {
2240 FPExtInst(const FPExtInst &CI)
2241 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
2244 /// @brief Constructor with insert-before-instruction semantics
2246 Value *S, ///< The value to be extended
2247 const Type *Ty, ///< The type to extend to
2248 const std::string &Name = "", ///< A name for the new instruction
2249 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2252 /// @brief Constructor with insert-at-end-of-block semantics
2254 Value *S, ///< The value to be extended
2255 const Type *Ty, ///< The type to extend to
2256 const std::string &Name, ///< A name for the new instruction
2257 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2260 /// @brief Clone an identical FPExtInst
2261 virtual CastInst *clone() const;
2263 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2264 static inline bool classof(const FPExtInst *) { return true; }
2265 static inline bool classof(const Instruction *I) {
2266 return I->getOpcode() == FPExt;
2268 static inline bool classof(const Value *V) {
2269 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2273 //===----------------------------------------------------------------------===//
2275 //===----------------------------------------------------------------------===//
2277 /// @brief This class represents a cast unsigned integer to floating point.
2278 class UIToFPInst : public CastInst {
2279 UIToFPInst(const UIToFPInst &CI)
2280 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
2283 /// @brief Constructor with insert-before-instruction semantics
2285 Value *S, ///< The value to be converted
2286 const Type *Ty, ///< The type to convert to
2287 const std::string &Name = "", ///< A name for the new instruction
2288 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2291 /// @brief Constructor with insert-at-end-of-block semantics
2293 Value *S, ///< The value to be converted
2294 const Type *Ty, ///< The type to convert to
2295 const std::string &Name, ///< A name for the new instruction
2296 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2299 /// @brief Clone an identical UIToFPInst
2300 virtual CastInst *clone() const;
2302 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2303 static inline bool classof(const UIToFPInst *) { return true; }
2304 static inline bool classof(const Instruction *I) {
2305 return I->getOpcode() == UIToFP;
2307 static inline bool classof(const Value *V) {
2308 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2312 //===----------------------------------------------------------------------===//
2314 //===----------------------------------------------------------------------===//
2316 /// @brief This class represents a cast from signed integer to floating point.
2317 class SIToFPInst : public CastInst {
2318 SIToFPInst(const SIToFPInst &CI)
2319 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
2322 /// @brief Constructor with insert-before-instruction semantics
2324 Value *S, ///< The value to be converted
2325 const Type *Ty, ///< The type to convert to
2326 const std::string &Name = "", ///< A name for the new instruction
2327 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2330 /// @brief Constructor with insert-at-end-of-block semantics
2332 Value *S, ///< The value to be converted
2333 const Type *Ty, ///< The type to convert to
2334 const std::string &Name, ///< A name for the new instruction
2335 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2338 /// @brief Clone an identical SIToFPInst
2339 virtual CastInst *clone() const;
2341 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2342 static inline bool classof(const SIToFPInst *) { return true; }
2343 static inline bool classof(const Instruction *I) {
2344 return I->getOpcode() == SIToFP;
2346 static inline bool classof(const Value *V) {
2347 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2351 //===----------------------------------------------------------------------===//
2353 //===----------------------------------------------------------------------===//
2355 /// @brief This class represents a cast from floating point to unsigned integer
2356 class FPToUIInst : public CastInst {
2357 FPToUIInst(const FPToUIInst &CI)
2358 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
2361 /// @brief Constructor with insert-before-instruction semantics
2363 Value *S, ///< The value to be converted
2364 const Type *Ty, ///< The type to convert to
2365 const std::string &Name = "", ///< A name for the new instruction
2366 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2369 /// @brief Constructor with insert-at-end-of-block semantics
2371 Value *S, ///< The value to be converted
2372 const Type *Ty, ///< The type to convert to
2373 const std::string &Name, ///< A name for the new instruction
2374 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
2377 /// @brief Clone an identical FPToUIInst
2378 virtual CastInst *clone() const;
2380 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2381 static inline bool classof(const FPToUIInst *) { return true; }
2382 static inline bool classof(const Instruction *I) {
2383 return I->getOpcode() == FPToUI;
2385 static inline bool classof(const Value *V) {
2386 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2390 //===----------------------------------------------------------------------===//
2392 //===----------------------------------------------------------------------===//
2394 /// @brief This class represents a cast from floating point to signed integer.
2395 class FPToSIInst : public CastInst {
2396 FPToSIInst(const FPToSIInst &CI)
2397 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2400 /// @brief Constructor with insert-before-instruction semantics
2402 Value *S, ///< The value to be converted
2403 const Type *Ty, ///< The type to convert to
2404 const std::string &Name = "", ///< A name for the new instruction
2405 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2408 /// @brief Constructor with insert-at-end-of-block semantics
2410 Value *S, ///< The value to be converted
2411 const Type *Ty, ///< The type to convert to
2412 const std::string &Name, ///< A name for the new instruction
2413 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2416 /// @brief Clone an identical FPToSIInst
2417 virtual CastInst *clone() const;
2419 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2420 static inline bool classof(const FPToSIInst *) { return true; }
2421 static inline bool classof(const Instruction *I) {
2422 return I->getOpcode() == FPToSI;
2424 static inline bool classof(const Value *V) {
2425 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2429 //===----------------------------------------------------------------------===//
2430 // IntToPtrInst Class
2431 //===----------------------------------------------------------------------===//
2433 /// @brief This class represents a cast from an integer to a pointer.
2434 class IntToPtrInst : public CastInst {
2435 IntToPtrInst(const IntToPtrInst &CI)
2436 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2439 /// @brief Constructor with insert-before-instruction semantics
2441 Value *S, ///< The value to be converted
2442 const Type *Ty, ///< The type to convert to
2443 const std::string &Name = "", ///< A name for the new instruction
2444 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2447 /// @brief Constructor with insert-at-end-of-block semantics
2449 Value *S, ///< The value to be converted
2450 const Type *Ty, ///< The type to convert to
2451 const std::string &Name, ///< A name for the new instruction
2452 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2455 /// @brief Clone an identical IntToPtrInst
2456 virtual CastInst *clone() const;
2458 // Methods for support type inquiry through isa, cast, and dyn_cast:
2459 static inline bool classof(const IntToPtrInst *) { return true; }
2460 static inline bool classof(const Instruction *I) {
2461 return I->getOpcode() == IntToPtr;
2463 static inline bool classof(const Value *V) {
2464 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2468 //===----------------------------------------------------------------------===//
2469 // PtrToIntInst Class
2470 //===----------------------------------------------------------------------===//
2472 /// @brief This class represents a cast from a pointer to an integer
2473 class PtrToIntInst : public CastInst {
2474 PtrToIntInst(const PtrToIntInst &CI)
2475 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2478 /// @brief Constructor with insert-before-instruction semantics
2480 Value *S, ///< The value to be converted
2481 const Type *Ty, ///< The type to convert to
2482 const std::string &Name = "", ///< A name for the new instruction
2483 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2486 /// @brief Constructor with insert-at-end-of-block semantics
2488 Value *S, ///< The value to be converted
2489 const Type *Ty, ///< The type to convert to
2490 const std::string &Name, ///< A name for the new instruction
2491 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2494 /// @brief Clone an identical PtrToIntInst
2495 virtual CastInst *clone() const;
2497 // Methods for support type inquiry through isa, cast, and dyn_cast:
2498 static inline bool classof(const PtrToIntInst *) { return true; }
2499 static inline bool classof(const Instruction *I) {
2500 return I->getOpcode() == PtrToInt;
2502 static inline bool classof(const Value *V) {
2503 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2507 //===----------------------------------------------------------------------===//
2508 // BitCastInst Class
2509 //===----------------------------------------------------------------------===//
2511 /// @brief This class represents a no-op cast from one type to another.
2512 class BitCastInst : public CastInst {
2513 BitCastInst(const BitCastInst &CI)
2514 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2517 /// @brief Constructor with insert-before-instruction semantics
2519 Value *S, ///< The value to be casted
2520 const Type *Ty, ///< The type to casted to
2521 const std::string &Name = "", ///< A name for the new instruction
2522 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2525 /// @brief Constructor with insert-at-end-of-block semantics
2527 Value *S, ///< The value to be casted
2528 const Type *Ty, ///< The type to casted to
2529 const std::string &Name, ///< A name for the new instruction
2530 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2533 /// @brief Clone an identical BitCastInst
2534 virtual CastInst *clone() const;
2536 // Methods for support type inquiry through isa, cast, and dyn_cast:
2537 static inline bool classof(const BitCastInst *) { return true; }
2538 static inline bool classof(const Instruction *I) {
2539 return I->getOpcode() == BitCast;
2541 static inline bool classof(const Value *V) {
2542 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2546 //===----------------------------------------------------------------------===//
2547 // GetResultInst Class
2548 //===----------------------------------------------------------------------===//
2550 /// GetResultInst - This instruction extracts individual result value from
2551 /// aggregate value, where aggregate value is returned by CallInst.
2553 class GetResultInst : public /*FIXME: Unary*/Instruction {
2554 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2557 GetResultInst(const GetResultInst &GRI) :
2558 Instruction(GRI.getType(), Instruction::GetResult, &Aggr, 1) {
2559 Aggr.init(GRI.Aggr, this);
2564 // allocate space for exactly one operand
2565 void *operator new(size_t s) {
2566 return User::operator new(s, 1);
2568 explicit GetResultInst(Value *Aggr, unsigned index,
2569 const std::string &Name = "",
2570 Instruction *InsertBefore = 0);
2572 /// isValidOperands - Return true if an getresult instruction can be
2573 /// formed with the specified operands.
2574 static bool isValidOperands(const Value *Aggr, unsigned index);
2576 virtual GetResultInst *clone() const;
2578 Value *getAggregateValue() {
2579 return getOperand(0);
2582 const Value *getAggregateValue() const {
2583 return getOperand(0);
2586 unsigned getIndex() const {
2590 unsigned getNumOperands() const { return 1; }
2592 // Methods for support type inquiry through isa, cast, and dyn_cast:
2593 static inline bool classof(const GetResultInst *) { return true; }
2594 static inline bool classof(const Instruction *I) {
2595 return (I->getOpcode() == Instruction::GetResult);
2597 static inline bool classof(const Value *V) {
2598 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2602 } // End llvm namespace