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)
1779 //===----------------------------------------------------------------------===//
1781 //===----------------------------------------------------------------------===//
1783 //===---------------------------------------------------------------------------
1784 /// ReturnInst - Return a value (possibly void), from a function. Execution
1785 /// does not continue in this function any longer.
1787 class ReturnInst : public TerminatorInst {
1788 ReturnInst(const ReturnInst &RI);
1791 // ReturnInst constructors:
1792 // ReturnInst() - 'ret void' instruction
1793 // ReturnInst( null) - 'ret void' instruction
1794 // ReturnInst(Value* X) - 'ret X' instruction
1795 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
1796 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1797 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
1798 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
1800 // NOTE: If the Value* passed is of type void then the constructor behaves as
1801 // if it was passed NULL.
1802 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
1803 Instruction *InsertBefore = 0);
1804 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
1805 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
1807 virtual ReturnInst *clone_impl() const;
1809 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
1810 Instruction *InsertBefore = 0) {
1811 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
1813 static ReturnInst* Create(LLVMContext &C, Value *retVal,
1814 BasicBlock *InsertAtEnd) {
1815 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
1817 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
1818 return new(0) ReturnInst(C, InsertAtEnd);
1820 virtual ~ReturnInst();
1822 /// Provide fast operand accessors
1823 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1825 /// Convenience accessor. Returns null if there is no return value.
1826 Value *getReturnValue() const {
1827 return getNumOperands() != 0 ? getOperand(0) : 0;
1830 unsigned getNumSuccessors() const { return 0; }
1832 // Methods for support type inquiry through isa, cast, and dyn_cast:
1833 static inline bool classof(const ReturnInst *) { return true; }
1834 static inline bool classof(const Instruction *I) {
1835 return (I->getOpcode() == Instruction::Ret);
1837 static inline bool classof(const Value *V) {
1838 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1841 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1842 virtual unsigned getNumSuccessorsV() const;
1843 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1847 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
1850 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
1852 //===----------------------------------------------------------------------===//
1854 //===----------------------------------------------------------------------===//
1856 //===---------------------------------------------------------------------------
1857 /// BranchInst - Conditional or Unconditional Branch instruction.
1859 class BranchInst : public TerminatorInst {
1860 /// Ops list - Branches are strange. The operands are ordered:
1861 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
1862 /// they don't have to check for cond/uncond branchness. These are mostly
1863 /// accessed relative from op_end().
1864 BranchInst(const BranchInst &BI);
1866 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1867 // BranchInst(BB *B) - 'br B'
1868 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1869 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1870 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1871 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1872 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1873 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
1874 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1875 Instruction *InsertBefore = 0);
1876 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
1877 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1878 BasicBlock *InsertAtEnd);
1880 virtual BranchInst *clone_impl() const;
1882 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
1883 return new(1) BranchInst(IfTrue, InsertBefore);
1885 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
1886 Value *Cond, Instruction *InsertBefore = 0) {
1887 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
1889 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
1890 return new(1) BranchInst(IfTrue, InsertAtEnd);
1892 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
1893 Value *Cond, BasicBlock *InsertAtEnd) {
1894 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
1897 /// Transparently provide more efficient getOperand methods.
1898 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1900 bool isUnconditional() const { return getNumOperands() == 1; }
1901 bool isConditional() const { return getNumOperands() == 3; }
1903 Value *getCondition() const {
1904 assert(isConditional() && "Cannot get condition of an uncond branch!");
1908 void setCondition(Value *V) {
1909 assert(isConditional() && "Cannot set condition of unconditional branch!");
1913 unsigned getNumSuccessors() const { return 1+isConditional(); }
1915 BasicBlock *getSuccessor(unsigned i) const {
1916 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1917 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
1920 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1921 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1922 *(&Op<-1>() - idx) = (Value*)NewSucc;
1925 // Methods for support type inquiry through isa, cast, and dyn_cast:
1926 static inline bool classof(const BranchInst *) { return true; }
1927 static inline bool classof(const Instruction *I) {
1928 return (I->getOpcode() == Instruction::Br);
1930 static inline bool classof(const Value *V) {
1931 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1934 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1935 virtual unsigned getNumSuccessorsV() const;
1936 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1940 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
1943 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
1945 //===----------------------------------------------------------------------===//
1947 //===----------------------------------------------------------------------===//
1949 //===---------------------------------------------------------------------------
1950 /// SwitchInst - Multiway switch
1952 class SwitchInst : public TerminatorInst {
1953 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1954 unsigned ReservedSpace;
1955 // Operand[0] = Value to switch on
1956 // Operand[1] = Default basic block destination
1957 // Operand[2n ] = Value to match
1958 // Operand[2n+1] = BasicBlock to go to on match
1959 SwitchInst(const SwitchInst &SI);
1960 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
1961 void growOperands();
1962 // allocate space for exactly zero operands
1963 void *operator new(size_t s) {
1964 return User::operator new(s, 0);
1966 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1967 /// switch on and a default destination. The number of additional cases can
1968 /// be specified here to make memory allocation more efficient. This
1969 /// constructor can also autoinsert before another instruction.
1970 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1971 Instruction *InsertBefore);
1973 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1974 /// switch on and a default destination. The number of additional cases can
1975 /// be specified here to make memory allocation more efficient. This
1976 /// constructor also autoinserts at the end of the specified BasicBlock.
1977 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1978 BasicBlock *InsertAtEnd);
1980 virtual SwitchInst *clone_impl() const;
1982 static SwitchInst *Create(Value *Value, BasicBlock *Default,
1983 unsigned NumCases, Instruction *InsertBefore = 0) {
1984 return new SwitchInst(Value, Default, NumCases, InsertBefore);
1986 static SwitchInst *Create(Value *Value, BasicBlock *Default,
1987 unsigned NumCases, BasicBlock *InsertAtEnd) {
1988 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
1992 /// Provide fast operand accessors
1993 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1995 // Accessor Methods for Switch stmt
1996 Value *getCondition() const { return getOperand(0); }
1997 void setCondition(Value *V) { setOperand(0, V); }
1999 BasicBlock *getDefaultDest() const {
2000 return cast<BasicBlock>(getOperand(1));
2003 /// getNumCases - return the number of 'cases' in this switch instruction.
2004 /// Note that case #0 is always the default case.
2005 unsigned getNumCases() const {
2006 return getNumOperands()/2;
2009 /// getCaseValue - Return the specified case value. Note that case #0, the
2010 /// default destination, does not have a case value.
2011 ConstantInt *getCaseValue(unsigned i) {
2012 assert(i && i < getNumCases() && "Illegal case value to get!");
2013 return getSuccessorValue(i);
2016 /// getCaseValue - Return the specified case value. Note that case #0, the
2017 /// default destination, does not have a case value.
2018 const ConstantInt *getCaseValue(unsigned i) const {
2019 assert(i && i < getNumCases() && "Illegal case value to get!");
2020 return getSuccessorValue(i);
2023 /// findCaseValue - Search all of the case values for the specified constant.
2024 /// If it is explicitly handled, return the case number of it, otherwise
2025 /// return 0 to indicate that it is handled by the default handler.
2026 unsigned findCaseValue(const ConstantInt *C) const {
2027 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2028 if (getCaseValue(i) == C)
2033 /// findCaseDest - Finds the unique case value for a given successor. Returns
2034 /// null if the successor is not found, not unique, or is the default case.
2035 ConstantInt *findCaseDest(BasicBlock *BB) {
2036 if (BB == getDefaultDest()) return NULL;
2038 ConstantInt *CI = NULL;
2039 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2040 if (getSuccessor(i) == BB) {
2041 if (CI) return NULL; // Multiple cases lead to BB.
2042 else CI = getCaseValue(i);
2048 /// addCase - Add an entry to the switch instruction...
2050 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2052 /// removeCase - This method removes the specified successor from the switch
2053 /// instruction. Note that this cannot be used to remove the default
2054 /// destination (successor #0). Also note that this operation may reorder the
2055 /// remaining cases at index idx and above.
2057 void removeCase(unsigned idx);
2059 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2060 BasicBlock *getSuccessor(unsigned idx) const {
2061 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2062 return cast<BasicBlock>(getOperand(idx*2+1));
2064 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2065 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2066 setOperand(idx*2+1, (Value*)NewSucc);
2069 // getSuccessorValue - Return the value associated with the specified
2071 ConstantInt *getSuccessorValue(unsigned idx) const {
2072 assert(idx < getNumSuccessors() && "Successor # out of range!");
2073 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2076 // Methods for support type inquiry through isa, cast, and dyn_cast:
2077 static inline bool classof(const SwitchInst *) { return true; }
2078 static inline bool classof(const Instruction *I) {
2079 return I->getOpcode() == Instruction::Switch;
2081 static inline bool classof(const Value *V) {
2082 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2085 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2086 virtual unsigned getNumSuccessorsV() const;
2087 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2091 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2094 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2097 //===----------------------------------------------------------------------===//
2098 // IndirectBrInst Class
2099 //===----------------------------------------------------------------------===//
2101 //===---------------------------------------------------------------------------
2102 /// IndirectBrInst - Indirect Branch Instruction.
2104 class IndirectBrInst : public TerminatorInst {
2105 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2106 unsigned ReservedSpace;
2107 // Operand[0] = Value to switch on
2108 // Operand[1] = Default basic block destination
2109 // Operand[2n ] = Value to match
2110 // Operand[2n+1] = BasicBlock to go to on match
2111 IndirectBrInst(const IndirectBrInst &IBI);
2112 void init(Value *Address, unsigned NumDests);
2113 void growOperands();
2114 // allocate space for exactly zero operands
2115 void *operator new(size_t s) {
2116 return User::operator new(s, 0);
2118 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2119 /// Address to jump to. The number of expected destinations can be specified
2120 /// here to make memory allocation more efficient. This constructor can also
2121 /// autoinsert before another instruction.
2122 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2124 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2125 /// Address to jump to. The number of expected destinations can be specified
2126 /// here to make memory allocation more efficient. This constructor also
2127 /// autoinserts at the end of the specified BasicBlock.
2128 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2130 virtual IndirectBrInst *clone_impl() const;
2132 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2133 Instruction *InsertBefore = 0) {
2134 return new IndirectBrInst(Address, NumDests, InsertBefore);
2136 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2137 BasicBlock *InsertAtEnd) {
2138 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2142 /// Provide fast operand accessors.
2143 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2145 // Accessor Methods for IndirectBrInst instruction.
2146 Value *getAddress() { return getOperand(0); }
2147 const Value *getAddress() const { return getOperand(0); }
2148 void setAddress(Value *V) { setOperand(0, V); }
2151 /// getNumDestinations - return the number of possible destinations in this
2152 /// indirectbr instruction.
2153 unsigned getNumDestinations() const { return getNumOperands()-1; }
2155 /// getDestination - Return the specified destination.
2156 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2157 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2159 /// addDestination - Add a destination.
2161 void addDestination(BasicBlock *Dest);
2163 /// removeDestination - This method removes the specified successor from the
2164 /// indirectbr instruction.
2165 void removeDestination(unsigned i);
2167 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2168 BasicBlock *getSuccessor(unsigned i) const {
2169 return cast<BasicBlock>(getOperand(i+1));
2171 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2172 setOperand(i+1, (Value*)NewSucc);
2175 // Methods for support type inquiry through isa, cast, and dyn_cast:
2176 static inline bool classof(const IndirectBrInst *) { return true; }
2177 static inline bool classof(const Instruction *I) {
2178 return I->getOpcode() == Instruction::IndirectBr;
2180 static inline bool classof(const Value *V) {
2181 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2184 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2185 virtual unsigned getNumSuccessorsV() const;
2186 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2190 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2193 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2196 //===----------------------------------------------------------------------===//
2198 //===----------------------------------------------------------------------===//
2200 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2201 /// calling convention of the call.
2203 class InvokeInst : public TerminatorInst {
2204 AttrListPtr AttributeList;
2205 InvokeInst(const InvokeInst &BI);
2206 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2207 ArrayRef<Value *> Args, const Twine &NameStr);
2209 /// Construct an InvokeInst given a range of arguments.
2211 /// @brief Construct an InvokeInst from a range of arguments
2212 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2213 ArrayRef<Value *> Args, unsigned Values,
2214 const Twine &NameStr, Instruction *InsertBefore);
2216 /// Construct an InvokeInst given a range of arguments.
2218 /// @brief Construct an InvokeInst from a range of arguments
2219 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2220 ArrayRef<Value *> Args, unsigned Values,
2221 const Twine &NameStr, BasicBlock *InsertAtEnd);
2223 virtual InvokeInst *clone_impl() const;
2225 static InvokeInst *Create(Value *Func,
2226 BasicBlock *IfNormal, BasicBlock *IfException,
2227 ArrayRef<Value *> Args, const Twine &NameStr = "",
2228 Instruction *InsertBefore = 0) {
2229 unsigned Values = unsigned(Args.size()) + 3;
2230 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2231 Values, NameStr, InsertBefore);
2233 static InvokeInst *Create(Value *Func,
2234 BasicBlock *IfNormal, BasicBlock *IfException,
2235 ArrayRef<Value *> Args, const Twine &NameStr,
2236 BasicBlock *InsertAtEnd) {
2237 unsigned Values = unsigned(Args.size()) + 3;
2238 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2239 Values, NameStr, InsertAtEnd);
2242 /// Provide fast operand accessors
2243 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2245 /// getNumArgOperands - Return the number of invoke arguments.
2247 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2249 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2251 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2252 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2254 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2256 CallingConv::ID getCallingConv() const {
2257 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2259 void setCallingConv(CallingConv::ID CC) {
2260 setInstructionSubclassData(static_cast<unsigned>(CC));
2263 /// getAttributes - Return the parameter attributes for this invoke.
2265 const AttrListPtr &getAttributes() const { return AttributeList; }
2267 /// setAttributes - Set the parameter attributes for this invoke.
2269 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2271 /// addAttribute - adds the attribute to the list of attributes.
2272 void addAttribute(unsigned i, Attributes attr);
2274 /// removeAttribute - removes the attribute from the list of attributes.
2275 void removeAttribute(unsigned i, Attributes attr);
2277 /// @brief Determine whether the call or the callee has the given attribute.
2278 bool paramHasAttr(unsigned i, Attributes attr) const;
2280 /// @brief Extract the alignment for a call or parameter (0=unknown).
2281 unsigned getParamAlignment(unsigned i) const {
2282 return AttributeList.getParamAlignment(i);
2285 /// @brief Return true if the call should not be inlined.
2286 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2287 void setIsNoInline(bool Value = true) {
2288 if (Value) addAttribute(~0, Attribute::NoInline);
2289 else removeAttribute(~0, Attribute::NoInline);
2292 /// @brief Determine if the call does not access memory.
2293 bool doesNotAccessMemory() const {
2294 return paramHasAttr(~0, Attribute::ReadNone);
2296 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2297 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2298 else removeAttribute(~0, Attribute::ReadNone);
2301 /// @brief Determine if the call does not access or only reads memory.
2302 bool onlyReadsMemory() const {
2303 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2305 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2306 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2307 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2310 /// @brief Determine if the call cannot return.
2311 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
2312 void setDoesNotReturn(bool DoesNotReturn = true) {
2313 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2314 else removeAttribute(~0, Attribute::NoReturn);
2317 /// @brief Determine if the call cannot unwind.
2318 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
2319 void setDoesNotThrow(bool DoesNotThrow = true) {
2320 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2321 else removeAttribute(~0, Attribute::NoUnwind);
2324 /// @brief Determine if the call returns a structure through first
2325 /// pointer argument.
2326 bool hasStructRetAttr() const {
2327 // Be friendly and also check the callee.
2328 return paramHasAttr(1, Attribute::StructRet);
2331 /// @brief Determine if any call argument is an aggregate passed by value.
2332 bool hasByValArgument() const {
2333 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2336 /// getCalledFunction - Return the function called, or null if this is an
2337 /// indirect function invocation.
2339 Function *getCalledFunction() const {
2340 return dyn_cast<Function>(Op<-3>());
2343 /// getCalledValue - Get a pointer to the function that is invoked by this
2345 const Value *getCalledValue() const { return Op<-3>(); }
2346 Value *getCalledValue() { return Op<-3>(); }
2348 /// setCalledFunction - Set the function called.
2349 void setCalledFunction(Value* Fn) {
2353 // get*Dest - Return the destination basic blocks...
2354 BasicBlock *getNormalDest() const {
2355 return cast<BasicBlock>(Op<-2>());
2357 BasicBlock *getUnwindDest() const {
2358 return cast<BasicBlock>(Op<-1>());
2360 void setNormalDest(BasicBlock *B) {
2361 Op<-2>() = reinterpret_cast<Value*>(B);
2363 void setUnwindDest(BasicBlock *B) {
2364 Op<-1>() = reinterpret_cast<Value*>(B);
2367 BasicBlock *getSuccessor(unsigned i) const {
2368 assert(i < 2 && "Successor # out of range for invoke!");
2369 return i == 0 ? getNormalDest() : getUnwindDest();
2372 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2373 assert(idx < 2 && "Successor # out of range for invoke!");
2374 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2377 unsigned getNumSuccessors() const { return 2; }
2379 // Methods for support type inquiry through isa, cast, and dyn_cast:
2380 static inline bool classof(const InvokeInst *) { return true; }
2381 static inline bool classof(const Instruction *I) {
2382 return (I->getOpcode() == Instruction::Invoke);
2384 static inline bool classof(const Value *V) {
2385 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2389 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2390 virtual unsigned getNumSuccessorsV() const;
2391 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2393 // Shadow Instruction::setInstructionSubclassData with a private forwarding
2394 // method so that subclasses cannot accidentally use it.
2395 void setInstructionSubclassData(unsigned short D) {
2396 Instruction::setInstructionSubclassData(D);
2401 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
2404 InvokeInst::InvokeInst(Value *Func,
2405 BasicBlock *IfNormal, BasicBlock *IfException,
2406 ArrayRef<Value *> Args, unsigned Values,
2407 const Twine &NameStr, Instruction *InsertBefore)
2408 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2409 ->getElementType())->getReturnType(),
2410 Instruction::Invoke,
2411 OperandTraits<InvokeInst>::op_end(this) - Values,
2412 Values, InsertBefore) {
2413 init(Func, IfNormal, IfException, Args, NameStr);
2415 InvokeInst::InvokeInst(Value *Func,
2416 BasicBlock *IfNormal, BasicBlock *IfException,
2417 ArrayRef<Value *> Args, unsigned Values,
2418 const Twine &NameStr, BasicBlock *InsertAtEnd)
2419 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2420 ->getElementType())->getReturnType(),
2421 Instruction::Invoke,
2422 OperandTraits<InvokeInst>::op_end(this) - Values,
2423 Values, InsertAtEnd) {
2424 init(Func, IfNormal, IfException, Args, NameStr);
2427 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2429 //===----------------------------------------------------------------------===//
2431 //===----------------------------------------------------------------------===//
2433 //===---------------------------------------------------------------------------
2434 /// UnwindInst - Immediately exit the current function, unwinding the stack
2435 /// until an invoke instruction is found.
2437 class UnwindInst : public TerminatorInst {
2438 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2440 virtual UnwindInst *clone_impl() const;
2442 // allocate space for exactly zero operands
2443 void *operator new(size_t s) {
2444 return User::operator new(s, 0);
2446 explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2447 explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2449 unsigned getNumSuccessors() const { return 0; }
2451 // Methods for support type inquiry through isa, cast, and dyn_cast:
2452 static inline bool classof(const UnwindInst *) { return true; }
2453 static inline bool classof(const Instruction *I) {
2454 return I->getOpcode() == Instruction::Unwind;
2456 static inline bool classof(const Value *V) {
2457 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2460 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2461 virtual unsigned getNumSuccessorsV() const;
2462 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2465 //===----------------------------------------------------------------------===//
2466 // UnreachableInst Class
2467 //===----------------------------------------------------------------------===//
2469 //===---------------------------------------------------------------------------
2470 /// UnreachableInst - This function has undefined behavior. In particular, the
2471 /// presence of this instruction indicates some higher level knowledge that the
2472 /// end of the block cannot be reached.
2474 class UnreachableInst : public TerminatorInst {
2475 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2477 virtual UnreachableInst *clone_impl() const;
2480 // allocate space for exactly zero operands
2481 void *operator new(size_t s) {
2482 return User::operator new(s, 0);
2484 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2485 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2487 unsigned getNumSuccessors() const { return 0; }
2489 // Methods for support type inquiry through isa, cast, and dyn_cast:
2490 static inline bool classof(const UnreachableInst *) { return true; }
2491 static inline bool classof(const Instruction *I) {
2492 return I->getOpcode() == Instruction::Unreachable;
2494 static inline bool classof(const Value *V) {
2495 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2498 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2499 virtual unsigned getNumSuccessorsV() const;
2500 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2503 //===----------------------------------------------------------------------===//
2505 //===----------------------------------------------------------------------===//
2507 /// @brief This class represents a truncation of integer types.
2508 class TruncInst : public CastInst {
2510 /// @brief Clone an identical TruncInst
2511 virtual TruncInst *clone_impl() const;
2514 /// @brief Constructor with insert-before-instruction semantics
2516 Value *S, ///< The value to be truncated
2517 Type *Ty, ///< The (smaller) type to truncate to
2518 const Twine &NameStr = "", ///< A name for the new instruction
2519 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2522 /// @brief Constructor with insert-at-end-of-block semantics
2524 Value *S, ///< The value to be truncated
2525 Type *Ty, ///< The (smaller) type to truncate to
2526 const Twine &NameStr, ///< A name for the new instruction
2527 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2530 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2531 static inline bool classof(const TruncInst *) { return true; }
2532 static inline bool classof(const Instruction *I) {
2533 return I->getOpcode() == Trunc;
2535 static inline bool classof(const Value *V) {
2536 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2540 //===----------------------------------------------------------------------===//
2542 //===----------------------------------------------------------------------===//
2544 /// @brief This class represents zero extension of integer types.
2545 class ZExtInst : public CastInst {
2547 /// @brief Clone an identical ZExtInst
2548 virtual ZExtInst *clone_impl() const;
2551 /// @brief Constructor with insert-before-instruction semantics
2553 Value *S, ///< The value to be zero extended
2554 Type *Ty, ///< The type to zero extend to
2555 const Twine &NameStr = "", ///< A name for the new instruction
2556 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2559 /// @brief Constructor with insert-at-end semantics.
2561 Value *S, ///< The value to be zero extended
2562 Type *Ty, ///< The type to zero extend to
2563 const Twine &NameStr, ///< A name for the new instruction
2564 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2567 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2568 static inline bool classof(const ZExtInst *) { return true; }
2569 static inline bool classof(const Instruction *I) {
2570 return I->getOpcode() == ZExt;
2572 static inline bool classof(const Value *V) {
2573 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2577 //===----------------------------------------------------------------------===//
2579 //===----------------------------------------------------------------------===//
2581 /// @brief This class represents a sign extension of integer types.
2582 class SExtInst : public CastInst {
2584 /// @brief Clone an identical SExtInst
2585 virtual SExtInst *clone_impl() const;
2588 /// @brief Constructor with insert-before-instruction semantics
2590 Value *S, ///< The value to be sign extended
2591 Type *Ty, ///< The type to sign extend to
2592 const Twine &NameStr = "", ///< A name for the new instruction
2593 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2596 /// @brief Constructor with insert-at-end-of-block semantics
2598 Value *S, ///< The value to be sign extended
2599 Type *Ty, ///< The type to sign extend to
2600 const Twine &NameStr, ///< A name for the new instruction
2601 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2604 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2605 static inline bool classof(const SExtInst *) { return true; }
2606 static inline bool classof(const Instruction *I) {
2607 return I->getOpcode() == SExt;
2609 static inline bool classof(const Value *V) {
2610 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2614 //===----------------------------------------------------------------------===//
2615 // FPTruncInst Class
2616 //===----------------------------------------------------------------------===//
2618 /// @brief This class represents a truncation of floating point types.
2619 class FPTruncInst : public CastInst {
2621 /// @brief Clone an identical FPTruncInst
2622 virtual FPTruncInst *clone_impl() const;
2625 /// @brief Constructor with insert-before-instruction semantics
2627 Value *S, ///< The value to be truncated
2628 Type *Ty, ///< The type to truncate to
2629 const Twine &NameStr = "", ///< A name for the new instruction
2630 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2633 /// @brief Constructor with insert-before-instruction semantics
2635 Value *S, ///< The value to be truncated
2636 Type *Ty, ///< The type to truncate to
2637 const Twine &NameStr, ///< A name for the new instruction
2638 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2641 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2642 static inline bool classof(const FPTruncInst *) { return true; }
2643 static inline bool classof(const Instruction *I) {
2644 return I->getOpcode() == FPTrunc;
2646 static inline bool classof(const Value *V) {
2647 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2651 //===----------------------------------------------------------------------===//
2653 //===----------------------------------------------------------------------===//
2655 /// @brief This class represents an extension of floating point types.
2656 class FPExtInst : public CastInst {
2658 /// @brief Clone an identical FPExtInst
2659 virtual FPExtInst *clone_impl() const;
2662 /// @brief Constructor with insert-before-instruction semantics
2664 Value *S, ///< The value to be extended
2665 Type *Ty, ///< The type to extend to
2666 const Twine &NameStr = "", ///< A name for the new instruction
2667 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2670 /// @brief Constructor with insert-at-end-of-block semantics
2672 Value *S, ///< The value to be extended
2673 Type *Ty, ///< The type to extend to
2674 const Twine &NameStr, ///< A name for the new instruction
2675 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2678 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2679 static inline bool classof(const FPExtInst *) { return true; }
2680 static inline bool classof(const Instruction *I) {
2681 return I->getOpcode() == FPExt;
2683 static inline bool classof(const Value *V) {
2684 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2688 //===----------------------------------------------------------------------===//
2690 //===----------------------------------------------------------------------===//
2692 /// @brief This class represents a cast unsigned integer to floating point.
2693 class UIToFPInst : public CastInst {
2695 /// @brief Clone an identical UIToFPInst
2696 virtual UIToFPInst *clone_impl() const;
2699 /// @brief Constructor with insert-before-instruction semantics
2701 Value *S, ///< The value to be converted
2702 Type *Ty, ///< The type to convert to
2703 const Twine &NameStr = "", ///< A name for the new instruction
2704 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2707 /// @brief Constructor with insert-at-end-of-block semantics
2709 Value *S, ///< The value to be converted
2710 Type *Ty, ///< The type to convert to
2711 const Twine &NameStr, ///< A name for the new instruction
2712 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2715 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2716 static inline bool classof(const UIToFPInst *) { return true; }
2717 static inline bool classof(const Instruction *I) {
2718 return I->getOpcode() == UIToFP;
2720 static inline bool classof(const Value *V) {
2721 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2725 //===----------------------------------------------------------------------===//
2727 //===----------------------------------------------------------------------===//
2729 /// @brief This class represents a cast from signed integer to floating point.
2730 class SIToFPInst : public CastInst {
2732 /// @brief Clone an identical SIToFPInst
2733 virtual SIToFPInst *clone_impl() const;
2736 /// @brief Constructor with insert-before-instruction semantics
2738 Value *S, ///< The value to be converted
2739 Type *Ty, ///< The type to convert to
2740 const Twine &NameStr = "", ///< A name for the new instruction
2741 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2744 /// @brief Constructor with insert-at-end-of-block semantics
2746 Value *S, ///< The value to be converted
2747 Type *Ty, ///< The type to convert to
2748 const Twine &NameStr, ///< A name for the new instruction
2749 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2752 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2753 static inline bool classof(const SIToFPInst *) { return true; }
2754 static inline bool classof(const Instruction *I) {
2755 return I->getOpcode() == SIToFP;
2757 static inline bool classof(const Value *V) {
2758 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2762 //===----------------------------------------------------------------------===//
2764 //===----------------------------------------------------------------------===//
2766 /// @brief This class represents a cast from floating point to unsigned integer
2767 class FPToUIInst : public CastInst {
2769 /// @brief Clone an identical FPToUIInst
2770 virtual FPToUIInst *clone_impl() const;
2773 /// @brief Constructor with insert-before-instruction semantics
2775 Value *S, ///< The value to be converted
2776 Type *Ty, ///< The type to convert to
2777 const Twine &NameStr = "", ///< A name for the new instruction
2778 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2781 /// @brief Constructor with insert-at-end-of-block semantics
2783 Value *S, ///< The value to be converted
2784 Type *Ty, ///< The type to convert to
2785 const Twine &NameStr, ///< A name for the new instruction
2786 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
2789 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2790 static inline bool classof(const FPToUIInst *) { return true; }
2791 static inline bool classof(const Instruction *I) {
2792 return I->getOpcode() == FPToUI;
2794 static inline bool classof(const Value *V) {
2795 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2799 //===----------------------------------------------------------------------===//
2801 //===----------------------------------------------------------------------===//
2803 /// @brief This class represents a cast from floating point to signed integer.
2804 class FPToSIInst : public CastInst {
2806 /// @brief Clone an identical FPToSIInst
2807 virtual FPToSIInst *clone_impl() const;
2810 /// @brief Constructor with insert-before-instruction semantics
2812 Value *S, ///< The value to be converted
2813 Type *Ty, ///< The type to convert to
2814 const Twine &NameStr = "", ///< A name for the new instruction
2815 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2818 /// @brief Constructor with insert-at-end-of-block semantics
2820 Value *S, ///< The value to be converted
2821 Type *Ty, ///< The type to convert to
2822 const Twine &NameStr, ///< A name for the new instruction
2823 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2826 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2827 static inline bool classof(const FPToSIInst *) { return true; }
2828 static inline bool classof(const Instruction *I) {
2829 return I->getOpcode() == FPToSI;
2831 static inline bool classof(const Value *V) {
2832 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2836 //===----------------------------------------------------------------------===//
2837 // IntToPtrInst Class
2838 //===----------------------------------------------------------------------===//
2840 /// @brief This class represents a cast from an integer to a pointer.
2841 class IntToPtrInst : public CastInst {
2843 /// @brief Constructor with insert-before-instruction semantics
2845 Value *S, ///< The value to be converted
2846 Type *Ty, ///< The type to convert to
2847 const Twine &NameStr = "", ///< A name for the new instruction
2848 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2851 /// @brief Constructor with insert-at-end-of-block semantics
2853 Value *S, ///< The value to be converted
2854 Type *Ty, ///< The type to convert to
2855 const Twine &NameStr, ///< A name for the new instruction
2856 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2859 /// @brief Clone an identical IntToPtrInst
2860 virtual IntToPtrInst *clone_impl() const;
2862 // Methods for support type inquiry through isa, cast, and dyn_cast:
2863 static inline bool classof(const IntToPtrInst *) { return true; }
2864 static inline bool classof(const Instruction *I) {
2865 return I->getOpcode() == IntToPtr;
2867 static inline bool classof(const Value *V) {
2868 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2872 //===----------------------------------------------------------------------===//
2873 // PtrToIntInst Class
2874 //===----------------------------------------------------------------------===//
2876 /// @brief This class represents a cast from a pointer to an integer
2877 class PtrToIntInst : public CastInst {
2879 /// @brief Clone an identical PtrToIntInst
2880 virtual PtrToIntInst *clone_impl() const;
2883 /// @brief Constructor with insert-before-instruction semantics
2885 Value *S, ///< The value to be converted
2886 Type *Ty, ///< The type to convert to
2887 const Twine &NameStr = "", ///< A name for the new instruction
2888 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2891 /// @brief Constructor with insert-at-end-of-block semantics
2893 Value *S, ///< The value to be converted
2894 Type *Ty, ///< The type to convert to
2895 const Twine &NameStr, ///< A name for the new instruction
2896 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2899 // Methods for support type inquiry through isa, cast, and dyn_cast:
2900 static inline bool classof(const PtrToIntInst *) { return true; }
2901 static inline bool classof(const Instruction *I) {
2902 return I->getOpcode() == PtrToInt;
2904 static inline bool classof(const Value *V) {
2905 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2909 //===----------------------------------------------------------------------===//
2910 // BitCastInst Class
2911 //===----------------------------------------------------------------------===//
2913 /// @brief This class represents a no-op cast from one type to another.
2914 class BitCastInst : public CastInst {
2916 /// @brief Clone an identical BitCastInst
2917 virtual BitCastInst *clone_impl() const;
2920 /// @brief Constructor with insert-before-instruction semantics
2922 Value *S, ///< The value to be casted
2923 Type *Ty, ///< The type to casted to
2924 const Twine &NameStr = "", ///< A name for the new instruction
2925 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2928 /// @brief Constructor with insert-at-end-of-block semantics
2930 Value *S, ///< The value to be casted
2931 Type *Ty, ///< The type to casted to
2932 const Twine &NameStr, ///< A name for the new instruction
2933 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2936 // Methods for support type inquiry through isa, cast, and dyn_cast:
2937 static inline bool classof(const BitCastInst *) { return true; }
2938 static inline bool classof(const Instruction *I) {
2939 return I->getOpcode() == BitCast;
2941 static inline bool classof(const Value *V) {
2942 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2946 } // End llvm namespace