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>() = SI.Op<0>();
295 Op<1>() = SI.Op<1>();
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 /// Null is returned if the indices are invalid for the specified
410 static const Type *getIndexedType(const Type *Ptr,
411 Value* const *Idx, unsigned NumIdx);
413 template<typename InputIterator>
414 static const Type *getIndexedType(const Type *Ptr,
415 InputIterator IdxBegin,
416 InputIterator IdxEnd,
417 // This argument ensures that we
418 // have an iterator we can do
419 // arithmetic on in constant time
420 std::random_access_iterator_tag) {
421 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
424 // This requires that the iterator points to contiguous memory.
425 return getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx);
427 return getIndexedType(Ptr, (Value *const*)0, NumIdx);
430 /// Constructors - Create a getelementptr instruction with a base pointer an
431 /// list of indices. The first ctor can optionally insert before an existing
432 /// instruction, the second appends the new instruction to the specified
434 template<typename InputIterator>
435 inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
436 InputIterator IdxEnd,
438 const std::string &Name,
439 Instruction *InsertBefore);
440 template<typename InputIterator>
441 inline GetElementPtrInst(Value *Ptr,
442 InputIterator IdxBegin, InputIterator IdxEnd,
444 const std::string &Name, BasicBlock *InsertAtEnd);
446 /// Constructors - These two constructors are convenience methods because one
447 /// and two index getelementptr instructions are so common.
448 GetElementPtrInst(Value *Ptr, Value *Idx, const std::string &Name = "",
449 Instruction *InsertBefore = 0);
450 GetElementPtrInst(Value *Ptr, Value *Idx,
451 const std::string &Name, BasicBlock *InsertAtEnd);
453 template<typename InputIterator>
454 static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin,
455 InputIterator IdxEnd,
456 const std::string &Name = "",
457 Instruction *InsertBefore = 0) {
458 typename std::iterator_traits<InputIterator>::difference_type Values =
459 1 + std::distance(IdxBegin, IdxEnd);
461 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, Name, InsertBefore);
463 template<typename InputIterator>
464 static GetElementPtrInst *Create(Value *Ptr,
465 InputIterator IdxBegin, InputIterator IdxEnd,
466 const std::string &Name,
467 BasicBlock *InsertAtEnd) {
468 typename std::iterator_traits<InputIterator>::difference_type Values =
469 1 + std::distance(IdxBegin, IdxEnd);
471 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, Name, InsertAtEnd);
474 /// Constructors - These two creators are convenience methods because one
475 /// index getelementptr instructions are so common.
476 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
477 const std::string &Name = "",
478 Instruction *InsertBefore = 0) {
479 return new(2) GetElementPtrInst(Ptr, Idx, Name, InsertBefore);
481 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
482 const std::string &Name,
483 BasicBlock *InsertAtEnd) {
484 return new(2) GetElementPtrInst(Ptr, Idx, Name, InsertAtEnd);
487 virtual GetElementPtrInst *clone() const;
489 /// Transparently provide more efficient getOperand methods.
490 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
492 // getType - Overload to return most specific pointer type...
493 const PointerType *getType() const {
494 return reinterpret_cast<const PointerType*>(Instruction::getType());
497 /// getIndexedType - Returns the type of the element that would be loaded with
498 /// a load instruction with the specified parameters.
500 /// Null is returned if the indices are invalid for the specified
503 template<typename InputIterator>
504 static const Type *getIndexedType(const Type *Ptr,
505 InputIterator IdxBegin,
506 InputIterator IdxEnd) {
507 return getIndexedType(Ptr, IdxBegin, IdxEnd,
508 typename std::iterator_traits<InputIterator>::
509 iterator_category());
511 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
513 inline op_iterator idx_begin() { return op_begin()+1; }
514 inline const_op_iterator idx_begin() const { return op_begin()+1; }
515 inline op_iterator idx_end() { return op_end(); }
516 inline const_op_iterator idx_end() const { return op_end(); }
518 Value *getPointerOperand() {
519 return getOperand(0);
521 const Value *getPointerOperand() const {
522 return getOperand(0);
524 static unsigned getPointerOperandIndex() {
525 return 0U; // get index for modifying correct operand
528 unsigned getNumIndices() const { // Note: always non-negative
529 return getNumOperands() - 1;
532 bool hasIndices() const {
533 return getNumOperands() > 1;
536 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
537 /// zeros. If so, the result pointer and the first operand have the same
538 /// value, just potentially different types.
539 bool hasAllZeroIndices() const;
541 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
542 /// constant integers. If so, the result pointer and the first operand have
543 /// a constant offset between them.
544 bool hasAllConstantIndices() const;
547 // Methods for support type inquiry through isa, cast, and dyn_cast:
548 static inline bool classof(const GetElementPtrInst *) { return true; }
549 static inline bool classof(const Instruction *I) {
550 return (I->getOpcode() == Instruction::GetElementPtr);
552 static inline bool classof(const Value *V) {
553 return isa<Instruction>(V) && classof(cast<Instruction>(V));
558 struct OperandTraits<GetElementPtrInst> : VariadicOperandTraits<1> {
561 template<typename InputIterator>
562 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
563 InputIterator IdxBegin,
564 InputIterator IdxEnd,
566 const std::string &Name,
567 Instruction *InsertBefore)
568 : Instruction(PointerType::get(checkType(
569 getIndexedType(Ptr->getType(),
571 cast<PointerType>(Ptr->getType())
572 ->getAddressSpace()),
574 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
575 Values, InsertBefore) {
576 init(Ptr, IdxBegin, IdxEnd, Name,
577 typename std::iterator_traits<InputIterator>::iterator_category());
579 template<typename InputIterator>
580 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
581 InputIterator IdxBegin,
582 InputIterator IdxEnd,
584 const std::string &Name,
585 BasicBlock *InsertAtEnd)
586 : Instruction(PointerType::get(checkType(
587 getIndexedType(Ptr->getType(),
589 cast<PointerType>(Ptr->getType())
590 ->getAddressSpace()),
592 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
593 Values, InsertAtEnd) {
594 init(Ptr, IdxBegin, IdxEnd, Name,
595 typename std::iterator_traits<InputIterator>::iterator_category());
599 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
602 //===----------------------------------------------------------------------===//
604 //===----------------------------------------------------------------------===//
606 /// This instruction compares its operands according to the predicate given
607 /// to the constructor. It only operates on integers or pointers. The operands
608 /// must be identical types.
609 /// @brief Represent an integer comparison operator.
610 class ICmpInst: public CmpInst {
612 /// @brief Constructor with insert-before-instruction semantics.
614 Predicate pred, ///< The predicate to use for the comparison
615 Value *LHS, ///< The left-hand-side of the expression
616 Value *RHS, ///< The right-hand-side of the expression
617 const std::string &Name = "", ///< Name of the instruction
618 Instruction *InsertBefore = 0 ///< Where to insert
619 ) : CmpInst(Type::Int1Ty, Instruction::ICmp, pred, LHS, RHS, Name,
621 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
622 pred <= CmpInst::LAST_ICMP_PREDICATE &&
623 "Invalid ICmp predicate value");
624 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
625 "Both operands to ICmp instruction are not of the same type!");
626 // Check that the operands are the right type
627 assert((getOperand(0)->getType()->isInteger() ||
628 isa<PointerType>(getOperand(0)->getType())) &&
629 "Invalid operand types for ICmp instruction");
632 /// @brief Constructor with insert-at-block-end semantics.
634 Predicate pred, ///< The predicate to use for the comparison
635 Value *LHS, ///< The left-hand-side of the expression
636 Value *RHS, ///< The right-hand-side of the expression
637 const std::string &Name, ///< Name of the instruction
638 BasicBlock *InsertAtEnd ///< Block to insert into.
639 ) : CmpInst(Type::Int1Ty, Instruction::ICmp, pred, LHS, RHS, Name,
641 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
642 pred <= CmpInst::LAST_ICMP_PREDICATE &&
643 "Invalid ICmp predicate value");
644 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
645 "Both operands to ICmp instruction are not of the same type!");
646 // Check that the operands are the right type
647 assert((getOperand(0)->getType()->isInteger() ||
648 isa<PointerType>(getOperand(0)->getType())) &&
649 "Invalid operand types for ICmp instruction");
652 /// @brief Return the predicate for this instruction.
653 Predicate getPredicate() const { return Predicate(SubclassData); }
655 /// @brief Set the predicate for this instruction to the specified value.
656 void setPredicate(Predicate P) { SubclassData = P; }
658 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
659 /// @returns the inverse predicate for the instruction's current predicate.
660 /// @brief Return the inverse of the instruction's predicate.
661 Predicate getInversePredicate() const {
662 return getInversePredicate(getPredicate());
665 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
666 /// @returns the inverse predicate for predicate provided in \p pred.
667 /// @brief Return the inverse of a given predicate
668 static Predicate getInversePredicate(Predicate pred);
670 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
671 /// @returns the predicate that would be the result of exchanging the two
672 /// operands of the ICmpInst instruction without changing the result
674 /// @brief Return the predicate as if the operands were swapped
675 Predicate getSwappedPredicate() const {
676 return getSwappedPredicate(getPredicate());
679 /// This is a static version that you can use without an instruction
681 /// @brief Return the predicate as if the operands were swapped.
682 static Predicate getSwappedPredicate(Predicate pred);
684 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
685 /// @returns the predicate that would be the result if the operand were
686 /// regarded as signed.
687 /// @brief Return the signed version of the predicate
688 Predicate getSignedPredicate() const {
689 return getSignedPredicate(getPredicate());
692 /// This is a static version that you can use without an instruction.
693 /// @brief Return the signed version of the predicate.
694 static Predicate getSignedPredicate(Predicate pred);
696 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
697 /// @returns the predicate that would be the result if the operand were
698 /// regarded as unsigned.
699 /// @brief Return the unsigned version of the predicate
700 Predicate getUnsignedPredicate() const {
701 return getUnsignedPredicate(getPredicate());
704 /// This is a static version that you can use without an instruction.
705 /// @brief Return the unsigned version of the predicate.
706 static Predicate getUnsignedPredicate(Predicate pred);
708 /// isEquality - Return true if this predicate is either EQ or NE. This also
709 /// tests for commutativity.
710 static bool isEquality(Predicate P) {
711 return P == ICMP_EQ || P == ICMP_NE;
714 /// isEquality - Return true if this predicate is either EQ or NE. This also
715 /// tests for commutativity.
716 bool isEquality() const {
717 return isEquality(getPredicate());
720 /// @returns true if the predicate of this ICmpInst is commutative
721 /// @brief Determine if this relation is commutative.
722 bool isCommutative() const { return isEquality(); }
724 /// isRelational - Return true if the predicate is relational (not EQ or NE).
726 bool isRelational() const {
727 return !isEquality();
730 /// isRelational - Return true if the predicate is relational (not EQ or NE).
732 static bool isRelational(Predicate P) {
733 return !isEquality(P);
736 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
737 /// @brief Determine if this instruction's predicate is signed.
738 bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); }
740 /// @returns true if the predicate provided is signed, false otherwise
741 /// @brief Determine if the predicate is signed.
742 static bool isSignedPredicate(Predicate pred);
744 /// @returns true if the specified compare predicate is
745 /// true when both operands are equal...
746 /// @brief Determine if the icmp is true when both operands are equal
747 static bool isTrueWhenEqual(ICmpInst::Predicate pred) {
748 return pred == ICmpInst::ICMP_EQ || pred == ICmpInst::ICMP_UGE ||
749 pred == ICmpInst::ICMP_SGE || pred == ICmpInst::ICMP_ULE ||
750 pred == ICmpInst::ICMP_SLE;
753 /// @returns true if the specified compare instruction is
754 /// true when both operands are equal...
755 /// @brief Determine if the ICmpInst returns true when both operands are equal
756 bool isTrueWhenEqual() {
757 return isTrueWhenEqual(getPredicate());
760 /// Initialize a set of values that all satisfy the predicate with C.
761 /// @brief Make a ConstantRange for a relation with a constant value.
762 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
764 /// Exchange the two operands to this instruction in such a way that it does
765 /// not modify the semantics of the instruction. The predicate value may be
766 /// changed to retain the same result if the predicate is order dependent
768 /// @brief Swap operands and adjust predicate.
769 void swapOperands() {
770 SubclassData = getSwappedPredicate();
771 Op<0>().swap(Op<1>());
774 virtual ICmpInst *clone() const;
776 // Methods for support type inquiry through isa, cast, and dyn_cast:
777 static inline bool classof(const ICmpInst *) { return true; }
778 static inline bool classof(const Instruction *I) {
779 return I->getOpcode() == Instruction::ICmp;
781 static inline bool classof(const Value *V) {
782 return isa<Instruction>(V) && classof(cast<Instruction>(V));
786 //===----------------------------------------------------------------------===//
788 //===----------------------------------------------------------------------===//
790 /// This instruction compares its operands according to the predicate given
791 /// to the constructor. It only operates on floating point values or packed
792 /// vectors of floating point values. The operands must be identical types.
793 /// @brief Represents a floating point comparison operator.
794 class FCmpInst: public CmpInst {
796 /// @brief Constructor with insert-before-instruction semantics.
798 Predicate pred, ///< The predicate to use for the comparison
799 Value *LHS, ///< The left-hand-side of the expression
800 Value *RHS, ///< The right-hand-side of the expression
801 const std::string &Name = "", ///< Name of the instruction
802 Instruction *InsertBefore = 0 ///< Where to insert
803 ) : CmpInst(Type::Int1Ty, Instruction::FCmp, pred, LHS, RHS, Name,
805 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
806 "Invalid FCmp predicate value");
807 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
808 "Both operands to FCmp instruction are not of the same type!");
809 // Check that the operands are the right type
810 assert(getOperand(0)->getType()->isFloatingPoint() &&
811 "Invalid operand types for FCmp instruction");
814 /// @brief Constructor with insert-at-block-end semantics.
816 Predicate pred, ///< The predicate to use for the comparison
817 Value *LHS, ///< The left-hand-side of the expression
818 Value *RHS, ///< The right-hand-side of the expression
819 const std::string &Name, ///< Name of the instruction
820 BasicBlock *InsertAtEnd ///< Block to insert into.
821 ) : CmpInst(Type::Int1Ty, Instruction::FCmp, pred, LHS, RHS, Name,
823 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
824 "Invalid FCmp predicate value");
825 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
826 "Both operands to FCmp instruction are not of the same type!");
827 // Check that the operands are the right type
828 assert(getOperand(0)->getType()->isFloatingPoint() &&
829 "Invalid operand types for FCmp instruction");
832 /// @brief Return the predicate for this instruction.
833 Predicate getPredicate() const { return Predicate(SubclassData); }
835 /// @brief Set the predicate for this instruction to the specified value.
836 void setPredicate(Predicate P) { SubclassData = P; }
838 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
839 /// @returns the inverse predicate for the instructions current predicate.
840 /// @brief Return the inverse of the predicate
841 Predicate getInversePredicate() const {
842 return getInversePredicate(getPredicate());
845 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
846 /// @returns the inverse predicate for \p pred.
847 /// @brief Return the inverse of a given predicate
848 static Predicate getInversePredicate(Predicate pred);
850 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
851 /// @returns the predicate that would be the result of exchanging the two
852 /// operands of the ICmpInst instruction without changing the result
854 /// @brief Return the predicate as if the operands were swapped
855 Predicate getSwappedPredicate() const {
856 return getSwappedPredicate(getPredicate());
859 /// This is a static version that you can use without an instruction
861 /// @brief Return the predicate as if the operands were swapped.
862 static Predicate getSwappedPredicate(Predicate Opcode);
864 /// This also tests for commutativity. If isEquality() returns true then
865 /// the predicate is also commutative. Only the equality predicates are
867 /// @returns true if the predicate of this instruction is EQ or NE.
868 /// @brief Determine if this is an equality predicate.
869 bool isEquality() const {
870 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
871 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
873 bool isCommutative() const { return isEquality(); }
875 /// @returns true if the predicate is relational (not EQ or NE).
876 /// @brief Determine if this a relational predicate.
877 bool isRelational() const { return !isEquality(); }
879 /// Exchange the two operands to this instruction in such a way that it does
880 /// not modify the semantics of the instruction. The predicate value may be
881 /// changed to retain the same result if the predicate is order dependent
883 /// @brief Swap operands and adjust predicate.
884 void swapOperands() {
885 SubclassData = getSwappedPredicate();
886 Op<0>().swap(Op<1>());
889 virtual FCmpInst *clone() const;
891 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
892 static inline bool classof(const FCmpInst *) { return true; }
893 static inline bool classof(const Instruction *I) {
894 return I->getOpcode() == Instruction::FCmp;
896 static inline bool classof(const Value *V) {
897 return isa<Instruction>(V) && classof(cast<Instruction>(V));
901 //===----------------------------------------------------------------------===//
903 //===----------------------------------------------------------------------===//
905 /// This instruction compares its operands according to the predicate given
906 /// to the constructor. It only operates on vectors of integers.
907 /// The operands must be identical types.
908 /// @brief Represents a vector integer comparison operator.
909 class VICmpInst: public CmpInst {
911 /// @brief Constructor with insert-before-instruction semantics.
913 Predicate pred, ///< The predicate to use for the comparison
914 Value *LHS, ///< The left-hand-side of the expression
915 Value *RHS, ///< The right-hand-side of the expression
916 const std::string &Name = "", ///< Name of the instruction
917 Instruction *InsertBefore = 0 ///< Where to insert
918 ) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, Name,
920 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
921 pred <= CmpInst::LAST_ICMP_PREDICATE &&
922 "Invalid VICmp predicate value");
923 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
924 "Both operands to VICmp instruction are not of the same type!");
927 /// @brief Constructor with insert-at-block-end semantics.
929 Predicate pred, ///< The predicate to use for the comparison
930 Value *LHS, ///< The left-hand-side of the expression
931 Value *RHS, ///< The right-hand-side of the expression
932 const std::string &Name, ///< Name of the instruction
933 BasicBlock *InsertAtEnd ///< Block to insert into.
934 ) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, Name,
936 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
937 pred <= CmpInst::LAST_ICMP_PREDICATE &&
938 "Invalid VICmp predicate value");
939 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
940 "Both operands to VICmp instruction are not of the same type!");
943 /// @brief Return the predicate for this instruction.
944 Predicate getPredicate() const { return Predicate(SubclassData); }
946 virtual VICmpInst *clone() const;
948 // Methods for support type inquiry through isa, cast, and dyn_cast:
949 static inline bool classof(const VICmpInst *) { return true; }
950 static inline bool classof(const Instruction *I) {
951 return I->getOpcode() == Instruction::VICmp;
953 static inline bool classof(const Value *V) {
954 return isa<Instruction>(V) && classof(cast<Instruction>(V));
958 //===----------------------------------------------------------------------===//
960 //===----------------------------------------------------------------------===//
962 /// This instruction compares its operands according to the predicate given
963 /// to the constructor. It only operates on vectors of floating point values.
964 /// The operands must be identical types.
965 /// @brief Represents a vector floating point comparison operator.
966 class VFCmpInst: public CmpInst {
968 /// @brief Constructor with insert-before-instruction semantics.
970 Predicate pred, ///< The predicate to use for the comparison
971 Value *LHS, ///< The left-hand-side of the expression
972 Value *RHS, ///< The right-hand-side of the expression
973 const std::string &Name = "", ///< Name of the instruction
974 Instruction *InsertBefore = 0 ///< Where to insert
975 ) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())),
976 Instruction::VFCmp, pred, LHS, RHS, Name, InsertBefore) {
977 assert(pred <= CmpInst::LAST_FCMP_PREDICATE &&
978 "Invalid VFCmp predicate value");
979 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
980 "Both operands to VFCmp instruction are not of the same type!");
983 /// @brief Constructor with insert-at-block-end semantics.
985 Predicate pred, ///< The predicate to use for the comparison
986 Value *LHS, ///< The left-hand-side of the expression
987 Value *RHS, ///< The right-hand-side of the expression
988 const std::string &Name, ///< Name of the instruction
989 BasicBlock *InsertAtEnd ///< Block to insert into.
990 ) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())),
991 Instruction::VFCmp, pred, LHS, RHS, Name, InsertAtEnd) {
992 assert(pred <= CmpInst::LAST_FCMP_PREDICATE &&
993 "Invalid VFCmp predicate value");
994 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
995 "Both operands to VFCmp instruction are not of the same type!");
998 /// @brief Return the predicate for this instruction.
999 Predicate getPredicate() const { return Predicate(SubclassData); }
1001 virtual VFCmpInst *clone() const;
1003 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1004 static inline bool classof(const VFCmpInst *) { return true; }
1005 static inline bool classof(const Instruction *I) {
1006 return I->getOpcode() == Instruction::VFCmp;
1008 static inline bool classof(const Value *V) {
1009 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1013 //===----------------------------------------------------------------------===//
1015 //===----------------------------------------------------------------------===//
1016 /// CallInst - This class represents a function call, abstracting a target
1017 /// machine's calling convention. This class uses low bit of the SubClassData
1018 /// field to indicate whether or not this is a tail call. The rest of the bits
1019 /// hold the calling convention of the call.
1022 class CallInst : public Instruction {
1023 PAListPtr ParamAttrs; ///< parameter attributes for call
1024 CallInst(const CallInst &CI);
1025 void init(Value *Func, Value* const *Params, unsigned NumParams);
1026 void init(Value *Func, Value *Actual1, Value *Actual2);
1027 void init(Value *Func, Value *Actual);
1028 void init(Value *Func);
1030 template<typename InputIterator>
1031 void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1032 const std::string &Name,
1033 // This argument ensures that we have an iterator we can
1034 // do arithmetic on in constant time
1035 std::random_access_iterator_tag) {
1036 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
1038 // This requires that the iterator points to contiguous memory.
1039 init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
1043 /// Construct a CallInst given a range of arguments. InputIterator
1044 /// must be a random-access iterator pointing to contiguous storage
1045 /// (e.g. a std::vector<>::iterator). Checks are made for
1046 /// random-accessness but not for contiguous storage as that would
1047 /// incur runtime overhead.
1048 /// @brief Construct a CallInst from a range of arguments
1049 template<typename InputIterator>
1050 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1051 const std::string &Name, Instruction *InsertBefore);
1053 /// Construct a CallInst given a range of arguments. InputIterator
1054 /// must be a random-access iterator pointing to contiguous storage
1055 /// (e.g. a std::vector<>::iterator). Checks are made for
1056 /// random-accessness but not for contiguous storage as that would
1057 /// incur runtime overhead.
1058 /// @brief Construct a CallInst from a range of arguments
1059 template<typename InputIterator>
1060 inline CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1061 const std::string &Name, BasicBlock *InsertAtEnd);
1063 CallInst(Value *F, Value *Actual, const std::string& Name,
1064 Instruction *InsertBefore);
1065 CallInst(Value *F, Value *Actual, const std::string& Name,
1066 BasicBlock *InsertAtEnd);
1067 explicit CallInst(Value *F, const std::string &Name,
1068 Instruction *InsertBefore);
1069 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
1071 template<typename InputIterator>
1072 static CallInst *Create(Value *Func,
1073 InputIterator ArgBegin, InputIterator ArgEnd,
1074 const std::string &Name = "",
1075 Instruction *InsertBefore = 0) {
1076 return new((unsigned)(ArgEnd - ArgBegin + 1))
1077 CallInst(Func, ArgBegin, ArgEnd, Name, InsertBefore);
1079 template<typename InputIterator>
1080 static CallInst *Create(Value *Func,
1081 InputIterator ArgBegin, InputIterator ArgEnd,
1082 const std::string &Name, BasicBlock *InsertAtEnd) {
1083 return new((unsigned)(ArgEnd - ArgBegin + 1))
1084 CallInst(Func, ArgBegin, ArgEnd, Name, InsertAtEnd);
1086 static CallInst *Create(Value *F, Value *Actual, const std::string& Name = "",
1087 Instruction *InsertBefore = 0) {
1088 return new(2) CallInst(F, Actual, Name, InsertBefore);
1090 static CallInst *Create(Value *F, Value *Actual, const std::string& Name,
1091 BasicBlock *InsertAtEnd) {
1092 return new(2) CallInst(F, Actual, Name, InsertAtEnd);
1094 static CallInst *Create(Value *F, const std::string &Name = "",
1095 Instruction *InsertBefore = 0) {
1096 return new(1) CallInst(F, Name, InsertBefore);
1098 static CallInst *Create(Value *F, const std::string &Name,
1099 BasicBlock *InsertAtEnd) {
1100 return new(1) CallInst(F, Name, InsertAtEnd);
1105 virtual CallInst *clone() const;
1107 /// Provide fast operand accessors
1108 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1110 bool isTailCall() const { return SubclassData & 1; }
1111 void setTailCall(bool isTailCall = true) {
1112 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
1115 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1117 unsigned getCallingConv() const { return SubclassData >> 1; }
1118 void setCallingConv(unsigned CC) {
1119 SubclassData = (SubclassData & 1) | (CC << 1);
1122 /// getParamAttrs - Return the parameter attributes for this call.
1124 const PAListPtr &getParamAttrs() const { return ParamAttrs; }
1126 /// setParamAttrs - Sets the parameter attributes for this call.
1127 void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
1129 /// addParamAttr - adds the attribute to the list of attributes.
1130 void addParamAttr(unsigned i, ParameterAttributes attr);
1132 /// @brief Determine whether the call or the callee has the given attribute.
1133 bool paramHasAttr(unsigned i, unsigned attr) const;
1135 /// @brief Extract the alignment for a call or parameter (0=unknown).
1136 unsigned getParamAlignment(unsigned i) const {
1137 return ParamAttrs.getParamAlignment(i);
1140 /// @brief Determine if the call does not access memory.
1141 bool doesNotAccessMemory() const {
1142 return paramHasAttr(0, ParamAttr::ReadNone);
1145 /// @brief Determine if the call does not access or only reads memory.
1146 bool onlyReadsMemory() const {
1147 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
1150 /// @brief Determine if the call cannot return.
1151 bool doesNotReturn() const {
1152 return paramHasAttr(0, ParamAttr::NoReturn);
1155 /// @brief Determine if the call cannot unwind.
1156 bool doesNotThrow() const {
1157 return paramHasAttr(0, ParamAttr::NoUnwind);
1159 void setDoesNotThrow(bool doesNotThrow = true);
1161 /// @brief Determine if the call returns a structure through first
1162 /// pointer argument.
1163 bool hasStructRetAttr() const {
1164 // Be friendly and also check the callee.
1165 return paramHasAttr(1, ParamAttr::StructRet);
1168 /// @brief Determine if any call argument is an aggregate passed by value.
1169 bool hasByValArgument() const {
1170 return ParamAttrs.hasAttrSomewhere(ParamAttr::ByVal);
1173 /// getCalledFunction - Return the function being called by this instruction
1174 /// if it is a direct call. If it is a call through a function pointer,
1176 Function *getCalledFunction() const {
1177 return dyn_cast<Function>(getOperand(0));
1180 /// getCalledValue - Get a pointer to the function that is invoked by this
1182 const Value *getCalledValue() const { return getOperand(0); }
1183 Value *getCalledValue() { return getOperand(0); }
1185 // Methods for support type inquiry through isa, cast, and dyn_cast:
1186 static inline bool classof(const CallInst *) { return true; }
1187 static inline bool classof(const Instruction *I) {
1188 return I->getOpcode() == Instruction::Call;
1190 static inline bool classof(const Value *V) {
1191 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1196 struct OperandTraits<CallInst> : VariadicOperandTraits<1> {
1199 template<typename InputIterator>
1200 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1201 const std::string &Name, BasicBlock *InsertAtEnd)
1202 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1203 ->getElementType())->getReturnType(),
1205 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1206 (unsigned)(ArgEnd - ArgBegin + 1), InsertAtEnd) {
1207 init(Func, ArgBegin, ArgEnd, Name,
1208 typename std::iterator_traits<InputIterator>::iterator_category());
1211 template<typename InputIterator>
1212 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1213 const std::string &Name, Instruction *InsertBefore)
1214 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1215 ->getElementType())->getReturnType(),
1217 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
1218 (unsigned)(ArgEnd - ArgBegin + 1), InsertBefore) {
1219 init(Func, ArgBegin, ArgEnd, Name,
1220 typename std::iterator_traits<InputIterator>::iterator_category());
1223 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1225 //===----------------------------------------------------------------------===//
1227 //===----------------------------------------------------------------------===//
1229 /// SelectInst - This class represents the LLVM 'select' instruction.
1231 class SelectInst : public Instruction {
1232 void init(Value *C, Value *S1, Value *S2) {
1238 SelectInst(const SelectInst &SI)
1239 : Instruction(SI.getType(), SI.getOpcode(), &Op<0>(), 3) {
1240 init(SI.Op<0>(), SI.Op<1>(), SI.Op<2>());
1242 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
1243 Instruction *InsertBefore)
1244 : Instruction(S1->getType(), Instruction::Select,
1245 &Op<0>(), 3, InsertBefore) {
1249 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
1250 BasicBlock *InsertAtEnd)
1251 : Instruction(S1->getType(), Instruction::Select,
1252 &Op<0>(), 3, InsertAtEnd) {
1257 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1258 const std::string &Name = "",
1259 Instruction *InsertBefore = 0) {
1260 return new(3) SelectInst(C, S1, S2, Name, InsertBefore);
1262 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1263 const std::string &Name, BasicBlock *InsertAtEnd) {
1264 return new(3) SelectInst(C, S1, S2, Name, InsertAtEnd);
1267 Value *getCondition() const { return Op<0>(); }
1268 Value *getTrueValue() const { return Op<1>(); }
1269 Value *getFalseValue() const { return Op<2>(); }
1271 /// Transparently provide more efficient getOperand methods.
1272 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1274 OtherOps getOpcode() const {
1275 return static_cast<OtherOps>(Instruction::getOpcode());
1278 virtual SelectInst *clone() const;
1280 // Methods for support type inquiry through isa, cast, and dyn_cast:
1281 static inline bool classof(const SelectInst *) { return true; }
1282 static inline bool classof(const Instruction *I) {
1283 return I->getOpcode() == Instruction::Select;
1285 static inline bool classof(const Value *V) {
1286 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1291 struct OperandTraits<SelectInst> : FixedNumOperandTraits<3> {
1294 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1296 //===----------------------------------------------------------------------===//
1298 //===----------------------------------------------------------------------===//
1300 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1301 /// an argument of the specified type given a va_list and increments that list
1303 class VAArgInst : public UnaryInstruction {
1304 VAArgInst(const VAArgInst &VAA)
1305 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
1307 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
1308 Instruction *InsertBefore = 0)
1309 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1312 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
1313 BasicBlock *InsertAtEnd)
1314 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1318 virtual VAArgInst *clone() const;
1320 // Methods for support type inquiry through isa, cast, and dyn_cast:
1321 static inline bool classof(const VAArgInst *) { return true; }
1322 static inline bool classof(const Instruction *I) {
1323 return I->getOpcode() == VAArg;
1325 static inline bool classof(const Value *V) {
1326 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1330 //===----------------------------------------------------------------------===//
1331 // ExtractElementInst Class
1332 //===----------------------------------------------------------------------===//
1334 /// ExtractElementInst - This instruction extracts a single (scalar)
1335 /// element from a VectorType value
1337 class ExtractElementInst : public Instruction {
1338 ExtractElementInst(const ExtractElementInst &EE) :
1339 Instruction(EE.getType(), ExtractElement, &Op<0>(), 2) {
1340 Op<0>() = EE.Op<0>();
1341 Op<1>() = EE.Op<1>();
1345 // allocate space for exactly two operands
1346 void *operator new(size_t s) {
1347 return User::operator new(s, 2); // FIXME: "unsigned Idx" forms of ctor?
1349 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
1350 Instruction *InsertBefore = 0);
1351 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
1352 Instruction *InsertBefore = 0);
1353 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
1354 BasicBlock *InsertAtEnd);
1355 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
1356 BasicBlock *InsertAtEnd);
1358 /// isValidOperands - Return true if an extractelement instruction can be
1359 /// formed with the specified operands.
1360 static bool isValidOperands(const Value *Vec, const Value *Idx);
1362 virtual ExtractElementInst *clone() const;
1364 /// Transparently provide more efficient getOperand methods.
1365 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1367 // Methods for support type inquiry through isa, cast, and dyn_cast:
1368 static inline bool classof(const ExtractElementInst *) { return true; }
1369 static inline bool classof(const Instruction *I) {
1370 return I->getOpcode() == Instruction::ExtractElement;
1372 static inline bool classof(const Value *V) {
1373 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1378 struct OperandTraits<ExtractElementInst> : FixedNumOperandTraits<2> {
1381 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1383 //===----------------------------------------------------------------------===//
1384 // InsertElementInst Class
1385 //===----------------------------------------------------------------------===//
1387 /// InsertElementInst - This instruction inserts a single (scalar)
1388 /// element into a VectorType value
1390 class InsertElementInst : public Instruction {
1391 InsertElementInst(const InsertElementInst &IE);
1392 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1393 const std::string &Name = "",Instruction *InsertBefore = 0);
1394 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1395 const std::string &Name = "",Instruction *InsertBefore = 0);
1396 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1397 const std::string &Name, BasicBlock *InsertAtEnd);
1398 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1399 const std::string &Name, BasicBlock *InsertAtEnd);
1401 static InsertElementInst *Create(const InsertElementInst &IE) {
1402 return new(IE.getNumOperands()) InsertElementInst(IE);
1404 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1405 const std::string &Name = "",
1406 Instruction *InsertBefore = 0) {
1407 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
1409 static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
1410 const std::string &Name = "",
1411 Instruction *InsertBefore = 0) {
1412 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
1414 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1415 const std::string &Name,
1416 BasicBlock *InsertAtEnd) {
1417 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
1419 static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
1420 const std::string &Name,
1421 BasicBlock *InsertAtEnd) {
1422 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
1425 /// isValidOperands - Return true if an insertelement instruction can be
1426 /// formed with the specified operands.
1427 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1430 virtual InsertElementInst *clone() const;
1432 /// getType - Overload to return most specific vector type.
1434 const VectorType *getType() const {
1435 return reinterpret_cast<const VectorType*>(Instruction::getType());
1438 /// Transparently provide more efficient getOperand methods.
1439 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1441 // Methods for support type inquiry through isa, cast, and dyn_cast:
1442 static inline bool classof(const InsertElementInst *) { return true; }
1443 static inline bool classof(const Instruction *I) {
1444 return I->getOpcode() == Instruction::InsertElement;
1446 static inline bool classof(const Value *V) {
1447 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1452 struct OperandTraits<InsertElementInst> : FixedNumOperandTraits<3> {
1455 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1457 //===----------------------------------------------------------------------===//
1458 // ShuffleVectorInst Class
1459 //===----------------------------------------------------------------------===//
1461 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1464 class ShuffleVectorInst : public Instruction {
1465 ShuffleVectorInst(const ShuffleVectorInst &IE);
1467 // allocate space for exactly three operands
1468 void *operator new(size_t s) {
1469 return User::operator new(s, 3);
1471 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1472 const std::string &Name = "", Instruction *InsertBefor = 0);
1473 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1474 const std::string &Name, BasicBlock *InsertAtEnd);
1476 /// isValidOperands - Return true if a shufflevector instruction can be
1477 /// formed with the specified operands.
1478 static bool isValidOperands(const Value *V1, const Value *V2,
1481 virtual ShuffleVectorInst *clone() const;
1483 /// getType - Overload to return most specific vector type.
1485 const VectorType *getType() const {
1486 return reinterpret_cast<const VectorType*>(Instruction::getType());
1489 /// Transparently provide more efficient getOperand methods.
1490 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1492 /// getMaskValue - Return the index from the shuffle mask for the specified
1493 /// output result. This is either -1 if the element is undef or a number less
1494 /// than 2*numelements.
1495 int getMaskValue(unsigned i) const;
1497 // Methods for support type inquiry through isa, cast, and dyn_cast:
1498 static inline bool classof(const ShuffleVectorInst *) { return true; }
1499 static inline bool classof(const Instruction *I) {
1500 return I->getOpcode() == Instruction::ShuffleVector;
1502 static inline bool classof(const Value *V) {
1503 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1508 struct OperandTraits<ShuffleVectorInst> : FixedNumOperandTraits<3> {
1511 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1513 //===----------------------------------------------------------------------===//
1514 // ExtractValueInst Class
1515 //===----------------------------------------------------------------------===//
1517 /// ExtractValueInst - This instruction extracts a struct member or array
1518 /// element value from an aggregate value.
1520 class ExtractValueInst : public Instruction {
1521 ExtractValueInst(const ExtractValueInst &EVI);
1522 void init(Value *Agg, Value* const *Idx, unsigned NumIdx);
1523 void init(Value *Agg, Value *Idx);
1525 template<typename InputIterator>
1526 void init(Value *Agg, InputIterator IdxBegin, InputIterator IdxEnd,
1527 const std::string &Name,
1528 // This argument ensures that we have an iterator we can
1529 // do arithmetic on in constant time
1530 std::random_access_iterator_tag) {
1531 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1534 // This requires that the iterator points to contiguous memory.
1535 init(Agg, &*IdxBegin, NumIdx); // FIXME: for the general case
1536 // we have to build an array here
1539 init(Agg, 0, NumIdx);
1545 /// getIndexedType - Returns the type of the element that would be extracted
1546 /// with an extractvalue instruction with the specified parameters.
1548 /// Null is returned if the indices are invalid for the specified
1551 static const Type *getIndexedType(const Type *Agg,
1552 Value* const *Idx, unsigned NumIdx);
1554 template<typename InputIterator>
1555 static const Type *getIndexedType(const Type *Ptr,
1556 InputIterator IdxBegin,
1557 InputIterator IdxEnd,
1558 // This argument ensures that we
1559 // have an iterator we can do
1560 // arithmetic on in constant time
1561 std::random_access_iterator_tag) {
1562 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1565 // This requires that the iterator points to contiguous memory.
1566 return getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx);
1568 return getIndexedType(Ptr, (Value *const*)0, NumIdx);
1571 /// Constructors - Create a extractvalue instruction with a base aggregate
1572 /// value and a list of indices. The first ctor can optionally insert before
1573 /// an existing instruction, the second appends the new instruction to the
1574 /// specified BasicBlock.
1575 template<typename InputIterator>
1576 inline ExtractValueInst(Value *Agg, InputIterator IdxBegin,
1577 InputIterator IdxEnd,
1579 const std::string &Name,
1580 Instruction *InsertBefore);
1581 template<typename InputIterator>
1582 inline ExtractValueInst(Value *Agg,
1583 InputIterator IdxBegin, InputIterator IdxEnd,
1585 const std::string &Name, BasicBlock *InsertAtEnd);
1587 /// Constructors - These two constructors are convenience methods because one
1588 /// and two index extractvalue instructions are so common.
1589 ExtractValueInst(Value *Agg, Value *Idx, const std::string &Name = "",
1590 Instruction *InsertBefore = 0);
1591 ExtractValueInst(Value *Agg, Value *Idx,
1592 const std::string &Name, BasicBlock *InsertAtEnd);
1594 template<typename InputIterator>
1595 static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin,
1596 InputIterator IdxEnd,
1597 const std::string &Name = "",
1598 Instruction *InsertBefore = 0) {
1599 typename std::iterator_traits<InputIterator>::difference_type Values =
1600 1 + std::distance(IdxBegin, IdxEnd);
1602 ExtractValueInst(Agg, IdxBegin, IdxEnd, Values, Name, InsertBefore);
1604 template<typename InputIterator>
1605 static ExtractValueInst *Create(Value *Agg,
1606 InputIterator IdxBegin, InputIterator IdxEnd,
1607 const std::string &Name,
1608 BasicBlock *InsertAtEnd) {
1609 typename std::iterator_traits<InputIterator>::difference_type Values =
1610 1 + std::distance(IdxBegin, IdxEnd);
1612 ExtractValueInst(Agg, IdxBegin, IdxEnd, Values, Name, InsertAtEnd);
1615 /// Constructors - These two creators are convenience methods because one
1616 /// index extractvalue instructions are much more common than those with
1618 static ExtractValueInst *Create(Value *Agg, Value *Idx,
1619 const std::string &Name = "",
1620 Instruction *InsertBefore = 0) {
1621 return new(2) ExtractValueInst(Agg, Idx, Name, InsertBefore);
1623 static ExtractValueInst *Create(Value *Agg, Value *Idx,
1624 const std::string &Name,
1625 BasicBlock *InsertAtEnd) {
1626 return new(2) ExtractValueInst(Agg, Idx, Name, InsertAtEnd);
1629 virtual ExtractValueInst *clone() const;
1631 /// Transparently provide more efficient getOperand methods.
1632 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1634 // getType - Overload to return most specific pointer type...
1635 const PointerType *getType() const {
1636 return reinterpret_cast<const PointerType*>(Instruction::getType());
1639 /// getIndexedType - Returns the type of the element that would be extracted
1640 /// with an extractvalue instruction with the specified parameters.
1642 /// Null is returned if the indices are invalid for the specified
1645 template<typename InputIterator>
1646 static const Type *getIndexedType(const Type *Ptr,
1647 InputIterator IdxBegin,
1648 InputIterator IdxEnd) {
1649 return getIndexedType(Ptr, IdxBegin, IdxEnd,
1650 typename std::iterator_traits<InputIterator>::
1651 iterator_category());
1653 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
1655 inline op_iterator idx_begin() { return op_begin()+1; }
1656 inline const_op_iterator idx_begin() const { return op_begin()+1; }
1657 inline op_iterator idx_end() { return op_end(); }
1658 inline const_op_iterator idx_end() const { return op_end(); }
1660 Value *getAggregateOperand() {
1661 return getOperand(0);
1663 const Value *getAggregateOperand() const {
1664 return getOperand(0);
1666 static unsigned getAggregateOperandIndex() {
1667 return 0U; // get index for modifying correct operand
1670 unsigned getNumIndices() const { // Note: always non-negative
1671 return getNumOperands() - 1;
1674 bool hasIndices() const {
1675 return getNumOperands() > 1;
1678 // Methods for support type inquiry through isa, cast, and dyn_cast:
1679 static inline bool classof(const ExtractValueInst *) { return true; }
1680 static inline bool classof(const Instruction *I) {
1681 return I->getOpcode() == Instruction::ExtractValue;
1683 static inline bool classof(const Value *V) {
1684 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1689 struct OperandTraits<ExtractValueInst> : VariadicOperandTraits<1> {
1692 template<typename InputIterator>
1693 ExtractValueInst::ExtractValueInst(Value *Agg,
1694 InputIterator IdxBegin,
1695 InputIterator IdxEnd,
1697 const std::string &Name,
1698 Instruction *InsertBefore)
1699 : Instruction(checkType(getIndexedType(Agg->getType(), IdxBegin, IdxEnd)),
1701 OperandTraits<ExtractValueInst>::op_end(this) - Values,
1702 Values, InsertBefore) {
1703 init(Agg, IdxBegin, IdxEnd, Name,
1704 typename std::iterator_traits<InputIterator>::iterator_category());
1706 template<typename InputIterator>
1707 ExtractValueInst::ExtractValueInst(Value *Agg,
1708 InputIterator IdxBegin,
1709 InputIterator IdxEnd,
1711 const std::string &Name,
1712 BasicBlock *InsertAtEnd)
1713 : Instruction(PointerType::get(checkType(
1714 getIndexedType(Agg->getType(),
1716 cast<PointerType>(Agg->getType())
1717 ->getAddressSpace()),
1719 OperandTraits<ExtractValueInst>::op_end(this) - Values,
1720 Values, InsertAtEnd) {
1721 init(Agg, IdxBegin, IdxEnd, Name,
1722 typename std::iterator_traits<InputIterator>::iterator_category());
1725 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractValueInst, Value)
1728 //===----------------------------------------------------------------------===//
1729 // InsertValueInst Class
1730 //===----------------------------------------------------------------------===//
1732 /// InsertValueInst - This instruction inserts a struct field of array element
1733 /// value into an aggregate value.
1735 class InsertValueInst : public Instruction {
1736 InsertValueInst(const InsertValueInst &IVI);
1737 void init(Value *Agg, Value *Val, Value* const *Idx, unsigned NumIdx);
1738 void init(Value *Agg, Value *Val, Value *Idx);
1740 template<typename InputIterator>
1741 void init(Value *Agg, Value *Val,
1742 InputIterator IdxBegin, InputIterator IdxEnd,
1743 const std::string &Name,
1744 // This argument ensures that we have an iterator we can
1745 // do arithmetic on in constant time
1746 std::random_access_iterator_tag) {
1747 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1750 // This requires that the iterator points to contiguous memory.
1751 init(Agg, Val, &*IdxBegin, NumIdx); // FIXME: for the general case
1752 // we have to build an array here
1755 init(Agg, Val, 0, NumIdx);
1761 /// Constructors - Create a insertvalue instruction with a base aggregate
1762 /// value, a value to insert, and a list of indices. The first ctor can
1763 /// optionally insert before an existing instruction, the second appends
1764 /// the new instruction to the specified BasicBlock.
1765 template<typename InputIterator>
1766 inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin,
1767 InputIterator IdxEnd,
1769 const std::string &Name,
1770 Instruction *InsertBefore);
1771 template<typename InputIterator>
1772 inline InsertValueInst(Value *Agg, Value *Val,
1773 InputIterator IdxBegin, InputIterator IdxEnd,
1775 const std::string &Name, BasicBlock *InsertAtEnd);
1777 /// Constructors - These two constructors are convenience methods because one
1778 /// and two index insertvalue instructions are so common.
1779 InsertValueInst(Value *Agg, Value *Val,
1780 Value *Idx, const std::string &Name = "",
1781 Instruction *InsertBefore = 0);
1782 InsertValueInst(Value *Agg, Value *Val, Value *Idx,
1783 const std::string &Name, BasicBlock *InsertAtEnd);
1785 template<typename InputIterator>
1786 static InsertValueInst *Create(Value *Agg, Value *Val, InputIterator IdxBegin,
1787 InputIterator IdxEnd,
1788 const std::string &Name = "",
1789 Instruction *InsertBefore = 0) {
1790 typename std::iterator_traits<InputIterator>::difference_type Values =
1791 1 + std::distance(IdxBegin, IdxEnd);
1793 InsertValueInst(Agg, Val, IdxBegin, IdxEnd, Values, Name, InsertBefore);
1795 template<typename InputIterator>
1796 static InsertValueInst *Create(Value *Agg, Value *Val,
1797 InputIterator IdxBegin, InputIterator IdxEnd,
1798 const std::string &Name,
1799 BasicBlock *InsertAtEnd) {
1800 typename std::iterator_traits<InputIterator>::difference_type Values =
1801 1 + std::distance(IdxBegin, IdxEnd);
1803 InsertValueInst(Agg, Val, IdxBegin, IdxEnd, Values, Name, InsertAtEnd);
1806 /// Constructors - These two creators are convenience methods because one
1807 /// index insertvalue instructions are much more common than those with
1809 static InsertValueInst *Create(Value *Agg, Value *Val, Value *Idx,
1810 const std::string &Name = "",
1811 Instruction *InsertBefore = 0) {
1812 return new(3) InsertValueInst(Agg, Val, Idx, Name, InsertBefore);
1814 static InsertValueInst *Create(Value *Agg, Value *Val, Value *Idx,
1815 const std::string &Name,
1816 BasicBlock *InsertAtEnd) {
1817 return new(3) InsertValueInst(Agg, Val, Idx, Name, InsertAtEnd);
1820 virtual InsertValueInst *clone() const;
1822 /// Transparently provide more efficient getOperand methods.
1823 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1825 // getType - Overload to return most specific pointer type...
1826 const PointerType *getType() const {
1827 return reinterpret_cast<const PointerType*>(Instruction::getType());
1830 inline op_iterator idx_begin() { return op_begin()+1; }
1831 inline const_op_iterator idx_begin() const { return op_begin()+1; }
1832 inline op_iterator idx_end() { return op_end(); }
1833 inline const_op_iterator idx_end() const { return op_end(); }
1835 Value *getAggregateOperand() {
1836 return getOperand(0);
1838 const Value *getAggregateOperand() const {
1839 return getOperand(0);
1841 static unsigned getAggregateOperandIndex() {
1842 return 0U; // get index for modifying correct operand
1845 Value *getInsertedValueOperand() {
1846 return getOperand(1);
1848 const Value *getInsertedValueOperand() const {
1849 return getOperand(1);
1851 static unsigned getInsertedValueOperandIndex() {
1852 return 1U; // get index for modifying correct operand
1855 unsigned getNumIndices() const { // Note: always non-negative
1856 return getNumOperands() - 2;
1859 bool hasIndices() const {
1860 return getNumOperands() > 2;
1863 // Methods for support type inquiry through isa, cast, and dyn_cast:
1864 static inline bool classof(const InsertValueInst *) { return true; }
1865 static inline bool classof(const Instruction *I) {
1866 return I->getOpcode() == Instruction::InsertValue;
1868 static inline bool classof(const Value *V) {
1869 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1874 struct OperandTraits<InsertValueInst> : VariadicOperandTraits<2> {
1877 template<typename InputIterator>
1878 InsertValueInst::InsertValueInst(Value *Agg,
1880 InputIterator IdxBegin,
1881 InputIterator IdxEnd,
1883 const std::string &Name,
1884 Instruction *InsertBefore)
1885 : Instruction(checkType(ExtractValueInst::getIndexedType(
1889 OperandTraits<InsertValueInst>::op_end(this) - Values,
1890 Values, InsertBefore) {
1891 init(Agg, Val, IdxBegin, IdxEnd, Name,
1892 typename std::iterator_traits<InputIterator>::iterator_category());
1894 template<typename InputIterator>
1895 InsertValueInst::InsertValueInst(Value *Agg,
1897 InputIterator IdxBegin,
1898 InputIterator IdxEnd,
1900 const std::string &Name,
1901 BasicBlock *InsertAtEnd)
1902 : Instruction(PointerType::get(checkType(
1903 ExtractValueInst::getIndexedType(
1906 cast<PointerType>(Val->getType())
1907 ->getAddressSpace()),
1909 OperandTraits<InsertValueInst>::op_end(this) - Values,
1910 Values, InsertAtEnd) {
1911 init(Agg, Val, IdxBegin, IdxEnd, Name,
1912 typename std::iterator_traits<InputIterator>::iterator_category());
1915 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1917 //===----------------------------------------------------------------------===//
1919 //===----------------------------------------------------------------------===//
1921 // PHINode - The PHINode class is used to represent the magical mystical PHI
1922 // node, that can not exist in nature, but can be synthesized in a computer
1923 // scientist's overactive imagination.
1925 class PHINode : public Instruction {
1926 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1927 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1928 /// the number actually in use.
1929 unsigned ReservedSpace;
1930 PHINode(const PHINode &PN);
1931 // allocate space for exactly zero operands
1932 void *operator new(size_t s) {
1933 return User::operator new(s, 0);
1935 explicit PHINode(const Type *Ty, const std::string &Name = "",
1936 Instruction *InsertBefore = 0)
1937 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1942 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1943 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1948 static PHINode *Create(const Type *Ty, const std::string &Name = "",
1949 Instruction *InsertBefore = 0) {
1950 return new PHINode(Ty, Name, InsertBefore);
1952 static PHINode *Create(const Type *Ty, const std::string &Name,
1953 BasicBlock *InsertAtEnd) {
1954 return new PHINode(Ty, Name, InsertAtEnd);
1958 /// reserveOperandSpace - This method can be used to avoid repeated
1959 /// reallocation of PHI operand lists by reserving space for the correct
1960 /// number of operands before adding them. Unlike normal vector reserves,
1961 /// this method can also be used to trim the operand space.
1962 void reserveOperandSpace(unsigned NumValues) {
1963 resizeOperands(NumValues*2);
1966 virtual PHINode *clone() const;
1968 /// Provide fast operand accessors
1969 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1971 /// getNumIncomingValues - Return the number of incoming edges
1973 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1975 /// getIncomingValue - Return incoming value number x
1977 Value *getIncomingValue(unsigned i) const {
1978 assert(i*2 < getNumOperands() && "Invalid value number!");
1979 return getOperand(i*2);
1981 void setIncomingValue(unsigned i, Value *V) {
1982 assert(i*2 < getNumOperands() && "Invalid value number!");
1985 unsigned getOperandNumForIncomingValue(unsigned i) {
1989 /// getIncomingBlock - Return incoming basic block number x
1991 BasicBlock *getIncomingBlock(unsigned i) const {
1992 return static_cast<BasicBlock*>(getOperand(i*2+1));
1994 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1995 setOperand(i*2+1, BB);
1997 unsigned getOperandNumForIncomingBlock(unsigned i) {
2001 /// addIncoming - Add an incoming value to the end of the PHI list
2003 void addIncoming(Value *V, BasicBlock *BB) {
2004 assert(V && "PHI node got a null value!");
2005 assert(BB && "PHI node got a null basic block!");
2006 assert(getType() == V->getType() &&
2007 "All operands to PHI node must be the same type as the PHI node!");
2008 unsigned OpNo = NumOperands;
2009 if (OpNo+2 > ReservedSpace)
2010 resizeOperands(0); // Get more space!
2011 // Initialize some new operands.
2012 NumOperands = OpNo+2;
2013 OperandList[OpNo] = V;
2014 OperandList[OpNo+1] = BB;
2017 /// removeIncomingValue - Remove an incoming value. This is useful if a
2018 /// predecessor basic block is deleted. The value removed is returned.
2020 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2021 /// is true), the PHI node is destroyed and any uses of it are replaced with
2022 /// dummy values. The only time there should be zero incoming values to a PHI
2023 /// node is when the block is dead, so this strategy is sound.
2025 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2027 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2028 int Idx = getBasicBlockIndex(BB);
2029 assert(Idx >= 0 && "Invalid basic block argument to remove!");
2030 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2033 /// getBasicBlockIndex - Return the first index of the specified basic
2034 /// block in the value list for this PHI. Returns -1 if no instance.
2036 int getBasicBlockIndex(const BasicBlock *BB) const {
2037 Use *OL = OperandList;
2038 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
2039 if (OL[i+1].get() == BB) return i/2;
2043 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2044 return getIncomingValue(getBasicBlockIndex(BB));
2047 /// hasConstantValue - If the specified PHI node always merges together the
2048 /// same value, return the value, otherwise return null.
2050 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
2052 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2053 static inline bool classof(const PHINode *) { return true; }
2054 static inline bool classof(const Instruction *I) {
2055 return I->getOpcode() == Instruction::PHI;
2057 static inline bool classof(const Value *V) {
2058 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2061 void resizeOperands(unsigned NumOperands);
2065 struct OperandTraits<PHINode> : HungoffOperandTraits<2> {
2068 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
2071 //===----------------------------------------------------------------------===//
2073 //===----------------------------------------------------------------------===//
2075 //===---------------------------------------------------------------------------
2076 /// ReturnInst - Return a value (possibly void), from a function. Execution
2077 /// does not continue in this function any longer.
2079 class ReturnInst : public TerminatorInst {
2080 ReturnInst(const ReturnInst &RI);
2081 void init(Value * const* retVals, unsigned N);
2084 // ReturnInst constructors:
2085 // ReturnInst() - 'ret void' instruction
2086 // ReturnInst( null) - 'ret void' instruction
2087 // ReturnInst(Value* X) - 'ret X' instruction
2088 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
2089 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
2090 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2091 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
2092 // ReturnInst(Value* X, N) - 'ret X,X+1...X+N-1' instruction
2093 // ReturnInst(Value* X, N, Inst *I) - 'ret X,X+1...X+N-1', insert before I
2094 // ReturnInst(Value* X, N, BB *B) - 'ret X,X+1...X+N-1', insert @ end of B
2096 // NOTE: If the Value* passed is of type void then the constructor behaves as
2097 // if it was passed NULL.
2098 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
2099 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
2100 ReturnInst(Value * const* retVals, unsigned N, Instruction *InsertBefore = 0);
2101 ReturnInst(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd);
2102 explicit ReturnInst(BasicBlock *InsertAtEnd);
2104 static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) {
2105 return new(!!retVal) ReturnInst(retVal, InsertBefore);
2107 static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) {
2108 return new(!!retVal) ReturnInst(retVal, InsertAtEnd);
2110 static ReturnInst* Create(Value * const* retVals, unsigned N,
2111 Instruction *InsertBefore = 0) {
2112 return new(N) ReturnInst(retVals, N, InsertBefore);
2114 static ReturnInst* Create(Value * const* retVals, unsigned N,
2115 BasicBlock *InsertAtEnd) {
2116 return new(N) ReturnInst(retVals, N, InsertAtEnd);
2118 static ReturnInst* Create(BasicBlock *InsertAtEnd) {
2119 return new(0) ReturnInst(InsertAtEnd);
2121 virtual ~ReturnInst();
2122 inline void operator delete(void*);
2124 virtual ReturnInst *clone() const;
2126 /// Provide fast operand accessors
2127 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2129 /// Convenience accessor
2130 Value *getReturnValue(unsigned n = 0) const {
2131 return n < getNumOperands()
2136 unsigned getNumSuccessors() const { return 0; }
2138 // Methods for support type inquiry through isa, cast, and dyn_cast:
2139 static inline bool classof(const ReturnInst *) { return true; }
2140 static inline bool classof(const Instruction *I) {
2141 return (I->getOpcode() == Instruction::Ret);
2143 static inline bool classof(const Value *V) {
2144 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2147 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2148 virtual unsigned getNumSuccessorsV() const;
2149 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2153 struct OperandTraits<ReturnInst> : VariadicOperandTraits<> {
2156 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2157 void ReturnInst::operator delete(void *it) {
2158 ReturnInst* me(static_cast<ReturnInst*>(it));
2159 Use::zap(OperandTraits<ReturnInst>::op_begin(me),
2160 OperandTraits<ReturnInst>::op_end(me),
2164 //===----------------------------------------------------------------------===//
2166 //===----------------------------------------------------------------------===//
2168 //===---------------------------------------------------------------------------
2169 /// BranchInst - Conditional or Unconditional Branch instruction.
2171 class BranchInst : public TerminatorInst {
2172 /// Ops list - Branches are strange. The operands are ordered:
2173 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
2174 /// they don't have to check for cond/uncond branchness.
2175 BranchInst(const BranchInst &BI);
2177 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2178 // BranchInst(BB *B) - 'br B'
2179 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2180 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2181 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2182 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2183 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2184 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2185 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2186 Instruction *InsertBefore = 0);
2187 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2188 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2189 BasicBlock *InsertAtEnd);
2191 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2192 return new(1) BranchInst(IfTrue, InsertBefore);
2194 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2195 Value *Cond, Instruction *InsertBefore = 0) {
2196 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2198 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2199 return new(1) BranchInst(IfTrue, InsertAtEnd);
2201 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2202 Value *Cond, BasicBlock *InsertAtEnd) {
2203 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2207 if (NumOperands == 1)
2208 NumOperands = (unsigned)((Use*)this - OperandList);
2211 /// Transparently provide more efficient getOperand methods.
2212 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2214 virtual BranchInst *clone() const;
2216 bool isUnconditional() const { return getNumOperands() == 1; }
2217 bool isConditional() const { return getNumOperands() == 3; }
2219 Value *getCondition() const {
2220 assert(isConditional() && "Cannot get condition of an uncond branch!");
2221 return getOperand(2);
2224 void setCondition(Value *V) {
2225 assert(isConditional() && "Cannot set condition of unconditional branch!");
2229 // setUnconditionalDest - Change the current branch to an unconditional branch
2230 // targeting the specified block.
2231 // FIXME: Eliminate this ugly method.
2232 void setUnconditionalDest(BasicBlock *Dest) {
2234 if (isConditional()) { // Convert this to an uncond branch.
2241 unsigned getNumSuccessors() const { return 1+isConditional(); }
2243 BasicBlock *getSuccessor(unsigned i) const {
2244 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2245 return cast<BasicBlock>(getOperand(i));
2248 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2249 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2250 setOperand(idx, NewSucc);
2253 // Methods for support type inquiry through isa, cast, and dyn_cast:
2254 static inline bool classof(const BranchInst *) { return true; }
2255 static inline bool classof(const Instruction *I) {
2256 return (I->getOpcode() == Instruction::Br);
2258 static inline bool classof(const Value *V) {
2259 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2262 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2263 virtual unsigned getNumSuccessorsV() const;
2264 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2268 struct OperandTraits<BranchInst> : HungoffOperandTraits<> {
2269 // we need to access operands via OperandList, since
2270 // the NumOperands may change from 3 to 1
2271 static inline void *allocate(unsigned); // FIXME
2274 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2276 //===----------------------------------------------------------------------===//
2278 //===----------------------------------------------------------------------===//
2280 //===---------------------------------------------------------------------------
2281 /// SwitchInst - Multiway switch
2283 class SwitchInst : public TerminatorInst {
2284 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2285 unsigned ReservedSpace;
2286 // Operand[0] = Value to switch on
2287 // Operand[1] = Default basic block destination
2288 // Operand[2n ] = Value to match
2289 // Operand[2n+1] = BasicBlock to go to on match
2290 SwitchInst(const SwitchInst &RI);
2291 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
2292 void resizeOperands(unsigned No);
2293 // allocate space for exactly zero operands
2294 void *operator new(size_t s) {
2295 return User::operator new(s, 0);
2297 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2298 /// switch on and a default destination. The number of additional cases can
2299 /// be specified here to make memory allocation more efficient. This
2300 /// constructor can also autoinsert before another instruction.
2301 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2302 Instruction *InsertBefore = 0);
2304 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2305 /// switch on and a default destination. The number of additional cases can
2306 /// be specified here to make memory allocation more efficient. This
2307 /// constructor also autoinserts at the end of the specified BasicBlock.
2308 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2309 BasicBlock *InsertAtEnd);
2311 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2312 unsigned NumCases, Instruction *InsertBefore = 0) {
2313 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2315 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2316 unsigned NumCases, BasicBlock *InsertAtEnd) {
2317 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2321 /// Provide fast operand accessors
2322 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2324 // Accessor Methods for Switch stmt
2325 Value *getCondition() const { return getOperand(0); }
2326 void setCondition(Value *V) { setOperand(0, V); }
2328 BasicBlock *getDefaultDest() const {
2329 return cast<BasicBlock>(getOperand(1));
2332 /// getNumCases - return the number of 'cases' in this switch instruction.
2333 /// Note that case #0 is always the default case.
2334 unsigned getNumCases() const {
2335 return getNumOperands()/2;
2338 /// getCaseValue - Return the specified case value. Note that case #0, the
2339 /// default destination, does not have a case value.
2340 ConstantInt *getCaseValue(unsigned i) {
2341 assert(i && i < getNumCases() && "Illegal case value to get!");
2342 return getSuccessorValue(i);
2345 /// getCaseValue - Return the specified case value. Note that case #0, the
2346 /// default destination, does not have a case value.
2347 const ConstantInt *getCaseValue(unsigned i) const {
2348 assert(i && i < getNumCases() && "Illegal case value to get!");
2349 return getSuccessorValue(i);
2352 /// findCaseValue - Search all of the case values for the specified constant.
2353 /// If it is explicitly handled, return the case number of it, otherwise
2354 /// return 0 to indicate that it is handled by the default handler.
2355 unsigned findCaseValue(const ConstantInt *C) const {
2356 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2357 if (getCaseValue(i) == C)
2362 /// findCaseDest - Finds the unique case value for a given successor. Returns
2363 /// null if the successor is not found, not unique, or is the default case.
2364 ConstantInt *findCaseDest(BasicBlock *BB) {
2365 if (BB == getDefaultDest()) return NULL;
2367 ConstantInt *CI = NULL;
2368 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2369 if (getSuccessor(i) == BB) {
2370 if (CI) return NULL; // Multiple cases lead to BB.
2371 else CI = getCaseValue(i);
2377 /// addCase - Add an entry to the switch instruction...
2379 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2381 /// removeCase - This method removes the specified successor from the switch
2382 /// instruction. Note that this cannot be used to remove the default
2383 /// destination (successor #0).
2385 void removeCase(unsigned idx);
2387 virtual SwitchInst *clone() const;
2389 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2390 BasicBlock *getSuccessor(unsigned idx) const {
2391 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2392 return cast<BasicBlock>(getOperand(idx*2+1));
2394 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2395 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2396 setOperand(idx*2+1, NewSucc);
2399 // getSuccessorValue - Return the value associated with the specified
2401 ConstantInt *getSuccessorValue(unsigned idx) const {
2402 assert(idx < getNumSuccessors() && "Successor # out of range!");
2403 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2406 // Methods for support type inquiry through isa, cast, and dyn_cast:
2407 static inline bool classof(const SwitchInst *) { return true; }
2408 static inline bool classof(const Instruction *I) {
2409 return I->getOpcode() == Instruction::Switch;
2411 static inline bool classof(const Value *V) {
2412 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2415 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2416 virtual unsigned getNumSuccessorsV() const;
2417 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2421 struct OperandTraits<SwitchInst> : HungoffOperandTraits<2> {
2424 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2427 //===----------------------------------------------------------------------===//
2429 //===----------------------------------------------------------------------===//
2431 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2432 /// calling convention of the call.
2434 class InvokeInst : public TerminatorInst {
2435 PAListPtr ParamAttrs;
2436 InvokeInst(const InvokeInst &BI);
2437 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
2438 Value* const *Args, unsigned NumArgs);
2440 template<typename InputIterator>
2441 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2442 InputIterator ArgBegin, InputIterator ArgEnd,
2443 const std::string &Name,
2444 // This argument ensures that we have an iterator we can
2445 // do arithmetic on in constant time
2446 std::random_access_iterator_tag) {
2447 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
2449 // This requires that the iterator points to contiguous memory.
2450 init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
2454 /// Construct an InvokeInst given a range of arguments.
2455 /// InputIterator must be a random-access iterator pointing to
2456 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
2457 /// made for random-accessness but not for contiguous storage as
2458 /// that would incur runtime overhead.
2460 /// @brief Construct an InvokeInst from a range of arguments
2461 template<typename InputIterator>
2462 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2463 InputIterator ArgBegin, InputIterator ArgEnd,
2465 const std::string &Name, Instruction *InsertBefore);
2467 /// Construct an InvokeInst given a range of arguments.
2468 /// InputIterator must be a random-access iterator pointing to
2469 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
2470 /// made for random-accessness but not for contiguous storage as
2471 /// that would incur runtime overhead.
2473 /// @brief Construct an InvokeInst from a range of arguments
2474 template<typename InputIterator>
2475 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2476 InputIterator ArgBegin, InputIterator ArgEnd,
2478 const std::string &Name, BasicBlock *InsertAtEnd);
2480 template<typename InputIterator>
2481 static InvokeInst *Create(Value *Func,
2482 BasicBlock *IfNormal, BasicBlock *IfException,
2483 InputIterator ArgBegin, InputIterator ArgEnd,
2484 const std::string &Name = "",
2485 Instruction *InsertBefore = 0) {
2486 unsigned Values(ArgEnd - ArgBegin + 3);
2487 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2488 Values, Name, InsertBefore);
2490 template<typename InputIterator>
2491 static InvokeInst *Create(Value *Func,
2492 BasicBlock *IfNormal, BasicBlock *IfException,
2493 InputIterator ArgBegin, InputIterator ArgEnd,
2494 const std::string &Name, BasicBlock *InsertAtEnd) {
2495 unsigned Values(ArgEnd - ArgBegin + 3);
2496 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2497 Values, Name, InsertAtEnd);
2500 virtual InvokeInst *clone() const;
2502 /// Provide fast operand accessors
2503 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2505 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2507 unsigned getCallingConv() const { return SubclassData; }
2508 void setCallingConv(unsigned CC) {
2512 /// getParamAttrs - Return the parameter attributes for this invoke.
2514 const PAListPtr &getParamAttrs() const { return ParamAttrs; }
2516 /// setParamAttrs - Set the parameter attributes for this invoke.
2518 void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
2520 /// @brief Determine whether the call or the callee has the given attribute.
2521 bool paramHasAttr(unsigned i, ParameterAttributes attr) const;
2523 /// addParamAttr - adds the attribute to the list of attributes.
2524 void addParamAttr(unsigned i, ParameterAttributes attr);
2526 /// @brief Extract the alignment for a call or parameter (0=unknown).
2527 unsigned getParamAlignment(unsigned i) const {
2528 return ParamAttrs.getParamAlignment(i);
2531 /// @brief Determine if the call does not access memory.
2532 bool doesNotAccessMemory() const {
2533 return paramHasAttr(0, ParamAttr::ReadNone);
2536 /// @brief Determine if the call does not access or only reads memory.
2537 bool onlyReadsMemory() const {
2538 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
2541 /// @brief Determine if the call cannot return.
2542 bool doesNotReturn() const {
2543 return paramHasAttr(0, ParamAttr::NoReturn);
2546 /// @brief Determine if the call cannot unwind.
2547 bool doesNotThrow() const {
2548 return paramHasAttr(0, ParamAttr::NoUnwind);
2550 void setDoesNotThrow(bool doesNotThrow = true);
2552 /// @brief Determine if the call returns a structure through first
2553 /// pointer argument.
2554 bool hasStructRetAttr() const {
2555 // Be friendly and also check the callee.
2556 return paramHasAttr(1, ParamAttr::StructRet);
2559 /// getCalledFunction - Return the function called, or null if this is an
2560 /// indirect function invocation.
2562 Function *getCalledFunction() const {
2563 return dyn_cast<Function>(getOperand(0));
2566 // getCalledValue - Get a pointer to a function that is invoked by this inst.
2567 Value *getCalledValue() const { return getOperand(0); }
2569 // get*Dest - Return the destination basic blocks...
2570 BasicBlock *getNormalDest() const {
2571 return cast<BasicBlock>(getOperand(1));
2573 BasicBlock *getUnwindDest() const {
2574 return cast<BasicBlock>(getOperand(2));
2576 void setNormalDest(BasicBlock *B) {
2580 void setUnwindDest(BasicBlock *B) {
2584 BasicBlock *getSuccessor(unsigned i) const {
2585 assert(i < 2 && "Successor # out of range for invoke!");
2586 return i == 0 ? getNormalDest() : getUnwindDest();
2589 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2590 assert(idx < 2 && "Successor # out of range for invoke!");
2591 setOperand(idx+1, NewSucc);
2594 unsigned getNumSuccessors() const { return 2; }
2596 // Methods for support type inquiry through isa, cast, and dyn_cast:
2597 static inline bool classof(const InvokeInst *) { return true; }
2598 static inline bool classof(const Instruction *I) {
2599 return (I->getOpcode() == Instruction::Invoke);
2601 static inline bool classof(const Value *V) {
2602 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2605 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2606 virtual unsigned getNumSuccessorsV() const;
2607 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2611 struct OperandTraits<InvokeInst> : VariadicOperandTraits<3> {
2614 template<typename InputIterator>
2615 InvokeInst::InvokeInst(Value *Func,
2616 BasicBlock *IfNormal, BasicBlock *IfException,
2617 InputIterator ArgBegin, InputIterator ArgEnd,
2619 const std::string &Name, Instruction *InsertBefore)
2620 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2621 ->getElementType())->getReturnType(),
2622 Instruction::Invoke,
2623 OperandTraits<InvokeInst>::op_end(this) - Values,
2624 Values, InsertBefore) {
2625 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
2626 typename std::iterator_traits<InputIterator>::iterator_category());
2628 template<typename InputIterator>
2629 InvokeInst::InvokeInst(Value *Func,
2630 BasicBlock *IfNormal, BasicBlock *IfException,
2631 InputIterator ArgBegin, InputIterator ArgEnd,
2633 const std::string &Name, BasicBlock *InsertAtEnd)
2634 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2635 ->getElementType())->getReturnType(),
2636 Instruction::Invoke,
2637 OperandTraits<InvokeInst>::op_end(this) - Values,
2638 Values, InsertAtEnd) {
2639 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
2640 typename std::iterator_traits<InputIterator>::iterator_category());
2643 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2645 //===----------------------------------------------------------------------===//
2647 //===----------------------------------------------------------------------===//
2649 //===---------------------------------------------------------------------------
2650 /// UnwindInst - Immediately exit the current function, unwinding the stack
2651 /// until an invoke instruction is found.
2653 class UnwindInst : public TerminatorInst {
2654 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2656 // allocate space for exactly zero operands
2657 void *operator new(size_t s) {
2658 return User::operator new(s, 0);
2660 explicit UnwindInst(Instruction *InsertBefore = 0);
2661 explicit UnwindInst(BasicBlock *InsertAtEnd);
2663 virtual UnwindInst *clone() const;
2665 unsigned getNumSuccessors() const { return 0; }
2667 // Methods for support type inquiry through isa, cast, and dyn_cast:
2668 static inline bool classof(const UnwindInst *) { return true; }
2669 static inline bool classof(const Instruction *I) {
2670 return I->getOpcode() == Instruction::Unwind;
2672 static inline bool classof(const Value *V) {
2673 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2676 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2677 virtual unsigned getNumSuccessorsV() const;
2678 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2681 //===----------------------------------------------------------------------===//
2682 // UnreachableInst Class
2683 //===----------------------------------------------------------------------===//
2685 //===---------------------------------------------------------------------------
2686 /// UnreachableInst - This function has undefined behavior. In particular, the
2687 /// presence of this instruction indicates some higher level knowledge that the
2688 /// end of the block cannot be reached.
2690 class UnreachableInst : public TerminatorInst {
2691 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2693 // allocate space for exactly zero operands
2694 void *operator new(size_t s) {
2695 return User::operator new(s, 0);
2697 explicit UnreachableInst(Instruction *InsertBefore = 0);
2698 explicit UnreachableInst(BasicBlock *InsertAtEnd);
2700 virtual UnreachableInst *clone() const;
2702 unsigned getNumSuccessors() const { return 0; }
2704 // Methods for support type inquiry through isa, cast, and dyn_cast:
2705 static inline bool classof(const UnreachableInst *) { return true; }
2706 static inline bool classof(const Instruction *I) {
2707 return I->getOpcode() == Instruction::Unreachable;
2709 static inline bool classof(const Value *V) {
2710 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2713 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2714 virtual unsigned getNumSuccessorsV() const;
2715 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2718 //===----------------------------------------------------------------------===//
2720 //===----------------------------------------------------------------------===//
2722 /// @brief This class represents a truncation of integer types.
2723 class TruncInst : public CastInst {
2724 /// Private copy constructor
2725 TruncInst(const TruncInst &CI)
2726 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
2729 /// @brief Constructor with insert-before-instruction semantics
2731 Value *S, ///< The value to be truncated
2732 const Type *Ty, ///< The (smaller) type to truncate to
2733 const std::string &Name = "", ///< A name for the new instruction
2734 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2737 /// @brief Constructor with insert-at-end-of-block semantics
2739 Value *S, ///< The value to be truncated
2740 const Type *Ty, ///< The (smaller) type to truncate to
2741 const std::string &Name, ///< A name for the new instruction
2742 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2745 /// @brief Clone an identical TruncInst
2746 virtual CastInst *clone() const;
2748 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2749 static inline bool classof(const TruncInst *) { return true; }
2750 static inline bool classof(const Instruction *I) {
2751 return I->getOpcode() == Trunc;
2753 static inline bool classof(const Value *V) {
2754 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2758 //===----------------------------------------------------------------------===//
2760 //===----------------------------------------------------------------------===//
2762 /// @brief This class represents zero extension of integer types.
2763 class ZExtInst : public CastInst {
2764 /// @brief Private copy constructor
2765 ZExtInst(const ZExtInst &CI)
2766 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
2769 /// @brief Constructor with insert-before-instruction semantics
2771 Value *S, ///< The value to be zero extended
2772 const Type *Ty, ///< The type to zero extend to
2773 const std::string &Name = "", ///< A name for the new instruction
2774 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2777 /// @brief Constructor with insert-at-end semantics.
2779 Value *S, ///< The value to be zero extended
2780 const Type *Ty, ///< The type to zero extend to
2781 const std::string &Name, ///< A name for the new instruction
2782 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2785 /// @brief Clone an identical ZExtInst
2786 virtual CastInst *clone() const;
2788 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2789 static inline bool classof(const ZExtInst *) { return true; }
2790 static inline bool classof(const Instruction *I) {
2791 return I->getOpcode() == ZExt;
2793 static inline bool classof(const Value *V) {
2794 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2798 //===----------------------------------------------------------------------===//
2800 //===----------------------------------------------------------------------===//
2802 /// @brief This class represents a sign extension of integer types.
2803 class SExtInst : public CastInst {
2804 /// @brief Private copy constructor
2805 SExtInst(const SExtInst &CI)
2806 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
2809 /// @brief Constructor with insert-before-instruction semantics
2811 Value *S, ///< The value to be sign extended
2812 const Type *Ty, ///< The type to sign extend to
2813 const std::string &Name = "", ///< A name for the new instruction
2814 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2817 /// @brief Constructor with insert-at-end-of-block semantics
2819 Value *S, ///< The value to be sign extended
2820 const Type *Ty, ///< The type to sign extend to
2821 const std::string &Name, ///< A name for the new instruction
2822 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2825 /// @brief Clone an identical SExtInst
2826 virtual CastInst *clone() const;
2828 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2829 static inline bool classof(const SExtInst *) { return true; }
2830 static inline bool classof(const Instruction *I) {
2831 return I->getOpcode() == SExt;
2833 static inline bool classof(const Value *V) {
2834 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2838 //===----------------------------------------------------------------------===//
2839 // FPTruncInst Class
2840 //===----------------------------------------------------------------------===//
2842 /// @brief This class represents a truncation of floating point types.
2843 class FPTruncInst : public CastInst {
2844 FPTruncInst(const FPTruncInst &CI)
2845 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
2848 /// @brief Constructor with insert-before-instruction semantics
2850 Value *S, ///< The value to be truncated
2851 const Type *Ty, ///< The type to truncate to
2852 const std::string &Name = "", ///< A name for the new instruction
2853 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2856 /// @brief Constructor with insert-before-instruction semantics
2858 Value *S, ///< The value to be truncated
2859 const Type *Ty, ///< The type to truncate to
2860 const std::string &Name, ///< A name for the new instruction
2861 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2864 /// @brief Clone an identical FPTruncInst
2865 virtual CastInst *clone() const;
2867 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2868 static inline bool classof(const FPTruncInst *) { return true; }
2869 static inline bool classof(const Instruction *I) {
2870 return I->getOpcode() == FPTrunc;
2872 static inline bool classof(const Value *V) {
2873 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2877 //===----------------------------------------------------------------------===//
2879 //===----------------------------------------------------------------------===//
2881 /// @brief This class represents an extension of floating point types.
2882 class FPExtInst : public CastInst {
2883 FPExtInst(const FPExtInst &CI)
2884 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
2887 /// @brief Constructor with insert-before-instruction semantics
2889 Value *S, ///< The value to be extended
2890 const Type *Ty, ///< The type to extend to
2891 const std::string &Name = "", ///< A name for the new instruction
2892 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2895 /// @brief Constructor with insert-at-end-of-block semantics
2897 Value *S, ///< The value to be extended
2898 const Type *Ty, ///< The type to extend to
2899 const std::string &Name, ///< A name for the new instruction
2900 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2903 /// @brief Clone an identical FPExtInst
2904 virtual CastInst *clone() const;
2906 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2907 static inline bool classof(const FPExtInst *) { return true; }
2908 static inline bool classof(const Instruction *I) {
2909 return I->getOpcode() == FPExt;
2911 static inline bool classof(const Value *V) {
2912 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2916 //===----------------------------------------------------------------------===//
2918 //===----------------------------------------------------------------------===//
2920 /// @brief This class represents a cast unsigned integer to floating point.
2921 class UIToFPInst : public CastInst {
2922 UIToFPInst(const UIToFPInst &CI)
2923 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
2926 /// @brief Constructor with insert-before-instruction semantics
2928 Value *S, ///< The value to be converted
2929 const Type *Ty, ///< The type to convert to
2930 const std::string &Name = "", ///< A name for the new instruction
2931 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2934 /// @brief Constructor with insert-at-end-of-block semantics
2936 Value *S, ///< The value to be converted
2937 const Type *Ty, ///< The type to convert to
2938 const std::string &Name, ///< A name for the new instruction
2939 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2942 /// @brief Clone an identical UIToFPInst
2943 virtual CastInst *clone() const;
2945 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2946 static inline bool classof(const UIToFPInst *) { return true; }
2947 static inline bool classof(const Instruction *I) {
2948 return I->getOpcode() == UIToFP;
2950 static inline bool classof(const Value *V) {
2951 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2955 //===----------------------------------------------------------------------===//
2957 //===----------------------------------------------------------------------===//
2959 /// @brief This class represents a cast from signed integer to floating point.
2960 class SIToFPInst : public CastInst {
2961 SIToFPInst(const SIToFPInst &CI)
2962 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
2965 /// @brief Constructor with insert-before-instruction semantics
2967 Value *S, ///< The value to be converted
2968 const Type *Ty, ///< The type to convert to
2969 const std::string &Name = "", ///< A name for the new instruction
2970 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2973 /// @brief Constructor with insert-at-end-of-block semantics
2975 Value *S, ///< The value to be converted
2976 const Type *Ty, ///< The type to convert to
2977 const std::string &Name, ///< A name for the new instruction
2978 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2981 /// @brief Clone an identical SIToFPInst
2982 virtual CastInst *clone() const;
2984 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2985 static inline bool classof(const SIToFPInst *) { return true; }
2986 static inline bool classof(const Instruction *I) {
2987 return I->getOpcode() == SIToFP;
2989 static inline bool classof(const Value *V) {
2990 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2994 //===----------------------------------------------------------------------===//
2996 //===----------------------------------------------------------------------===//
2998 /// @brief This class represents a cast from floating point to unsigned integer
2999 class FPToUIInst : public CastInst {
3000 FPToUIInst(const FPToUIInst &CI)
3001 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
3004 /// @brief Constructor with insert-before-instruction semantics
3006 Value *S, ///< The value to be converted
3007 const Type *Ty, ///< The type to convert to
3008 const std::string &Name = "", ///< A name for the new instruction
3009 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3012 /// @brief Constructor with insert-at-end-of-block semantics
3014 Value *S, ///< The value to be converted
3015 const Type *Ty, ///< The type to convert to
3016 const std::string &Name, ///< A name for the new instruction
3017 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3020 /// @brief Clone an identical FPToUIInst
3021 virtual CastInst *clone() const;
3023 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3024 static inline bool classof(const FPToUIInst *) { return true; }
3025 static inline bool classof(const Instruction *I) {
3026 return I->getOpcode() == FPToUI;
3028 static inline bool classof(const Value *V) {
3029 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3033 //===----------------------------------------------------------------------===//
3035 //===----------------------------------------------------------------------===//
3037 /// @brief This class represents a cast from floating point to signed integer.
3038 class FPToSIInst : public CastInst {
3039 FPToSIInst(const FPToSIInst &CI)
3040 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
3043 /// @brief Constructor with insert-before-instruction semantics
3045 Value *S, ///< The value to be converted
3046 const Type *Ty, ///< The type to convert to
3047 const std::string &Name = "", ///< A name for the new instruction
3048 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3051 /// @brief Constructor with insert-at-end-of-block semantics
3053 Value *S, ///< The value to be converted
3054 const Type *Ty, ///< The type to convert to
3055 const std::string &Name, ///< A name for the new instruction
3056 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3059 /// @brief Clone an identical FPToSIInst
3060 virtual CastInst *clone() const;
3062 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3063 static inline bool classof(const FPToSIInst *) { return true; }
3064 static inline bool classof(const Instruction *I) {
3065 return I->getOpcode() == FPToSI;
3067 static inline bool classof(const Value *V) {
3068 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3072 //===----------------------------------------------------------------------===//
3073 // IntToPtrInst Class
3074 //===----------------------------------------------------------------------===//
3076 /// @brief This class represents a cast from an integer to a pointer.
3077 class IntToPtrInst : public CastInst {
3078 IntToPtrInst(const IntToPtrInst &CI)
3079 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
3082 /// @brief Constructor with insert-before-instruction semantics
3084 Value *S, ///< The value to be converted
3085 const Type *Ty, ///< The type to convert to
3086 const std::string &Name = "", ///< A name for the new instruction
3087 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3090 /// @brief Constructor with insert-at-end-of-block semantics
3092 Value *S, ///< The value to be converted
3093 const Type *Ty, ///< The type to convert to
3094 const std::string &Name, ///< A name for the new instruction
3095 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3098 /// @brief Clone an identical IntToPtrInst
3099 virtual CastInst *clone() const;
3101 // Methods for support type inquiry through isa, cast, and dyn_cast:
3102 static inline bool classof(const IntToPtrInst *) { return true; }
3103 static inline bool classof(const Instruction *I) {
3104 return I->getOpcode() == IntToPtr;
3106 static inline bool classof(const Value *V) {
3107 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3111 //===----------------------------------------------------------------------===//
3112 // PtrToIntInst Class
3113 //===----------------------------------------------------------------------===//
3115 /// @brief This class represents a cast from a pointer to an integer
3116 class PtrToIntInst : public CastInst {
3117 PtrToIntInst(const PtrToIntInst &CI)
3118 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
3121 /// @brief Constructor with insert-before-instruction semantics
3123 Value *S, ///< The value to be converted
3124 const Type *Ty, ///< The type to convert to
3125 const std::string &Name = "", ///< A name for the new instruction
3126 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3129 /// @brief Constructor with insert-at-end-of-block semantics
3131 Value *S, ///< The value to be converted
3132 const Type *Ty, ///< The type to convert to
3133 const std::string &Name, ///< A name for the new instruction
3134 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3137 /// @brief Clone an identical PtrToIntInst
3138 virtual CastInst *clone() const;
3140 // Methods for support type inquiry through isa, cast, and dyn_cast:
3141 static inline bool classof(const PtrToIntInst *) { return true; }
3142 static inline bool classof(const Instruction *I) {
3143 return I->getOpcode() == PtrToInt;
3145 static inline bool classof(const Value *V) {
3146 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3150 //===----------------------------------------------------------------------===//
3151 // BitCastInst Class
3152 //===----------------------------------------------------------------------===//
3154 /// @brief This class represents a no-op cast from one type to another.
3155 class BitCastInst : public CastInst {
3156 BitCastInst(const BitCastInst &CI)
3157 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
3160 /// @brief Constructor with insert-before-instruction semantics
3162 Value *S, ///< The value to be casted
3163 const Type *Ty, ///< The type to casted to
3164 const std::string &Name = "", ///< A name for the new instruction
3165 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3168 /// @brief Constructor with insert-at-end-of-block semantics
3170 Value *S, ///< The value to be casted
3171 const Type *Ty, ///< The type to casted to
3172 const std::string &Name, ///< A name for the new instruction
3173 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3176 /// @brief Clone an identical BitCastInst
3177 virtual CastInst *clone() const;
3179 // Methods for support type inquiry through isa, cast, and dyn_cast:
3180 static inline bool classof(const BitCastInst *) { return true; }
3181 static inline bool classof(const Instruction *I) {
3182 return I->getOpcode() == BitCast;
3184 static inline bool classof(const Value *V) {
3185 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3189 //===----------------------------------------------------------------------===//
3190 // GetResultInst Class
3191 //===----------------------------------------------------------------------===//
3193 /// GetResultInst - This instruction extracts individual result value from
3194 /// aggregate value, where aggregate value is returned by CallInst.
3196 class GetResultInst : public UnaryInstruction {
3198 GetResultInst(const GetResultInst &GRI) :
3199 UnaryInstruction(GRI.getType(), Instruction::GetResult, GRI.getOperand(0)),
3204 GetResultInst(Value *Aggr, unsigned index,
3205 const std::string &Name = "",
3206 Instruction *InsertBefore = 0);
3208 /// isValidOperands - Return true if an getresult instruction can be
3209 /// formed with the specified operands.
3210 static bool isValidOperands(const Value *Aggr, unsigned index);
3212 virtual GetResultInst *clone() const;
3214 Value *getAggregateValue() {
3215 return getOperand(0);
3218 const Value *getAggregateValue() const {
3219 return getOperand(0);
3222 unsigned getIndex() const {
3226 // Methods for support type inquiry through isa, cast, and dyn_cast:
3227 static inline bool classof(const GetResultInst *) { return true; }
3228 static inline bool classof(const Instruction *I) {
3229 return (I->getOpcode() == Instruction::GetResult);
3231 static inline bool classof(const Value *V) {
3232 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3236 } // End llvm namespace