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
19 #include "llvm/InstrTypes.h"
20 #include "llvm/DerivedTypes.h"
21 #include "llvm/Attributes.h"
22 #include "llvm/CallingConv.h"
23 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/Support/ErrorHandling.h"
39 // Consume = 3, // Not specified yet.
43 SequentiallyConsistent = 7
46 enum SynchronizationScope {
51 //===----------------------------------------------------------------------===//
53 //===----------------------------------------------------------------------===//
55 /// AllocaInst - an instruction to allocate memory on the stack
57 class AllocaInst : public UnaryInstruction {
59 virtual AllocaInst *clone_impl() const;
61 explicit AllocaInst(Type *Ty, Value *ArraySize = 0,
62 const Twine &Name = "", Instruction *InsertBefore = 0);
63 AllocaInst(Type *Ty, Value *ArraySize,
64 const Twine &Name, BasicBlock *InsertAtEnd);
66 AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
67 AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
69 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
70 const Twine &Name = "", Instruction *InsertBefore = 0);
71 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
72 const Twine &Name, BasicBlock *InsertAtEnd);
74 // Out of line virtual method, so the vtable, etc. has a home.
75 virtual ~AllocaInst();
77 /// isArrayAllocation - Return true if there is an allocation size parameter
78 /// to the allocation instruction that is not 1.
80 bool isArrayAllocation() const;
82 /// getArraySize - Get the number of elements allocated. For a simple
83 /// allocation of a single element, this will return a constant 1 value.
85 const Value *getArraySize() const { return getOperand(0); }
86 Value *getArraySize() { return getOperand(0); }
88 /// getType - Overload to return most specific pointer type
90 PointerType *getType() const {
91 return reinterpret_cast<PointerType*>(Instruction::getType());
94 /// getAllocatedType - Return the type that is being allocated by the
97 Type *getAllocatedType() const;
99 /// getAlignment - Return the alignment of the memory that is being allocated
100 /// by the instruction.
102 unsigned getAlignment() const {
103 return (1u << getSubclassDataFromInstruction()) >> 1;
105 void setAlignment(unsigned Align);
107 /// isStaticAlloca - Return true if this alloca is in the entry block of the
108 /// function and is a constant size. If so, the code generator will fold it
109 /// into the prolog/epilog code, so it is basically free.
110 bool isStaticAlloca() const;
112 // Methods for support type inquiry through isa, cast, and dyn_cast:
113 static inline bool classof(const AllocaInst *) { return true; }
114 static inline bool classof(const Instruction *I) {
115 return (I->getOpcode() == Instruction::Alloca);
117 static inline bool classof(const Value *V) {
118 return isa<Instruction>(V) && classof(cast<Instruction>(V));
121 // Shadow Instruction::setInstructionSubclassData with a private forwarding
122 // method so that subclasses cannot accidentally use it.
123 void setInstructionSubclassData(unsigned short D) {
124 Instruction::setInstructionSubclassData(D);
129 //===----------------------------------------------------------------------===//
131 //===----------------------------------------------------------------------===//
133 /// LoadInst - an instruction for reading from memory. This uses the
134 /// SubclassData field in Value to store whether or not the load is volatile.
136 class LoadInst : public UnaryInstruction {
139 virtual LoadInst *clone_impl() const;
141 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
142 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
143 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
144 Instruction *InsertBefore = 0);
145 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
146 unsigned Align, Instruction *InsertBefore = 0);
147 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
148 BasicBlock *InsertAtEnd);
149 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
150 unsigned Align, BasicBlock *InsertAtEnd);
152 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
153 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
154 explicit LoadInst(Value *Ptr, const char *NameStr = 0,
155 bool isVolatile = false, Instruction *InsertBefore = 0);
156 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
157 BasicBlock *InsertAtEnd);
159 /// isVolatile - Return true if this is a load from a volatile memory
162 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
164 /// setVolatile - Specify whether this is a volatile load or not.
166 void setVolatile(bool V) {
167 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
171 /// getAlignment - Return the alignment of the access that is being performed
173 unsigned getAlignment() const {
174 return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
177 void setAlignment(unsigned Align);
179 Value *getPointerOperand() { return getOperand(0); }
180 const Value *getPointerOperand() const { return getOperand(0); }
181 static unsigned getPointerOperandIndex() { return 0U; }
183 unsigned getPointerAddressSpace() const {
184 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
188 // Methods for support type inquiry through isa, cast, and dyn_cast:
189 static inline bool classof(const LoadInst *) { return true; }
190 static inline bool classof(const Instruction *I) {
191 return I->getOpcode() == Instruction::Load;
193 static inline bool classof(const Value *V) {
194 return isa<Instruction>(V) && classof(cast<Instruction>(V));
197 // Shadow Instruction::setInstructionSubclassData with a private forwarding
198 // method so that subclasses cannot accidentally use it.
199 void setInstructionSubclassData(unsigned short D) {
200 Instruction::setInstructionSubclassData(D);
205 //===----------------------------------------------------------------------===//
207 //===----------------------------------------------------------------------===//
209 /// StoreInst - an instruction for storing to memory
211 class StoreInst : public Instruction {
212 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
215 virtual StoreInst *clone_impl() const;
217 // allocate space for exactly two operands
218 void *operator new(size_t s) {
219 return User::operator new(s, 2);
221 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
222 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
223 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
224 Instruction *InsertBefore = 0);
225 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
226 unsigned Align, Instruction *InsertBefore = 0);
227 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
228 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
229 unsigned Align, BasicBlock *InsertAtEnd);
232 /// isVolatile - Return true if this is a load from a volatile memory
235 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
237 /// setVolatile - Specify whether this is a volatile load or not.
239 void setVolatile(bool V) {
240 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
244 /// Transparently provide more efficient getOperand methods.
245 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
247 /// getAlignment - Return the alignment of the access that is being performed
249 unsigned getAlignment() const {
250 return (1 << (getSubclassDataFromInstruction() >> 1)) >> 1;
253 void setAlignment(unsigned Align);
255 Value *getValueOperand() { return getOperand(0); }
256 const Value *getValueOperand() const { return getOperand(0); }
258 Value *getPointerOperand() { return getOperand(1); }
259 const Value *getPointerOperand() const { return getOperand(1); }
260 static unsigned getPointerOperandIndex() { return 1U; }
262 unsigned getPointerAddressSpace() const {
263 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
266 // Methods for support type inquiry through isa, cast, and dyn_cast:
267 static inline bool classof(const StoreInst *) { return true; }
268 static inline bool classof(const Instruction *I) {
269 return I->getOpcode() == Instruction::Store;
271 static inline bool classof(const Value *V) {
272 return isa<Instruction>(V) && classof(cast<Instruction>(V));
275 // Shadow Instruction::setInstructionSubclassData with a private forwarding
276 // method so that subclasses cannot accidentally use it.
277 void setInstructionSubclassData(unsigned short D) {
278 Instruction::setInstructionSubclassData(D);
283 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
286 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
288 //===----------------------------------------------------------------------===//
290 //===----------------------------------------------------------------------===//
292 /// FenceInst - an instruction for ordering other memory operations
294 class FenceInst : public Instruction {
295 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
296 void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
298 virtual FenceInst *clone_impl() const;
300 // allocate space for exactly zero operands
301 void *operator new(size_t s) {
302 return User::operator new(s, 0);
305 // Ordering may only be Acquire, Release, AcquireRelease, or
306 // SequentiallyConsistent.
307 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
308 SynchronizationScope SynchScope = CrossThread,
309 Instruction *InsertBefore = 0);
310 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
311 SynchronizationScope SynchScope,
312 BasicBlock *InsertAtEnd);
314 /// Returns the ordering effect of this fence.
315 AtomicOrdering getOrdering() const {
316 return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
319 /// Set the ordering constraint on this fence. May only be Acquire, Release,
320 /// AcquireRelease, or SequentiallyConsistent.
321 void setOrdering(AtomicOrdering Ordering) {
326 case SequentiallyConsistent:
327 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
331 llvm_unreachable("FenceInst ordering must be Acquire, Release,"
332 " AcquireRelease, or SequentiallyConsistent");
336 SynchronizationScope getSynchScope() const {
337 return SynchronizationScope(getSubclassDataFromInstruction() & 1);
340 /// Specify whether this fence orders other operations with respect to all
341 /// concurrently executing threads, or only with respect to signal handlers
342 /// executing in the same thread.
343 void setSynchScope(SynchronizationScope xthread) {
344 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
348 // Methods for support type inquiry through isa, cast, and dyn_cast:
349 static inline bool classof(const FenceInst *) { return true; }
350 static inline bool classof(const Instruction *I) {
351 return I->getOpcode() == Instruction::Fence;
353 static inline bool classof(const Value *V) {
354 return isa<Instruction>(V) && classof(cast<Instruction>(V));
357 // Shadow Instruction::setInstructionSubclassData with a private forwarding
358 // method so that subclasses cannot accidentally use it.
359 void setInstructionSubclassData(unsigned short D) {
360 Instruction::setInstructionSubclassData(D);
364 //===----------------------------------------------------------------------===//
365 // GetElementPtrInst Class
366 //===----------------------------------------------------------------------===//
368 // checkGEPType - Simple wrapper function to give a better assertion failure
369 // message on bad indexes for a gep instruction.
371 static inline Type *checkGEPType(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, ArrayRef<Value *> IdxList, const Twine &NameStr);
383 /// Constructors - Create a getelementptr instruction with a base pointer an
384 /// list of indices. The first ctor can optionally insert before an existing
385 /// instruction, the second appends the new instruction to the specified
387 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
388 unsigned Values, const Twine &NameStr,
389 Instruction *InsertBefore);
390 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
391 unsigned Values, const Twine &NameStr,
392 BasicBlock *InsertAtEnd);
394 virtual GetElementPtrInst *clone_impl() const;
396 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
397 const Twine &NameStr = "",
398 Instruction *InsertBefore = 0) {
399 unsigned Values = 1 + unsigned(IdxList.size());
401 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
403 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
404 const Twine &NameStr,
405 BasicBlock *InsertAtEnd) {
406 unsigned Values = 1 + unsigned(IdxList.size());
408 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
411 /// Create an "inbounds" getelementptr. See the documentation for the
412 /// "inbounds" flag in LangRef.html for details.
413 static GetElementPtrInst *CreateInBounds(Value *Ptr,
414 ArrayRef<Value *> IdxList,
415 const Twine &NameStr = "",
416 Instruction *InsertBefore = 0) {
417 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
418 GEP->setIsInBounds(true);
421 static GetElementPtrInst *CreateInBounds(Value *Ptr,
422 ArrayRef<Value *> IdxList,
423 const Twine &NameStr,
424 BasicBlock *InsertAtEnd) {
425 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
426 GEP->setIsInBounds(true);
430 /// Transparently provide more efficient getOperand methods.
431 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
433 // getType - Overload to return most specific pointer type...
434 PointerType *getType() const {
435 return reinterpret_cast<PointerType*>(Instruction::getType());
438 /// getIndexedType - Returns the type of the element that would be loaded with
439 /// a load instruction with the specified parameters.
441 /// Null is returned if the indices are invalid for the specified
444 static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList);
445 static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList);
446 static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList);
448 inline op_iterator idx_begin() { return op_begin()+1; }
449 inline const_op_iterator idx_begin() const { return op_begin()+1; }
450 inline op_iterator idx_end() { return op_end(); }
451 inline const_op_iterator idx_end() const { return op_end(); }
453 Value *getPointerOperand() {
454 return getOperand(0);
456 const Value *getPointerOperand() const {
457 return getOperand(0);
459 static unsigned getPointerOperandIndex() {
460 return 0U; // get index for modifying correct operand
463 unsigned getPointerAddressSpace() const {
464 return cast<PointerType>(getType())->getAddressSpace();
467 /// getPointerOperandType - Method to return the pointer operand as a
469 PointerType *getPointerOperandType() const {
470 return reinterpret_cast<PointerType*>(getPointerOperand()->getType());
474 unsigned getNumIndices() const { // Note: always non-negative
475 return getNumOperands() - 1;
478 bool hasIndices() const {
479 return getNumOperands() > 1;
482 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
483 /// zeros. If so, the result pointer and the first operand have the same
484 /// value, just potentially different types.
485 bool hasAllZeroIndices() const;
487 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
488 /// constant integers. If so, the result pointer and the first operand have
489 /// a constant offset between them.
490 bool hasAllConstantIndices() const;
492 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
493 /// See LangRef.html for the meaning of inbounds on a getelementptr.
494 void setIsInBounds(bool b = true);
496 /// isInBounds - Determine whether the GEP has the inbounds flag.
497 bool isInBounds() const;
499 // Methods for support type inquiry through isa, cast, and dyn_cast:
500 static inline bool classof(const GetElementPtrInst *) { return true; }
501 static inline bool classof(const Instruction *I) {
502 return (I->getOpcode() == Instruction::GetElementPtr);
504 static inline bool classof(const Value *V) {
505 return isa<Instruction>(V) && classof(cast<Instruction>(V));
510 struct OperandTraits<GetElementPtrInst> :
511 public VariadicOperandTraits<GetElementPtrInst, 1> {
514 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
515 ArrayRef<Value *> IdxList,
517 const Twine &NameStr,
518 Instruction *InsertBefore)
519 : Instruction(PointerType::get(checkGEPType(
520 getIndexedType(Ptr->getType(), IdxList)),
521 cast<PointerType>(Ptr->getType())
522 ->getAddressSpace()),
524 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
525 Values, InsertBefore) {
526 init(Ptr, IdxList, NameStr);
528 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
529 ArrayRef<Value *> IdxList,
531 const Twine &NameStr,
532 BasicBlock *InsertAtEnd)
533 : Instruction(PointerType::get(checkGEPType(
534 getIndexedType(Ptr->getType(), IdxList)),
535 cast<PointerType>(Ptr->getType())
536 ->getAddressSpace()),
538 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
539 Values, InsertAtEnd) {
540 init(Ptr, IdxList, NameStr);
544 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
547 //===----------------------------------------------------------------------===//
549 //===----------------------------------------------------------------------===//
551 /// This instruction compares its operands according to the predicate given
552 /// to the constructor. It only operates on integers or pointers. The operands
553 /// must be identical types.
554 /// @brief Represent an integer comparison operator.
555 class ICmpInst: public CmpInst {
557 /// @brief Clone an identical ICmpInst
558 virtual ICmpInst *clone_impl() const;
560 /// @brief Constructor with insert-before-instruction semantics.
562 Instruction *InsertBefore, ///< Where to insert
563 Predicate pred, ///< The predicate to use for the comparison
564 Value *LHS, ///< The left-hand-side of the expression
565 Value *RHS, ///< The right-hand-side of the expression
566 const Twine &NameStr = "" ///< Name of the instruction
567 ) : CmpInst(makeCmpResultType(LHS->getType()),
568 Instruction::ICmp, pred, LHS, RHS, NameStr,
570 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
571 pred <= CmpInst::LAST_ICMP_PREDICATE &&
572 "Invalid ICmp predicate value");
573 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
574 "Both operands to ICmp instruction are not of the same type!");
575 // Check that the operands are the right type
576 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
577 getOperand(0)->getType()->isPointerTy()) &&
578 "Invalid operand types for ICmp instruction");
581 /// @brief Constructor with insert-at-end semantics.
583 BasicBlock &InsertAtEnd, ///< Block to insert into.
584 Predicate pred, ///< The predicate to use for the comparison
585 Value *LHS, ///< The left-hand-side of the expression
586 Value *RHS, ///< The right-hand-side of the expression
587 const Twine &NameStr = "" ///< Name of the instruction
588 ) : CmpInst(makeCmpResultType(LHS->getType()),
589 Instruction::ICmp, pred, LHS, RHS, NameStr,
591 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
592 pred <= CmpInst::LAST_ICMP_PREDICATE &&
593 "Invalid ICmp predicate value");
594 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
595 "Both operands to ICmp instruction are not of the same type!");
596 // Check that the operands are the right type
597 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
598 getOperand(0)->getType()->isPointerTy()) &&
599 "Invalid operand types for ICmp instruction");
602 /// @brief Constructor with no-insertion semantics
604 Predicate pred, ///< The predicate to use for the comparison
605 Value *LHS, ///< The left-hand-side of the expression
606 Value *RHS, ///< The right-hand-side of the expression
607 const Twine &NameStr = "" ///< Name of the instruction
608 ) : CmpInst(makeCmpResultType(LHS->getType()),
609 Instruction::ICmp, pred, LHS, RHS, NameStr) {
610 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
611 pred <= CmpInst::LAST_ICMP_PREDICATE &&
612 "Invalid ICmp predicate value");
613 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
614 "Both operands to ICmp instruction are not of the same type!");
615 // Check that the operands are the right type
616 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
617 getOperand(0)->getType()->isPointerTy()) &&
618 "Invalid operand types for ICmp instruction");
621 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
622 /// @returns the predicate that would be the result if the operand were
623 /// regarded as signed.
624 /// @brief Return the signed version of the predicate
625 Predicate getSignedPredicate() const {
626 return getSignedPredicate(getPredicate());
629 /// This is a static version that you can use without an instruction.
630 /// @brief Return the signed version of the predicate.
631 static Predicate getSignedPredicate(Predicate pred);
633 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
634 /// @returns the predicate that would be the result if the operand were
635 /// regarded as unsigned.
636 /// @brief Return the unsigned version of the predicate
637 Predicate getUnsignedPredicate() const {
638 return getUnsignedPredicate(getPredicate());
641 /// This is a static version that you can use without an instruction.
642 /// @brief Return the unsigned version of the predicate.
643 static Predicate getUnsignedPredicate(Predicate pred);
645 /// isEquality - Return true if this predicate is either EQ or NE. This also
646 /// tests for commutativity.
647 static bool isEquality(Predicate P) {
648 return P == ICMP_EQ || P == ICMP_NE;
651 /// isEquality - Return true if this predicate is either EQ or NE. This also
652 /// tests for commutativity.
653 bool isEquality() const {
654 return isEquality(getPredicate());
657 /// @returns true if the predicate of this ICmpInst is commutative
658 /// @brief Determine if this relation is commutative.
659 bool isCommutative() const { return isEquality(); }
661 /// isRelational - Return true if the predicate is relational (not EQ or NE).
663 bool isRelational() const {
664 return !isEquality();
667 /// isRelational - Return true if the predicate is relational (not EQ or NE).
669 static bool isRelational(Predicate P) {
670 return !isEquality(P);
673 /// Initialize a set of values that all satisfy the predicate with C.
674 /// @brief Make a ConstantRange for a relation with a constant value.
675 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
677 /// Exchange the two operands to this instruction in such a way that it does
678 /// not modify the semantics of the instruction. The predicate value may be
679 /// changed to retain the same result if the predicate is order dependent
681 /// @brief Swap operands and adjust predicate.
682 void swapOperands() {
683 setPredicate(getSwappedPredicate());
684 Op<0>().swap(Op<1>());
687 // Methods for support type inquiry through isa, cast, and dyn_cast:
688 static inline bool classof(const ICmpInst *) { return true; }
689 static inline bool classof(const Instruction *I) {
690 return I->getOpcode() == Instruction::ICmp;
692 static inline bool classof(const Value *V) {
693 return isa<Instruction>(V) && classof(cast<Instruction>(V));
698 //===----------------------------------------------------------------------===//
700 //===----------------------------------------------------------------------===//
702 /// This instruction compares its operands according to the predicate given
703 /// to the constructor. It only operates on floating point values or packed
704 /// vectors of floating point values. The operands must be identical types.
705 /// @brief Represents a floating point comparison operator.
706 class FCmpInst: public CmpInst {
708 /// @brief Clone an identical FCmpInst
709 virtual FCmpInst *clone_impl() const;
711 /// @brief Constructor with insert-before-instruction semantics.
713 Instruction *InsertBefore, ///< Where to insert
714 Predicate pred, ///< The predicate to use for the comparison
715 Value *LHS, ///< The left-hand-side of the expression
716 Value *RHS, ///< The right-hand-side of the expression
717 const Twine &NameStr = "" ///< Name of the instruction
718 ) : CmpInst(makeCmpResultType(LHS->getType()),
719 Instruction::FCmp, pred, LHS, RHS, NameStr,
721 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
722 "Invalid FCmp predicate value");
723 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
724 "Both operands to FCmp instruction are not of the same type!");
725 // Check that the operands are the right type
726 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
727 "Invalid operand types for FCmp instruction");
730 /// @brief Constructor with insert-at-end semantics.
732 BasicBlock &InsertAtEnd, ///< Block to insert into.
733 Predicate pred, ///< The predicate to use for the comparison
734 Value *LHS, ///< The left-hand-side of the expression
735 Value *RHS, ///< The right-hand-side of the expression
736 const Twine &NameStr = "" ///< Name of the instruction
737 ) : CmpInst(makeCmpResultType(LHS->getType()),
738 Instruction::FCmp, pred, LHS, RHS, NameStr,
740 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
741 "Invalid FCmp predicate value");
742 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
743 "Both operands to FCmp instruction are not of the same type!");
744 // Check that the operands are the right type
745 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
746 "Invalid operand types for FCmp instruction");
749 /// @brief Constructor with no-insertion semantics
751 Predicate pred, ///< The predicate to use for the comparison
752 Value *LHS, ///< The left-hand-side of the expression
753 Value *RHS, ///< The right-hand-side of the expression
754 const Twine &NameStr = "" ///< Name of the instruction
755 ) : CmpInst(makeCmpResultType(LHS->getType()),
756 Instruction::FCmp, pred, LHS, RHS, NameStr) {
757 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
758 "Invalid FCmp predicate value");
759 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
760 "Both operands to FCmp instruction are not of the same type!");
761 // Check that the operands are the right type
762 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
763 "Invalid operand types for FCmp instruction");
766 /// @returns true if the predicate of this instruction is EQ or NE.
767 /// @brief Determine if this is an equality predicate.
768 bool isEquality() const {
769 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
770 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
773 /// @returns true if the predicate of this instruction is commutative.
774 /// @brief Determine if this is a commutative predicate.
775 bool isCommutative() const {
776 return isEquality() ||
777 getPredicate() == FCMP_FALSE ||
778 getPredicate() == FCMP_TRUE ||
779 getPredicate() == FCMP_ORD ||
780 getPredicate() == FCMP_UNO;
783 /// @returns true if the predicate is relational (not EQ or NE).
784 /// @brief Determine if this a relational predicate.
785 bool isRelational() const { return !isEquality(); }
787 /// Exchange the two operands to this instruction in such a way that it does
788 /// not modify the semantics of the instruction. The predicate value may be
789 /// changed to retain the same result if the predicate is order dependent
791 /// @brief Swap operands and adjust predicate.
792 void swapOperands() {
793 setPredicate(getSwappedPredicate());
794 Op<0>().swap(Op<1>());
797 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
798 static inline bool classof(const FCmpInst *) { return true; }
799 static inline bool classof(const Instruction *I) {
800 return I->getOpcode() == Instruction::FCmp;
802 static inline bool classof(const Value *V) {
803 return isa<Instruction>(V) && classof(cast<Instruction>(V));
807 //===----------------------------------------------------------------------===//
808 /// CallInst - This class represents a function call, abstracting a target
809 /// machine's calling convention. This class uses low bit of the SubClassData
810 /// field to indicate whether or not this is a tail call. The rest of the bits
811 /// hold the calling convention of the call.
813 class CallInst : public Instruction {
814 AttrListPtr AttributeList; ///< parameter attributes for call
815 CallInst(const CallInst &CI);
816 void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
817 void init(Value *Func, const Twine &NameStr);
819 /// Construct a CallInst given a range of arguments.
820 /// @brief Construct a CallInst from a range of arguments
821 inline CallInst(Value *Func, ArrayRef<Value *> Args,
822 const Twine &NameStr, Instruction *InsertBefore);
824 /// Construct a CallInst given a range of arguments.
825 /// @brief Construct a CallInst from a range of arguments
826 inline CallInst(Value *Func, ArrayRef<Value *> Args,
827 const Twine &NameStr, BasicBlock *InsertAtEnd);
829 CallInst(Value *F, Value *Actual, const Twine &NameStr,
830 Instruction *InsertBefore);
831 CallInst(Value *F, Value *Actual, const Twine &NameStr,
832 BasicBlock *InsertAtEnd);
833 explicit CallInst(Value *F, const Twine &NameStr,
834 Instruction *InsertBefore);
835 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
837 virtual CallInst *clone_impl() const;
839 static CallInst *Create(Value *Func,
840 ArrayRef<Value *> Args,
841 const Twine &NameStr = "",
842 Instruction *InsertBefore = 0) {
843 return new(unsigned(Args.size() + 1))
844 CallInst(Func, Args, NameStr, InsertBefore);
846 static CallInst *Create(Value *Func,
847 ArrayRef<Value *> Args,
848 const Twine &NameStr, BasicBlock *InsertAtEnd) {
849 return new(unsigned(Args.size() + 1))
850 CallInst(Func, Args, NameStr, InsertAtEnd);
852 static CallInst *Create(Value *F, const Twine &NameStr = "",
853 Instruction *InsertBefore = 0) {
854 return new(1) CallInst(F, NameStr, InsertBefore);
856 static CallInst *Create(Value *F, const Twine &NameStr,
857 BasicBlock *InsertAtEnd) {
858 return new(1) CallInst(F, NameStr, InsertAtEnd);
860 /// CreateMalloc - Generate the IR for a call to malloc:
861 /// 1. Compute the malloc call's argument as the specified type's size,
862 /// possibly multiplied by the array size if the array size is not
864 /// 2. Call malloc with that argument.
865 /// 3. Bitcast the result of the malloc call to the specified type.
866 static Instruction *CreateMalloc(Instruction *InsertBefore,
867 Type *IntPtrTy, Type *AllocTy,
868 Value *AllocSize, Value *ArraySize = 0,
869 Function* MallocF = 0,
870 const Twine &Name = "");
871 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
872 Type *IntPtrTy, Type *AllocTy,
873 Value *AllocSize, Value *ArraySize = 0,
874 Function* MallocF = 0,
875 const Twine &Name = "");
876 /// CreateFree - Generate the IR for a call to the builtin free function.
877 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
878 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
882 bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
883 void setTailCall(bool isTC = true) {
884 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
888 /// Provide fast operand accessors
889 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
891 /// getNumArgOperands - Return the number of call arguments.
893 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
895 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
897 Value *getArgOperand(unsigned i) const { return getOperand(i); }
898 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
900 /// getCallingConv/setCallingConv - Get or set the calling convention of this
902 CallingConv::ID getCallingConv() const {
903 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
905 void setCallingConv(CallingConv::ID CC) {
906 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
907 (static_cast<unsigned>(CC) << 1));
910 /// getAttributes - Return the parameter attributes for this call.
912 const AttrListPtr &getAttributes() const { return AttributeList; }
914 /// setAttributes - Set the parameter attributes for this call.
916 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
918 /// addAttribute - adds the attribute to the list of attributes.
919 void addAttribute(unsigned i, Attributes attr);
921 /// removeAttribute - removes the attribute from the list of attributes.
922 void removeAttribute(unsigned i, Attributes attr);
924 /// @brief Determine whether the call or the callee has the given attribute.
925 bool paramHasAttr(unsigned i, Attributes attr) const;
927 /// @brief Extract the alignment for a call or parameter (0=unknown).
928 unsigned getParamAlignment(unsigned i) const {
929 return AttributeList.getParamAlignment(i);
932 /// @brief Return true if the call should not be inlined.
933 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
934 void setIsNoInline(bool Value = true) {
935 if (Value) addAttribute(~0, Attribute::NoInline);
936 else removeAttribute(~0, Attribute::NoInline);
939 /// @brief Determine if the call does not access memory.
940 bool doesNotAccessMemory() const {
941 return paramHasAttr(~0, Attribute::ReadNone);
943 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
944 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
945 else removeAttribute(~0, Attribute::ReadNone);
948 /// @brief Determine if the call does not access or only reads memory.
949 bool onlyReadsMemory() const {
950 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
952 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
953 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
954 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
957 /// @brief Determine if the call cannot return.
958 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
959 void setDoesNotReturn(bool DoesNotReturn = true) {
960 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
961 else removeAttribute(~0, Attribute::NoReturn);
964 /// @brief Determine if the call cannot unwind.
965 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
966 void setDoesNotThrow(bool DoesNotThrow = true) {
967 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
968 else removeAttribute(~0, Attribute::NoUnwind);
971 /// @brief Determine if the call returns a structure through first
972 /// pointer argument.
973 bool hasStructRetAttr() const {
974 // Be friendly and also check the callee.
975 return paramHasAttr(1, Attribute::StructRet);
978 /// @brief Determine if any call argument is an aggregate passed by value.
979 bool hasByValArgument() const {
980 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
983 /// getCalledFunction - Return the function called, or null if this is an
984 /// indirect function invocation.
986 Function *getCalledFunction() const {
987 return dyn_cast<Function>(Op<-1>());
990 /// getCalledValue - Get a pointer to the function that is invoked by this
992 const Value *getCalledValue() const { return Op<-1>(); }
993 Value *getCalledValue() { return Op<-1>(); }
995 /// setCalledFunction - Set the function called.
996 void setCalledFunction(Value* Fn) {
1000 /// isInlineAsm - Check if this call is an inline asm statement.
1001 bool isInlineAsm() const {
1002 return isa<InlineAsm>(Op<-1>());
1005 // Methods for support type inquiry through isa, cast, and dyn_cast:
1006 static inline bool classof(const CallInst *) { return true; }
1007 static inline bool classof(const Instruction *I) {
1008 return I->getOpcode() == Instruction::Call;
1010 static inline bool classof(const Value *V) {
1011 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1014 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1015 // method so that subclasses cannot accidentally use it.
1016 void setInstructionSubclassData(unsigned short D) {
1017 Instruction::setInstructionSubclassData(D);
1022 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1025 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1026 const Twine &NameStr, BasicBlock *InsertAtEnd)
1027 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1028 ->getElementType())->getReturnType(),
1030 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1031 unsigned(Args.size() + 1), InsertAtEnd) {
1032 init(Func, Args, NameStr);
1035 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1036 const Twine &NameStr, Instruction *InsertBefore)
1037 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1038 ->getElementType())->getReturnType(),
1040 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1041 unsigned(Args.size() + 1), InsertBefore) {
1042 init(Func, Args, NameStr);
1046 // Note: if you get compile errors about private methods then
1047 // please update your code to use the high-level operand
1048 // interfaces. See line 943 above.
1049 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1051 //===----------------------------------------------------------------------===//
1053 //===----------------------------------------------------------------------===//
1055 /// SelectInst - This class represents the LLVM 'select' instruction.
1057 class SelectInst : public Instruction {
1058 void init(Value *C, Value *S1, Value *S2) {
1059 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1065 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1066 Instruction *InsertBefore)
1067 : Instruction(S1->getType(), Instruction::Select,
1068 &Op<0>(), 3, InsertBefore) {
1072 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1073 BasicBlock *InsertAtEnd)
1074 : Instruction(S1->getType(), Instruction::Select,
1075 &Op<0>(), 3, InsertAtEnd) {
1080 virtual SelectInst *clone_impl() const;
1082 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1083 const Twine &NameStr = "",
1084 Instruction *InsertBefore = 0) {
1085 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1087 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1088 const Twine &NameStr,
1089 BasicBlock *InsertAtEnd) {
1090 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1093 const Value *getCondition() const { return Op<0>(); }
1094 const Value *getTrueValue() const { return Op<1>(); }
1095 const Value *getFalseValue() const { return Op<2>(); }
1096 Value *getCondition() { return Op<0>(); }
1097 Value *getTrueValue() { return Op<1>(); }
1098 Value *getFalseValue() { return Op<2>(); }
1100 /// areInvalidOperands - Return a string if the specified operands are invalid
1101 /// for a select operation, otherwise return null.
1102 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1104 /// Transparently provide more efficient getOperand methods.
1105 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1107 OtherOps getOpcode() const {
1108 return static_cast<OtherOps>(Instruction::getOpcode());
1111 // Methods for support type inquiry through isa, cast, and dyn_cast:
1112 static inline bool classof(const SelectInst *) { return true; }
1113 static inline bool classof(const Instruction *I) {
1114 return I->getOpcode() == Instruction::Select;
1116 static inline bool classof(const Value *V) {
1117 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1122 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1125 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1127 //===----------------------------------------------------------------------===//
1129 //===----------------------------------------------------------------------===//
1131 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1132 /// an argument of the specified type given a va_list and increments that list
1134 class VAArgInst : public UnaryInstruction {
1136 virtual VAArgInst *clone_impl() const;
1139 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1140 Instruction *InsertBefore = 0)
1141 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1144 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1145 BasicBlock *InsertAtEnd)
1146 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1150 Value *getPointerOperand() { return getOperand(0); }
1151 const Value *getPointerOperand() const { return getOperand(0); }
1152 static unsigned getPointerOperandIndex() { return 0U; }
1154 // Methods for support type inquiry through isa, cast, and dyn_cast:
1155 static inline bool classof(const VAArgInst *) { return true; }
1156 static inline bool classof(const Instruction *I) {
1157 return I->getOpcode() == VAArg;
1159 static inline bool classof(const Value *V) {
1160 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1164 //===----------------------------------------------------------------------===//
1165 // ExtractElementInst Class
1166 //===----------------------------------------------------------------------===//
1168 /// ExtractElementInst - This instruction extracts a single (scalar)
1169 /// element from a VectorType value
1171 class ExtractElementInst : public Instruction {
1172 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1173 Instruction *InsertBefore = 0);
1174 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1175 BasicBlock *InsertAtEnd);
1177 virtual ExtractElementInst *clone_impl() const;
1180 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1181 const Twine &NameStr = "",
1182 Instruction *InsertBefore = 0) {
1183 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1185 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1186 const Twine &NameStr,
1187 BasicBlock *InsertAtEnd) {
1188 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1191 /// isValidOperands - Return true if an extractelement instruction can be
1192 /// formed with the specified operands.
1193 static bool isValidOperands(const Value *Vec, const Value *Idx);
1195 Value *getVectorOperand() { return Op<0>(); }
1196 Value *getIndexOperand() { return Op<1>(); }
1197 const Value *getVectorOperand() const { return Op<0>(); }
1198 const Value *getIndexOperand() const { return Op<1>(); }
1200 VectorType *getVectorOperandType() const {
1201 return reinterpret_cast<VectorType*>(getVectorOperand()->getType());
1205 /// Transparently provide more efficient getOperand methods.
1206 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1208 // Methods for support type inquiry through isa, cast, and dyn_cast:
1209 static inline bool classof(const ExtractElementInst *) { return true; }
1210 static inline bool classof(const Instruction *I) {
1211 return I->getOpcode() == Instruction::ExtractElement;
1213 static inline bool classof(const Value *V) {
1214 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1219 struct OperandTraits<ExtractElementInst> :
1220 public FixedNumOperandTraits<ExtractElementInst, 2> {
1223 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1225 //===----------------------------------------------------------------------===//
1226 // InsertElementInst Class
1227 //===----------------------------------------------------------------------===//
1229 /// InsertElementInst - This instruction inserts a single (scalar)
1230 /// element into a VectorType value
1232 class InsertElementInst : public Instruction {
1233 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1234 const Twine &NameStr = "",
1235 Instruction *InsertBefore = 0);
1236 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1237 const Twine &NameStr, BasicBlock *InsertAtEnd);
1239 virtual InsertElementInst *clone_impl() const;
1242 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1243 const Twine &NameStr = "",
1244 Instruction *InsertBefore = 0) {
1245 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1247 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1248 const Twine &NameStr,
1249 BasicBlock *InsertAtEnd) {
1250 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1253 /// isValidOperands - Return true if an insertelement instruction can be
1254 /// formed with the specified operands.
1255 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1258 /// getType - Overload to return most specific vector type.
1260 VectorType *getType() const {
1261 return reinterpret_cast<VectorType*>(Instruction::getType());
1264 /// Transparently provide more efficient getOperand methods.
1265 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1267 // Methods for support type inquiry through isa, cast, and dyn_cast:
1268 static inline bool classof(const InsertElementInst *) { return true; }
1269 static inline bool classof(const Instruction *I) {
1270 return I->getOpcode() == Instruction::InsertElement;
1272 static inline bool classof(const Value *V) {
1273 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1278 struct OperandTraits<InsertElementInst> :
1279 public FixedNumOperandTraits<InsertElementInst, 3> {
1282 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1284 //===----------------------------------------------------------------------===//
1285 // ShuffleVectorInst Class
1286 //===----------------------------------------------------------------------===//
1288 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1291 class ShuffleVectorInst : public Instruction {
1293 virtual ShuffleVectorInst *clone_impl() const;
1296 // allocate space for exactly three operands
1297 void *operator new(size_t s) {
1298 return User::operator new(s, 3);
1300 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1301 const Twine &NameStr = "",
1302 Instruction *InsertBefor = 0);
1303 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1304 const Twine &NameStr, BasicBlock *InsertAtEnd);
1306 /// isValidOperands - Return true if a shufflevector instruction can be
1307 /// formed with the specified operands.
1308 static bool isValidOperands(const Value *V1, const Value *V2,
1311 /// getType - Overload to return most specific vector type.
1313 VectorType *getType() const {
1314 return reinterpret_cast<VectorType*>(Instruction::getType());
1317 /// Transparently provide more efficient getOperand methods.
1318 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1320 /// getMaskValue - Return the index from the shuffle mask for the specified
1321 /// output result. This is either -1 if the element is undef or a number less
1322 /// than 2*numelements.
1323 int getMaskValue(unsigned i) const;
1325 // Methods for support type inquiry through isa, cast, and dyn_cast:
1326 static inline bool classof(const ShuffleVectorInst *) { return true; }
1327 static inline bool classof(const Instruction *I) {
1328 return I->getOpcode() == Instruction::ShuffleVector;
1330 static inline bool classof(const Value *V) {
1331 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1336 struct OperandTraits<ShuffleVectorInst> :
1337 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1340 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1342 //===----------------------------------------------------------------------===//
1343 // ExtractValueInst Class
1344 //===----------------------------------------------------------------------===//
1346 /// ExtractValueInst - This instruction extracts a struct member or array
1347 /// element value from an aggregate value.
1349 class ExtractValueInst : public UnaryInstruction {
1350 SmallVector<unsigned, 4> Indices;
1352 ExtractValueInst(const ExtractValueInst &EVI);
1353 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1355 /// Constructors - Create a extractvalue instruction with a base aggregate
1356 /// value and a list of indices. The first ctor can optionally insert before
1357 /// an existing instruction, the second appends the new instruction to the
1358 /// specified BasicBlock.
1359 inline ExtractValueInst(Value *Agg,
1360 ArrayRef<unsigned> Idxs,
1361 const Twine &NameStr,
1362 Instruction *InsertBefore);
1363 inline ExtractValueInst(Value *Agg,
1364 ArrayRef<unsigned> Idxs,
1365 const Twine &NameStr, BasicBlock *InsertAtEnd);
1367 // allocate space for exactly one operand
1368 void *operator new(size_t s) {
1369 return User::operator new(s, 1);
1372 virtual ExtractValueInst *clone_impl() const;
1375 static ExtractValueInst *Create(Value *Agg,
1376 ArrayRef<unsigned> Idxs,
1377 const Twine &NameStr = "",
1378 Instruction *InsertBefore = 0) {
1380 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1382 static ExtractValueInst *Create(Value *Agg,
1383 ArrayRef<unsigned> Idxs,
1384 const Twine &NameStr,
1385 BasicBlock *InsertAtEnd) {
1386 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1389 /// getIndexedType - Returns the type of the element that would be extracted
1390 /// with an extractvalue instruction with the specified parameters.
1392 /// Null is returned if the indices are invalid for the specified type.
1393 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
1395 typedef const unsigned* idx_iterator;
1396 inline idx_iterator idx_begin() const { return Indices.begin(); }
1397 inline idx_iterator idx_end() const { return Indices.end(); }
1399 Value *getAggregateOperand() {
1400 return getOperand(0);
1402 const Value *getAggregateOperand() const {
1403 return getOperand(0);
1405 static unsigned getAggregateOperandIndex() {
1406 return 0U; // get index for modifying correct operand
1409 ArrayRef<unsigned> getIndices() const {
1413 unsigned getNumIndices() const {
1414 return (unsigned)Indices.size();
1417 bool hasIndices() const {
1421 // Methods for support type inquiry through isa, cast, and dyn_cast:
1422 static inline bool classof(const ExtractValueInst *) { return true; }
1423 static inline bool classof(const Instruction *I) {
1424 return I->getOpcode() == Instruction::ExtractValue;
1426 static inline bool classof(const Value *V) {
1427 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1431 ExtractValueInst::ExtractValueInst(Value *Agg,
1432 ArrayRef<unsigned> Idxs,
1433 const Twine &NameStr,
1434 Instruction *InsertBefore)
1435 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1436 ExtractValue, Agg, InsertBefore) {
1437 init(Idxs, NameStr);
1439 ExtractValueInst::ExtractValueInst(Value *Agg,
1440 ArrayRef<unsigned> Idxs,
1441 const Twine &NameStr,
1442 BasicBlock *InsertAtEnd)
1443 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1444 ExtractValue, Agg, InsertAtEnd) {
1445 init(Idxs, NameStr);
1449 //===----------------------------------------------------------------------===//
1450 // InsertValueInst Class
1451 //===----------------------------------------------------------------------===//
1453 /// InsertValueInst - This instruction inserts a struct field of array element
1454 /// value into an aggregate value.
1456 class InsertValueInst : public Instruction {
1457 SmallVector<unsigned, 4> Indices;
1459 void *operator new(size_t, unsigned); // Do not implement
1460 InsertValueInst(const InsertValueInst &IVI);
1461 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1462 const Twine &NameStr);
1464 /// Constructors - Create a insertvalue instruction with a base aggregate
1465 /// value, a value to insert, and a list of indices. The first ctor can
1466 /// optionally insert before an existing instruction, the second appends
1467 /// the new instruction to the specified BasicBlock.
1468 inline InsertValueInst(Value *Agg, Value *Val,
1469 ArrayRef<unsigned> Idxs,
1470 const Twine &NameStr,
1471 Instruction *InsertBefore);
1472 inline InsertValueInst(Value *Agg, Value *Val,
1473 ArrayRef<unsigned> Idxs,
1474 const Twine &NameStr, BasicBlock *InsertAtEnd);
1476 /// Constructors - These two constructors are convenience methods because one
1477 /// and two index insertvalue instructions are so common.
1478 InsertValueInst(Value *Agg, Value *Val,
1479 unsigned Idx, const Twine &NameStr = "",
1480 Instruction *InsertBefore = 0);
1481 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1482 const Twine &NameStr, BasicBlock *InsertAtEnd);
1484 virtual InsertValueInst *clone_impl() const;
1486 // allocate space for exactly two operands
1487 void *operator new(size_t s) {
1488 return User::operator new(s, 2);
1491 static InsertValueInst *Create(Value *Agg, Value *Val,
1492 ArrayRef<unsigned> Idxs,
1493 const Twine &NameStr = "",
1494 Instruction *InsertBefore = 0) {
1495 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1497 static InsertValueInst *Create(Value *Agg, Value *Val,
1498 ArrayRef<unsigned> Idxs,
1499 const Twine &NameStr,
1500 BasicBlock *InsertAtEnd) {
1501 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1504 /// Transparently provide more efficient getOperand methods.
1505 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1507 typedef const unsigned* idx_iterator;
1508 inline idx_iterator idx_begin() const { return Indices.begin(); }
1509 inline idx_iterator idx_end() const { return Indices.end(); }
1511 Value *getAggregateOperand() {
1512 return getOperand(0);
1514 const Value *getAggregateOperand() const {
1515 return getOperand(0);
1517 static unsigned getAggregateOperandIndex() {
1518 return 0U; // get index for modifying correct operand
1521 Value *getInsertedValueOperand() {
1522 return getOperand(1);
1524 const Value *getInsertedValueOperand() const {
1525 return getOperand(1);
1527 static unsigned getInsertedValueOperandIndex() {
1528 return 1U; // get index for modifying correct operand
1531 ArrayRef<unsigned> getIndices() const {
1535 unsigned getNumIndices() const {
1536 return (unsigned)Indices.size();
1539 bool hasIndices() const {
1543 // Methods for support type inquiry through isa, cast, and dyn_cast:
1544 static inline bool classof(const InsertValueInst *) { return true; }
1545 static inline bool classof(const Instruction *I) {
1546 return I->getOpcode() == Instruction::InsertValue;
1548 static inline bool classof(const Value *V) {
1549 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1554 struct OperandTraits<InsertValueInst> :
1555 public FixedNumOperandTraits<InsertValueInst, 2> {
1558 InsertValueInst::InsertValueInst(Value *Agg,
1560 ArrayRef<unsigned> Idxs,
1561 const Twine &NameStr,
1562 Instruction *InsertBefore)
1563 : Instruction(Agg->getType(), InsertValue,
1564 OperandTraits<InsertValueInst>::op_begin(this),
1566 init(Agg, Val, Idxs, NameStr);
1568 InsertValueInst::InsertValueInst(Value *Agg,
1570 ArrayRef<unsigned> Idxs,
1571 const Twine &NameStr,
1572 BasicBlock *InsertAtEnd)
1573 : Instruction(Agg->getType(), InsertValue,
1574 OperandTraits<InsertValueInst>::op_begin(this),
1576 init(Agg, Val, Idxs, NameStr);
1579 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1581 //===----------------------------------------------------------------------===//
1583 //===----------------------------------------------------------------------===//
1585 // PHINode - The PHINode class is used to represent the magical mystical PHI
1586 // node, that can not exist in nature, but can be synthesized in a computer
1587 // scientist's overactive imagination.
1589 class PHINode : public Instruction {
1590 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1591 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1592 /// the number actually in use.
1593 unsigned ReservedSpace;
1594 PHINode(const PHINode &PN);
1595 // allocate space for exactly zero operands
1596 void *operator new(size_t s) {
1597 return User::operator new(s, 0);
1599 explicit PHINode(Type *Ty, unsigned NumReservedValues,
1600 const Twine &NameStr = "", Instruction *InsertBefore = 0)
1601 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1602 ReservedSpace(NumReservedValues) {
1604 OperandList = allocHungoffUses(ReservedSpace);
1607 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
1608 BasicBlock *InsertAtEnd)
1609 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1610 ReservedSpace(NumReservedValues) {
1612 OperandList = allocHungoffUses(ReservedSpace);
1615 // allocHungoffUses - this is more complicated than the generic
1616 // User::allocHungoffUses, because we have to allocate Uses for the incoming
1617 // values and pointers to the incoming blocks, all in one allocation.
1618 Use *allocHungoffUses(unsigned) const;
1620 virtual PHINode *clone_impl() const;
1622 /// Constructors - NumReservedValues is a hint for the number of incoming
1623 /// edges that this phi node will have (use 0 if you really have no idea).
1624 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
1625 const Twine &NameStr = "",
1626 Instruction *InsertBefore = 0) {
1627 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
1629 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
1630 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1631 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
1635 /// Provide fast operand accessors
1636 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1638 // Block iterator interface. This provides access to the list of incoming
1639 // basic blocks, which parallels the list of incoming values.
1641 typedef BasicBlock **block_iterator;
1642 typedef BasicBlock * const *const_block_iterator;
1644 block_iterator block_begin() {
1646 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
1647 return reinterpret_cast<block_iterator>(ref + 1);
1650 const_block_iterator block_begin() const {
1651 const Use::UserRef *ref =
1652 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
1653 return reinterpret_cast<const_block_iterator>(ref + 1);
1656 block_iterator block_end() {
1657 return block_begin() + getNumOperands();
1660 const_block_iterator block_end() const {
1661 return block_begin() + getNumOperands();
1664 /// getNumIncomingValues - Return the number of incoming edges
1666 unsigned getNumIncomingValues() const { return getNumOperands(); }
1668 /// getIncomingValue - Return incoming value number x
1670 Value *getIncomingValue(unsigned i) const {
1671 return getOperand(i);
1673 void setIncomingValue(unsigned i, Value *V) {
1676 static unsigned getOperandNumForIncomingValue(unsigned i) {
1679 static unsigned getIncomingValueNumForOperand(unsigned i) {
1683 /// getIncomingBlock - Return incoming basic block number @p i.
1685 BasicBlock *getIncomingBlock(unsigned i) const {
1686 return block_begin()[i];
1689 /// getIncomingBlock - Return incoming basic block corresponding
1690 /// to an operand of the PHI.
1692 BasicBlock *getIncomingBlock(const Use &U) const {
1693 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
1694 return getIncomingBlock(unsigned(&U - op_begin()));
1697 /// getIncomingBlock - Return incoming basic block corresponding
1698 /// to value use iterator.
1700 template <typename U>
1701 BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
1702 return getIncomingBlock(I.getUse());
1705 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1706 block_begin()[i] = BB;
1709 /// addIncoming - Add an incoming value to the end of the PHI list
1711 void addIncoming(Value *V, BasicBlock *BB) {
1712 assert(V && "PHI node got a null value!");
1713 assert(BB && "PHI node got a null basic block!");
1714 assert(getType() == V->getType() &&
1715 "All operands to PHI node must be the same type as the PHI node!");
1716 if (NumOperands == ReservedSpace)
1717 growOperands(); // Get more space!
1718 // Initialize some new operands.
1720 setIncomingValue(NumOperands - 1, V);
1721 setIncomingBlock(NumOperands - 1, BB);
1724 /// removeIncomingValue - Remove an incoming value. This is useful if a
1725 /// predecessor basic block is deleted. The value removed is returned.
1727 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1728 /// is true), the PHI node is destroyed and any uses of it are replaced with
1729 /// dummy values. The only time there should be zero incoming values to a PHI
1730 /// node is when the block is dead, so this strategy is sound.
1732 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1734 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
1735 int Idx = getBasicBlockIndex(BB);
1736 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1737 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1740 /// getBasicBlockIndex - Return the first index of the specified basic
1741 /// block in the value list for this PHI. Returns -1 if no instance.
1743 int getBasicBlockIndex(const BasicBlock *BB) const {
1744 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
1745 if (block_begin()[i] == BB)
1750 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1751 int Idx = getBasicBlockIndex(BB);
1752 assert(Idx >= 0 && "Invalid basic block argument!");
1753 return getIncomingValue(Idx);
1756 /// hasConstantValue - If the specified PHI node always merges together the
1757 /// same value, return the value, otherwise return null.
1758 Value *hasConstantValue() const;
1760 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1761 static inline bool classof(const PHINode *) { return true; }
1762 static inline bool classof(const Instruction *I) {
1763 return I->getOpcode() == Instruction::PHI;
1765 static inline bool classof(const Value *V) {
1766 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1769 void growOperands();
1773 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
1776 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
1778 //===----------------------------------------------------------------------===//
1779 // LandingPadInst Class
1780 //===----------------------------------------------------------------------===//
1782 //===---------------------------------------------------------------------------
1783 /// LandingPadInst - The landingpad instruction holds all of the information
1784 /// necessary to generate correct exception handling. The landingpad instruction
1785 /// cannot be moved from the top of a landing pad block, which itself is
1786 /// accessible only from the 'unwind' edge of an invoke.
1788 class LandingPadInst : public Instruction {
1789 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1790 /// the number actually in use.
1791 unsigned ReservedSpace;
1793 /// IsCleanup - True if the landingpad instruction is also a cleanup.
1795 LandingPadInst(const LandingPadInst &LP);
1797 enum ClauseType { Catch, Filter };
1799 /// ClauseIdxs - This indexes into the OperandList, indicating what the
1800 /// values are at a given index.
1801 SmallVector<ClauseType, 8> ClauseIdxs;
1803 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1804 // Allocate space for exactly zero operands.
1805 void *operator new(size_t s) {
1806 return User::operator new(s, 0);
1808 void growOperands();
1809 void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
1811 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
1812 unsigned NumReservedValues, const Twine &NameStr,
1813 Instruction *InsertBefore)
1814 : Instruction(RetTy, Instruction::LandingPad, 0, 0, InsertBefore),
1816 init(PersonalityFn, 1 + NumReservedValues, NameStr);
1818 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
1819 unsigned NumReservedValues, const Twine &NameStr,
1820 BasicBlock *InsertAtEnd)
1821 : Instruction(RetTy, Instruction::LandingPad, 0, 0, InsertAtEnd),
1823 init(PersonalityFn, 1 + NumReservedValues, NameStr);
1826 virtual LandingPadInst *clone_impl() const;
1828 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
1829 unsigned NumReservedValues,
1830 const Twine &NameStr = "",
1831 Instruction *InsertBefore = 0) {
1832 return new LandingPadInst(RetTy, PersonalityFn, NumReservedValues, NameStr,
1835 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
1836 unsigned NumReservedValues,
1837 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1838 return new LandingPadInst(RetTy, PersonalityFn, NumReservedValues, NameStr,
1843 /// Provide fast operand accessors
1844 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1846 /// getPersonalityFn - Get the personality function associated with this
1848 const Value *getPersonalityFn() const { return getOperand(0); }
1850 // Simple accessors.
1851 bool isCleanup() const { return IsCleanup; }
1852 void setCleanup(bool Val) { IsCleanup = Val; }
1854 /// addClause - Add a clause to the landing pad.
1855 void addClause(ClauseType CT, Value *ClauseVal);
1857 /// getClauseType - Return the type of the clause at this index. The two
1858 /// supported clauses are Catch and Filter.
1859 ClauseType getClauseType(unsigned I) const {
1860 assert(I < ClauseIdxs.size() && "Index too large!");
1861 return ClauseIdxs[I];
1864 /// getClauseValue - Return the value of the clause at this index.
1865 Value *getClauseValue(unsigned I) const {
1866 assert(I + 1 < getNumOperands() && "Index too large!");
1867 return OperandList[I + 1];
1870 /// getNumClauses - Get the number of clauses for this landing pad.
1871 unsigned getNumClauses() const { return getNumOperands() - 1; }
1873 /// reserveClauses - Grow the size of the operand list to accomodate the new
1874 /// number of clauses.
1875 void reserveClauses(unsigned Size);
1877 // Methods for support type inquiry through isa, cast, and dyn_cast:
1878 static inline bool classof(const LandingPadInst *) { return true; }
1879 static inline bool classof(const Instruction *I) {
1880 return I->getOpcode() == Instruction::LandingPad;
1882 static inline bool classof(const Value *V) {
1883 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1888 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
1891 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
1893 //===----------------------------------------------------------------------===//
1895 //===----------------------------------------------------------------------===//
1897 //===---------------------------------------------------------------------------
1898 /// ReturnInst - Return a value (possibly void), from a function. Execution
1899 /// does not continue in this function any longer.
1901 class ReturnInst : public TerminatorInst {
1902 ReturnInst(const ReturnInst &RI);
1905 // ReturnInst constructors:
1906 // ReturnInst() - 'ret void' instruction
1907 // ReturnInst( null) - 'ret void' instruction
1908 // ReturnInst(Value* X) - 'ret X' instruction
1909 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
1910 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1911 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
1912 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
1914 // NOTE: If the Value* passed is of type void then the constructor behaves as
1915 // if it was passed NULL.
1916 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
1917 Instruction *InsertBefore = 0);
1918 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
1919 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
1921 virtual ReturnInst *clone_impl() const;
1923 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
1924 Instruction *InsertBefore = 0) {
1925 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
1927 static ReturnInst* Create(LLVMContext &C, Value *retVal,
1928 BasicBlock *InsertAtEnd) {
1929 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
1931 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
1932 return new(0) ReturnInst(C, InsertAtEnd);
1934 virtual ~ReturnInst();
1936 /// Provide fast operand accessors
1937 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1939 /// Convenience accessor. Returns null if there is no return value.
1940 Value *getReturnValue() const {
1941 return getNumOperands() != 0 ? getOperand(0) : 0;
1944 unsigned getNumSuccessors() const { return 0; }
1946 // Methods for support type inquiry through isa, cast, and dyn_cast:
1947 static inline bool classof(const ReturnInst *) { return true; }
1948 static inline bool classof(const Instruction *I) {
1949 return (I->getOpcode() == Instruction::Ret);
1951 static inline bool classof(const Value *V) {
1952 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1955 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1956 virtual unsigned getNumSuccessorsV() const;
1957 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1961 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
1964 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
1966 //===----------------------------------------------------------------------===//
1968 //===----------------------------------------------------------------------===//
1970 //===---------------------------------------------------------------------------
1971 /// BranchInst - Conditional or Unconditional Branch instruction.
1973 class BranchInst : public TerminatorInst {
1974 /// Ops list - Branches are strange. The operands are ordered:
1975 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
1976 /// they don't have to check for cond/uncond branchness. These are mostly
1977 /// accessed relative from op_end().
1978 BranchInst(const BranchInst &BI);
1980 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1981 // BranchInst(BB *B) - 'br B'
1982 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1983 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1984 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1985 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1986 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1987 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1988 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1989 Instruction *InsertBefore = 0);
1990 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1991 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1992 BasicBlock *InsertAtEnd);
1994 virtual BranchInst *clone_impl() const;
1996 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
1997 return new(1) BranchInst(IfTrue, InsertBefore);
1999 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2000 Value *Cond, Instruction *InsertBefore = 0) {
2001 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2003 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2004 return new(1) BranchInst(IfTrue, InsertAtEnd);
2006 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2007 Value *Cond, BasicBlock *InsertAtEnd) {
2008 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2011 /// Transparently provide more efficient getOperand methods.
2012 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2014 bool isUnconditional() const { return getNumOperands() == 1; }
2015 bool isConditional() const { return getNumOperands() == 3; }
2017 Value *getCondition() const {
2018 assert(isConditional() && "Cannot get condition of an uncond branch!");
2022 void setCondition(Value *V) {
2023 assert(isConditional() && "Cannot set condition of unconditional branch!");
2027 unsigned getNumSuccessors() const { return 1+isConditional(); }
2029 BasicBlock *getSuccessor(unsigned i) const {
2030 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2031 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2034 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2035 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2036 *(&Op<-1>() - idx) = (Value*)NewSucc;
2039 // Methods for support type inquiry through isa, cast, and dyn_cast:
2040 static inline bool classof(const BranchInst *) { return true; }
2041 static inline bool classof(const Instruction *I) {
2042 return (I->getOpcode() == Instruction::Br);
2044 static inline bool classof(const Value *V) {
2045 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2048 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2049 virtual unsigned getNumSuccessorsV() const;
2050 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2054 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2057 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2059 //===----------------------------------------------------------------------===//
2061 //===----------------------------------------------------------------------===//
2063 //===---------------------------------------------------------------------------
2064 /// SwitchInst - Multiway switch
2066 class SwitchInst : public TerminatorInst {
2067 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2068 unsigned ReservedSpace;
2069 // Operand[0] = Value to switch on
2070 // Operand[1] = Default basic block destination
2071 // Operand[2n ] = Value to match
2072 // Operand[2n+1] = BasicBlock to go to on match
2073 SwitchInst(const SwitchInst &SI);
2074 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2075 void growOperands();
2076 // allocate space for exactly zero operands
2077 void *operator new(size_t s) {
2078 return User::operator new(s, 0);
2080 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2081 /// switch on and a default destination. The number of additional cases can
2082 /// be specified here to make memory allocation more efficient. This
2083 /// constructor can also autoinsert before another instruction.
2084 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2085 Instruction *InsertBefore);
2087 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2088 /// switch on and a default destination. The number of additional cases can
2089 /// be specified here to make memory allocation more efficient. This
2090 /// constructor also autoinserts at the end of the specified BasicBlock.
2091 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2092 BasicBlock *InsertAtEnd);
2094 virtual SwitchInst *clone_impl() const;
2096 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2097 unsigned NumCases, Instruction *InsertBefore = 0) {
2098 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2100 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2101 unsigned NumCases, BasicBlock *InsertAtEnd) {
2102 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2106 /// Provide fast operand accessors
2107 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2109 // Accessor Methods for Switch stmt
2110 Value *getCondition() const { return getOperand(0); }
2111 void setCondition(Value *V) { setOperand(0, V); }
2113 BasicBlock *getDefaultDest() const {
2114 return cast<BasicBlock>(getOperand(1));
2117 /// getNumCases - return the number of 'cases' in this switch instruction.
2118 /// Note that case #0 is always the default case.
2119 unsigned getNumCases() const {
2120 return getNumOperands()/2;
2123 /// getCaseValue - Return the specified case value. Note that case #0, the
2124 /// default destination, does not have a case value.
2125 ConstantInt *getCaseValue(unsigned i) {
2126 assert(i && i < getNumCases() && "Illegal case value to get!");
2127 return getSuccessorValue(i);
2130 /// getCaseValue - Return the specified case value. Note that case #0, the
2131 /// default destination, does not have a case value.
2132 const ConstantInt *getCaseValue(unsigned i) const {
2133 assert(i && i < getNumCases() && "Illegal case value to get!");
2134 return getSuccessorValue(i);
2137 /// findCaseValue - Search all of the case values for the specified constant.
2138 /// If it is explicitly handled, return the case number of it, otherwise
2139 /// return 0 to indicate that it is handled by the default handler.
2140 unsigned findCaseValue(const ConstantInt *C) const {
2141 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2142 if (getCaseValue(i) == C)
2147 /// findCaseDest - Finds the unique case value for a given successor. Returns
2148 /// null if the successor is not found, not unique, or is the default case.
2149 ConstantInt *findCaseDest(BasicBlock *BB) {
2150 if (BB == getDefaultDest()) return NULL;
2152 ConstantInt *CI = NULL;
2153 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2154 if (getSuccessor(i) == BB) {
2155 if (CI) return NULL; // Multiple cases lead to BB.
2156 else CI = getCaseValue(i);
2162 /// addCase - Add an entry to the switch instruction...
2164 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2166 /// removeCase - This method removes the specified successor from the switch
2167 /// instruction. Note that this cannot be used to remove the default
2168 /// destination (successor #0). Also note that this operation may reorder the
2169 /// remaining cases at index idx and above.
2171 void removeCase(unsigned idx);
2173 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2174 BasicBlock *getSuccessor(unsigned idx) const {
2175 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2176 return cast<BasicBlock>(getOperand(idx*2+1));
2178 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2179 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2180 setOperand(idx*2+1, (Value*)NewSucc);
2183 // getSuccessorValue - Return the value associated with the specified
2185 ConstantInt *getSuccessorValue(unsigned idx) const {
2186 assert(idx < getNumSuccessors() && "Successor # out of range!");
2187 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2190 // Methods for support type inquiry through isa, cast, and dyn_cast:
2191 static inline bool classof(const SwitchInst *) { return true; }
2192 static inline bool classof(const Instruction *I) {
2193 return I->getOpcode() == Instruction::Switch;
2195 static inline bool classof(const Value *V) {
2196 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2199 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2200 virtual unsigned getNumSuccessorsV() const;
2201 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2205 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2208 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2211 //===----------------------------------------------------------------------===//
2212 // IndirectBrInst Class
2213 //===----------------------------------------------------------------------===//
2215 //===---------------------------------------------------------------------------
2216 /// IndirectBrInst - Indirect Branch Instruction.
2218 class IndirectBrInst : public TerminatorInst {
2219 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2220 unsigned ReservedSpace;
2221 // Operand[0] = Value to switch on
2222 // Operand[1] = Default basic block destination
2223 // Operand[2n ] = Value to match
2224 // Operand[2n+1] = BasicBlock to go to on match
2225 IndirectBrInst(const IndirectBrInst &IBI);
2226 void init(Value *Address, unsigned NumDests);
2227 void growOperands();
2228 // allocate space for exactly zero operands
2229 void *operator new(size_t s) {
2230 return User::operator new(s, 0);
2232 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2233 /// Address to jump to. The number of expected destinations can be specified
2234 /// here to make memory allocation more efficient. This constructor can also
2235 /// autoinsert before another instruction.
2236 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2238 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2239 /// Address to jump to. The number of expected destinations can be specified
2240 /// here to make memory allocation more efficient. This constructor also
2241 /// autoinserts at the end of the specified BasicBlock.
2242 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2244 virtual IndirectBrInst *clone_impl() const;
2246 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2247 Instruction *InsertBefore = 0) {
2248 return new IndirectBrInst(Address, NumDests, InsertBefore);
2250 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2251 BasicBlock *InsertAtEnd) {
2252 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2256 /// Provide fast operand accessors.
2257 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2259 // Accessor Methods for IndirectBrInst instruction.
2260 Value *getAddress() { return getOperand(0); }
2261 const Value *getAddress() const { return getOperand(0); }
2262 void setAddress(Value *V) { setOperand(0, V); }
2265 /// getNumDestinations - return the number of possible destinations in this
2266 /// indirectbr instruction.
2267 unsigned getNumDestinations() const { return getNumOperands()-1; }
2269 /// getDestination - Return the specified destination.
2270 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2271 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2273 /// addDestination - Add a destination.
2275 void addDestination(BasicBlock *Dest);
2277 /// removeDestination - This method removes the specified successor from the
2278 /// indirectbr instruction.
2279 void removeDestination(unsigned i);
2281 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2282 BasicBlock *getSuccessor(unsigned i) const {
2283 return cast<BasicBlock>(getOperand(i+1));
2285 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2286 setOperand(i+1, (Value*)NewSucc);
2289 // Methods for support type inquiry through isa, cast, and dyn_cast:
2290 static inline bool classof(const IndirectBrInst *) { return true; }
2291 static inline bool classof(const Instruction *I) {
2292 return I->getOpcode() == Instruction::IndirectBr;
2294 static inline bool classof(const Value *V) {
2295 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2298 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2299 virtual unsigned getNumSuccessorsV() const;
2300 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2304 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2307 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2310 //===----------------------------------------------------------------------===//
2312 //===----------------------------------------------------------------------===//
2314 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2315 /// calling convention of the call.
2317 class InvokeInst : public TerminatorInst {
2318 AttrListPtr AttributeList;
2319 InvokeInst(const InvokeInst &BI);
2320 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2321 ArrayRef<Value *> Args, const Twine &NameStr);
2323 /// Construct an InvokeInst given a range of arguments.
2325 /// @brief Construct an InvokeInst from a range of arguments
2326 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2327 ArrayRef<Value *> Args, unsigned Values,
2328 const Twine &NameStr, Instruction *InsertBefore);
2330 /// Construct an InvokeInst given a range of arguments.
2332 /// @brief Construct an InvokeInst from a range of arguments
2333 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2334 ArrayRef<Value *> Args, unsigned Values,
2335 const Twine &NameStr, BasicBlock *InsertAtEnd);
2337 virtual InvokeInst *clone_impl() const;
2339 static InvokeInst *Create(Value *Func,
2340 BasicBlock *IfNormal, BasicBlock *IfException,
2341 ArrayRef<Value *> Args, const Twine &NameStr = "",
2342 Instruction *InsertBefore = 0) {
2343 unsigned Values = unsigned(Args.size()) + 3;
2344 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2345 Values, NameStr, InsertBefore);
2347 static InvokeInst *Create(Value *Func,
2348 BasicBlock *IfNormal, BasicBlock *IfException,
2349 ArrayRef<Value *> Args, const Twine &NameStr,
2350 BasicBlock *InsertAtEnd) {
2351 unsigned Values = unsigned(Args.size()) + 3;
2352 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2353 Values, NameStr, InsertAtEnd);
2356 /// Provide fast operand accessors
2357 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2359 /// getNumArgOperands - Return the number of invoke arguments.
2361 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2363 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2365 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2366 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2368 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2370 CallingConv::ID getCallingConv() const {
2371 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2373 void setCallingConv(CallingConv::ID CC) {
2374 setInstructionSubclassData(static_cast<unsigned>(CC));
2377 /// getAttributes - Return the parameter attributes for this invoke.
2379 const AttrListPtr &getAttributes() const { return AttributeList; }
2381 /// setAttributes - Set the parameter attributes for this invoke.
2383 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2385 /// addAttribute - adds the attribute to the list of attributes.
2386 void addAttribute(unsigned i, Attributes attr);
2388 /// removeAttribute - removes the attribute from the list of attributes.
2389 void removeAttribute(unsigned i, Attributes attr);
2391 /// @brief Determine whether the call or the callee has the given attribute.
2392 bool paramHasAttr(unsigned i, Attributes attr) const;
2394 /// @brief Extract the alignment for a call or parameter (0=unknown).
2395 unsigned getParamAlignment(unsigned i) const {
2396 return AttributeList.getParamAlignment(i);
2399 /// @brief Return true if the call should not be inlined.
2400 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2401 void setIsNoInline(bool Value = true) {
2402 if (Value) addAttribute(~0, Attribute::NoInline);
2403 else removeAttribute(~0, Attribute::NoInline);
2406 /// @brief Determine if the call does not access memory.
2407 bool doesNotAccessMemory() const {
2408 return paramHasAttr(~0, Attribute::ReadNone);
2410 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2411 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2412 else removeAttribute(~0, Attribute::ReadNone);
2415 /// @brief Determine if the call does not access or only reads memory.
2416 bool onlyReadsMemory() const {
2417 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2419 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2420 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2421 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2424 /// @brief Determine if the call cannot return.
2425 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
2426 void setDoesNotReturn(bool DoesNotReturn = true) {
2427 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2428 else removeAttribute(~0, Attribute::NoReturn);
2431 /// @brief Determine if the call cannot unwind.
2432 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
2433 void setDoesNotThrow(bool DoesNotThrow = true) {
2434 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2435 else removeAttribute(~0, Attribute::NoUnwind);
2438 /// @brief Determine if the call returns a structure through first
2439 /// pointer argument.
2440 bool hasStructRetAttr() const {
2441 // Be friendly and also check the callee.
2442 return paramHasAttr(1, Attribute::StructRet);
2445 /// @brief Determine if any call argument is an aggregate passed by value.
2446 bool hasByValArgument() const {
2447 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2450 /// getCalledFunction - Return the function called, or null if this is an
2451 /// indirect function invocation.
2453 Function *getCalledFunction() const {
2454 return dyn_cast<Function>(Op<-3>());
2457 /// getCalledValue - Get a pointer to the function that is invoked by this
2459 const Value *getCalledValue() const { return Op<-3>(); }
2460 Value *getCalledValue() { return Op<-3>(); }
2462 /// setCalledFunction - Set the function called.
2463 void setCalledFunction(Value* Fn) {
2467 // get*Dest - Return the destination basic blocks...
2468 BasicBlock *getNormalDest() const {
2469 return cast<BasicBlock>(Op<-2>());
2471 BasicBlock *getUnwindDest() const {
2472 return cast<BasicBlock>(Op<-1>());
2474 void setNormalDest(BasicBlock *B) {
2475 Op<-2>() = reinterpret_cast<Value*>(B);
2477 void setUnwindDest(BasicBlock *B) {
2478 Op<-1>() = reinterpret_cast<Value*>(B);
2481 // getLandingPad - Get the landingpad instruction from the landing pad block
2482 // (the unwind destination).
2483 LandingPadInst *getLandingPad() const;
2485 BasicBlock *getSuccessor(unsigned i) const {
2486 assert(i < 2 && "Successor # out of range for invoke!");
2487 return i == 0 ? getNormalDest() : getUnwindDest();
2490 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2491 assert(idx < 2 && "Successor # out of range for invoke!");
2492 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2495 unsigned getNumSuccessors() const { return 2; }
2497 // Methods for support type inquiry through isa, cast, and dyn_cast:
2498 static inline bool classof(const InvokeInst *) { return true; }
2499 static inline bool classof(const Instruction *I) {
2500 return (I->getOpcode() == Instruction::Invoke);
2502 static inline bool classof(const Value *V) {
2503 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2507 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2508 virtual unsigned getNumSuccessorsV() const;
2509 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2511 // Shadow Instruction::setInstructionSubclassData with a private forwarding
2512 // method so that subclasses cannot accidentally use it.
2513 void setInstructionSubclassData(unsigned short D) {
2514 Instruction::setInstructionSubclassData(D);
2519 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
2522 InvokeInst::InvokeInst(Value *Func,
2523 BasicBlock *IfNormal, BasicBlock *IfException,
2524 ArrayRef<Value *> Args, unsigned Values,
2525 const Twine &NameStr, Instruction *InsertBefore)
2526 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2527 ->getElementType())->getReturnType(),
2528 Instruction::Invoke,
2529 OperandTraits<InvokeInst>::op_end(this) - Values,
2530 Values, InsertBefore) {
2531 init(Func, IfNormal, IfException, Args, NameStr);
2533 InvokeInst::InvokeInst(Value *Func,
2534 BasicBlock *IfNormal, BasicBlock *IfException,
2535 ArrayRef<Value *> Args, unsigned Values,
2536 const Twine &NameStr, BasicBlock *InsertAtEnd)
2537 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2538 ->getElementType())->getReturnType(),
2539 Instruction::Invoke,
2540 OperandTraits<InvokeInst>::op_end(this) - Values,
2541 Values, InsertAtEnd) {
2542 init(Func, IfNormal, IfException, Args, NameStr);
2545 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2547 //===----------------------------------------------------------------------===//
2549 //===----------------------------------------------------------------------===//
2551 //===---------------------------------------------------------------------------
2552 /// UnwindInst - Immediately exit the current function, unwinding the stack
2553 /// until an invoke instruction is found.
2555 class UnwindInst : public TerminatorInst {
2556 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2558 virtual UnwindInst *clone_impl() const;
2560 // allocate space for exactly zero operands
2561 void *operator new(size_t s) {
2562 return User::operator new(s, 0);
2564 explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2565 explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2567 unsigned getNumSuccessors() const { return 0; }
2569 // Methods for support type inquiry through isa, cast, and dyn_cast:
2570 static inline bool classof(const UnwindInst *) { return true; }
2571 static inline bool classof(const Instruction *I) {
2572 return I->getOpcode() == Instruction::Unwind;
2574 static inline bool classof(const Value *V) {
2575 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2578 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2579 virtual unsigned getNumSuccessorsV() const;
2580 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2583 //===----------------------------------------------------------------------===//
2585 //===----------------------------------------------------------------------===//
2587 //===---------------------------------------------------------------------------
2588 /// ResumeInst - Resume the propagation of an exception.
2590 class ResumeInst : public TerminatorInst {
2591 ResumeInst(const ResumeInst &RI);
2593 explicit ResumeInst(LLVMContext &C, Value *Exn, Instruction *InsertBefore=0);
2594 ResumeInst(LLVMContext &C, Value *Exn, BasicBlock *InsertAtEnd);
2596 virtual ResumeInst *clone_impl() const;
2598 static ResumeInst *Create(LLVMContext &C, Value *Exn,
2599 Instruction *InsertBefore = 0) {
2600 return new(1) ResumeInst(C, Exn, InsertBefore);
2602 static ResumeInst *Create(LLVMContext &C, Value *Exn,
2603 BasicBlock *InsertAtEnd) {
2604 return new(1) ResumeInst(C, Exn, InsertAtEnd);
2607 /// Provide fast operand accessors
2608 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2610 /// Convenience accessor.
2611 Value *getResumeValue() const { return Op<0>(); }
2613 unsigned getNumSuccessors() const { return 0; }
2615 // Methods for support type inquiry through isa, cast, and dyn_cast:
2616 static inline bool classof(const ResumeInst *) { return true; }
2617 static inline bool classof(const Instruction *I) {
2618 return I->getOpcode() == Instruction::Resume;
2620 static inline bool classof(const Value *V) {
2621 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2624 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2625 virtual unsigned getNumSuccessorsV() const;
2626 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2630 struct OperandTraits<ResumeInst> :
2631 public FixedNumOperandTraits<ResumeInst, 1> {
2634 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
2636 //===----------------------------------------------------------------------===//
2637 // UnreachableInst Class
2638 //===----------------------------------------------------------------------===//
2640 //===---------------------------------------------------------------------------
2641 /// UnreachableInst - This function has undefined behavior. In particular, the
2642 /// presence of this instruction indicates some higher level knowledge that the
2643 /// end of the block cannot be reached.
2645 class UnreachableInst : public TerminatorInst {
2646 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2648 virtual UnreachableInst *clone_impl() const;
2651 // allocate space for exactly zero operands
2652 void *operator new(size_t s) {
2653 return User::operator new(s, 0);
2655 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2656 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2658 unsigned getNumSuccessors() const { return 0; }
2660 // Methods for support type inquiry through isa, cast, and dyn_cast:
2661 static inline bool classof(const UnreachableInst *) { return true; }
2662 static inline bool classof(const Instruction *I) {
2663 return I->getOpcode() == Instruction::Unreachable;
2665 static inline bool classof(const Value *V) {
2666 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2669 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2670 virtual unsigned getNumSuccessorsV() const;
2671 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2674 //===----------------------------------------------------------------------===//
2676 //===----------------------------------------------------------------------===//
2678 /// @brief This class represents a truncation of integer types.
2679 class TruncInst : public CastInst {
2681 /// @brief Clone an identical TruncInst
2682 virtual TruncInst *clone_impl() const;
2685 /// @brief Constructor with insert-before-instruction semantics
2687 Value *S, ///< The value to be truncated
2688 Type *Ty, ///< The (smaller) type to truncate to
2689 const Twine &NameStr = "", ///< A name for the new instruction
2690 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2693 /// @brief Constructor with insert-at-end-of-block semantics
2695 Value *S, ///< The value to be truncated
2696 Type *Ty, ///< The (smaller) type to truncate to
2697 const Twine &NameStr, ///< A name for the new instruction
2698 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2701 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2702 static inline bool classof(const TruncInst *) { return true; }
2703 static inline bool classof(const Instruction *I) {
2704 return I->getOpcode() == Trunc;
2706 static inline bool classof(const Value *V) {
2707 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2711 //===----------------------------------------------------------------------===//
2713 //===----------------------------------------------------------------------===//
2715 /// @brief This class represents zero extension of integer types.
2716 class ZExtInst : public CastInst {
2718 /// @brief Clone an identical ZExtInst
2719 virtual ZExtInst *clone_impl() const;
2722 /// @brief Constructor with insert-before-instruction semantics
2724 Value *S, ///< The value to be zero extended
2725 Type *Ty, ///< The type to zero extend to
2726 const Twine &NameStr = "", ///< A name for the new instruction
2727 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2730 /// @brief Constructor with insert-at-end semantics.
2732 Value *S, ///< The value to be zero extended
2733 Type *Ty, ///< The type to zero extend to
2734 const Twine &NameStr, ///< A name for the new instruction
2735 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2738 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2739 static inline bool classof(const ZExtInst *) { return true; }
2740 static inline bool classof(const Instruction *I) {
2741 return I->getOpcode() == ZExt;
2743 static inline bool classof(const Value *V) {
2744 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2748 //===----------------------------------------------------------------------===//
2750 //===----------------------------------------------------------------------===//
2752 /// @brief This class represents a sign extension of integer types.
2753 class SExtInst : public CastInst {
2755 /// @brief Clone an identical SExtInst
2756 virtual SExtInst *clone_impl() const;
2759 /// @brief Constructor with insert-before-instruction semantics
2761 Value *S, ///< The value to be sign extended
2762 Type *Ty, ///< The type to sign extend to
2763 const Twine &NameStr = "", ///< A name for the new instruction
2764 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2767 /// @brief Constructor with insert-at-end-of-block semantics
2769 Value *S, ///< The value to be sign extended
2770 Type *Ty, ///< The type to sign extend to
2771 const Twine &NameStr, ///< A name for the new instruction
2772 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2775 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2776 static inline bool classof(const SExtInst *) { return true; }
2777 static inline bool classof(const Instruction *I) {
2778 return I->getOpcode() == SExt;
2780 static inline bool classof(const Value *V) {
2781 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2785 //===----------------------------------------------------------------------===//
2786 // FPTruncInst Class
2787 //===----------------------------------------------------------------------===//
2789 /// @brief This class represents a truncation of floating point types.
2790 class FPTruncInst : public CastInst {
2792 /// @brief Clone an identical FPTruncInst
2793 virtual FPTruncInst *clone_impl() const;
2796 /// @brief Constructor with insert-before-instruction semantics
2798 Value *S, ///< The value to be truncated
2799 Type *Ty, ///< The type to truncate to
2800 const Twine &NameStr = "", ///< A name for the new instruction
2801 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2804 /// @brief Constructor with insert-before-instruction semantics
2806 Value *S, ///< The value to be truncated
2807 Type *Ty, ///< The type to truncate to
2808 const Twine &NameStr, ///< A name for the new instruction
2809 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2812 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2813 static inline bool classof(const FPTruncInst *) { return true; }
2814 static inline bool classof(const Instruction *I) {
2815 return I->getOpcode() == FPTrunc;
2817 static inline bool classof(const Value *V) {
2818 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2822 //===----------------------------------------------------------------------===//
2824 //===----------------------------------------------------------------------===//
2826 /// @brief This class represents an extension of floating point types.
2827 class FPExtInst : public CastInst {
2829 /// @brief Clone an identical FPExtInst
2830 virtual FPExtInst *clone_impl() const;
2833 /// @brief Constructor with insert-before-instruction semantics
2835 Value *S, ///< The value to be extended
2836 Type *Ty, ///< The type to extend to
2837 const Twine &NameStr = "", ///< A name for the new instruction
2838 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2841 /// @brief Constructor with insert-at-end-of-block semantics
2843 Value *S, ///< The value to be extended
2844 Type *Ty, ///< The type to extend to
2845 const Twine &NameStr, ///< A name for the new instruction
2846 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2849 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2850 static inline bool classof(const FPExtInst *) { return true; }
2851 static inline bool classof(const Instruction *I) {
2852 return I->getOpcode() == FPExt;
2854 static inline bool classof(const Value *V) {
2855 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2859 //===----------------------------------------------------------------------===//
2861 //===----------------------------------------------------------------------===//
2863 /// @brief This class represents a cast unsigned integer to floating point.
2864 class UIToFPInst : public CastInst {
2866 /// @brief Clone an identical UIToFPInst
2867 virtual UIToFPInst *clone_impl() const;
2870 /// @brief Constructor with insert-before-instruction semantics
2872 Value *S, ///< The value to be converted
2873 Type *Ty, ///< The type to convert to
2874 const Twine &NameStr = "", ///< A name for the new instruction
2875 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2878 /// @brief Constructor with insert-at-end-of-block semantics
2880 Value *S, ///< The value to be converted
2881 Type *Ty, ///< The type to convert to
2882 const Twine &NameStr, ///< A name for the new instruction
2883 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2886 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2887 static inline bool classof(const UIToFPInst *) { return true; }
2888 static inline bool classof(const Instruction *I) {
2889 return I->getOpcode() == UIToFP;
2891 static inline bool classof(const Value *V) {
2892 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2896 //===----------------------------------------------------------------------===//
2898 //===----------------------------------------------------------------------===//
2900 /// @brief This class represents a cast from signed integer to floating point.
2901 class SIToFPInst : public CastInst {
2903 /// @brief Clone an identical SIToFPInst
2904 virtual SIToFPInst *clone_impl() const;
2907 /// @brief Constructor with insert-before-instruction semantics
2909 Value *S, ///< The value to be converted
2910 Type *Ty, ///< The type to convert to
2911 const Twine &NameStr = "", ///< A name for the new instruction
2912 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2915 /// @brief Constructor with insert-at-end-of-block semantics
2917 Value *S, ///< The value to be converted
2918 Type *Ty, ///< The type to convert to
2919 const Twine &NameStr, ///< A name for the new instruction
2920 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2923 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2924 static inline bool classof(const SIToFPInst *) { return true; }
2925 static inline bool classof(const Instruction *I) {
2926 return I->getOpcode() == SIToFP;
2928 static inline bool classof(const Value *V) {
2929 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2933 //===----------------------------------------------------------------------===//
2935 //===----------------------------------------------------------------------===//
2937 /// @brief This class represents a cast from floating point to unsigned integer
2938 class FPToUIInst : public CastInst {
2940 /// @brief Clone an identical FPToUIInst
2941 virtual FPToUIInst *clone_impl() const;
2944 /// @brief Constructor with insert-before-instruction semantics
2946 Value *S, ///< The value to be converted
2947 Type *Ty, ///< The type to convert to
2948 const Twine &NameStr = "", ///< A name for the new instruction
2949 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2952 /// @brief Constructor with insert-at-end-of-block semantics
2954 Value *S, ///< The value to be converted
2955 Type *Ty, ///< The type to convert to
2956 const Twine &NameStr, ///< A name for the new instruction
2957 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
2960 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2961 static inline bool classof(const FPToUIInst *) { return true; }
2962 static inline bool classof(const Instruction *I) {
2963 return I->getOpcode() == FPToUI;
2965 static inline bool classof(const Value *V) {
2966 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2970 //===----------------------------------------------------------------------===//
2972 //===----------------------------------------------------------------------===//
2974 /// @brief This class represents a cast from floating point to signed integer.
2975 class FPToSIInst : public CastInst {
2977 /// @brief Clone an identical FPToSIInst
2978 virtual FPToSIInst *clone_impl() const;
2981 /// @brief Constructor with insert-before-instruction semantics
2983 Value *S, ///< The value to be converted
2984 Type *Ty, ///< The type to convert to
2985 const Twine &NameStr = "", ///< A name for the new instruction
2986 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2989 /// @brief Constructor with insert-at-end-of-block semantics
2991 Value *S, ///< The value to be converted
2992 Type *Ty, ///< The type to convert to
2993 const Twine &NameStr, ///< A name for the new instruction
2994 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2997 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2998 static inline bool classof(const FPToSIInst *) { return true; }
2999 static inline bool classof(const Instruction *I) {
3000 return I->getOpcode() == FPToSI;
3002 static inline bool classof(const Value *V) {
3003 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3007 //===----------------------------------------------------------------------===//
3008 // IntToPtrInst Class
3009 //===----------------------------------------------------------------------===//
3011 /// @brief This class represents a cast from an integer to a pointer.
3012 class IntToPtrInst : public CastInst {
3014 /// @brief Constructor with insert-before-instruction semantics
3016 Value *S, ///< The value to be converted
3017 Type *Ty, ///< The type to convert to
3018 const Twine &NameStr = "", ///< A name for the new instruction
3019 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3022 /// @brief Constructor with insert-at-end-of-block semantics
3024 Value *S, ///< The value to be converted
3025 Type *Ty, ///< The type to convert to
3026 const Twine &NameStr, ///< A name for the new instruction
3027 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3030 /// @brief Clone an identical IntToPtrInst
3031 virtual IntToPtrInst *clone_impl() const;
3033 // Methods for support type inquiry through isa, cast, and dyn_cast:
3034 static inline bool classof(const IntToPtrInst *) { return true; }
3035 static inline bool classof(const Instruction *I) {
3036 return I->getOpcode() == IntToPtr;
3038 static inline bool classof(const Value *V) {
3039 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3043 //===----------------------------------------------------------------------===//
3044 // PtrToIntInst Class
3045 //===----------------------------------------------------------------------===//
3047 /// @brief This class represents a cast from a pointer to an integer
3048 class PtrToIntInst : public CastInst {
3050 /// @brief Clone an identical PtrToIntInst
3051 virtual PtrToIntInst *clone_impl() const;
3054 /// @brief Constructor with insert-before-instruction semantics
3056 Value *S, ///< The value to be converted
3057 Type *Ty, ///< The type to convert to
3058 const Twine &NameStr = "", ///< A name for the new instruction
3059 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3062 /// @brief Constructor with insert-at-end-of-block semantics
3064 Value *S, ///< The value to be converted
3065 Type *Ty, ///< The type to convert to
3066 const Twine &NameStr, ///< A name for the new instruction
3067 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3070 // Methods for support type inquiry through isa, cast, and dyn_cast:
3071 static inline bool classof(const PtrToIntInst *) { return true; }
3072 static inline bool classof(const Instruction *I) {
3073 return I->getOpcode() == PtrToInt;
3075 static inline bool classof(const Value *V) {
3076 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3080 //===----------------------------------------------------------------------===//
3081 // BitCastInst Class
3082 //===----------------------------------------------------------------------===//
3084 /// @brief This class represents a no-op cast from one type to another.
3085 class BitCastInst : public CastInst {
3087 /// @brief Clone an identical BitCastInst
3088 virtual BitCastInst *clone_impl() const;
3091 /// @brief Constructor with insert-before-instruction semantics
3093 Value *S, ///< The value to be casted
3094 Type *Ty, ///< The type to casted to
3095 const Twine &NameStr = "", ///< A name for the new instruction
3096 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3099 /// @brief Constructor with insert-at-end-of-block semantics
3101 Value *S, ///< The value to be casted
3102 Type *Ty, ///< The type to casted to
3103 const Twine &NameStr, ///< A name for the new instruction
3104 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3107 // Methods for support type inquiry through isa, cast, and dyn_cast:
3108 static inline bool classof(const BitCastInst *) { return true; }
3109 static inline bool classof(const Instruction *I) {
3110 return I->getOpcode() == BitCast;
3112 static inline bool classof(const Value *V) {
3113 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3117 } // End llvm namespace