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 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
403 // This requires that the itoerator points to contiguous memory.
404 init(Ptr, &*IdxBegin, NumIdx);
407 init(Ptr, 0, NumIdx);
413 /// getIndexedType - Returns the type of the element that would be loaded with
414 /// a load instruction with the specified parameters.
416 /// A null type is returned if the indices are invalid for the specified
419 static const Type *getIndexedType(const Type *Ptr,
420 Value* const *Idx, unsigned NumIdx,
421 bool AllowStructLeaf = false);
423 template<typename InputIterator>
424 static const Type *getIndexedType(const Type *Ptr,
425 InputIterator IdxBegin,
426 InputIterator IdxEnd,
427 bool AllowStructLeaf,
428 // This argument ensures that we
429 // have an iterator we can do
430 // arithmetic on in constant time
431 std::random_access_iterator_tag) {
432 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
435 // This requires that the iterator points to contiguous memory.
436 return(getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx,
440 return(getIndexedType(Ptr, (Value *const*)0, NumIdx, AllowStructLeaf));
444 /// Constructors - Create a getelementptr instruction with a base pointer an
445 /// list of indices. The first ctor can optionally insert before an existing
446 /// instruction, the second appends the new instruction to the specified
448 template<typename InputIterator>
449 GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
450 InputIterator IdxEnd,
451 const std::string &Name = "",
452 Instruction *InsertBefore = 0)
453 : Instruction(PointerType::get(
454 checkType(getIndexedType(Ptr->getType(),
455 IdxBegin, IdxEnd, true)),
456 cast<PointerType>(Ptr->getType())->getAddressSpace()),
457 GetElementPtr, 0, 0, InsertBefore) {
458 init(Ptr, IdxBegin, IdxEnd, Name,
459 typename std::iterator_traits<InputIterator>::iterator_category());
461 template<typename InputIterator>
462 GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
463 const std::string &Name, BasicBlock *InsertAtEnd)
464 : Instruction(PointerType::get(
465 checkType(getIndexedType(Ptr->getType(),
466 IdxBegin, IdxEnd, true)),
467 cast<PointerType>(Ptr->getType())->getAddressSpace()),
468 GetElementPtr, 0, 0, InsertAtEnd) {
469 init(Ptr, IdxBegin, IdxEnd, Name,
470 typename std::iterator_traits<InputIterator>::iterator_category());
473 /// Constructors - These two constructors are convenience methods because one
474 /// and two index getelementptr instructions are so common.
475 GetElementPtrInst(Value *Ptr, Value *Idx,
476 const std::string &Name = "", Instruction *InsertBefore = 0);
477 GetElementPtrInst(Value *Ptr, Value *Idx,
478 const std::string &Name, BasicBlock *InsertAtEnd);
480 template<typename InputIterator>
481 static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin,
482 InputIterator IdxEnd,
483 const std::string &Name = "",
484 Instruction *InsertBefore = 0) {
485 return new(0/*FIXME*/) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name, InsertBefore);
487 template<typename InputIterator>
488 static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
489 const std::string &Name, BasicBlock *InsertAtEnd) {
490 return new(0/*FIXME*/) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name, InsertAtEnd);
493 /// Constructors - These two constructors are convenience methods because one
494 /// and two index getelementptr instructions are so common.
495 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
496 const std::string &Name = "", Instruction *InsertBefore = 0) {
497 return new(2/*FIXME*/) GetElementPtrInst(Ptr, Idx, Name, InsertBefore);
499 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
500 const std::string &Name, BasicBlock *InsertAtEnd) {
501 return new(2/*FIXME*/) GetElementPtrInst(Ptr, Idx, Name, InsertAtEnd);
503 ~GetElementPtrInst();
505 virtual GetElementPtrInst *clone() const;
507 // getType - Overload to return most specific pointer type...
508 const PointerType *getType() const {
509 return reinterpret_cast<const PointerType*>(Instruction::getType());
512 /// getIndexedType - Returns the type of the element that would be loaded with
513 /// a load instruction with the specified parameters.
515 /// A null type is returned if the indices are invalid for the specified
518 template<typename InputIterator>
519 static const Type *getIndexedType(const Type *Ptr,
520 InputIterator IdxBegin,
521 InputIterator IdxEnd,
522 bool AllowStructLeaf = false) {
523 return(getIndexedType(Ptr, IdxBegin, IdxEnd, AllowStructLeaf,
524 typename std::iterator_traits<InputIterator>::
525 iterator_category()));
527 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
529 inline op_iterator idx_begin() { return op_begin()+1; }
530 inline const_op_iterator idx_begin() const { return op_begin()+1; }
531 inline op_iterator idx_end() { return op_end(); }
532 inline const_op_iterator idx_end() const { return op_end(); }
534 Value *getPointerOperand() {
535 return getOperand(0);
537 const Value *getPointerOperand() const {
538 return getOperand(0);
540 static unsigned getPointerOperandIndex() {
541 return 0U; // get index for modifying correct operand
544 unsigned getNumIndices() const { // Note: always non-negative
545 return getNumOperands() - 1;
548 bool hasIndices() const {
549 return getNumOperands() > 1;
552 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
553 /// zeros. If so, the result pointer and the first operand have the same
554 /// value, just potentially different types.
555 bool hasAllZeroIndices() const;
557 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
558 /// constant integers. If so, the result pointer and the first operand have
559 /// a constant offset between them.
560 bool hasAllConstantIndices() const;
563 // Methods for support type inquiry through isa, cast, and dyn_cast:
564 static inline bool classof(const GetElementPtrInst *) { return true; }
565 static inline bool classof(const Instruction *I) {
566 return (I->getOpcode() == Instruction::GetElementPtr);
568 static inline bool classof(const Value *V) {
569 return isa<Instruction>(V) && classof(cast<Instruction>(V));
573 //===----------------------------------------------------------------------===//
575 //===----------------------------------------------------------------------===//
577 /// This instruction compares its operands according to the predicate given
578 /// to the constructor. It only operates on integers, pointers, or packed
579 /// vectors of integrals. The two operands must be the same type.
580 /// @brief Represent an integer comparison operator.
581 class ICmpInst: public CmpInst {
583 /// This enumeration lists the possible predicates for the ICmpInst. The
584 /// values in the range 0-31 are reserved for FCmpInst while values in the
585 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
586 /// predicate values are not overlapping between the classes.
588 ICMP_EQ = 32, ///< equal
589 ICMP_NE = 33, ///< not equal
590 ICMP_UGT = 34, ///< unsigned greater than
591 ICMP_UGE = 35, ///< unsigned greater or equal
592 ICMP_ULT = 36, ///< unsigned less than
593 ICMP_ULE = 37, ///< unsigned less or equal
594 ICMP_SGT = 38, ///< signed greater than
595 ICMP_SGE = 39, ///< signed greater or equal
596 ICMP_SLT = 40, ///< signed less than
597 ICMP_SLE = 41, ///< signed less or equal
598 FIRST_ICMP_PREDICATE = ICMP_EQ,
599 LAST_ICMP_PREDICATE = ICMP_SLE,
600 BAD_ICMP_PREDICATE = ICMP_SLE + 1
603 /// @brief Constructor with insert-before-instruction semantics.
605 Predicate pred, ///< The predicate to use for the comparison
606 Value *LHS, ///< The left-hand-side of the expression
607 Value *RHS, ///< The right-hand-side of the expression
608 const std::string &Name = "", ///< Name of the instruction
609 Instruction *InsertBefore = 0 ///< Where to insert
610 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
613 /// @brief Constructor with insert-at-block-end semantics.
615 Predicate pred, ///< The predicate to use for the comparison
616 Value *LHS, ///< The left-hand-side of the expression
617 Value *RHS, ///< The right-hand-side of the expression
618 const std::string &Name, ///< Name of the instruction
619 BasicBlock *InsertAtEnd ///< Block to insert into.
620 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
623 /// @brief Return the predicate for this instruction.
624 Predicate getPredicate() const { return Predicate(SubclassData); }
626 /// @brief Set the predicate for this instruction to the specified value.
627 void setPredicate(Predicate P) { SubclassData = P; }
629 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
630 /// @returns the inverse predicate for the instruction's current predicate.
631 /// @brief Return the inverse of the instruction's predicate.
632 Predicate getInversePredicate() const {
633 return getInversePredicate(getPredicate());
636 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
637 /// @returns the inverse predicate for predicate provided in \p pred.
638 /// @brief Return the inverse of a given predicate
639 static Predicate getInversePredicate(Predicate pred);
641 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
642 /// @returns the predicate that would be the result of exchanging the two
643 /// operands of the ICmpInst instruction without changing the result
645 /// @brief Return the predicate as if the operands were swapped
646 Predicate getSwappedPredicate() const {
647 return getSwappedPredicate(getPredicate());
650 /// This is a static version that you can use without an instruction
652 /// @brief Return the predicate as if the operands were swapped.
653 static Predicate getSwappedPredicate(Predicate pred);
655 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
656 /// @returns the predicate that would be the result if the operand were
657 /// regarded as signed.
658 /// @brief Return the signed version of the predicate
659 Predicate getSignedPredicate() const {
660 return getSignedPredicate(getPredicate());
663 /// This is a static version that you can use without an instruction.
664 /// @brief Return the signed version of the predicate.
665 static Predicate getSignedPredicate(Predicate pred);
667 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
668 /// @returns the predicate that would be the result if the operand were
669 /// regarded as unsigned.
670 /// @brief Return the unsigned version of the predicate
671 Predicate getUnsignedPredicate() const {
672 return getUnsignedPredicate(getPredicate());
675 /// This is a static version that you can use without an instruction.
676 /// @brief Return the unsigned version of the predicate.
677 static Predicate getUnsignedPredicate(Predicate pred);
679 /// isEquality - Return true if this predicate is either EQ or NE. This also
680 /// tests for commutativity.
681 static bool isEquality(Predicate P) {
682 return P == ICMP_EQ || P == ICMP_NE;
685 /// isEquality - Return true if this predicate is either EQ or NE. This also
686 /// tests for commutativity.
687 bool isEquality() const {
688 return isEquality(getPredicate());
691 /// @returns true if the predicate of this ICmpInst is commutative
692 /// @brief Determine if this relation is commutative.
693 bool isCommutative() const { return isEquality(); }
695 /// isRelational - Return true if the predicate is relational (not EQ or NE).
697 bool isRelational() const {
698 return !isEquality();
701 /// isRelational - Return true if the predicate is relational (not EQ or NE).
703 static bool isRelational(Predicate P) {
704 return !isEquality(P);
707 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
708 /// @brief Determine if this instruction's predicate is signed.
709 bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); }
711 /// @returns true if the predicate provided is signed, false otherwise
712 /// @brief Determine if the predicate is signed.
713 static bool isSignedPredicate(Predicate pred);
715 /// Initialize a set of values that all satisfy the predicate with C.
716 /// @brief Make a ConstantRange for a relation with a constant value.
717 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
719 /// Exchange the two operands to this instruction in such a way that it does
720 /// not modify the semantics of the instruction. The predicate value may be
721 /// changed to retain the same result if the predicate is order dependent
723 /// @brief Swap operands and adjust predicate.
724 void swapOperands() {
725 SubclassData = getSwappedPredicate();
726 std::swap(Ops[0], Ops[1]);
729 virtual ICmpInst *clone() const;
731 // Methods for support type inquiry through isa, cast, and dyn_cast:
732 static inline bool classof(const ICmpInst *) { return true; }
733 static inline bool classof(const Instruction *I) {
734 return I->getOpcode() == Instruction::ICmp;
736 static inline bool classof(const Value *V) {
737 return isa<Instruction>(V) && classof(cast<Instruction>(V));
741 //===----------------------------------------------------------------------===//
743 //===----------------------------------------------------------------------===//
745 /// This instruction compares its operands according to the predicate given
746 /// to the constructor. It only operates on floating point values or packed
747 /// vectors of floating point values. The operands must be identical types.
748 /// @brief Represents a floating point comparison operator.
749 class FCmpInst: public CmpInst {
751 /// This enumeration lists the possible predicates for the FCmpInst. Values
752 /// in the range 0-31 are reserved for FCmpInst.
754 // Opcode U L G E Intuitive operation
755 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
756 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
757 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
758 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
759 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
760 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
761 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
762 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
763 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
764 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
765 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
766 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
767 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
768 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
769 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
770 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
771 FIRST_FCMP_PREDICATE = FCMP_FALSE,
772 LAST_FCMP_PREDICATE = FCMP_TRUE,
773 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
776 /// @brief Constructor with insert-before-instruction semantics.
778 Predicate pred, ///< The predicate to use for the comparison
779 Value *LHS, ///< The left-hand-side of the expression
780 Value *RHS, ///< The right-hand-side of the expression
781 const std::string &Name = "", ///< Name of the instruction
782 Instruction *InsertBefore = 0 ///< Where to insert
783 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
786 /// @brief Constructor with insert-at-block-end semantics.
788 Predicate pred, ///< The predicate to use for the comparison
789 Value *LHS, ///< The left-hand-side of the expression
790 Value *RHS, ///< The right-hand-side of the expression
791 const std::string &Name, ///< Name of the instruction
792 BasicBlock *InsertAtEnd ///< Block to insert into.
793 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
796 /// @brief Return the predicate for this instruction.
797 Predicate getPredicate() const { return Predicate(SubclassData); }
799 /// @brief Set the predicate for this instruction to the specified value.
800 void setPredicate(Predicate P) { SubclassData = P; }
802 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
803 /// @returns the inverse predicate for the instructions current predicate.
804 /// @brief Return the inverse of the predicate
805 Predicate getInversePredicate() const {
806 return getInversePredicate(getPredicate());
809 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
810 /// @returns the inverse predicate for \p pred.
811 /// @brief Return the inverse of a given predicate
812 static Predicate getInversePredicate(Predicate pred);
814 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
815 /// @returns the predicate that would be the result of exchanging the two
816 /// operands of the ICmpInst instruction without changing the result
818 /// @brief Return the predicate as if the operands were swapped
819 Predicate getSwappedPredicate() const {
820 return getSwappedPredicate(getPredicate());
823 /// This is a static version that you can use without an instruction
825 /// @brief Return the predicate as if the operands were swapped.
826 static Predicate getSwappedPredicate(Predicate Opcode);
828 /// This also tests for commutativity. If isEquality() returns true then
829 /// the predicate is also commutative. Only the equality predicates are
831 /// @returns true if the predicate of this instruction is EQ or NE.
832 /// @brief Determine if this is an equality predicate.
833 bool isEquality() const {
834 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
835 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
837 bool isCommutative() const { return isEquality(); }
839 /// @returns true if the predicate is relational (not EQ or NE).
840 /// @brief Determine if this a relational predicate.
841 bool isRelational() const { return !isEquality(); }
843 /// Exchange the two operands to this instruction in such a way that it does
844 /// not modify the semantics of the instruction. The predicate value may be
845 /// changed to retain the same result if the predicate is order dependent
847 /// @brief Swap operands and adjust predicate.
848 void swapOperands() {
849 SubclassData = getSwappedPredicate();
850 std::swap(Ops[0], Ops[1]);
853 virtual FCmpInst *clone() const;
855 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
856 static inline bool classof(const FCmpInst *) { return true; }
857 static inline bool classof(const Instruction *I) {
858 return I->getOpcode() == Instruction::FCmp;
860 static inline bool classof(const Value *V) {
861 return isa<Instruction>(V) && classof(cast<Instruction>(V));
865 //===----------------------------------------------------------------------===//
867 //===----------------------------------------------------------------------===//
868 /// CallInst - This class represents a function call, abstracting a target
869 /// machine's calling convention. This class uses low bit of the SubClassData
870 /// field to indicate whether or not this is a tail call. The rest of the bits
871 /// hold the calling convention of the call.
874 class CallInst : public Instruction {
875 PAListPtr ParamAttrs; ///< parameter attributes for call
876 CallInst(const CallInst &CI);
877 void init(Value *Func, Value* const *Params, unsigned NumParams);
878 void init(Value *Func, Value *Actual1, Value *Actual2);
879 void init(Value *Func, Value *Actual);
880 void init(Value *Func);
882 template<typename InputIterator>
883 void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
884 const std::string &Name,
885 // This argument ensures that we have an iterator we can
886 // do arithmetic on in constant time
887 std::random_access_iterator_tag) {
888 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
890 // This requires that the iterator points to contiguous memory.
891 init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
895 /// Construct a CallInst given a range of arguments. InputIterator
896 /// must be a random-access iterator pointing to contiguous storage
897 /// (e.g. a std::vector<>::iterator). Checks are made for
898 /// random-accessness but not for contiguous storage as that would
899 /// incur runtime overhead.
900 /// @brief Construct a CallInst from a range of arguments
901 template<typename InputIterator>
902 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
903 const std::string &Name = "", Instruction *InsertBefore = 0)
904 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
905 ->getElementType())->getReturnType(),
906 Instruction::Call, 0, 0, InsertBefore) {
907 init(Func, ArgBegin, ArgEnd, Name,
908 typename std::iterator_traits<InputIterator>::iterator_category());
911 /// Construct a CallInst given a range of arguments. InputIterator
912 /// must be a random-access iterator pointing to contiguous storage
913 /// (e.g. a std::vector<>::iterator). Checks are made for
914 /// random-accessness but not for contiguous storage as that would
915 /// incur runtime overhead.
916 /// @brief Construct a CallInst from a range of arguments
917 template<typename InputIterator>
918 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
919 const std::string &Name, BasicBlock *InsertAtEnd)
920 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
921 ->getElementType())->getReturnType(),
922 Instruction::Call, 0, 0, InsertAtEnd) {
923 init(Func, ArgBegin, ArgEnd, Name,
924 typename std::iterator_traits<InputIterator>::iterator_category());
927 CallInst(Value *F, Value *Actual, const std::string& Name = "",
928 Instruction *InsertBefore = 0);
929 CallInst(Value *F, Value *Actual, const std::string& Name,
930 BasicBlock *InsertAtEnd);
931 explicit CallInst(Value *F, const std::string &Name = "",
932 Instruction *InsertBefore = 0);
933 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
935 template<typename InputIterator>
936 static CallInst *Create(Value *Func, InputIterator ArgBegin,
937 InputIterator ArgEnd,
938 const std::string &Name = "",
939 Instruction *InsertBefore = 0) {
940 return new(ArgEnd - ArgBegin + 1)
941 CallInst(Func, ArgBegin, ArgEnd, Name, InsertBefore);
943 template<typename InputIterator>
944 static CallInst *Create(Value *Func, InputIterator ArgBegin,
945 InputIterator ArgEnd, const std::string &Name,
946 BasicBlock *InsertAtEnd) {
947 return new(ArgEnd - ArgBegin + 1)
948 CallInst(Func, ArgBegin, ArgEnd, Name, InsertAtEnd);
950 static CallInst *Create(Value *F, Value *Actual, const std::string& Name = "",
951 Instruction *InsertBefore = 0) {
952 return new(2) CallInst(F, Actual, Name, InsertBefore);
954 static CallInst *Create(Value *F, Value *Actual, const std::string& Name,
955 BasicBlock *InsertAtEnd) {
956 return new(2) CallInst(F, Actual, Name, InsertAtEnd);
958 static CallInst *Create(Value *F, const std::string &Name = "",
959 Instruction *InsertBefore = 0) {
960 return new(1) CallInst(F, Name, InsertBefore);
962 static CallInst *Create(Value *F, const std::string &Name,
963 BasicBlock *InsertAtEnd) {
964 return new(1) CallInst(F, Name, InsertAtEnd);
969 virtual CallInst *clone() const;
971 bool isTailCall() const { return SubclassData & 1; }
972 void setTailCall(bool isTailCall = true) {
973 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
976 /// getCallingConv/setCallingConv - Get or set the calling convention of this
978 unsigned getCallingConv() const { return SubclassData >> 1; }
979 void setCallingConv(unsigned CC) {
980 SubclassData = (SubclassData & 1) | (CC << 1);
983 /// getParamAttrs - Return the parameter attributes for this call.
985 const PAListPtr &getParamAttrs() const { return ParamAttrs; }
987 /// setParamAttrs - Sets the parameter attributes for this call.
988 void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
990 /// @brief Determine whether the call or the callee has the given attribute.
991 bool paramHasAttr(unsigned i, unsigned attr) const;
993 /// @brief Extract the alignment for a call or parameter (0=unknown).
994 unsigned getParamAlignment(unsigned i) const {
995 return ParamAttrs.getParamAlignment(i);
998 /// @brief Determine if the call does not access memory.
999 bool doesNotAccessMemory() const {
1000 return paramHasAttr(0, ParamAttr::ReadNone);
1003 /// @brief Determine if the call does not access or only reads memory.
1004 bool onlyReadsMemory() const {
1005 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
1008 /// @brief Determine if the call cannot return.
1009 bool doesNotReturn() const {
1010 return paramHasAttr(0, ParamAttr::NoReturn);
1013 /// @brief Determine if the call cannot unwind.
1014 bool doesNotThrow() const {
1015 return paramHasAttr(0, ParamAttr::NoUnwind);
1017 void setDoesNotThrow(bool doesNotThrow = true);
1019 /// @brief Determine if the call returns a structure through first
1020 /// pointer argument.
1021 bool hasStructRetAttr() const {
1022 // Be friendly and also check the callee.
1023 return paramHasAttr(1, ParamAttr::StructRet);
1026 /// @brief Determine if any call argument is an aggregate passed by value.
1027 bool hasByValArgument() const {
1028 return ParamAttrs.hasAttrSomewhere(ParamAttr::ByVal);
1031 /// getCalledFunction - Return the function being called by this instruction
1032 /// if it is a direct call. If it is a call through a function pointer,
1034 Function *getCalledFunction() const {
1035 return dyn_cast<Function>(getOperand(0));
1038 /// getCalledValue - Get a pointer to the function that is invoked by this
1040 const Value *getCalledValue() const { return getOperand(0); }
1041 Value *getCalledValue() { return getOperand(0); }
1043 // Methods for support type inquiry through isa, cast, and dyn_cast:
1044 static inline bool classof(const CallInst *) { return true; }
1045 static inline bool classof(const Instruction *I) {
1046 return I->getOpcode() == Instruction::Call;
1048 static inline bool classof(const Value *V) {
1049 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1053 //===----------------------------------------------------------------------===//
1055 //===----------------------------------------------------------------------===//
1057 /// SelectInst - This class represents the LLVM 'select' instruction.
1059 class SelectInst : public Instruction {
1062 void init(Value *C, Value *S1, Value *S2) {
1063 Ops[0].init(C, this);
1064 Ops[1].init(S1, this);
1065 Ops[2].init(S2, this);
1068 SelectInst(const SelectInst &SI)
1069 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
1070 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
1072 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
1073 Instruction *InsertBefore = 0)
1074 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
1078 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
1079 BasicBlock *InsertAtEnd)
1080 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
1085 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1086 const std::string &Name = "",
1087 Instruction *InsertBefore = 0) {
1088 return new(3) SelectInst(C, S1, S2, Name, InsertBefore);
1090 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1091 const std::string &Name, BasicBlock *InsertAtEnd) {
1092 return new(3) SelectInst(C, S1, S2, Name, InsertAtEnd);
1095 Value *getCondition() const { return Ops[0]; }
1096 Value *getTrueValue() const { return Ops[1]; }
1097 Value *getFalseValue() const { return Ops[2]; }
1099 /// Transparently provide more efficient getOperand methods.
1100 Value *getOperand(unsigned i) const {
1101 assert(i < 3 && "getOperand() out of range!");
1104 void setOperand(unsigned i, Value *Val) {
1105 assert(i < 3 && "setOperand() out of range!");
1108 unsigned getNumOperands() const { return 3; }
1110 OtherOps getOpcode() const {
1111 return static_cast<OtherOps>(Instruction::getOpcode());
1114 virtual SelectInst *clone() const;
1116 // Methods for support type inquiry through isa, cast, and dyn_cast:
1117 static inline bool classof(const SelectInst *) { return true; }
1118 static inline bool classof(const Instruction *I) {
1119 return I->getOpcode() == Instruction::Select;
1121 static inline bool classof(const Value *V) {
1122 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1126 //===----------------------------------------------------------------------===//
1128 //===----------------------------------------------------------------------===//
1130 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1131 /// an argument of the specified type given a va_list and increments that list
1133 class VAArgInst : public UnaryInstruction {
1134 VAArgInst(const VAArgInst &VAA)
1135 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
1137 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
1138 Instruction *InsertBefore = 0)
1139 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1142 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
1143 BasicBlock *InsertAtEnd)
1144 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1148 virtual VAArgInst *clone() const;
1150 // Methods for support type inquiry through isa, cast, and dyn_cast:
1151 static inline bool classof(const VAArgInst *) { return true; }
1152 static inline bool classof(const Instruction *I) {
1153 return I->getOpcode() == VAArg;
1155 static inline bool classof(const Value *V) {
1156 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1160 //===----------------------------------------------------------------------===//
1161 // ExtractElementInst Class
1162 //===----------------------------------------------------------------------===//
1164 /// ExtractElementInst - This instruction extracts a single (scalar)
1165 /// element from a VectorType value
1167 class ExtractElementInst : public Instruction {
1169 ExtractElementInst(const ExtractElementInst &EE) :
1170 Instruction(EE.getType(), ExtractElement, Ops, 2) {
1171 Ops[0].init(EE.Ops[0], this);
1172 Ops[1].init(EE.Ops[1], this);
1176 // allocate space for exactly two operands
1177 void *operator new(size_t s) {
1178 return User::operator new(s, 2); // FIXME: unsigned Idx forms of constructor?
1180 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
1181 Instruction *InsertBefore = 0);
1182 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
1183 Instruction *InsertBefore = 0);
1184 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
1185 BasicBlock *InsertAtEnd);
1186 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
1187 BasicBlock *InsertAtEnd);
1189 /// isValidOperands - Return true if an extractelement instruction can be
1190 /// formed with the specified operands.
1191 static bool isValidOperands(const Value *Vec, const Value *Idx);
1193 virtual ExtractElementInst *clone() const;
1195 /// Transparently provide more efficient getOperand methods.
1196 Value *getOperand(unsigned i) const {
1197 assert(i < 2 && "getOperand() out of range!");
1200 void setOperand(unsigned i, Value *Val) {
1201 assert(i < 2 && "setOperand() out of range!");
1204 unsigned getNumOperands() const { return 2; }
1206 // Methods for support type inquiry through isa, cast, and dyn_cast:
1207 static inline bool classof(const ExtractElementInst *) { return true; }
1208 static inline bool classof(const Instruction *I) {
1209 return I->getOpcode() == Instruction::ExtractElement;
1211 static inline bool classof(const Value *V) {
1212 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1216 //===----------------------------------------------------------------------===//
1217 // InsertElementInst Class
1218 //===----------------------------------------------------------------------===//
1220 /// InsertElementInst - This instruction inserts a single (scalar)
1221 /// element into a VectorType value
1223 class InsertElementInst : public Instruction {
1225 InsertElementInst(const InsertElementInst &IE);
1226 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1227 const std::string &Name = "",Instruction *InsertBefore = 0);
1228 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1229 const std::string &Name = "",Instruction *InsertBefore = 0);
1230 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1231 const std::string &Name, BasicBlock *InsertAtEnd);
1232 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1233 const std::string &Name, BasicBlock *InsertAtEnd);
1235 static InsertElementInst *Create(const InsertElementInst &IE) {
1236 return new(IE.getNumOperands()) InsertElementInst(IE);
1238 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1239 const std::string &Name = "",Instruction *InsertBefore = 0) {
1240 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
1242 static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
1243 const std::string &Name = "",
1244 Instruction *InsertBefore = 0) {
1245 return new(3/*FIXME*/)
1246 InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
1248 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1249 const std::string &Name,
1250 BasicBlock *InsertAtEnd) {
1251 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
1253 static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
1254 const std::string &Name,
1255 BasicBlock *InsertAtEnd) {
1256 return new(3/*FIXME*/)
1257 InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
1260 /// isValidOperands - Return true if an insertelement instruction can be
1261 /// formed with the specified operands.
1262 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1265 virtual InsertElementInst *clone() const;
1267 /// getType - Overload to return most specific vector type.
1269 const VectorType *getType() const {
1270 return reinterpret_cast<const VectorType*>(Instruction::getType());
1273 /// Transparently provide more efficient getOperand methods.
1274 Value *getOperand(unsigned i) const {
1275 assert(i < 3 && "getOperand() out of range!");
1278 void setOperand(unsigned i, Value *Val) {
1279 assert(i < 3 && "setOperand() out of range!");
1282 unsigned getNumOperands() const { return 3; }
1284 // Methods for support type inquiry through isa, cast, and dyn_cast:
1285 static inline bool classof(const InsertElementInst *) { return true; }
1286 static inline bool classof(const Instruction *I) {
1287 return I->getOpcode() == Instruction::InsertElement;
1289 static inline bool classof(const Value *V) {
1290 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1294 //===----------------------------------------------------------------------===//
1295 // ShuffleVectorInst Class
1296 //===----------------------------------------------------------------------===//
1298 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1301 class ShuffleVectorInst : public Instruction {
1303 ShuffleVectorInst(const ShuffleVectorInst &IE);
1305 // allocate space for exactly three operands
1306 void *operator new(size_t s) {
1307 return User::operator new(s, 3);
1309 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1310 const std::string &Name = "", Instruction *InsertBefor = 0);
1311 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1312 const std::string &Name, BasicBlock *InsertAtEnd);
1314 /// isValidOperands - Return true if a shufflevector instruction can be
1315 /// formed with the specified operands.
1316 static bool isValidOperands(const Value *V1, const Value *V2,
1319 virtual ShuffleVectorInst *clone() const;
1321 /// getType - Overload to return most specific vector type.
1323 const VectorType *getType() const {
1324 return reinterpret_cast<const VectorType*>(Instruction::getType());
1327 /// Transparently provide more efficient getOperand methods.
1328 const Value *getOperand(unsigned i) const {
1329 assert(i < 3 && "getOperand() out of range!");
1332 Value *getOperand(unsigned i) {
1333 assert(i < 3 && "getOperand() out of range!");
1336 void setOperand(unsigned i, Value *Val) {
1337 assert(i < 3 && "setOperand() out of range!");
1340 unsigned getNumOperands() const { return 3; }
1342 /// getMaskValue - Return the index from the shuffle mask for the specified
1343 /// output result. This is either -1 if the element is undef or a number less
1344 /// than 2*numelements.
1345 int getMaskValue(unsigned i) const;
1347 // Methods for support type inquiry through isa, cast, and dyn_cast:
1348 static inline bool classof(const ShuffleVectorInst *) { return true; }
1349 static inline bool classof(const Instruction *I) {
1350 return I->getOpcode() == Instruction::ShuffleVector;
1352 static inline bool classof(const Value *V) {
1353 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1358 //===----------------------------------------------------------------------===//
1360 //===----------------------------------------------------------------------===//
1362 // PHINode - The PHINode class is used to represent the magical mystical PHI
1363 // node, that can not exist in nature, but can be synthesized in a computer
1364 // scientist's overactive imagination.
1366 class PHINode : public Instruction {
1367 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1368 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1369 /// the number actually in use.
1370 unsigned ReservedSpace;
1371 PHINode(const PHINode &PN);
1372 // allocate space for exactly zero operands
1373 void *operator new(size_t s) {
1374 return User::operator new(s, 0);
1376 explicit PHINode(const Type *Ty, const std::string &Name = "",
1377 Instruction *InsertBefore = 0)
1378 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1383 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1384 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1389 static PHINode *Create(const Type *Ty, const std::string &Name = "",
1390 Instruction *InsertBefore = 0) {
1391 return new PHINode(Ty, Name, InsertBefore);
1393 static PHINode *Create(const Type *Ty, const std::string &Name,
1394 BasicBlock *InsertAtEnd) {
1395 return new PHINode(Ty, Name, InsertAtEnd);
1399 /// reserveOperandSpace - This method can be used to avoid repeated
1400 /// reallocation of PHI operand lists by reserving space for the correct
1401 /// number of operands before adding them. Unlike normal vector reserves,
1402 /// this method can also be used to trim the operand space.
1403 void reserveOperandSpace(unsigned NumValues) {
1404 resizeOperands(NumValues*2);
1407 virtual PHINode *clone() const;
1409 /// getNumIncomingValues - Return the number of incoming edges
1411 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1413 /// getIncomingValue - Return incoming value number x
1415 Value *getIncomingValue(unsigned i) const {
1416 assert(i*2 < getNumOperands() && "Invalid value number!");
1417 return getOperand(i*2);
1419 void setIncomingValue(unsigned i, Value *V) {
1420 assert(i*2 < getNumOperands() && "Invalid value number!");
1423 unsigned getOperandNumForIncomingValue(unsigned i) {
1427 /// getIncomingBlock - Return incoming basic block number x
1429 BasicBlock *getIncomingBlock(unsigned i) const {
1430 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1432 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1433 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1435 unsigned getOperandNumForIncomingBlock(unsigned i) {
1439 /// addIncoming - Add an incoming value to the end of the PHI list
1441 void addIncoming(Value *V, BasicBlock *BB) {
1442 assert(V && "PHI node got a null value!");
1443 assert(BB && "PHI node got a null basic block!");
1444 assert(getType() == V->getType() &&
1445 "All operands to PHI node must be the same type as the PHI node!");
1446 unsigned OpNo = NumOperands;
1447 if (OpNo+2 > ReservedSpace)
1448 resizeOperands(0); // Get more space!
1449 // Initialize some new operands.
1450 NumOperands = OpNo+2;
1451 OperandList[OpNo].init(V, this);
1452 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1455 /// removeIncomingValue - Remove an incoming value. This is useful if a
1456 /// predecessor basic block is deleted. The value removed is returned.
1458 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1459 /// is true), the PHI node is destroyed and any uses of it are replaced with
1460 /// dummy values. The only time there should be zero incoming values to a PHI
1461 /// node is when the block is dead, so this strategy is sound.
1463 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1465 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1466 int Idx = getBasicBlockIndex(BB);
1467 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1468 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1471 /// getBasicBlockIndex - Return the first index of the specified basic
1472 /// block in the value list for this PHI. Returns -1 if no instance.
1474 int getBasicBlockIndex(const BasicBlock *BB) const {
1475 Use *OL = OperandList;
1476 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1477 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1481 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1482 return getIncomingValue(getBasicBlockIndex(BB));
1485 /// hasConstantValue - If the specified PHI node always merges together the
1486 /// same value, return the value, otherwise return null.
1488 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1490 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1491 static inline bool classof(const PHINode *) { return true; }
1492 static inline bool classof(const Instruction *I) {
1493 return I->getOpcode() == Instruction::PHI;
1495 static inline bool classof(const Value *V) {
1496 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1499 void resizeOperands(unsigned NumOperands);
1502 //===----------------------------------------------------------------------===//
1504 //===----------------------------------------------------------------------===//
1506 //===---------------------------------------------------------------------------
1507 /// ReturnInst - Return a value (possibly void), from a function. Execution
1508 /// does not continue in this function any longer.
1510 class ReturnInst : public TerminatorInst {
1512 ReturnInst(const ReturnInst &RI);
1513 void init(Value * const* retVals, unsigned N);
1516 // ReturnInst constructors:
1517 // ReturnInst() - 'ret void' instruction
1518 // ReturnInst( null) - 'ret void' instruction
1519 // ReturnInst(Value* X) - 'ret X' instruction
1520 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1521 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1522 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1523 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1524 // ReturnInst(Value* X, N) - 'ret X,X+1...X+N-1' instruction
1525 // ReturnInst(Value* X, N, Inst *) - 'ret X,X+1...X+N-1', insert before I
1526 // ReturnInst(Value* X, N, BB *) - 'ret X,X+1...X+N-1', insert @ end of BB
1528 // NOTE: If the Value* passed is of type void then the constructor behaves as
1529 // if it was passed NULL.
1530 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1531 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1532 ReturnInst(Value * const* retVals, unsigned N);
1533 ReturnInst(Value * const* retVals, unsigned N, Instruction *InsertBefore);
1534 ReturnInst(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd);
1535 explicit ReturnInst(BasicBlock *InsertAtEnd);
1537 static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) {
1538 return new(!!retVal) ReturnInst(retVal, InsertBefore);
1540 static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) {
1541 return new(!!retVal) ReturnInst(retVal, InsertAtEnd);
1543 static ReturnInst* Create(Value * const* retVals, unsigned N) {
1544 return new(N) ReturnInst(retVals, N);
1546 static ReturnInst* Create(Value * const* retVals, unsigned N,
1547 Instruction *InsertBefore) {
1548 return new(N) ReturnInst(retVals, N, InsertBefore);
1550 static ReturnInst* Create(Value * const* retVals, unsigned N,
1551 BasicBlock *InsertAtEnd) {
1552 return new(N) ReturnInst(retVals, N, InsertAtEnd);
1554 static ReturnInst* Create(BasicBlock *InsertAtEnd) {
1555 return new(0) ReturnInst(InsertAtEnd);
1557 virtual ~ReturnInst();
1559 virtual ReturnInst *clone() const;
1561 Value *getOperand(unsigned n = 0) const {
1562 if (getNumOperands() > 1)
1563 return TerminatorInst::getOperand(n);
1568 Value *getReturnValue(unsigned n = 0) const {
1569 return getOperand(n);
1572 unsigned getNumSuccessors() const { return 0; }
1574 // Methods for support type inquiry through isa, cast, and dyn_cast:
1575 static inline bool classof(const ReturnInst *) { return true; }
1576 static inline bool classof(const Instruction *I) {
1577 return (I->getOpcode() == Instruction::Ret);
1579 static inline bool classof(const Value *V) {
1580 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1583 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1584 virtual unsigned getNumSuccessorsV() const;
1585 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1588 //===----------------------------------------------------------------------===//
1590 //===----------------------------------------------------------------------===//
1592 //===---------------------------------------------------------------------------
1593 /// BranchInst - Conditional or Unconditional Branch instruction.
1595 class BranchInst : public TerminatorInst {
1596 /// Ops list - Branches are strange. The operands are ordered:
1597 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1598 /// they don't have to check for cond/uncond branchness.
1600 BranchInst(const BranchInst &BI);
1602 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1603 // BranchInst(BB *B) - 'br B'
1604 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1605 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1606 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1607 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1608 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1609 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1610 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1611 Instruction *InsertBefore = 0);
1612 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1613 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1614 BasicBlock *InsertAtEnd);
1616 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
1617 return new(1) BranchInst(IfTrue, InsertBefore);
1619 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1620 Instruction *InsertBefore = 0) {
1621 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
1623 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
1624 return new(1) BranchInst(IfTrue, InsertAtEnd);
1626 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1627 BasicBlock *InsertAtEnd) {
1628 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
1631 /// Transparently provide more efficient getOperand methods.
1632 Value *getOperand(unsigned i) const {
1633 assert(i < getNumOperands() && "getOperand() out of range!");
1636 void setOperand(unsigned i, Value *Val) {
1637 assert(i < getNumOperands() && "setOperand() out of range!");
1641 virtual BranchInst *clone() const;
1643 bool isUnconditional() const { return getNumOperands() == 1; }
1644 bool isConditional() const { return getNumOperands() == 3; }
1646 Value *getCondition() const {
1647 assert(isConditional() && "Cannot get condition of an uncond branch!");
1648 return getOperand(2);
1651 void setCondition(Value *V) {
1652 assert(isConditional() && "Cannot set condition of unconditional branch!");
1656 // setUnconditionalDest - Change the current branch to an unconditional branch
1657 // targeting the specified block.
1658 // FIXME: Eliminate this ugly method.
1659 void setUnconditionalDest(BasicBlock *Dest) {
1660 if (isConditional()) { // Convert this to an uncond branch.
1665 setOperand(0, reinterpret_cast<Value*>(Dest));
1668 unsigned getNumSuccessors() const { return 1+isConditional(); }
1670 BasicBlock *getSuccessor(unsigned i) const {
1671 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1672 return cast<BasicBlock>(getOperand(i));
1675 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1676 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1677 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1680 // Methods for support type inquiry through isa, cast, and dyn_cast:
1681 static inline bool classof(const BranchInst *) { return true; }
1682 static inline bool classof(const Instruction *I) {
1683 return (I->getOpcode() == Instruction::Br);
1685 static inline bool classof(const Value *V) {
1686 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1689 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1690 virtual unsigned getNumSuccessorsV() const;
1691 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1694 //===----------------------------------------------------------------------===//
1696 //===----------------------------------------------------------------------===//
1698 //===---------------------------------------------------------------------------
1699 /// SwitchInst - Multiway switch
1701 class SwitchInst : public TerminatorInst {
1702 unsigned ReservedSpace;
1703 // Operand[0] = Value to switch on
1704 // Operand[1] = Default basic block destination
1705 // Operand[2n ] = Value to match
1706 // Operand[2n+1] = BasicBlock to go to on match
1707 SwitchInst(const SwitchInst &RI);
1708 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1709 void resizeOperands(unsigned No);
1710 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1711 /// switch on and a default destination. The number of additional cases can
1712 /// be specified here to make memory allocation more efficient. This
1713 /// constructor can also autoinsert before another instruction.
1714 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1715 Instruction *InsertBefore = 0);
1717 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1718 /// switch on and a default destination. The number of additional cases can
1719 /// be specified here to make memory allocation more efficient. This
1720 /// constructor also autoinserts at the end of the specified BasicBlock.
1721 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1722 BasicBlock *InsertAtEnd);
1724 static SwitchInst *Create(Value *Value, BasicBlock *Default, unsigned NumCases,
1725 Instruction *InsertBefore = 0) {
1726 return new(NumCases/*FIXME*/)
1727 SwitchInst(Value, Default, NumCases, InsertBefore);
1729 static SwitchInst *Create(Value *Value, BasicBlock *Default, unsigned NumCases,
1730 BasicBlock *InsertAtEnd) {
1731 return new(NumCases/*FIXME*/)
1732 SwitchInst(Value, Default, NumCases, InsertAtEnd);
1736 // Accessor Methods for Switch stmt
1737 Value *getCondition() const { return getOperand(0); }
1738 void setCondition(Value *V) { setOperand(0, V); }
1740 BasicBlock *getDefaultDest() const {
1741 return cast<BasicBlock>(getOperand(1));
1744 /// getNumCases - return the number of 'cases' in this switch instruction.
1745 /// Note that case #0 is always the default case.
1746 unsigned getNumCases() const {
1747 return getNumOperands()/2;
1750 /// getCaseValue - Return the specified case value. Note that case #0, the
1751 /// default destination, does not have a case value.
1752 ConstantInt *getCaseValue(unsigned i) {
1753 assert(i && i < getNumCases() && "Illegal case value to get!");
1754 return getSuccessorValue(i);
1757 /// getCaseValue - Return the specified case value. Note that case #0, the
1758 /// default destination, does not have a case value.
1759 const ConstantInt *getCaseValue(unsigned i) const {
1760 assert(i && i < getNumCases() && "Illegal case value to get!");
1761 return getSuccessorValue(i);
1764 /// findCaseValue - Search all of the case values for the specified constant.
1765 /// If it is explicitly handled, return the case number of it, otherwise
1766 /// return 0 to indicate that it is handled by the default handler.
1767 unsigned findCaseValue(const ConstantInt *C) const {
1768 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1769 if (getCaseValue(i) == C)
1774 /// findCaseDest - Finds the unique case value for a given successor. Returns
1775 /// null if the successor is not found, not unique, or is the default case.
1776 ConstantInt *findCaseDest(BasicBlock *BB) {
1777 if (BB == getDefaultDest()) return NULL;
1779 ConstantInt *CI = NULL;
1780 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1781 if (getSuccessor(i) == BB) {
1782 if (CI) return NULL; // Multiple cases lead to BB.
1783 else CI = getCaseValue(i);
1789 /// addCase - Add an entry to the switch instruction...
1791 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1793 /// removeCase - This method removes the specified successor from the switch
1794 /// instruction. Note that this cannot be used to remove the default
1795 /// destination (successor #0).
1797 void removeCase(unsigned idx);
1799 virtual SwitchInst *clone() const;
1801 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1802 BasicBlock *getSuccessor(unsigned idx) const {
1803 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1804 return cast<BasicBlock>(getOperand(idx*2+1));
1806 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1807 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1808 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1811 // getSuccessorValue - Return the value associated with the specified
1813 ConstantInt *getSuccessorValue(unsigned idx) const {
1814 assert(idx < getNumSuccessors() && "Successor # out of range!");
1815 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1818 // Methods for support type inquiry through isa, cast, and dyn_cast:
1819 static inline bool classof(const SwitchInst *) { return true; }
1820 static inline bool classof(const Instruction *I) {
1821 return I->getOpcode() == Instruction::Switch;
1823 static inline bool classof(const Value *V) {
1824 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1827 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1828 virtual unsigned getNumSuccessorsV() const;
1829 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1832 //===----------------------------------------------------------------------===//
1834 //===----------------------------------------------------------------------===//
1836 //===---------------------------------------------------------------------------
1838 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1839 /// calling convention of the call.
1841 class InvokeInst : public TerminatorInst {
1842 PAListPtr ParamAttrs;
1843 InvokeInst(const InvokeInst &BI);
1844 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1845 Value* const *Args, unsigned NumArgs);
1847 template<typename InputIterator>
1848 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1849 InputIterator ArgBegin, InputIterator ArgEnd,
1850 const std::string &Name,
1851 // This argument ensures that we have an iterator we can
1852 // do arithmetic on in constant time
1853 std::random_access_iterator_tag) {
1854 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
1856 // This requires that the iterator points to contiguous memory.
1857 init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
1861 /// Construct an InvokeInst given a range of arguments.
1862 /// InputIterator must be a random-access iterator pointing to
1863 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
1864 /// made for random-accessness but not for contiguous storage as
1865 /// that would incur runtime overhead.
1867 /// @brief Construct an InvokeInst from a range of arguments
1868 template<typename InputIterator>
1869 InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1870 InputIterator ArgBegin, InputIterator ArgEnd,
1871 const std::string &Name = "", Instruction *InsertBefore = 0)
1872 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
1873 ->getElementType())->getReturnType(),
1874 Instruction::Invoke, 0, 0, InsertBefore) {
1875 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
1876 typename std::iterator_traits<InputIterator>::iterator_category());
1879 /// Construct an InvokeInst given a range of arguments.
1880 /// InputIterator must be a random-access iterator pointing to
1881 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
1882 /// made for random-accessness but not for contiguous storage as
1883 /// that would incur runtime overhead.
1885 /// @brief Construct an InvokeInst from a range of arguments
1886 template<typename InputIterator>
1887 InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1888 InputIterator ArgBegin, InputIterator ArgEnd,
1889 const std::string &Name, BasicBlock *InsertAtEnd)
1890 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
1891 ->getElementType())->getReturnType(),
1892 Instruction::Invoke, 0, 0, InsertAtEnd) {
1893 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
1894 typename std::iterator_traits<InputIterator>::iterator_category());
1897 template<typename InputIterator>
1898 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
1899 BasicBlock *IfException,
1900 InputIterator ArgBegin, InputIterator ArgEnd,
1901 const std::string &Name = "",
1902 Instruction *InsertBefore = 0) {
1903 return new(ArgEnd - ArgBegin + 3)
1904 InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, InsertBefore);
1906 template<typename InputIterator>
1907 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
1908 BasicBlock *IfException,
1909 InputIterator ArgBegin, InputIterator ArgEnd,
1910 const std::string &Name, BasicBlock *InsertAtEnd) {
1911 return new(ArgEnd - ArgBegin + 3)
1912 InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, InsertAtEnd);
1917 virtual InvokeInst *clone() const;
1919 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1921 unsigned getCallingConv() const { return SubclassData; }
1922 void setCallingConv(unsigned CC) {
1926 /// getParamAttrs - Return the parameter attributes for this invoke.
1928 const PAListPtr &getParamAttrs() const { return ParamAttrs; }
1930 /// setParamAttrs - Set the parameter attributes for this invoke.
1932 void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
1934 /// @brief Determine whether the call or the callee has the given attribute.
1935 bool paramHasAttr(unsigned i, ParameterAttributes attr) const;
1937 /// @brief Extract the alignment for a call or parameter (0=unknown).
1938 unsigned getParamAlignment(unsigned i) const {
1939 return ParamAttrs.getParamAlignment(i);
1942 /// @brief Determine if the call does not access memory.
1943 bool doesNotAccessMemory() const {
1944 return paramHasAttr(0, ParamAttr::ReadNone);
1947 /// @brief Determine if the call does not access or only reads memory.
1948 bool onlyReadsMemory() const {
1949 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
1952 /// @brief Determine if the call cannot return.
1953 bool doesNotReturn() const {
1954 return paramHasAttr(0, ParamAttr::NoReturn);
1957 /// @brief Determine if the call cannot unwind.
1958 bool doesNotThrow() const {
1959 return paramHasAttr(0, ParamAttr::NoUnwind);
1961 void setDoesNotThrow(bool doesNotThrow = true);
1963 /// @brief Determine if the call returns a structure through first
1964 /// pointer argument.
1965 bool hasStructRetAttr() const {
1966 // Be friendly and also check the callee.
1967 return paramHasAttr(1, ParamAttr::StructRet);
1970 /// getCalledFunction - Return the function called, or null if this is an
1971 /// indirect function invocation.
1973 Function *getCalledFunction() const {
1974 return dyn_cast<Function>(getOperand(0));
1977 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1978 Value *getCalledValue() const { return getOperand(0); }
1980 // get*Dest - Return the destination basic blocks...
1981 BasicBlock *getNormalDest() const {
1982 return cast<BasicBlock>(getOperand(1));
1984 BasicBlock *getUnwindDest() const {
1985 return cast<BasicBlock>(getOperand(2));
1987 void setNormalDest(BasicBlock *B) {
1988 setOperand(1, reinterpret_cast<Value*>(B));
1991 void setUnwindDest(BasicBlock *B) {
1992 setOperand(2, reinterpret_cast<Value*>(B));
1995 BasicBlock *getSuccessor(unsigned i) const {
1996 assert(i < 2 && "Successor # out of range for invoke!");
1997 return i == 0 ? getNormalDest() : getUnwindDest();
2000 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2001 assert(idx < 2 && "Successor # out of range for invoke!");
2002 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
2005 unsigned getNumSuccessors() const { return 2; }
2007 // Methods for support type inquiry through isa, cast, and dyn_cast:
2008 static inline bool classof(const InvokeInst *) { return true; }
2009 static inline bool classof(const Instruction *I) {
2010 return (I->getOpcode() == Instruction::Invoke);
2012 static inline bool classof(const Value *V) {
2013 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2016 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2017 virtual unsigned getNumSuccessorsV() const;
2018 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2022 //===----------------------------------------------------------------------===//
2024 //===----------------------------------------------------------------------===//
2026 //===---------------------------------------------------------------------------
2027 /// UnwindInst - Immediately exit the current function, unwinding the stack
2028 /// until an invoke instruction is found.
2030 class UnwindInst : public TerminatorInst {
2031 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2033 // allocate space for exactly zero operands
2034 void *operator new(size_t s) {
2035 return User::operator new(s, 0);
2037 explicit UnwindInst(Instruction *InsertBefore = 0);
2038 explicit UnwindInst(BasicBlock *InsertAtEnd);
2040 virtual UnwindInst *clone() const;
2042 unsigned getNumSuccessors() const { return 0; }
2044 // Methods for support type inquiry through isa, cast, and dyn_cast:
2045 static inline bool classof(const UnwindInst *) { return true; }
2046 static inline bool classof(const Instruction *I) {
2047 return I->getOpcode() == Instruction::Unwind;
2049 static inline bool classof(const Value *V) {
2050 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2053 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2054 virtual unsigned getNumSuccessorsV() const;
2055 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2058 //===----------------------------------------------------------------------===//
2059 // UnreachableInst Class
2060 //===----------------------------------------------------------------------===//
2062 //===---------------------------------------------------------------------------
2063 /// UnreachableInst - This function has undefined behavior. In particular, the
2064 /// presence of this instruction indicates some higher level knowledge that the
2065 /// end of the block cannot be reached.
2067 class UnreachableInst : public TerminatorInst {
2068 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2070 // allocate space for exactly zero operands
2071 void *operator new(size_t s) {
2072 return User::operator new(s, 0);
2074 explicit UnreachableInst(Instruction *InsertBefore = 0);
2075 explicit UnreachableInst(BasicBlock *InsertAtEnd);
2077 virtual UnreachableInst *clone() const;
2079 unsigned getNumSuccessors() const { return 0; }
2081 // Methods for support type inquiry through isa, cast, and dyn_cast:
2082 static inline bool classof(const UnreachableInst *) { return true; }
2083 static inline bool classof(const Instruction *I) {
2084 return I->getOpcode() == Instruction::Unreachable;
2086 static inline bool classof(const Value *V) {
2087 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2090 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2091 virtual unsigned getNumSuccessorsV() const;
2092 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2095 //===----------------------------------------------------------------------===//
2097 //===----------------------------------------------------------------------===//
2099 /// @brief This class represents a truncation of integer types.
2100 class TruncInst : public CastInst {
2101 /// Private copy constructor
2102 TruncInst(const TruncInst &CI)
2103 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
2106 /// @brief Constructor with insert-before-instruction semantics
2108 Value *S, ///< The value to be truncated
2109 const Type *Ty, ///< The (smaller) type to truncate to
2110 const std::string &Name = "", ///< A name for the new instruction
2111 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2114 /// @brief Constructor with insert-at-end-of-block semantics
2116 Value *S, ///< The value to be truncated
2117 const Type *Ty, ///< The (smaller) type to truncate to
2118 const std::string &Name, ///< A name for the new instruction
2119 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2122 /// @brief Clone an identical TruncInst
2123 virtual CastInst *clone() const;
2125 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2126 static inline bool classof(const TruncInst *) { return true; }
2127 static inline bool classof(const Instruction *I) {
2128 return I->getOpcode() == Trunc;
2130 static inline bool classof(const Value *V) {
2131 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2135 //===----------------------------------------------------------------------===//
2137 //===----------------------------------------------------------------------===//
2139 /// @brief This class represents zero extension of integer types.
2140 class ZExtInst : public CastInst {
2141 /// @brief Private copy constructor
2142 ZExtInst(const ZExtInst &CI)
2143 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
2146 /// @brief Constructor with insert-before-instruction semantics
2148 Value *S, ///< The value to be zero extended
2149 const Type *Ty, ///< The type to zero extend to
2150 const std::string &Name = "", ///< A name for the new instruction
2151 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2154 /// @brief Constructor with insert-at-end semantics.
2156 Value *S, ///< The value to be zero extended
2157 const Type *Ty, ///< The type to zero extend to
2158 const std::string &Name, ///< A name for the new instruction
2159 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2162 /// @brief Clone an identical ZExtInst
2163 virtual CastInst *clone() const;
2165 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2166 static inline bool classof(const ZExtInst *) { return true; }
2167 static inline bool classof(const Instruction *I) {
2168 return I->getOpcode() == ZExt;
2170 static inline bool classof(const Value *V) {
2171 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2175 //===----------------------------------------------------------------------===//
2177 //===----------------------------------------------------------------------===//
2179 /// @brief This class represents a sign extension of integer types.
2180 class SExtInst : public CastInst {
2181 /// @brief Private copy constructor
2182 SExtInst(const SExtInst &CI)
2183 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
2186 /// @brief Constructor with insert-before-instruction semantics
2188 Value *S, ///< The value to be sign extended
2189 const Type *Ty, ///< The type to sign extend to
2190 const std::string &Name = "", ///< A name for the new instruction
2191 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2194 /// @brief Constructor with insert-at-end-of-block semantics
2196 Value *S, ///< The value to be sign extended
2197 const Type *Ty, ///< The type to sign extend to
2198 const std::string &Name, ///< A name for the new instruction
2199 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2202 /// @brief Clone an identical SExtInst
2203 virtual CastInst *clone() const;
2205 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2206 static inline bool classof(const SExtInst *) { return true; }
2207 static inline bool classof(const Instruction *I) {
2208 return I->getOpcode() == SExt;
2210 static inline bool classof(const Value *V) {
2211 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2215 //===----------------------------------------------------------------------===//
2216 // FPTruncInst Class
2217 //===----------------------------------------------------------------------===//
2219 /// @brief This class represents a truncation of floating point types.
2220 class FPTruncInst : public CastInst {
2221 FPTruncInst(const FPTruncInst &CI)
2222 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
2225 /// @brief Constructor with insert-before-instruction semantics
2227 Value *S, ///< The value to be truncated
2228 const Type *Ty, ///< The type to truncate to
2229 const std::string &Name = "", ///< A name for the new instruction
2230 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2233 /// @brief Constructor with insert-before-instruction semantics
2235 Value *S, ///< The value to be truncated
2236 const Type *Ty, ///< The type to truncate to
2237 const std::string &Name, ///< A name for the new instruction
2238 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2241 /// @brief Clone an identical FPTruncInst
2242 virtual CastInst *clone() const;
2244 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2245 static inline bool classof(const FPTruncInst *) { return true; }
2246 static inline bool classof(const Instruction *I) {
2247 return I->getOpcode() == FPTrunc;
2249 static inline bool classof(const Value *V) {
2250 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2254 //===----------------------------------------------------------------------===//
2256 //===----------------------------------------------------------------------===//
2258 /// @brief This class represents an extension of floating point types.
2259 class FPExtInst : public CastInst {
2260 FPExtInst(const FPExtInst &CI)
2261 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
2264 /// @brief Constructor with insert-before-instruction semantics
2266 Value *S, ///< The value to be extended
2267 const Type *Ty, ///< The type to extend to
2268 const std::string &Name = "", ///< A name for the new instruction
2269 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2272 /// @brief Constructor with insert-at-end-of-block semantics
2274 Value *S, ///< The value to be extended
2275 const Type *Ty, ///< The type to extend to
2276 const std::string &Name, ///< A name for the new instruction
2277 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2280 /// @brief Clone an identical FPExtInst
2281 virtual CastInst *clone() const;
2283 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2284 static inline bool classof(const FPExtInst *) { return true; }
2285 static inline bool classof(const Instruction *I) {
2286 return I->getOpcode() == FPExt;
2288 static inline bool classof(const Value *V) {
2289 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2293 //===----------------------------------------------------------------------===//
2295 //===----------------------------------------------------------------------===//
2297 /// @brief This class represents a cast unsigned integer to floating point.
2298 class UIToFPInst : public CastInst {
2299 UIToFPInst(const UIToFPInst &CI)
2300 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
2303 /// @brief Constructor with insert-before-instruction semantics
2305 Value *S, ///< The value to be converted
2306 const Type *Ty, ///< The type to convert to
2307 const std::string &Name = "", ///< A name for the new instruction
2308 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2311 /// @brief Constructor with insert-at-end-of-block semantics
2313 Value *S, ///< The value to be converted
2314 const Type *Ty, ///< The type to convert to
2315 const std::string &Name, ///< A name for the new instruction
2316 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2319 /// @brief Clone an identical UIToFPInst
2320 virtual CastInst *clone() const;
2322 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2323 static inline bool classof(const UIToFPInst *) { return true; }
2324 static inline bool classof(const Instruction *I) {
2325 return I->getOpcode() == UIToFP;
2327 static inline bool classof(const Value *V) {
2328 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2332 //===----------------------------------------------------------------------===//
2334 //===----------------------------------------------------------------------===//
2336 /// @brief This class represents a cast from signed integer to floating point.
2337 class SIToFPInst : public CastInst {
2338 SIToFPInst(const SIToFPInst &CI)
2339 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
2342 /// @brief Constructor with insert-before-instruction semantics
2344 Value *S, ///< The value to be converted
2345 const Type *Ty, ///< The type to convert to
2346 const std::string &Name = "", ///< A name for the new instruction
2347 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2350 /// @brief Constructor with insert-at-end-of-block semantics
2352 Value *S, ///< The value to be converted
2353 const Type *Ty, ///< The type to convert to
2354 const std::string &Name, ///< A name for the new instruction
2355 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2358 /// @brief Clone an identical SIToFPInst
2359 virtual CastInst *clone() const;
2361 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2362 static inline bool classof(const SIToFPInst *) { return true; }
2363 static inline bool classof(const Instruction *I) {
2364 return I->getOpcode() == SIToFP;
2366 static inline bool classof(const Value *V) {
2367 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2371 //===----------------------------------------------------------------------===//
2373 //===----------------------------------------------------------------------===//
2375 /// @brief This class represents a cast from floating point to unsigned integer
2376 class FPToUIInst : public CastInst {
2377 FPToUIInst(const FPToUIInst &CI)
2378 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
2381 /// @brief Constructor with insert-before-instruction semantics
2383 Value *S, ///< The value to be converted
2384 const Type *Ty, ///< The type to convert to
2385 const std::string &Name = "", ///< A name for the new instruction
2386 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2389 /// @brief Constructor with insert-at-end-of-block semantics
2391 Value *S, ///< The value to be converted
2392 const Type *Ty, ///< The type to convert to
2393 const std::string &Name, ///< A name for the new instruction
2394 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
2397 /// @brief Clone an identical FPToUIInst
2398 virtual CastInst *clone() const;
2400 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2401 static inline bool classof(const FPToUIInst *) { return true; }
2402 static inline bool classof(const Instruction *I) {
2403 return I->getOpcode() == FPToUI;
2405 static inline bool classof(const Value *V) {
2406 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2410 //===----------------------------------------------------------------------===//
2412 //===----------------------------------------------------------------------===//
2414 /// @brief This class represents a cast from floating point to signed integer.
2415 class FPToSIInst : public CastInst {
2416 FPToSIInst(const FPToSIInst &CI)
2417 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2420 /// @brief Constructor with insert-before-instruction semantics
2422 Value *S, ///< The value to be converted
2423 const Type *Ty, ///< The type to convert to
2424 const std::string &Name = "", ///< A name for the new instruction
2425 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2428 /// @brief Constructor with insert-at-end-of-block semantics
2430 Value *S, ///< The value to be converted
2431 const Type *Ty, ///< The type to convert to
2432 const std::string &Name, ///< A name for the new instruction
2433 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2436 /// @brief Clone an identical FPToSIInst
2437 virtual CastInst *clone() const;
2439 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2440 static inline bool classof(const FPToSIInst *) { return true; }
2441 static inline bool classof(const Instruction *I) {
2442 return I->getOpcode() == FPToSI;
2444 static inline bool classof(const Value *V) {
2445 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2449 //===----------------------------------------------------------------------===//
2450 // IntToPtrInst Class
2451 //===----------------------------------------------------------------------===//
2453 /// @brief This class represents a cast from an integer to a pointer.
2454 class IntToPtrInst : public CastInst {
2455 IntToPtrInst(const IntToPtrInst &CI)
2456 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2459 /// @brief Constructor with insert-before-instruction semantics
2461 Value *S, ///< The value to be converted
2462 const Type *Ty, ///< The type to convert to
2463 const std::string &Name = "", ///< A name for the new instruction
2464 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2467 /// @brief Constructor with insert-at-end-of-block semantics
2469 Value *S, ///< The value to be converted
2470 const Type *Ty, ///< The type to convert to
2471 const std::string &Name, ///< A name for the new instruction
2472 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2475 /// @brief Clone an identical IntToPtrInst
2476 virtual CastInst *clone() const;
2478 // Methods for support type inquiry through isa, cast, and dyn_cast:
2479 static inline bool classof(const IntToPtrInst *) { return true; }
2480 static inline bool classof(const Instruction *I) {
2481 return I->getOpcode() == IntToPtr;
2483 static inline bool classof(const Value *V) {
2484 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2488 //===----------------------------------------------------------------------===//
2489 // PtrToIntInst Class
2490 //===----------------------------------------------------------------------===//
2492 /// @brief This class represents a cast from a pointer to an integer
2493 class PtrToIntInst : public CastInst {
2494 PtrToIntInst(const PtrToIntInst &CI)
2495 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2498 /// @brief Constructor with insert-before-instruction semantics
2500 Value *S, ///< The value to be converted
2501 const Type *Ty, ///< The type to convert to
2502 const std::string &Name = "", ///< A name for the new instruction
2503 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2506 /// @brief Constructor with insert-at-end-of-block semantics
2508 Value *S, ///< The value to be converted
2509 const Type *Ty, ///< The type to convert to
2510 const std::string &Name, ///< A name for the new instruction
2511 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2514 /// @brief Clone an identical PtrToIntInst
2515 virtual CastInst *clone() const;
2517 // Methods for support type inquiry through isa, cast, and dyn_cast:
2518 static inline bool classof(const PtrToIntInst *) { return true; }
2519 static inline bool classof(const Instruction *I) {
2520 return I->getOpcode() == PtrToInt;
2522 static inline bool classof(const Value *V) {
2523 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2527 //===----------------------------------------------------------------------===//
2528 // BitCastInst Class
2529 //===----------------------------------------------------------------------===//
2531 /// @brief This class represents a no-op cast from one type to another.
2532 class BitCastInst : public CastInst {
2533 BitCastInst(const BitCastInst &CI)
2534 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2537 /// @brief Constructor with insert-before-instruction semantics
2539 Value *S, ///< The value to be casted
2540 const Type *Ty, ///< The type to casted to
2541 const std::string &Name = "", ///< A name for the new instruction
2542 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2545 /// @brief Constructor with insert-at-end-of-block semantics
2547 Value *S, ///< The value to be casted
2548 const Type *Ty, ///< The type to casted to
2549 const std::string &Name, ///< A name for the new instruction
2550 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2553 /// @brief Clone an identical BitCastInst
2554 virtual CastInst *clone() const;
2556 // Methods for support type inquiry through isa, cast, and dyn_cast:
2557 static inline bool classof(const BitCastInst *) { return true; }
2558 static inline bool classof(const Instruction *I) {
2559 return I->getOpcode() == BitCast;
2561 static inline bool classof(const Value *V) {
2562 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2566 //===----------------------------------------------------------------------===//
2567 // GetResultInst Class
2568 //===----------------------------------------------------------------------===//
2570 /// GetResultInst - This instruction extracts individual result value from
2571 /// aggregate value, where aggregate value is returned by CallInst.
2573 class GetResultInst : public /*FIXME: Unary*/Instruction {
2574 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2577 GetResultInst(const GetResultInst &GRI) :
2578 Instruction(GRI.getType(), Instruction::GetResult, &Aggr, 1) {
2579 Aggr.init(GRI.Aggr, this);
2584 // allocate space for exactly one operand
2585 void *operator new(size_t s) {
2586 return User::operator new(s, 1);
2588 explicit GetResultInst(Value *Aggr, unsigned index,
2589 const std::string &Name = "",
2590 Instruction *InsertBefore = 0);
2592 /// isValidOperands - Return true if an getresult instruction can be
2593 /// formed with the specified operands.
2594 static bool isValidOperands(const Value *Aggr, unsigned index);
2596 virtual GetResultInst *clone() const;
2598 Value *getAggregateValue() {
2599 return getOperand(0);
2602 const Value *getAggregateValue() const {
2603 return getOperand(0);
2606 unsigned getIndex() const {
2610 unsigned getNumOperands() const { return 1; }
2612 // Methods for support type inquiry through isa, cast, and dyn_cast:
2613 static inline bool classof(const GetResultInst *) { return true; }
2614 static inline bool classof(const Instruction *I) {
2615 return (I->getOpcode() == Instruction::GetResult);
2617 static inline bool classof(const Value *V) {
2618 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2622 } // End llvm namespace