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"
24 #include "llvm/BasicBlock.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
292 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store,
294 Op<0>().init(SI.Op<0>(), this);
295 Op<1>().init(SI.Op<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 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
334 /// getAlignment - Return the alignment of the access that is being performed
336 unsigned getAlignment() const {
337 return (1 << (SubclassData>>1)) >> 1;
340 void setAlignment(unsigned Align);
342 virtual StoreInst *clone() const;
344 Value *getPointerOperand() { return getOperand(1); }
345 const Value *getPointerOperand() const { return getOperand(1); }
346 static unsigned getPointerOperandIndex() { return 1U; }
348 // Methods for support type inquiry through isa, cast, and dyn_cast:
349 static inline bool classof(const StoreInst *) { return true; }
350 static inline bool classof(const Instruction *I) {
351 return I->getOpcode() == Instruction::Store;
353 static inline bool classof(const Value *V) {
354 return isa<Instruction>(V) && classof(cast<Instruction>(V));
359 struct OperandTraits<StoreInst> : FixedNumOperandTraits<2> {
362 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
364 //===----------------------------------------------------------------------===//
365 // GetElementPtrInst Class
366 //===----------------------------------------------------------------------===//
368 // checkType - Simple wrapper function to give a better assertion failure
369 // message on bad indexes for a gep instruction.
371 static inline const Type *checkType(const Type *Ty) {
372 assert(Ty && "Invalid GetElementPtrInst indices for type!");
376 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
377 /// access elements of arrays and structs
379 class GetElementPtrInst : public Instruction {
380 GetElementPtrInst(const GetElementPtrInst &GEPI);
381 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
382 void init(Value *Ptr, Value *Idx);
384 template<typename InputIterator>
385 void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
386 const std::string &Name,
387 // This argument ensures that we have an iterator we can
388 // do arithmetic on in constant time
389 std::random_access_iterator_tag) {
390 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
393 // This requires that the iterator points to contiguous memory.
394 init(Ptr, &*IdxBegin, NumIdx); // FIXME: for the general case
395 // we have to build an array here
398 init(Ptr, 0, NumIdx);
404 /// getIndexedType - Returns the type of the element that would be loaded with
405 /// a load instruction with the specified parameters.
407 /// A null type is returned if the indices are invalid for the specified
410 static const Type *getIndexedType(const Type *Ptr,
411 Value* const *Idx, unsigned NumIdx,
412 bool AllowStructLeaf = false);
414 template<typename InputIterator>
415 static const Type *getIndexedType(const Type *Ptr,
416 InputIterator IdxBegin,
417 InputIterator IdxEnd,
418 bool AllowStructLeaf,
419 // This argument ensures that we
420 // have an iterator we can do
421 // arithmetic on in constant time
422 std::random_access_iterator_tag) {
423 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
426 // This requires that the iterator points to contiguous memory.
427 return(getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx,
431 return(getIndexedType(Ptr, (Value *const*)0, NumIdx, AllowStructLeaf));
435 /// Constructors - Create a getelementptr instruction with a base pointer an
436 /// list of indices. The first ctor can optionally insert before an existing
437 /// instruction, the second appends the new instruction to the specified
439 template<typename InputIterator>
440 inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
441 InputIterator IdxEnd,
443 const std::string &Name,
444 Instruction *InsertBefore);
445 template<typename InputIterator>
446 inline GetElementPtrInst(Value *Ptr,
447 InputIterator IdxBegin, InputIterator IdxEnd,
449 const std::string &Name, BasicBlock *InsertAtEnd);
451 /// Constructors - These two constructors are convenience methods because one
452 /// and two index getelementptr instructions are so common.
453 GetElementPtrInst(Value *Ptr, Value *Idx, const std::string &Name = "",
454 Instruction *InsertBefore = 0);
455 GetElementPtrInst(Value *Ptr, Value *Idx,
456 const std::string &Name, BasicBlock *InsertAtEnd);
458 template<typename InputIterator>
459 static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin,
460 InputIterator IdxEnd,
461 const std::string &Name = "",
462 Instruction *InsertBefore = 0) {
463 typename std::iterator_traits<InputIterator>::difference_type Values =
464 1 + std::distance(IdxBegin, IdxEnd);
466 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, Name, InsertBefore);
468 template<typename InputIterator>
469 static GetElementPtrInst *Create(Value *Ptr,
470 InputIterator IdxBegin, InputIterator IdxEnd,
471 const std::string &Name,
472 BasicBlock *InsertAtEnd) {
473 typename std::iterator_traits<InputIterator>::difference_type Values =
474 1 + std::distance(IdxBegin, IdxEnd);
476 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, Name, InsertAtEnd);
479 /// Constructors - These two creators are convenience methods because one
480 /// index getelementptr instructions are so common.
481 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
482 const std::string &Name = "",
483 Instruction *InsertBefore = 0) {
484 return new(2) GetElementPtrInst(Ptr, Idx, Name, InsertBefore);
486 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
487 const std::string &Name,
488 BasicBlock *InsertAtEnd) {
489 return new(2) GetElementPtrInst(Ptr, Idx, Name, InsertAtEnd);
492 virtual GetElementPtrInst *clone() const;
494 /// Transparently provide more efficient getOperand methods.
495 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
497 // getType - Overload to return most specific pointer type...
498 const PointerType *getType() const {
499 return reinterpret_cast<const PointerType*>(Instruction::getType());
502 /// getIndexedType - Returns the type of the element that would be loaded with
503 /// a load instruction with the specified parameters.
505 /// A null type is returned if the indices are invalid for the specified
508 template<typename InputIterator>
509 static const Type *getIndexedType(const Type *Ptr,
510 InputIterator IdxBegin,
511 InputIterator IdxEnd,
512 bool AllowStructLeaf = false) {
513 return(getIndexedType(Ptr, IdxBegin, IdxEnd, AllowStructLeaf,
514 typename std::iterator_traits<InputIterator>::
515 iterator_category()));
517 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
519 inline op_iterator idx_begin() { return op_begin()+1; }
520 inline const_op_iterator idx_begin() const { return op_begin()+1; }
521 inline op_iterator idx_end() { return op_end(); }
522 inline const_op_iterator idx_end() const { return op_end(); }
524 Value *getPointerOperand() {
525 return getOperand(0);
527 const Value *getPointerOperand() const {
528 return getOperand(0);
530 static unsigned getPointerOperandIndex() {
531 return 0U; // get index for modifying correct operand
534 unsigned getNumIndices() const { // Note: always non-negative
535 return getNumOperands() - 1;
538 bool hasIndices() const {
539 return getNumOperands() > 1;
542 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
543 /// zeros. If so, the result pointer and the first operand have the same
544 /// value, just potentially different types.
545 bool hasAllZeroIndices() const;
547 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
548 /// constant integers. If so, the result pointer and the first operand have
549 /// a constant offset between them.
550 bool hasAllConstantIndices() const;
553 // Methods for support type inquiry through isa, cast, and dyn_cast:
554 static inline bool classof(const GetElementPtrInst *) { return true; }
555 static inline bool classof(const Instruction *I) {
556 return (I->getOpcode() == Instruction::GetElementPtr);
558 static inline bool classof(const Value *V) {
559 return isa<Instruction>(V) && classof(cast<Instruction>(V));
564 struct OperandTraits<GetElementPtrInst> : VariadicOperandTraits<1> {
567 template<typename InputIterator>
568 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
569 InputIterator IdxBegin,
570 InputIterator IdxEnd,
572 const std::string &Name,
573 Instruction *InsertBefore)
574 : Instruction(PointerType::get(checkType(
575 getIndexedType(Ptr->getType(),
576 IdxBegin, IdxEnd, true)),
577 cast<PointerType>(Ptr->getType())
578 ->getAddressSpace()),
580 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
581 Values, InsertBefore) {
582 init(Ptr, IdxBegin, IdxEnd, Name,
583 typename std::iterator_traits<InputIterator>::iterator_category());
585 template<typename InputIterator>
586 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
587 InputIterator IdxBegin,
588 InputIterator IdxEnd,
590 const std::string &Name,
591 BasicBlock *InsertAtEnd)
592 : Instruction(PointerType::get(checkType(
593 getIndexedType(Ptr->getType(),
594 IdxBegin, IdxEnd, true)),
595 cast<PointerType>(Ptr->getType())
596 ->getAddressSpace()),
598 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
599 Values, InsertAtEnd) {
600 init(Ptr, IdxBegin, IdxEnd, Name,
601 typename std::iterator_traits<InputIterator>::iterator_category());
605 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
608 //===----------------------------------------------------------------------===//
610 //===----------------------------------------------------------------------===//
612 /// This instruction compares its operands according to the predicate given
613 /// to the constructor. It only operates on integers, pointers, or packed
614 /// vectors of integrals. The two operands must be the same type.
615 /// @brief Represent an integer comparison operator.
616 class ICmpInst: public CmpInst {
618 /// This enumeration lists the possible predicates for the ICmpInst. The
619 /// values in the range 0-31 are reserved for FCmpInst while values in the
620 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
621 /// predicate values are not overlapping between the classes.
623 ICMP_EQ = 32, ///< equal
624 ICMP_NE = 33, ///< not equal
625 ICMP_UGT = 34, ///< unsigned greater than
626 ICMP_UGE = 35, ///< unsigned greater or equal
627 ICMP_ULT = 36, ///< unsigned less than
628 ICMP_ULE = 37, ///< unsigned less or equal
629 ICMP_SGT = 38, ///< signed greater than
630 ICMP_SGE = 39, ///< signed greater or equal
631 ICMP_SLT = 40, ///< signed less than
632 ICMP_SLE = 41, ///< signed less or equal
633 FIRST_ICMP_PREDICATE = ICMP_EQ,
634 LAST_ICMP_PREDICATE = ICMP_SLE,
635 BAD_ICMP_PREDICATE = ICMP_SLE + 1
638 /// @brief Constructor with insert-before-instruction semantics.
640 Predicate pred, ///< The predicate to use for the comparison
641 Value *LHS, ///< The left-hand-side of the expression
642 Value *RHS, ///< The right-hand-side of the expression
643 const std::string &Name = "", ///< Name of the instruction
644 Instruction *InsertBefore = 0 ///< Where to insert
645 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
648 /// @brief Constructor with insert-at-block-end semantics.
650 Predicate pred, ///< The predicate to use for the comparison
651 Value *LHS, ///< The left-hand-side of the expression
652 Value *RHS, ///< The right-hand-side of the expression
653 const std::string &Name, ///< Name of the instruction
654 BasicBlock *InsertAtEnd ///< Block to insert into.
655 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
658 /// @brief Return the predicate for this instruction.
659 Predicate getPredicate() const { return Predicate(SubclassData); }
661 /// @brief Set the predicate for this instruction to the specified value.
662 void setPredicate(Predicate P) { SubclassData = P; }
664 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
665 /// @returns the inverse predicate for the instruction's current predicate.
666 /// @brief Return the inverse of the instruction's predicate.
667 Predicate getInversePredicate() const {
668 return getInversePredicate(getPredicate());
671 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
672 /// @returns the inverse predicate for predicate provided in \p pred.
673 /// @brief Return the inverse of a given predicate
674 static Predicate getInversePredicate(Predicate pred);
676 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
677 /// @returns the predicate that would be the result of exchanging the two
678 /// operands of the ICmpInst instruction without changing the result
680 /// @brief Return the predicate as if the operands were swapped
681 Predicate getSwappedPredicate() const {
682 return getSwappedPredicate(getPredicate());
685 /// This is a static version that you can use without an instruction
687 /// @brief Return the predicate as if the operands were swapped.
688 static Predicate getSwappedPredicate(Predicate pred);
690 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
691 /// @returns the predicate that would be the result if the operand were
692 /// regarded as signed.
693 /// @brief Return the signed version of the predicate
694 Predicate getSignedPredicate() const {
695 return getSignedPredicate(getPredicate());
698 /// This is a static version that you can use without an instruction.
699 /// @brief Return the signed version of the predicate.
700 static Predicate getSignedPredicate(Predicate pred);
702 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
703 /// @returns the predicate that would be the result if the operand were
704 /// regarded as unsigned.
705 /// @brief Return the unsigned version of the predicate
706 Predicate getUnsignedPredicate() const {
707 return getUnsignedPredicate(getPredicate());
710 /// This is a static version that you can use without an instruction.
711 /// @brief Return the unsigned version of the predicate.
712 static Predicate getUnsignedPredicate(Predicate pred);
714 /// isEquality - Return true if this predicate is either EQ or NE. This also
715 /// tests for commutativity.
716 static bool isEquality(Predicate P) {
717 return P == ICMP_EQ || P == ICMP_NE;
720 /// isEquality - Return true if this predicate is either EQ or NE. This also
721 /// tests for commutativity.
722 bool isEquality() const {
723 return isEquality(getPredicate());
726 /// @returns true if the predicate of this ICmpInst is commutative
727 /// @brief Determine if this relation is commutative.
728 bool isCommutative() const { return isEquality(); }
730 /// isRelational - Return true if the predicate is relational (not EQ or NE).
732 bool isRelational() const {
733 return !isEquality();
736 /// isRelational - Return true if the predicate is relational (not EQ or NE).
738 static bool isRelational(Predicate P) {
739 return !isEquality(P);
742 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
743 /// @brief Determine if this instruction's predicate is signed.
744 bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); }
746 /// @returns true if the predicate provided is signed, false otherwise
747 /// @brief Determine if the predicate is signed.
748 static bool isSignedPredicate(Predicate pred);
750 /// Initialize a set of values that all satisfy the predicate with C.
751 /// @brief Make a ConstantRange for a relation with a constant value.
752 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
754 /// Exchange the two operands to this instruction in such a way that it does
755 /// not modify the semantics of the instruction. The predicate value may be
756 /// changed to retain the same result if the predicate is order dependent
758 /// @brief Swap operands and adjust predicate.
759 void swapOperands() {
760 SubclassData = getSwappedPredicate();
761 std::swap(Op<0>(), Op<1>());
764 virtual ICmpInst *clone() const;
766 // Methods for support type inquiry through isa, cast, and dyn_cast:
767 static inline bool classof(const ICmpInst *) { return true; }
768 static inline bool classof(const Instruction *I) {
769 return I->getOpcode() == Instruction::ICmp;
771 static inline bool classof(const Value *V) {
772 return isa<Instruction>(V) && classof(cast<Instruction>(V));
776 //===----------------------------------------------------------------------===//
778 //===----------------------------------------------------------------------===//
780 /// This instruction compares its operands according to the predicate given
781 /// to the constructor. It only operates on floating point values or packed
782 /// vectors of floating point values. The operands must be identical types.
783 /// @brief Represents a floating point comparison operator.
784 class FCmpInst: public CmpInst {
786 /// This enumeration lists the possible predicates for the FCmpInst. Values
787 /// in the range 0-31 are reserved for FCmpInst.
789 // Opcode U L G E Intuitive operation
790 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
791 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
792 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
793 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
794 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
795 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
796 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
797 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
798 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
799 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
800 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
801 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
802 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
803 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
804 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
805 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
806 FIRST_FCMP_PREDICATE = FCMP_FALSE,
807 LAST_FCMP_PREDICATE = FCMP_TRUE,
808 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
811 /// @brief Constructor with insert-before-instruction semantics.
813 Predicate pred, ///< The predicate to use for the comparison
814 Value *LHS, ///< The left-hand-side of the expression
815 Value *RHS, ///< The right-hand-side of the expression
816 const std::string &Name = "", ///< Name of the instruction
817 Instruction *InsertBefore = 0 ///< Where to insert
818 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
821 /// @brief Constructor with insert-at-block-end semantics.
823 Predicate pred, ///< The predicate to use for the comparison
824 Value *LHS, ///< The left-hand-side of the expression
825 Value *RHS, ///< The right-hand-side of the expression
826 const std::string &Name, ///< Name of the instruction
827 BasicBlock *InsertAtEnd ///< Block to insert into.
828 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
831 /// @brief Return the predicate for this instruction.
832 Predicate getPredicate() const { return Predicate(SubclassData); }
834 /// @brief Set the predicate for this instruction to the specified value.
835 void setPredicate(Predicate P) { SubclassData = P; }
837 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
838 /// @returns the inverse predicate for the instructions current predicate.
839 /// @brief Return the inverse of the predicate
840 Predicate getInversePredicate() const {
841 return getInversePredicate(getPredicate());
844 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
845 /// @returns the inverse predicate for \p pred.
846 /// @brief Return the inverse of a given predicate
847 static Predicate getInversePredicate(Predicate pred);
849 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
850 /// @returns the predicate that would be the result of exchanging the two
851 /// operands of the ICmpInst instruction without changing the result
853 /// @brief Return the predicate as if the operands were swapped
854 Predicate getSwappedPredicate() const {
855 return getSwappedPredicate(getPredicate());
858 /// This is a static version that you can use without an instruction
860 /// @brief Return the predicate as if the operands were swapped.
861 static Predicate getSwappedPredicate(Predicate Opcode);
863 /// This also tests for commutativity. If isEquality() returns true then
864 /// the predicate is also commutative. Only the equality predicates are
866 /// @returns true if the predicate of this instruction is EQ or NE.
867 /// @brief Determine if this is an equality predicate.
868 bool isEquality() const {
869 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
870 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
872 bool isCommutative() const { return isEquality(); }
874 /// @returns true if the predicate is relational (not EQ or NE).
875 /// @brief Determine if this a relational predicate.
876 bool isRelational() const { return !isEquality(); }
878 /// Exchange the two operands to this instruction in such a way that it does
879 /// not modify the semantics of the instruction. The predicate value may be
880 /// changed to retain the same result if the predicate is order dependent
882 /// @brief Swap operands and adjust predicate.
883 void swapOperands() {
884 SubclassData = getSwappedPredicate();
885 std::swap(Op<0>(), Op<1>());
888 virtual FCmpInst *clone() const;
890 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
891 static inline bool classof(const FCmpInst *) { return true; }
892 static inline bool classof(const Instruction *I) {
893 return I->getOpcode() == Instruction::FCmp;
895 static inline bool classof(const Value *V) {
896 return isa<Instruction>(V) && classof(cast<Instruction>(V));
900 //===----------------------------------------------------------------------===//
902 //===----------------------------------------------------------------------===//
903 /// CallInst - This class represents a function call, abstracting a target
904 /// machine's calling convention. This class uses low bit of the SubClassData
905 /// field to indicate whether or not this is a tail call. The rest of the bits
906 /// hold the calling convention of the call.
909 class CallInst : public Instruction {
910 PAListPtr ParamAttrs; ///< parameter attributes for call
911 CallInst(const CallInst &CI);
912 void init(Value *Func, Value* const *Params, unsigned NumParams);
913 void init(Value *Func, Value *Actual1, Value *Actual2);
914 void init(Value *Func, Value *Actual);
915 void init(Value *Func);
917 template<typename InputIterator>
918 void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
919 const std::string &Name,
920 // This argument ensures that we have an iterator we can
921 // do arithmetic on in constant time
922 std::random_access_iterator_tag) {
923 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
925 // This requires that the iterator points to contiguous memory.
926 init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
930 /// Construct a CallInst given a range of arguments. InputIterator
931 /// must be a random-access iterator pointing to contiguous storage
932 /// (e.g. a std::vector<>::iterator). Checks are made for
933 /// random-accessness but not for contiguous storage as that would
934 /// incur runtime overhead.
935 /// @brief Construct a CallInst from a range of arguments
936 template<typename InputIterator>
937 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
938 const std::string &Name, Instruction *InsertBefore);
940 /// Construct a CallInst given a range of arguments. InputIterator
941 /// must be a random-access iterator pointing to contiguous storage
942 /// (e.g. a std::vector<>::iterator). Checks are made for
943 /// random-accessness but not for contiguous storage as that would
944 /// incur runtime overhead.
945 /// @brief Construct a CallInst from a range of arguments
946 template<typename InputIterator>
947 inline CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
948 const std::string &Name, BasicBlock *InsertAtEnd);
950 CallInst(Value *F, Value *Actual, const std::string& Name,
951 Instruction *InsertBefore);
952 CallInst(Value *F, Value *Actual, const std::string& Name,
953 BasicBlock *InsertAtEnd);
954 explicit CallInst(Value *F, const std::string &Name,
955 Instruction *InsertBefore);
956 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
958 template<typename InputIterator>
959 static CallInst *Create(Value *Func,
960 InputIterator ArgBegin, InputIterator ArgEnd,
961 const std::string &Name = "",
962 Instruction *InsertBefore = 0) {
963 return new(ArgEnd - ArgBegin + 1)
964 CallInst(Func, ArgBegin, ArgEnd, Name, InsertBefore);
966 template<typename InputIterator>
967 static CallInst *Create(Value *Func,
968 InputIterator ArgBegin, InputIterator ArgEnd,
969 const std::string &Name, BasicBlock *InsertAtEnd) {
970 return new(ArgEnd - ArgBegin + 1)
971 CallInst(Func, ArgBegin, ArgEnd, Name, InsertAtEnd);
973 static CallInst *Create(Value *F, Value *Actual, const std::string& Name = "",
974 Instruction *InsertBefore = 0) {
975 return new(2) CallInst(F, Actual, Name, InsertBefore);
977 static CallInst *Create(Value *F, Value *Actual, const std::string& Name,
978 BasicBlock *InsertAtEnd) {
979 return new(2) CallInst(F, Actual, Name, InsertAtEnd);
981 static CallInst *Create(Value *F, const std::string &Name = "",
982 Instruction *InsertBefore = 0) {
983 return new(1) CallInst(F, Name, InsertBefore);
985 static CallInst *Create(Value *F, const std::string &Name,
986 BasicBlock *InsertAtEnd) {
987 return new(1) CallInst(F, Name, InsertAtEnd);
992 virtual CallInst *clone() const;
994 /// Provide fast operand accessors
995 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
997 bool isTailCall() const { return SubclassData & 1; }
998 void setTailCall(bool isTailCall = true) {
999 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
1002 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1004 unsigned getCallingConv() const { return SubclassData >> 1; }
1005 void setCallingConv(unsigned CC) {
1006 SubclassData = (SubclassData & 1) | (CC << 1);
1009 /// getParamAttrs - Return the parameter attributes for this call.
1011 const PAListPtr &getParamAttrs() const { return ParamAttrs; }
1013 /// setParamAttrs - Sets the parameter attributes for this call.
1014 void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
1016 /// @brief Determine whether the call or the callee has the given attribute.
1017 bool paramHasAttr(unsigned i, unsigned attr) const;
1019 /// @brief Extract the alignment for a call or parameter (0=unknown).
1020 unsigned getParamAlignment(unsigned i) const {
1021 return ParamAttrs.getParamAlignment(i);
1024 /// @brief Determine if the call does not access memory.
1025 bool doesNotAccessMemory() const {
1026 return paramHasAttr(0, ParamAttr::ReadNone);
1029 /// @brief Determine if the call does not access or only reads memory.
1030 bool onlyReadsMemory() const {
1031 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
1034 /// @brief Determine if the call cannot return.
1035 bool doesNotReturn() const {
1036 return paramHasAttr(0, ParamAttr::NoReturn);
1039 /// @brief Determine if the call cannot unwind.
1040 bool doesNotThrow() const {
1041 return paramHasAttr(0, ParamAttr::NoUnwind);
1043 void setDoesNotThrow(bool doesNotThrow = true);
1045 /// @brief Determine if the call returns a structure through first
1046 /// pointer argument.
1047 bool hasStructRetAttr() const {
1048 // Be friendly and also check the callee.
1049 return paramHasAttr(1, ParamAttr::StructRet);
1052 /// @brief Determine if any call argument is an aggregate passed by value.
1053 bool hasByValArgument() const {
1054 return ParamAttrs.hasAttrSomewhere(ParamAttr::ByVal);
1057 /// getCalledFunction - Return the function being called by this instruction
1058 /// if it is a direct call. If it is a call through a function pointer,
1060 Function *getCalledFunction() const {
1061 return dyn_cast<Function>(getOperand(0));
1064 /// getCalledValue - Get a pointer to the function that is invoked by this
1066 const Value *getCalledValue() const { return getOperand(0); }
1067 Value *getCalledValue() { return getOperand(0); }
1069 // Methods for support type inquiry through isa, cast, and dyn_cast:
1070 static inline bool classof(const CallInst *) { return true; }
1071 static inline bool classof(const Instruction *I) {
1072 return I->getOpcode() == Instruction::Call;
1074 static inline bool classof(const Value *V) {
1075 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1080 struct OperandTraits<CallInst> : VariadicOperandTraits<1> {
1083 template<typename InputIterator>
1084 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1085 const std::string &Name, BasicBlock *InsertAtEnd)
1086 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1087 ->getElementType())->getReturnType(),
1089 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1090 ArgEnd - ArgBegin + 1, InsertAtEnd) {
1091 init(Func, ArgBegin, ArgEnd, Name,
1092 typename std::iterator_traits<InputIterator>::iterator_category());
1095 template<typename InputIterator>
1096 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1097 const std::string &Name, Instruction *InsertBefore)
1098 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1099 ->getElementType())->getReturnType(),
1101 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1102 ArgEnd - ArgBegin + 1, InsertBefore) {
1103 init(Func, ArgBegin, ArgEnd, Name,
1104 typename std::iterator_traits<InputIterator>::iterator_category());
1107 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1109 //===----------------------------------------------------------------------===//
1111 //===----------------------------------------------------------------------===//
1113 /// SelectInst - This class represents the LLVM 'select' instruction.
1115 class SelectInst : public Instruction {
1116 void init(Value *C, Value *S1, Value *S2) {
1122 SelectInst(const SelectInst &SI)
1123 : Instruction(SI.getType(), SI.getOpcode(), &Op<0>(), 3) {
1124 init(SI.Op<0>(), SI.Op<1>(), SI.Op<2>());
1126 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
1127 Instruction *InsertBefore)
1128 : Instruction(S1->getType(), Instruction::Select,
1129 &Op<0>(), 3, InsertBefore) {
1133 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
1134 BasicBlock *InsertAtEnd)
1135 : Instruction(S1->getType(), Instruction::Select,
1136 &Op<0>(), 3, InsertAtEnd) {
1141 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1142 const std::string &Name = "",
1143 Instruction *InsertBefore = 0) {
1144 return new(3) SelectInst(C, S1, S2, Name, InsertBefore);
1146 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1147 const std::string &Name, BasicBlock *InsertAtEnd) {
1148 return new(3) SelectInst(C, S1, S2, Name, InsertAtEnd);
1151 Value *getCondition() const { return Op<0>(); }
1152 Value *getTrueValue() const { return Op<1>(); }
1153 Value *getFalseValue() const { return Op<2>(); }
1155 /// Transparently provide more efficient getOperand methods.
1156 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1158 OtherOps getOpcode() const {
1159 return static_cast<OtherOps>(Instruction::getOpcode());
1162 virtual SelectInst *clone() const;
1164 // Methods for support type inquiry through isa, cast, and dyn_cast:
1165 static inline bool classof(const SelectInst *) { return true; }
1166 static inline bool classof(const Instruction *I) {
1167 return I->getOpcode() == Instruction::Select;
1169 static inline bool classof(const Value *V) {
1170 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1175 struct OperandTraits<SelectInst> : FixedNumOperandTraits<3> {
1178 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1180 //===----------------------------------------------------------------------===//
1182 //===----------------------------------------------------------------------===//
1184 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1185 /// an argument of the specified type given a va_list and increments that list
1187 class VAArgInst : public UnaryInstruction {
1188 VAArgInst(const VAArgInst &VAA)
1189 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
1191 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
1192 Instruction *InsertBefore = 0)
1193 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1196 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
1197 BasicBlock *InsertAtEnd)
1198 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1202 virtual VAArgInst *clone() const;
1204 // Methods for support type inquiry through isa, cast, and dyn_cast:
1205 static inline bool classof(const VAArgInst *) { return true; }
1206 static inline bool classof(const Instruction *I) {
1207 return I->getOpcode() == VAArg;
1209 static inline bool classof(const Value *V) {
1210 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1214 //===----------------------------------------------------------------------===//
1215 // ExtractElementInst Class
1216 //===----------------------------------------------------------------------===//
1218 /// ExtractElementInst - This instruction extracts a single (scalar)
1219 /// element from a VectorType value
1221 class ExtractElementInst : public Instruction {
1222 ExtractElementInst(const ExtractElementInst &EE) :
1223 Instruction(EE.getType(), ExtractElement, &Op<0>(), 2) {
1224 Op<0>().init(EE.Op<0>(), this);
1225 Op<1>().init(EE.Op<1>(), this);
1229 // allocate space for exactly two operands
1230 void *operator new(size_t s) {
1231 return User::operator new(s, 2); // FIXME: "unsigned Idx" forms of ctor?
1233 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
1234 Instruction *InsertBefore = 0);
1235 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
1236 Instruction *InsertBefore = 0);
1237 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
1238 BasicBlock *InsertAtEnd);
1239 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
1240 BasicBlock *InsertAtEnd);
1242 /// isValidOperands - Return true if an extractelement instruction can be
1243 /// formed with the specified operands.
1244 static bool isValidOperands(const Value *Vec, const Value *Idx);
1246 virtual ExtractElementInst *clone() const;
1248 /// Transparently provide more efficient getOperand methods.
1249 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1251 // Methods for support type inquiry through isa, cast, and dyn_cast:
1252 static inline bool classof(const ExtractElementInst *) { return true; }
1253 static inline bool classof(const Instruction *I) {
1254 return I->getOpcode() == Instruction::ExtractElement;
1256 static inline bool classof(const Value *V) {
1257 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1262 struct OperandTraits<ExtractElementInst> : FixedNumOperandTraits<2> {
1265 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1267 //===----------------------------------------------------------------------===//
1268 // InsertElementInst Class
1269 //===----------------------------------------------------------------------===//
1271 /// InsertElementInst - This instruction inserts a single (scalar)
1272 /// element into a VectorType value
1274 class InsertElementInst : public Instruction {
1275 InsertElementInst(const InsertElementInst &IE);
1276 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1277 const std::string &Name = "",Instruction *InsertBefore = 0);
1278 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1279 const std::string &Name = "",Instruction *InsertBefore = 0);
1280 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1281 const std::string &Name, BasicBlock *InsertAtEnd);
1282 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1283 const std::string &Name, BasicBlock *InsertAtEnd);
1285 static InsertElementInst *Create(const InsertElementInst &IE) {
1286 return new(IE.getNumOperands()) InsertElementInst(IE);
1288 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1289 const std::string &Name = "",
1290 Instruction *InsertBefore = 0) {
1291 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
1293 static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
1294 const std::string &Name = "",
1295 Instruction *InsertBefore = 0) {
1296 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
1298 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1299 const std::string &Name,
1300 BasicBlock *InsertAtEnd) {
1301 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
1303 static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
1304 const std::string &Name,
1305 BasicBlock *InsertAtEnd) {
1306 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
1309 /// isValidOperands - Return true if an insertelement instruction can be
1310 /// formed with the specified operands.
1311 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1314 virtual InsertElementInst *clone() const;
1316 /// getType - Overload to return most specific vector type.
1318 const VectorType *getType() const {
1319 return reinterpret_cast<const VectorType*>(Instruction::getType());
1322 /// Transparently provide more efficient getOperand methods.
1323 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1325 // Methods for support type inquiry through isa, cast, and dyn_cast:
1326 static inline bool classof(const InsertElementInst *) { return true; }
1327 static inline bool classof(const Instruction *I) {
1328 return I->getOpcode() == Instruction::InsertElement;
1330 static inline bool classof(const Value *V) {
1331 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1336 struct OperandTraits<InsertElementInst> : FixedNumOperandTraits<3> {
1339 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1341 //===----------------------------------------------------------------------===//
1342 // ShuffleVectorInst Class
1343 //===----------------------------------------------------------------------===//
1345 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1348 class ShuffleVectorInst : public Instruction {
1349 ShuffleVectorInst(const ShuffleVectorInst &IE);
1351 // allocate space for exactly three operands
1352 void *operator new(size_t s) {
1353 return User::operator new(s, 3);
1355 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1356 const std::string &Name = "", Instruction *InsertBefor = 0);
1357 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1358 const std::string &Name, BasicBlock *InsertAtEnd);
1360 /// isValidOperands - Return true if a shufflevector instruction can be
1361 /// formed with the specified operands.
1362 static bool isValidOperands(const Value *V1, const Value *V2,
1365 virtual ShuffleVectorInst *clone() const;
1367 /// getType - Overload to return most specific vector type.
1369 const VectorType *getType() const {
1370 return reinterpret_cast<const VectorType*>(Instruction::getType());
1373 /// Transparently provide more efficient getOperand methods.
1374 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1376 /// getMaskValue - Return the index from the shuffle mask for the specified
1377 /// output result. This is either -1 if the element is undef or a number less
1378 /// than 2*numelements.
1379 int getMaskValue(unsigned i) const;
1381 // Methods for support type inquiry through isa, cast, and dyn_cast:
1382 static inline bool classof(const ShuffleVectorInst *) { return true; }
1383 static inline bool classof(const Instruction *I) {
1384 return I->getOpcode() == Instruction::ShuffleVector;
1386 static inline bool classof(const Value *V) {
1387 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1392 struct OperandTraits<ShuffleVectorInst> : FixedNumOperandTraits<3> {
1395 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1397 //===----------------------------------------------------------------------===//
1399 //===----------------------------------------------------------------------===//
1401 // PHINode - The PHINode class is used to represent the magical mystical PHI
1402 // node, that can not exist in nature, but can be synthesized in a computer
1403 // scientist's overactive imagination.
1405 class PHINode : public Instruction {
1406 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1407 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1408 /// the number actually in use.
1409 unsigned ReservedSpace;
1410 PHINode(const PHINode &PN);
1411 // allocate space for exactly zero operands
1412 void *operator new(size_t s) {
1413 return User::operator new(s, 0);
1415 explicit PHINode(const Type *Ty, const std::string &Name = "",
1416 Instruction *InsertBefore = 0)
1417 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1422 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1423 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1428 static PHINode *Create(const Type *Ty, const std::string &Name = "",
1429 Instruction *InsertBefore = 0) {
1430 return new PHINode(Ty, Name, InsertBefore);
1432 static PHINode *Create(const Type *Ty, const std::string &Name,
1433 BasicBlock *InsertAtEnd) {
1434 return new PHINode(Ty, Name, InsertAtEnd);
1438 /// reserveOperandSpace - This method can be used to avoid repeated
1439 /// reallocation of PHI operand lists by reserving space for the correct
1440 /// number of operands before adding them. Unlike normal vector reserves,
1441 /// this method can also be used to trim the operand space.
1442 void reserveOperandSpace(unsigned NumValues) {
1443 resizeOperands(NumValues*2);
1446 virtual PHINode *clone() const;
1448 /// Provide fast operand accessors
1449 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1451 /// getNumIncomingValues - Return the number of incoming edges
1453 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1455 /// getIncomingValue - Return incoming value number x
1457 Value *getIncomingValue(unsigned i) const {
1458 assert(i*2 < getNumOperands() && "Invalid value number!");
1459 return getOperand(i*2);
1461 void setIncomingValue(unsigned i, Value *V) {
1462 assert(i*2 < getNumOperands() && "Invalid value number!");
1465 unsigned getOperandNumForIncomingValue(unsigned i) {
1469 /// getIncomingBlock - Return incoming basic block number x
1471 BasicBlock *getIncomingBlock(unsigned i) const {
1472 return static_cast<BasicBlock*>(getOperand(i*2+1));
1474 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1475 setOperand(i*2+1, BB);
1477 unsigned getOperandNumForIncomingBlock(unsigned i) {
1481 /// addIncoming - Add an incoming value to the end of the PHI list
1483 void addIncoming(Value *V, BasicBlock *BB) {
1484 assert(V && "PHI node got a null value!");
1485 assert(BB && "PHI node got a null basic block!");
1486 assert(getType() == V->getType() &&
1487 "All operands to PHI node must be the same type as the PHI node!");
1488 unsigned OpNo = NumOperands;
1489 if (OpNo+2 > ReservedSpace)
1490 resizeOperands(0); // Get more space!
1491 // Initialize some new operands.
1492 NumOperands = OpNo+2;
1493 OperandList[OpNo].init(V, this);
1494 OperandList[OpNo+1].init(BB, this);
1497 /// removeIncomingValue - Remove an incoming value. This is useful if a
1498 /// predecessor basic block is deleted. The value removed is returned.
1500 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1501 /// is true), the PHI node is destroyed and any uses of it are replaced with
1502 /// dummy values. The only time there should be zero incoming values to a PHI
1503 /// node is when the block is dead, so this strategy is sound.
1505 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1507 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
1508 int Idx = getBasicBlockIndex(BB);
1509 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1510 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1513 /// getBasicBlockIndex - Return the first index of the specified basic
1514 /// block in the value list for this PHI. Returns -1 if no instance.
1516 int getBasicBlockIndex(const BasicBlock *BB) const {
1517 Use *OL = OperandList;
1518 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1519 if (OL[i+1].get() == BB) return i/2;
1523 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1524 return getIncomingValue(getBasicBlockIndex(BB));
1527 /// hasConstantValue - If the specified PHI node always merges together the
1528 /// same value, return the value, otherwise return null.
1530 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1532 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1533 static inline bool classof(const PHINode *) { return true; }
1534 static inline bool classof(const Instruction *I) {
1535 return I->getOpcode() == Instruction::PHI;
1537 static inline bool classof(const Value *V) {
1538 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1541 void resizeOperands(unsigned NumOperands);
1545 struct OperandTraits<PHINode> : HungoffOperandTraits<2> {
1548 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
1551 //===----------------------------------------------------------------------===//
1553 //===----------------------------------------------------------------------===//
1555 //===---------------------------------------------------------------------------
1556 /// ReturnInst - Return a value (possibly void), from a function. Execution
1557 /// does not continue in this function any longer.
1559 class ReturnInst : public TerminatorInst {
1560 ReturnInst(const ReturnInst &RI);
1561 void init(Value * const* retVals, unsigned N);
1564 // ReturnInst constructors:
1565 // ReturnInst() - 'ret void' instruction
1566 // ReturnInst( null) - 'ret void' instruction
1567 // ReturnInst(Value* X) - 'ret X' instruction
1568 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
1569 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1570 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
1571 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
1572 // ReturnInst(Value* X, N) - 'ret X,X+1...X+N-1' instruction
1573 // ReturnInst(Value* X, N, Inst *I) - 'ret X,X+1...X+N-1', insert before I
1574 // ReturnInst(Value* X, N, BB *B) - 'ret X,X+1...X+N-1', insert @ end of B
1576 // NOTE: If the Value* passed is of type void then the constructor behaves as
1577 // if it was passed NULL.
1578 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1579 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1580 ReturnInst(Value * const* retVals, unsigned N, Instruction *InsertBefore = 0);
1581 ReturnInst(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd);
1582 explicit ReturnInst(BasicBlock *InsertAtEnd);
1584 static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) {
1585 return new(!!retVal) ReturnInst(retVal, InsertBefore);
1587 static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) {
1588 return new(!!retVal) ReturnInst(retVal, InsertAtEnd);
1590 static ReturnInst* Create(Value * const* retVals, unsigned N,
1591 Instruction *InsertBefore = 0) {
1592 return new(N) ReturnInst(retVals, N, InsertBefore);
1594 static ReturnInst* Create(Value * const* retVals, unsigned N,
1595 BasicBlock *InsertAtEnd) {
1596 return new(N) ReturnInst(retVals, N, InsertAtEnd);
1598 static ReturnInst* Create(BasicBlock *InsertAtEnd) {
1599 return new(0) ReturnInst(InsertAtEnd);
1601 virtual ~ReturnInst();
1602 inline void operator delete(void*);
1604 virtual ReturnInst *clone() const;
1606 /// Provide fast operand accessors
1607 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1609 /// Convenience accessor
1610 Value *getReturnValue(unsigned n = 0) const {
1611 return n < getNumOperands()
1616 unsigned getNumSuccessors() const { return 0; }
1618 // Methods for support type inquiry through isa, cast, and dyn_cast:
1619 static inline bool classof(const ReturnInst *) { return true; }
1620 static inline bool classof(const Instruction *I) {
1621 return (I->getOpcode() == Instruction::Ret);
1623 static inline bool classof(const Value *V) {
1624 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1627 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1628 virtual unsigned getNumSuccessorsV() const;
1629 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1633 struct OperandTraits<ReturnInst> : VariadicOperandTraits<> {
1636 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
1637 void ReturnInst::operator delete(void *it) {
1638 ReturnInst* me(static_cast<ReturnInst*>(it));
1639 Use::zap(OperandTraits<ReturnInst>::op_begin(me),
1640 OperandTraits<ReturnInst>::op_end(me),
1644 //===----------------------------------------------------------------------===//
1646 //===----------------------------------------------------------------------===//
1648 //===---------------------------------------------------------------------------
1649 /// BranchInst - Conditional or Unconditional Branch instruction.
1651 class BranchInst : public TerminatorInst {
1652 /// Ops list - Branches are strange. The operands are ordered:
1653 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1654 /// they don't have to check for cond/uncond branchness.
1655 BranchInst(const BranchInst &BI);
1657 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1658 // BranchInst(BB *B) - 'br B'
1659 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1660 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1661 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1662 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1663 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1664 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1665 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1666 Instruction *InsertBefore = 0);
1667 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1668 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1669 BasicBlock *InsertAtEnd);
1671 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
1672 return new(1) BranchInst(IfTrue, InsertBefore);
1674 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
1675 Value *Cond, Instruction *InsertBefore = 0) {
1676 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
1678 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
1679 return new(1) BranchInst(IfTrue, InsertAtEnd);
1681 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
1682 Value *Cond, BasicBlock *InsertAtEnd) {
1683 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
1688 if (NumOperands == 1)
1690 NumOperands = (Use*)this - OperandList;
1694 /// Transparently provide more efficient getOperand methods.
1695 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1697 virtual BranchInst *clone() const;
1699 bool isUnconditional() const { return getNumOperands() == 1; }
1700 bool isConditional() const { return getNumOperands() == 3; }
1702 Value *getCondition() const {
1703 assert(isConditional() && "Cannot get condition of an uncond branch!");
1704 return getOperand(2);
1707 void setCondition(Value *V) {
1708 assert(isConditional() && "Cannot set condition of unconditional branch!");
1712 // setUnconditionalDest - Change the current branch to an unconditional branch
1713 // targeting the specified block.
1714 // FIXME: Eliminate this ugly method.
1715 void setUnconditionalDest(BasicBlock *Dest) {
1717 if (isConditional()) { // Convert this to an uncond branch.
1724 unsigned getNumSuccessors() const { return 1+isConditional(); }
1726 BasicBlock *getSuccessor(unsigned i) const {
1727 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1728 return cast<BasicBlock>(getOperand(i));
1731 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1732 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1733 setOperand(idx, NewSucc);
1736 // Methods for support type inquiry through isa, cast, and dyn_cast:
1737 static inline bool classof(const BranchInst *) { return true; }
1738 static inline bool classof(const Instruction *I) {
1739 return (I->getOpcode() == Instruction::Br);
1741 static inline bool classof(const Value *V) {
1742 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1745 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1746 virtual unsigned getNumSuccessorsV() const;
1747 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1751 struct OperandTraits<BranchInst> : HungoffOperandTraits<> {
1752 // we need to access operands via OperandList, since
1753 // the NumOperands may change from 3 to 1
1754 static inline void *allocate(unsigned); // FIXME
1757 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
1759 //===----------------------------------------------------------------------===//
1761 //===----------------------------------------------------------------------===//
1763 //===---------------------------------------------------------------------------
1764 /// SwitchInst - Multiway switch
1766 class SwitchInst : public TerminatorInst {
1767 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1768 unsigned ReservedSpace;
1769 // Operand[0] = Value to switch on
1770 // Operand[1] = Default basic block destination
1771 // Operand[2n ] = Value to match
1772 // Operand[2n+1] = BasicBlock to go to on match
1773 SwitchInst(const SwitchInst &RI);
1774 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1775 void resizeOperands(unsigned No);
1776 // allocate space for exactly zero operands
1777 void *operator new(size_t s) {
1778 return User::operator new(s, 0);
1780 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1781 /// switch on and a default destination. The number of additional cases can
1782 /// be specified here to make memory allocation more efficient. This
1783 /// constructor can also autoinsert before another instruction.
1784 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1785 Instruction *InsertBefore = 0);
1787 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1788 /// switch on and a default destination. The number of additional cases can
1789 /// be specified here to make memory allocation more efficient. This
1790 /// constructor also autoinserts at the end of the specified BasicBlock.
1791 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1792 BasicBlock *InsertAtEnd);
1794 static SwitchInst *Create(Value *Value, BasicBlock *Default,
1795 unsigned NumCases, Instruction *InsertBefore = 0) {
1796 return new SwitchInst(Value, Default, NumCases, InsertBefore);
1798 static SwitchInst *Create(Value *Value, BasicBlock *Default,
1799 unsigned NumCases, BasicBlock *InsertAtEnd) {
1800 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
1804 /// Provide fast operand accessors
1805 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1807 // Accessor Methods for Switch stmt
1808 Value *getCondition() const { return getOperand(0); }
1809 void setCondition(Value *V) { setOperand(0, V); }
1811 BasicBlock *getDefaultDest() const {
1812 return cast<BasicBlock>(getOperand(1));
1815 /// getNumCases - return the number of 'cases' in this switch instruction.
1816 /// Note that case #0 is always the default case.
1817 unsigned getNumCases() const {
1818 return getNumOperands()/2;
1821 /// getCaseValue - Return the specified case value. Note that case #0, the
1822 /// default destination, does not have a case value.
1823 ConstantInt *getCaseValue(unsigned i) {
1824 assert(i && i < getNumCases() && "Illegal case value to get!");
1825 return getSuccessorValue(i);
1828 /// getCaseValue - Return the specified case value. Note that case #0, the
1829 /// default destination, does not have a case value.
1830 const ConstantInt *getCaseValue(unsigned i) const {
1831 assert(i && i < getNumCases() && "Illegal case value to get!");
1832 return getSuccessorValue(i);
1835 /// findCaseValue - Search all of the case values for the specified constant.
1836 /// If it is explicitly handled, return the case number of it, otherwise
1837 /// return 0 to indicate that it is handled by the default handler.
1838 unsigned findCaseValue(const ConstantInt *C) const {
1839 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1840 if (getCaseValue(i) == C)
1845 /// findCaseDest - Finds the unique case value for a given successor. Returns
1846 /// null if the successor is not found, not unique, or is the default case.
1847 ConstantInt *findCaseDest(BasicBlock *BB) {
1848 if (BB == getDefaultDest()) return NULL;
1850 ConstantInt *CI = NULL;
1851 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1852 if (getSuccessor(i) == BB) {
1853 if (CI) return NULL; // Multiple cases lead to BB.
1854 else CI = getCaseValue(i);
1860 /// addCase - Add an entry to the switch instruction...
1862 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1864 /// removeCase - This method removes the specified successor from the switch
1865 /// instruction. Note that this cannot be used to remove the default
1866 /// destination (successor #0).
1868 void removeCase(unsigned idx);
1870 virtual SwitchInst *clone() const;
1872 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1873 BasicBlock *getSuccessor(unsigned idx) const {
1874 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1875 return cast<BasicBlock>(getOperand(idx*2+1));
1877 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1878 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1879 setOperand(idx*2+1, NewSucc);
1882 // getSuccessorValue - Return the value associated with the specified
1884 ConstantInt *getSuccessorValue(unsigned idx) const {
1885 assert(idx < getNumSuccessors() && "Successor # out of range!");
1886 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1889 // Methods for support type inquiry through isa, cast, and dyn_cast:
1890 static inline bool classof(const SwitchInst *) { return true; }
1891 static inline bool classof(const Instruction *I) {
1892 return I->getOpcode() == Instruction::Switch;
1894 static inline bool classof(const Value *V) {
1895 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1898 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1899 virtual unsigned getNumSuccessorsV() const;
1900 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1904 struct OperandTraits<SwitchInst> : HungoffOperandTraits<2> {
1907 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
1910 //===----------------------------------------------------------------------===//
1912 //===----------------------------------------------------------------------===//
1914 //===---------------------------------------------------------------------------
1916 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1917 /// calling convention of the call.
1919 class InvokeInst : public TerminatorInst {
1920 PAListPtr ParamAttrs;
1921 InvokeInst(const InvokeInst &BI);
1922 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1923 Value* const *Args, unsigned NumArgs);
1925 template<typename InputIterator>
1926 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1927 InputIterator ArgBegin, InputIterator ArgEnd,
1928 const std::string &Name,
1929 // This argument ensures that we have an iterator we can
1930 // do arithmetic on in constant time
1931 std::random_access_iterator_tag) {
1932 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
1934 // This requires that the iterator points to contiguous memory.
1935 init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
1939 /// Construct an InvokeInst given a range of arguments.
1940 /// InputIterator must be a random-access iterator pointing to
1941 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
1942 /// made for random-accessness but not for contiguous storage as
1943 /// that would incur runtime overhead.
1945 /// @brief Construct an InvokeInst from a range of arguments
1946 template<typename InputIterator>
1947 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1948 InputIterator ArgBegin, InputIterator ArgEnd,
1950 const std::string &Name, Instruction *InsertBefore);
1952 /// Construct an InvokeInst given a range of arguments.
1953 /// InputIterator must be a random-access iterator pointing to
1954 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
1955 /// made for random-accessness but not for contiguous storage as
1956 /// that would incur runtime overhead.
1958 /// @brief Construct an InvokeInst from a range of arguments
1959 template<typename InputIterator>
1960 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1961 InputIterator ArgBegin, InputIterator ArgEnd,
1963 const std::string &Name, BasicBlock *InsertAtEnd);
1965 template<typename InputIterator>
1966 static InvokeInst *Create(Value *Func,
1967 BasicBlock *IfNormal, BasicBlock *IfException,
1968 InputIterator ArgBegin, InputIterator ArgEnd,
1969 const std::string &Name = "",
1970 Instruction *InsertBefore = 0) {
1971 unsigned Values(ArgEnd - ArgBegin + 3);
1972 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
1973 Values, Name, InsertBefore);
1975 template<typename InputIterator>
1976 static InvokeInst *Create(Value *Func,
1977 BasicBlock *IfNormal, BasicBlock *IfException,
1978 InputIterator ArgBegin, InputIterator ArgEnd,
1979 const std::string &Name, BasicBlock *InsertAtEnd) {
1980 unsigned Values(ArgEnd - ArgBegin + 3);
1981 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
1982 Values, Name, InsertAtEnd);
1985 virtual InvokeInst *clone() const;
1987 /// Provide fast operand accessors
1988 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1990 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1992 unsigned getCallingConv() const { return SubclassData; }
1993 void setCallingConv(unsigned CC) {
1997 /// getParamAttrs - Return the parameter attributes for this invoke.
1999 const PAListPtr &getParamAttrs() const { return ParamAttrs; }
2001 /// setParamAttrs - Set the parameter attributes for this invoke.
2003 void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
2005 /// @brief Determine whether the call or the callee has the given attribute.
2006 bool paramHasAttr(unsigned i, ParameterAttributes attr) const;
2008 /// @brief Extract the alignment for a call or parameter (0=unknown).
2009 unsigned getParamAlignment(unsigned i) const {
2010 return ParamAttrs.getParamAlignment(i);
2013 /// @brief Determine if the call does not access memory.
2014 bool doesNotAccessMemory() const {
2015 return paramHasAttr(0, ParamAttr::ReadNone);
2018 /// @brief Determine if the call does not access or only reads memory.
2019 bool onlyReadsMemory() const {
2020 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
2023 /// @brief Determine if the call cannot return.
2024 bool doesNotReturn() const {
2025 return paramHasAttr(0, ParamAttr::NoReturn);
2028 /// @brief Determine if the call cannot unwind.
2029 bool doesNotThrow() const {
2030 return paramHasAttr(0, ParamAttr::NoUnwind);
2032 void setDoesNotThrow(bool doesNotThrow = true);
2034 /// @brief Determine if the call returns a structure through first
2035 /// pointer argument.
2036 bool hasStructRetAttr() const {
2037 // Be friendly and also check the callee.
2038 return paramHasAttr(1, ParamAttr::StructRet);
2041 /// getCalledFunction - Return the function called, or null if this is an
2042 /// indirect function invocation.
2044 Function *getCalledFunction() const {
2045 return dyn_cast<Function>(getOperand(0));
2048 // getCalledValue - Get a pointer to a function that is invoked by this inst.
2049 Value *getCalledValue() const { return getOperand(0); }
2051 // get*Dest - Return the destination basic blocks...
2052 BasicBlock *getNormalDest() const {
2053 return cast<BasicBlock>(getOperand(1));
2055 BasicBlock *getUnwindDest() const {
2056 return cast<BasicBlock>(getOperand(2));
2058 void setNormalDest(BasicBlock *B) {
2062 void setUnwindDest(BasicBlock *B) {
2066 BasicBlock *getSuccessor(unsigned i) const {
2067 assert(i < 2 && "Successor # out of range for invoke!");
2068 return i == 0 ? getNormalDest() : getUnwindDest();
2071 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2072 assert(idx < 2 && "Successor # out of range for invoke!");
2073 setOperand(idx+1, NewSucc);
2076 unsigned getNumSuccessors() const { return 2; }
2078 // Methods for support type inquiry through isa, cast, and dyn_cast:
2079 static inline bool classof(const InvokeInst *) { return true; }
2080 static inline bool classof(const Instruction *I) {
2081 return (I->getOpcode() == Instruction::Invoke);
2083 static inline bool classof(const Value *V) {
2084 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2087 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2088 virtual unsigned getNumSuccessorsV() const;
2089 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2093 struct OperandTraits<InvokeInst> : VariadicOperandTraits<3> {
2096 template<typename InputIterator>
2097 InvokeInst::InvokeInst(Value *Func,
2098 BasicBlock *IfNormal, BasicBlock *IfException,
2099 InputIterator ArgBegin, InputIterator ArgEnd,
2101 const std::string &Name, Instruction *InsertBefore)
2102 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2103 ->getElementType())->getReturnType(),
2104 Instruction::Invoke,
2105 OperandTraits<InvokeInst>::op_end(this) - Values,
2106 Values, InsertBefore) {
2107 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
2108 typename std::iterator_traits<InputIterator>::iterator_category());
2110 template<typename InputIterator>
2111 InvokeInst::InvokeInst(Value *Func,
2112 BasicBlock *IfNormal, BasicBlock *IfException,
2113 InputIterator ArgBegin, InputIterator ArgEnd,
2115 const std::string &Name, BasicBlock *InsertAtEnd)
2116 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2117 ->getElementType())->getReturnType(),
2118 Instruction::Invoke,
2119 OperandTraits<InvokeInst>::op_end(this) - Values,
2120 Values, InsertAtEnd) {
2121 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
2122 typename std::iterator_traits<InputIterator>::iterator_category());
2125 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2127 //===----------------------------------------------------------------------===//
2129 //===----------------------------------------------------------------------===//
2131 //===---------------------------------------------------------------------------
2132 /// UnwindInst - Immediately exit the current function, unwinding the stack
2133 /// until an invoke instruction is found.
2135 class UnwindInst : public TerminatorInst {
2136 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2138 // allocate space for exactly zero operands
2139 void *operator new(size_t s) {
2140 return User::operator new(s, 0);
2142 explicit UnwindInst(Instruction *InsertBefore = 0);
2143 explicit UnwindInst(BasicBlock *InsertAtEnd);
2145 virtual UnwindInst *clone() const;
2147 unsigned getNumSuccessors() const { return 0; }
2149 // Methods for support type inquiry through isa, cast, and dyn_cast:
2150 static inline bool classof(const UnwindInst *) { return true; }
2151 static inline bool classof(const Instruction *I) {
2152 return I->getOpcode() == Instruction::Unwind;
2154 static inline bool classof(const Value *V) {
2155 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2158 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2159 virtual unsigned getNumSuccessorsV() const;
2160 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2163 //===----------------------------------------------------------------------===//
2164 // UnreachableInst Class
2165 //===----------------------------------------------------------------------===//
2167 //===---------------------------------------------------------------------------
2168 /// UnreachableInst - This function has undefined behavior. In particular, the
2169 /// presence of this instruction indicates some higher level knowledge that the
2170 /// end of the block cannot be reached.
2172 class UnreachableInst : public TerminatorInst {
2173 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2175 // allocate space for exactly zero operands
2176 void *operator new(size_t s) {
2177 return User::operator new(s, 0);
2179 explicit UnreachableInst(Instruction *InsertBefore = 0);
2180 explicit UnreachableInst(BasicBlock *InsertAtEnd);
2182 virtual UnreachableInst *clone() const;
2184 unsigned getNumSuccessors() const { return 0; }
2186 // Methods for support type inquiry through isa, cast, and dyn_cast:
2187 static inline bool classof(const UnreachableInst *) { return true; }
2188 static inline bool classof(const Instruction *I) {
2189 return I->getOpcode() == Instruction::Unreachable;
2191 static inline bool classof(const Value *V) {
2192 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2195 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2196 virtual unsigned getNumSuccessorsV() const;
2197 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2200 //===----------------------------------------------------------------------===//
2202 //===----------------------------------------------------------------------===//
2204 /// @brief This class represents a truncation of integer types.
2205 class TruncInst : public CastInst {
2206 /// Private copy constructor
2207 TruncInst(const TruncInst &CI)
2208 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
2211 /// @brief Constructor with insert-before-instruction semantics
2213 Value *S, ///< The value to be truncated
2214 const Type *Ty, ///< The (smaller) type to truncate to
2215 const std::string &Name = "", ///< A name for the new instruction
2216 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2219 /// @brief Constructor with insert-at-end-of-block semantics
2221 Value *S, ///< The value to be truncated
2222 const Type *Ty, ///< The (smaller) type to truncate to
2223 const std::string &Name, ///< A name for the new instruction
2224 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2227 /// @brief Clone an identical TruncInst
2228 virtual CastInst *clone() const;
2230 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2231 static inline bool classof(const TruncInst *) { return true; }
2232 static inline bool classof(const Instruction *I) {
2233 return I->getOpcode() == Trunc;
2235 static inline bool classof(const Value *V) {
2236 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2240 //===----------------------------------------------------------------------===//
2242 //===----------------------------------------------------------------------===//
2244 /// @brief This class represents zero extension of integer types.
2245 class ZExtInst : public CastInst {
2246 /// @brief Private copy constructor
2247 ZExtInst(const ZExtInst &CI)
2248 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
2251 /// @brief Constructor with insert-before-instruction semantics
2253 Value *S, ///< The value to be zero extended
2254 const Type *Ty, ///< The type to zero extend to
2255 const std::string &Name = "", ///< A name for the new instruction
2256 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2259 /// @brief Constructor with insert-at-end semantics.
2261 Value *S, ///< The value to be zero extended
2262 const Type *Ty, ///< The type to zero extend to
2263 const std::string &Name, ///< A name for the new instruction
2264 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2267 /// @brief Clone an identical ZExtInst
2268 virtual CastInst *clone() const;
2270 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2271 static inline bool classof(const ZExtInst *) { return true; }
2272 static inline bool classof(const Instruction *I) {
2273 return I->getOpcode() == ZExt;
2275 static inline bool classof(const Value *V) {
2276 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2280 //===----------------------------------------------------------------------===//
2282 //===----------------------------------------------------------------------===//
2284 /// @brief This class represents a sign extension of integer types.
2285 class SExtInst : public CastInst {
2286 /// @brief Private copy constructor
2287 SExtInst(const SExtInst &CI)
2288 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
2291 /// @brief Constructor with insert-before-instruction semantics
2293 Value *S, ///< The value to be sign extended
2294 const Type *Ty, ///< The type to sign extend to
2295 const std::string &Name = "", ///< A name for the new instruction
2296 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2299 /// @brief Constructor with insert-at-end-of-block semantics
2301 Value *S, ///< The value to be sign extended
2302 const Type *Ty, ///< The type to sign extend to
2303 const std::string &Name, ///< A name for the new instruction
2304 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2307 /// @brief Clone an identical SExtInst
2308 virtual CastInst *clone() const;
2310 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2311 static inline bool classof(const SExtInst *) { return true; }
2312 static inline bool classof(const Instruction *I) {
2313 return I->getOpcode() == SExt;
2315 static inline bool classof(const Value *V) {
2316 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2320 //===----------------------------------------------------------------------===//
2321 // FPTruncInst Class
2322 //===----------------------------------------------------------------------===//
2324 /// @brief This class represents a truncation of floating point types.
2325 class FPTruncInst : public CastInst {
2326 FPTruncInst(const FPTruncInst &CI)
2327 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
2330 /// @brief Constructor with insert-before-instruction semantics
2332 Value *S, ///< The value to be truncated
2333 const Type *Ty, ///< The type to truncate to
2334 const std::string &Name = "", ///< A name for the new instruction
2335 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2338 /// @brief Constructor with insert-before-instruction semantics
2340 Value *S, ///< The value to be truncated
2341 const Type *Ty, ///< The type to truncate to
2342 const std::string &Name, ///< A name for the new instruction
2343 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2346 /// @brief Clone an identical FPTruncInst
2347 virtual CastInst *clone() const;
2349 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2350 static inline bool classof(const FPTruncInst *) { return true; }
2351 static inline bool classof(const Instruction *I) {
2352 return I->getOpcode() == FPTrunc;
2354 static inline bool classof(const Value *V) {
2355 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2359 //===----------------------------------------------------------------------===//
2361 //===----------------------------------------------------------------------===//
2363 /// @brief This class represents an extension of floating point types.
2364 class FPExtInst : public CastInst {
2365 FPExtInst(const FPExtInst &CI)
2366 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
2369 /// @brief Constructor with insert-before-instruction semantics
2371 Value *S, ///< The value to be extended
2372 const Type *Ty, ///< The type to extend to
2373 const std::string &Name = "", ///< A name for the new instruction
2374 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2377 /// @brief Constructor with insert-at-end-of-block semantics
2379 Value *S, ///< The value to be extended
2380 const Type *Ty, ///< The type to extend to
2381 const std::string &Name, ///< A name for the new instruction
2382 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2385 /// @brief Clone an identical FPExtInst
2386 virtual CastInst *clone() const;
2388 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2389 static inline bool classof(const FPExtInst *) { return true; }
2390 static inline bool classof(const Instruction *I) {
2391 return I->getOpcode() == FPExt;
2393 static inline bool classof(const Value *V) {
2394 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2398 //===----------------------------------------------------------------------===//
2400 //===----------------------------------------------------------------------===//
2402 /// @brief This class represents a cast unsigned integer to floating point.
2403 class UIToFPInst : public CastInst {
2404 UIToFPInst(const UIToFPInst &CI)
2405 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
2408 /// @brief Constructor with insert-before-instruction semantics
2410 Value *S, ///< The value to be converted
2411 const Type *Ty, ///< The type to convert to
2412 const std::string &Name = "", ///< A name for the new instruction
2413 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2416 /// @brief Constructor with insert-at-end-of-block semantics
2418 Value *S, ///< The value to be converted
2419 const Type *Ty, ///< The type to convert to
2420 const std::string &Name, ///< A name for the new instruction
2421 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2424 /// @brief Clone an identical UIToFPInst
2425 virtual CastInst *clone() const;
2427 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2428 static inline bool classof(const UIToFPInst *) { return true; }
2429 static inline bool classof(const Instruction *I) {
2430 return I->getOpcode() == UIToFP;
2432 static inline bool classof(const Value *V) {
2433 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2437 //===----------------------------------------------------------------------===//
2439 //===----------------------------------------------------------------------===//
2441 /// @brief This class represents a cast from signed integer to floating point.
2442 class SIToFPInst : public CastInst {
2443 SIToFPInst(const SIToFPInst &CI)
2444 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
2447 /// @brief Constructor with insert-before-instruction semantics
2449 Value *S, ///< The value to be converted
2450 const Type *Ty, ///< The type to convert to
2451 const std::string &Name = "", ///< A name for the new instruction
2452 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2455 /// @brief Constructor with insert-at-end-of-block semantics
2457 Value *S, ///< The value to be converted
2458 const Type *Ty, ///< The type to convert to
2459 const std::string &Name, ///< A name for the new instruction
2460 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2463 /// @brief Clone an identical SIToFPInst
2464 virtual CastInst *clone() const;
2466 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2467 static inline bool classof(const SIToFPInst *) { return true; }
2468 static inline bool classof(const Instruction *I) {
2469 return I->getOpcode() == SIToFP;
2471 static inline bool classof(const Value *V) {
2472 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2476 //===----------------------------------------------------------------------===//
2478 //===----------------------------------------------------------------------===//
2480 /// @brief This class represents a cast from floating point to unsigned integer
2481 class FPToUIInst : public CastInst {
2482 FPToUIInst(const FPToUIInst &CI)
2483 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
2486 /// @brief Constructor with insert-before-instruction semantics
2488 Value *S, ///< The value to be converted
2489 const Type *Ty, ///< The type to convert to
2490 const std::string &Name = "", ///< A name for the new instruction
2491 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2494 /// @brief Constructor with insert-at-end-of-block semantics
2496 Value *S, ///< The value to be converted
2497 const Type *Ty, ///< The type to convert to
2498 const std::string &Name, ///< A name for the new instruction
2499 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
2502 /// @brief Clone an identical FPToUIInst
2503 virtual CastInst *clone() const;
2505 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2506 static inline bool classof(const FPToUIInst *) { return true; }
2507 static inline bool classof(const Instruction *I) {
2508 return I->getOpcode() == FPToUI;
2510 static inline bool classof(const Value *V) {
2511 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2515 //===----------------------------------------------------------------------===//
2517 //===----------------------------------------------------------------------===//
2519 /// @brief This class represents a cast from floating point to signed integer.
2520 class FPToSIInst : public CastInst {
2521 FPToSIInst(const FPToSIInst &CI)
2522 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2525 /// @brief Constructor with insert-before-instruction semantics
2527 Value *S, ///< The value to be converted
2528 const Type *Ty, ///< The type to convert to
2529 const std::string &Name = "", ///< A name for the new instruction
2530 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2533 /// @brief Constructor with insert-at-end-of-block semantics
2535 Value *S, ///< The value to be converted
2536 const Type *Ty, ///< The type to convert to
2537 const std::string &Name, ///< A name for the new instruction
2538 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2541 /// @brief Clone an identical FPToSIInst
2542 virtual CastInst *clone() const;
2544 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2545 static inline bool classof(const FPToSIInst *) { return true; }
2546 static inline bool classof(const Instruction *I) {
2547 return I->getOpcode() == FPToSI;
2549 static inline bool classof(const Value *V) {
2550 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2554 //===----------------------------------------------------------------------===//
2555 // IntToPtrInst Class
2556 //===----------------------------------------------------------------------===//
2558 /// @brief This class represents a cast from an integer to a pointer.
2559 class IntToPtrInst : public CastInst {
2560 IntToPtrInst(const IntToPtrInst &CI)
2561 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2564 /// @brief Constructor with insert-before-instruction semantics
2566 Value *S, ///< The value to be converted
2567 const Type *Ty, ///< The type to convert to
2568 const std::string &Name = "", ///< A name for the new instruction
2569 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2572 /// @brief Constructor with insert-at-end-of-block semantics
2574 Value *S, ///< The value to be converted
2575 const Type *Ty, ///< The type to convert to
2576 const std::string &Name, ///< A name for the new instruction
2577 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2580 /// @brief Clone an identical IntToPtrInst
2581 virtual CastInst *clone() const;
2583 // Methods for support type inquiry through isa, cast, and dyn_cast:
2584 static inline bool classof(const IntToPtrInst *) { return true; }
2585 static inline bool classof(const Instruction *I) {
2586 return I->getOpcode() == IntToPtr;
2588 static inline bool classof(const Value *V) {
2589 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2593 //===----------------------------------------------------------------------===//
2594 // PtrToIntInst Class
2595 //===----------------------------------------------------------------------===//
2597 /// @brief This class represents a cast from a pointer to an integer
2598 class PtrToIntInst : public CastInst {
2599 PtrToIntInst(const PtrToIntInst &CI)
2600 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2603 /// @brief Constructor with insert-before-instruction semantics
2605 Value *S, ///< The value to be converted
2606 const Type *Ty, ///< The type to convert to
2607 const std::string &Name = "", ///< A name for the new instruction
2608 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2611 /// @brief Constructor with insert-at-end-of-block semantics
2613 Value *S, ///< The value to be converted
2614 const Type *Ty, ///< The type to convert to
2615 const std::string &Name, ///< A name for the new instruction
2616 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2619 /// @brief Clone an identical PtrToIntInst
2620 virtual CastInst *clone() const;
2622 // Methods for support type inquiry through isa, cast, and dyn_cast:
2623 static inline bool classof(const PtrToIntInst *) { return true; }
2624 static inline bool classof(const Instruction *I) {
2625 return I->getOpcode() == PtrToInt;
2627 static inline bool classof(const Value *V) {
2628 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2632 //===----------------------------------------------------------------------===//
2633 // BitCastInst Class
2634 //===----------------------------------------------------------------------===//
2636 /// @brief This class represents a no-op cast from one type to another.
2637 class BitCastInst : public CastInst {
2638 BitCastInst(const BitCastInst &CI)
2639 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2642 /// @brief Constructor with insert-before-instruction semantics
2644 Value *S, ///< The value to be casted
2645 const Type *Ty, ///< The type to casted to
2646 const std::string &Name = "", ///< A name for the new instruction
2647 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2650 /// @brief Constructor with insert-at-end-of-block semantics
2652 Value *S, ///< The value to be casted
2653 const Type *Ty, ///< The type to casted to
2654 const std::string &Name, ///< A name for the new instruction
2655 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2658 /// @brief Clone an identical BitCastInst
2659 virtual CastInst *clone() const;
2661 // Methods for support type inquiry through isa, cast, and dyn_cast:
2662 static inline bool classof(const BitCastInst *) { return true; }
2663 static inline bool classof(const Instruction *I) {
2664 return I->getOpcode() == BitCast;
2666 static inline bool classof(const Value *V) {
2667 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2671 //===----------------------------------------------------------------------===//
2672 // GetResultInst Class
2673 //===----------------------------------------------------------------------===//
2675 /// GetResultInst - This instruction extracts individual result value from
2676 /// aggregate value, where aggregate value is returned by CallInst.
2678 class GetResultInst : public /*FIXME: Unary*/Instruction {
2679 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2681 GetResultInst(const GetResultInst &GRI) :
2682 Instruction(GRI.getType(), Instruction::GetResult, &Op<0>(), 1) {
2683 Op<0>().init(GRI.Op<0>(), this);
2688 // allocate space for exactly one operand
2689 void *operator new(size_t s) {
2690 return User::operator new(s, 1);
2692 GetResultInst(Value *Aggr, unsigned index,
2693 const std::string &Name = "",
2694 Instruction *InsertBefore = 0);
2696 /// isValidOperands - Return true if an getresult instruction can be
2697 /// formed with the specified operands.
2698 static bool isValidOperands(const Value *Aggr, unsigned index);
2700 virtual GetResultInst *clone() const;
2702 Value *getAggregateValue() {
2703 return getOperand(0);
2706 const Value *getAggregateValue() const {
2707 return getOperand(0);
2710 unsigned getIndex() const {
2714 /// Provide fast operand accessors
2715 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2717 // Methods for support type inquiry through isa, cast, and dyn_cast:
2718 static inline bool classof(const GetResultInst *) { return true; }
2719 static inline bool classof(const Instruction *I) {
2720 return (I->getOpcode() == Instruction::GetResult);
2722 static inline bool classof(const Value *V) {
2723 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2727 // FIXME: these are redundant if GetResultInst < UnaryInstruction
2729 struct OperandTraits<GetResultInst> : FixedNumOperandTraits<1> {
2732 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetResultInst, Value)
2735 } // End llvm namespace