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 // AtomicCmpXchgInst Class
366 //===----------------------------------------------------------------------===//
368 /// AtomicCmpXchgInst - an instruction that atomically checks whether a
369 /// specified value is in a memory location, and, if it is, stores a new value
370 /// there. Returns the value that was loaded.
372 class AtomicCmpXchgInst : public Instruction {
373 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
374 void Init(Value *Ptr, Value *Cmp, Value *NewVal,
375 AtomicOrdering Ordering, SynchronizationScope SynchScope);
377 virtual AtomicCmpXchgInst *clone_impl() const;
379 // allocate space for exactly three operands
380 void *operator new(size_t s) {
381 return User::operator new(s, 3);
383 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
384 AtomicOrdering Ordering, SynchronizationScope SynchScope,
385 Instruction *InsertBefore = 0);
386 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
387 AtomicOrdering Ordering, SynchronizationScope SynchScope,
388 BasicBlock *InsertAtEnd);
390 /// isVolatile - Return true if this is a cmpxchg from a volatile memory
393 bool isVolatile() const {
394 return getSubclassDataFromInstruction() & 1;
397 /// setVolatile - Specify whether this is a volatile cmpxchg.
399 void setVolatile(bool V) {
400 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
404 /// Transparently provide more efficient getOperand methods.
405 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
407 /// Set the ordering constraint on this cmpxchg.
408 void setOrdering(AtomicOrdering Ordering) {
409 assert(Ordering != NotAtomic &&
410 "CmpXchg instructions can only be atomic.");
411 setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
415 /// Specify whether this cmpxchg is atomic and orders other operations with
416 /// respect to all concurrently executing threads, or only with respect to
417 /// signal handlers executing in the same thread.
418 void setSynchScope(SynchronizationScope SynchScope) {
419 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
423 /// Returns the ordering constraint on this cmpxchg.
424 AtomicOrdering getOrdering() const {
425 return AtomicOrdering(getSubclassDataFromInstruction() >> 2);
428 /// Returns whether this cmpxchg is atomic between threads or only within a
430 SynchronizationScope getSynchScope() const {
431 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
434 Value *getPointerOperand() { return getOperand(0); }
435 const Value *getPointerOperand() const { return getOperand(0); }
436 static unsigned getPointerOperandIndex() { return 0U; }
438 Value *getCompareOperand() { return getOperand(1); }
439 const Value *getCompareOperand() const { return getOperand(1); }
441 Value *getNewValOperand() { return getOperand(2); }
442 const Value *getNewValOperand() const { return getOperand(2); }
444 unsigned getPointerAddressSpace() const {
445 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
448 // Methods for support type inquiry through isa, cast, and dyn_cast:
449 static inline bool classof(const AtomicCmpXchgInst *) { return true; }
450 static inline bool classof(const Instruction *I) {
451 return I->getOpcode() == Instruction::AtomicCmpXchg;
453 static inline bool classof(const Value *V) {
454 return isa<Instruction>(V) && classof(cast<Instruction>(V));
457 // Shadow Instruction::setInstructionSubclassData with a private forwarding
458 // method so that subclasses cannot accidentally use it.
459 void setInstructionSubclassData(unsigned short D) {
460 Instruction::setInstructionSubclassData(D);
465 struct OperandTraits<AtomicCmpXchgInst> :
466 public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
469 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)
471 //===----------------------------------------------------------------------===//
472 // AtomicRMWInst Class
473 //===----------------------------------------------------------------------===//
475 /// AtomicRMWInst - an instruction that atomically reads a memory location,
476 /// combines it with another value, and then stores the result back. Returns
479 class AtomicRMWInst : public Instruction {
480 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
482 virtual AtomicRMWInst *clone_impl() const;
484 /// This enumeration lists the possible modifications atomicrmw can make. In
485 /// the descriptions, 'p' is the pointer to the instruction's memory location,
486 /// 'old' is the initial value of *p, and 'v' is the other value passed to the
487 /// instruction. These instructions always return 'old'.
503 /// *p = old >signed v ? old : v
505 /// *p = old <signed v ? old : v
507 /// *p = old >unsigned v ? old : v
509 /// *p = old <unsigned v ? old : v
517 // allocate space for exactly two operands
518 void *operator new(size_t s) {
519 return User::operator new(s, 2);
521 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
522 AtomicOrdering Ordering, SynchronizationScope SynchScope,
523 Instruction *InsertBefore = 0);
524 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
525 AtomicOrdering Ordering, SynchronizationScope SynchScope,
526 BasicBlock *InsertAtEnd);
528 BinOp getOperation() const {
529 return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
532 void setOperation(BinOp Operation) {
533 unsigned short SubclassData = getSubclassDataFromInstruction();
534 setInstructionSubclassData((SubclassData & 31) |
538 /// isVolatile - Return true if this is a RMW on a volatile memory location.
540 bool isVolatile() const {
541 return getSubclassDataFromInstruction() & 1;
544 /// setVolatile - Specify whether this is a volatile RMW or not.
546 void setVolatile(bool V) {
547 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
551 /// Transparently provide more efficient getOperand methods.
552 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
554 /// Set the ordering constraint on this RMW.
555 void setOrdering(AtomicOrdering Ordering) {
556 assert(Ordering != NotAtomic &&
557 "atomicrmw instructions can only be atomic.");
558 setInstructionSubclassData((getSubclassDataFromInstruction() & ~28) |
562 /// Specify whether this RMW orders other operations with respect to all
563 /// concurrently executing threads, or only with respect to signal handlers
564 /// executing in the same thread.
565 void setSynchScope(SynchronizationScope SynchScope) {
566 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
570 /// Returns the ordering constraint on this RMW.
571 AtomicOrdering getOrdering() const {
572 return AtomicOrdering((getSubclassDataFromInstruction() & 28) >> 2);
575 /// Returns whether this RMW is atomic between threads or only within a
577 SynchronizationScope getSynchScope() const {
578 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
581 Value *getPointerOperand() { return getOperand(0); }
582 const Value *getPointerOperand() const { return getOperand(0); }
583 static unsigned getPointerOperandIndex() { return 0U; }
585 Value *getValOperand() { return getOperand(1); }
586 const Value *getValOperand() const { return getOperand(1); }
588 unsigned getPointerAddressSpace() const {
589 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
592 // Methods for support type inquiry through isa, cast, and dyn_cast:
593 static inline bool classof(const AtomicRMWInst *) { return true; }
594 static inline bool classof(const Instruction *I) {
595 return I->getOpcode() == Instruction::AtomicRMW;
597 static inline bool classof(const Value *V) {
598 return isa<Instruction>(V) && classof(cast<Instruction>(V));
601 void Init(BinOp Operation, Value *Ptr, Value *Val,
602 AtomicOrdering Ordering, SynchronizationScope SynchScope);
603 // Shadow Instruction::setInstructionSubclassData with a private forwarding
604 // method so that subclasses cannot accidentally use it.
605 void setInstructionSubclassData(unsigned short D) {
606 Instruction::setInstructionSubclassData(D);
611 struct OperandTraits<AtomicRMWInst>
612 : public FixedNumOperandTraits<AtomicRMWInst,2> {
615 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)
617 //===----------------------------------------------------------------------===//
618 // GetElementPtrInst Class
619 //===----------------------------------------------------------------------===//
621 // checkGEPType - Simple wrapper function to give a better assertion failure
622 // message on bad indexes for a gep instruction.
624 static inline Type *checkGEPType(Type *Ty) {
625 assert(Ty && "Invalid GetElementPtrInst indices for type!");
629 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
630 /// access elements of arrays and structs
632 class GetElementPtrInst : public Instruction {
633 GetElementPtrInst(const GetElementPtrInst &GEPI);
634 void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
636 /// Constructors - Create a getelementptr instruction with a base pointer an
637 /// list of indices. The first ctor can optionally insert before an existing
638 /// instruction, the second appends the new instruction to the specified
640 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
641 unsigned Values, const Twine &NameStr,
642 Instruction *InsertBefore);
643 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
644 unsigned Values, const Twine &NameStr,
645 BasicBlock *InsertAtEnd);
647 virtual GetElementPtrInst *clone_impl() const;
649 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
650 const Twine &NameStr = "",
651 Instruction *InsertBefore = 0) {
652 unsigned Values = 1 + unsigned(IdxList.size());
654 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
656 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
657 const Twine &NameStr,
658 BasicBlock *InsertAtEnd) {
659 unsigned Values = 1 + unsigned(IdxList.size());
661 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
664 /// Create an "inbounds" getelementptr. See the documentation for the
665 /// "inbounds" flag in LangRef.html for details.
666 static GetElementPtrInst *CreateInBounds(Value *Ptr,
667 ArrayRef<Value *> IdxList,
668 const Twine &NameStr = "",
669 Instruction *InsertBefore = 0) {
670 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
671 GEP->setIsInBounds(true);
674 static GetElementPtrInst *CreateInBounds(Value *Ptr,
675 ArrayRef<Value *> IdxList,
676 const Twine &NameStr,
677 BasicBlock *InsertAtEnd) {
678 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
679 GEP->setIsInBounds(true);
683 /// Transparently provide more efficient getOperand methods.
684 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
686 // getType - Overload to return most specific pointer type...
687 PointerType *getType() const {
688 return reinterpret_cast<PointerType*>(Instruction::getType());
691 /// getIndexedType - Returns the type of the element that would be loaded with
692 /// a load instruction with the specified parameters.
694 /// Null is returned if the indices are invalid for the specified
697 static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList);
698 static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList);
699 static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList);
701 inline op_iterator idx_begin() { return op_begin()+1; }
702 inline const_op_iterator idx_begin() const { return op_begin()+1; }
703 inline op_iterator idx_end() { return op_end(); }
704 inline const_op_iterator idx_end() const { return op_end(); }
706 Value *getPointerOperand() {
707 return getOperand(0);
709 const Value *getPointerOperand() const {
710 return getOperand(0);
712 static unsigned getPointerOperandIndex() {
713 return 0U; // get index for modifying correct operand
716 unsigned getPointerAddressSpace() const {
717 return cast<PointerType>(getType())->getAddressSpace();
720 /// getPointerOperandType - Method to return the pointer operand as a
722 PointerType *getPointerOperandType() const {
723 return reinterpret_cast<PointerType*>(getPointerOperand()->getType());
727 unsigned getNumIndices() const { // Note: always non-negative
728 return getNumOperands() - 1;
731 bool hasIndices() const {
732 return getNumOperands() > 1;
735 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
736 /// zeros. If so, the result pointer and the first operand have the same
737 /// value, just potentially different types.
738 bool hasAllZeroIndices() const;
740 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
741 /// constant integers. If so, the result pointer and the first operand have
742 /// a constant offset between them.
743 bool hasAllConstantIndices() const;
745 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
746 /// See LangRef.html for the meaning of inbounds on a getelementptr.
747 void setIsInBounds(bool b = true);
749 /// isInBounds - Determine whether the GEP has the inbounds flag.
750 bool isInBounds() const;
752 // Methods for support type inquiry through isa, cast, and dyn_cast:
753 static inline bool classof(const GetElementPtrInst *) { return true; }
754 static inline bool classof(const Instruction *I) {
755 return (I->getOpcode() == Instruction::GetElementPtr);
757 static inline bool classof(const Value *V) {
758 return isa<Instruction>(V) && classof(cast<Instruction>(V));
763 struct OperandTraits<GetElementPtrInst> :
764 public VariadicOperandTraits<GetElementPtrInst, 1> {
767 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
768 ArrayRef<Value *> IdxList,
770 const Twine &NameStr,
771 Instruction *InsertBefore)
772 : Instruction(PointerType::get(checkGEPType(
773 getIndexedType(Ptr->getType(), IdxList)),
774 cast<PointerType>(Ptr->getType())
775 ->getAddressSpace()),
777 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
778 Values, InsertBefore) {
779 init(Ptr, IdxList, NameStr);
781 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
782 ArrayRef<Value *> IdxList,
784 const Twine &NameStr,
785 BasicBlock *InsertAtEnd)
786 : Instruction(PointerType::get(checkGEPType(
787 getIndexedType(Ptr->getType(), IdxList)),
788 cast<PointerType>(Ptr->getType())
789 ->getAddressSpace()),
791 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
792 Values, InsertAtEnd) {
793 init(Ptr, IdxList, NameStr);
797 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
800 //===----------------------------------------------------------------------===//
802 //===----------------------------------------------------------------------===//
804 /// This instruction compares its operands according to the predicate given
805 /// to the constructor. It only operates on integers or pointers. The operands
806 /// must be identical types.
807 /// @brief Represent an integer comparison operator.
808 class ICmpInst: public CmpInst {
810 /// @brief Clone an identical ICmpInst
811 virtual ICmpInst *clone_impl() const;
813 /// @brief Constructor with insert-before-instruction semantics.
815 Instruction *InsertBefore, ///< Where to insert
816 Predicate pred, ///< The predicate to use for the comparison
817 Value *LHS, ///< The left-hand-side of the expression
818 Value *RHS, ///< The right-hand-side of the expression
819 const Twine &NameStr = "" ///< Name of the instruction
820 ) : CmpInst(makeCmpResultType(LHS->getType()),
821 Instruction::ICmp, pred, LHS, RHS, NameStr,
823 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
824 pred <= CmpInst::LAST_ICMP_PREDICATE &&
825 "Invalid ICmp predicate value");
826 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
827 "Both operands to ICmp instruction are not of the same type!");
828 // Check that the operands are the right type
829 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
830 getOperand(0)->getType()->isPointerTy()) &&
831 "Invalid operand types for ICmp instruction");
834 /// @brief Constructor with insert-at-end semantics.
836 BasicBlock &InsertAtEnd, ///< Block to insert into.
837 Predicate pred, ///< The predicate to use for the comparison
838 Value *LHS, ///< The left-hand-side of the expression
839 Value *RHS, ///< The right-hand-side of the expression
840 const Twine &NameStr = "" ///< Name of the instruction
841 ) : CmpInst(makeCmpResultType(LHS->getType()),
842 Instruction::ICmp, pred, LHS, RHS, NameStr,
844 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
845 pred <= CmpInst::LAST_ICMP_PREDICATE &&
846 "Invalid ICmp predicate value");
847 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
848 "Both operands to ICmp instruction are not of the same type!");
849 // Check that the operands are the right type
850 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
851 getOperand(0)->getType()->isPointerTy()) &&
852 "Invalid operand types for ICmp instruction");
855 /// @brief Constructor with no-insertion semantics
857 Predicate pred, ///< The predicate to use for the comparison
858 Value *LHS, ///< The left-hand-side of the expression
859 Value *RHS, ///< The right-hand-side of the expression
860 const Twine &NameStr = "" ///< Name of the instruction
861 ) : CmpInst(makeCmpResultType(LHS->getType()),
862 Instruction::ICmp, pred, LHS, RHS, NameStr) {
863 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
864 pred <= CmpInst::LAST_ICMP_PREDICATE &&
865 "Invalid ICmp predicate value");
866 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
867 "Both operands to ICmp instruction are not of the same type!");
868 // Check that the operands are the right type
869 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
870 getOperand(0)->getType()->isPointerTy()) &&
871 "Invalid operand types for ICmp instruction");
874 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
875 /// @returns the predicate that would be the result if the operand were
876 /// regarded as signed.
877 /// @brief Return the signed version of the predicate
878 Predicate getSignedPredicate() const {
879 return getSignedPredicate(getPredicate());
882 /// This is a static version that you can use without an instruction.
883 /// @brief Return the signed version of the predicate.
884 static Predicate getSignedPredicate(Predicate pred);
886 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
887 /// @returns the predicate that would be the result if the operand were
888 /// regarded as unsigned.
889 /// @brief Return the unsigned version of the predicate
890 Predicate getUnsignedPredicate() const {
891 return getUnsignedPredicate(getPredicate());
894 /// This is a static version that you can use without an instruction.
895 /// @brief Return the unsigned version of the predicate.
896 static Predicate getUnsignedPredicate(Predicate pred);
898 /// isEquality - Return true if this predicate is either EQ or NE. This also
899 /// tests for commutativity.
900 static bool isEquality(Predicate P) {
901 return P == ICMP_EQ || P == ICMP_NE;
904 /// isEquality - Return true if this predicate is either EQ or NE. This also
905 /// tests for commutativity.
906 bool isEquality() const {
907 return isEquality(getPredicate());
910 /// @returns true if the predicate of this ICmpInst is commutative
911 /// @brief Determine if this relation is commutative.
912 bool isCommutative() const { return isEquality(); }
914 /// isRelational - Return true if the predicate is relational (not EQ or NE).
916 bool isRelational() const {
917 return !isEquality();
920 /// isRelational - Return true if the predicate is relational (not EQ or NE).
922 static bool isRelational(Predicate P) {
923 return !isEquality(P);
926 /// Initialize a set of values that all satisfy the predicate with C.
927 /// @brief Make a ConstantRange for a relation with a constant value.
928 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
930 /// Exchange the two operands to this instruction in such a way that it does
931 /// not modify the semantics of the instruction. The predicate value may be
932 /// changed to retain the same result if the predicate is order dependent
934 /// @brief Swap operands and adjust predicate.
935 void swapOperands() {
936 setPredicate(getSwappedPredicate());
937 Op<0>().swap(Op<1>());
940 // Methods for support type inquiry through isa, cast, and dyn_cast:
941 static inline bool classof(const ICmpInst *) { return true; }
942 static inline bool classof(const Instruction *I) {
943 return I->getOpcode() == Instruction::ICmp;
945 static inline bool classof(const Value *V) {
946 return isa<Instruction>(V) && classof(cast<Instruction>(V));
951 //===----------------------------------------------------------------------===//
953 //===----------------------------------------------------------------------===//
955 /// This instruction compares its operands according to the predicate given
956 /// to the constructor. It only operates on floating point values or packed
957 /// vectors of floating point values. The operands must be identical types.
958 /// @brief Represents a floating point comparison operator.
959 class FCmpInst: public CmpInst {
961 /// @brief Clone an identical FCmpInst
962 virtual FCmpInst *clone_impl() const;
964 /// @brief Constructor with insert-before-instruction semantics.
966 Instruction *InsertBefore, ///< Where to insert
967 Predicate pred, ///< The predicate to use for the comparison
968 Value *LHS, ///< The left-hand-side of the expression
969 Value *RHS, ///< The right-hand-side of the expression
970 const Twine &NameStr = "" ///< Name of the instruction
971 ) : CmpInst(makeCmpResultType(LHS->getType()),
972 Instruction::FCmp, pred, LHS, RHS, NameStr,
974 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
975 "Invalid FCmp predicate value");
976 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
977 "Both operands to FCmp instruction are not of the same type!");
978 // Check that the operands are the right type
979 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
980 "Invalid operand types for FCmp instruction");
983 /// @brief Constructor with insert-at-end semantics.
985 BasicBlock &InsertAtEnd, ///< Block to insert into.
986 Predicate pred, ///< The predicate to use for the comparison
987 Value *LHS, ///< The left-hand-side of the expression
988 Value *RHS, ///< The right-hand-side of the expression
989 const Twine &NameStr = "" ///< Name of the instruction
990 ) : CmpInst(makeCmpResultType(LHS->getType()),
991 Instruction::FCmp, pred, LHS, RHS, NameStr,
993 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
994 "Invalid FCmp predicate value");
995 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
996 "Both operands to FCmp instruction are not of the same type!");
997 // Check that the operands are the right type
998 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
999 "Invalid operand types for FCmp instruction");
1002 /// @brief Constructor with no-insertion semantics
1004 Predicate pred, ///< The predicate to use for the comparison
1005 Value *LHS, ///< The left-hand-side of the expression
1006 Value *RHS, ///< The right-hand-side of the expression
1007 const Twine &NameStr = "" ///< Name of the instruction
1008 ) : CmpInst(makeCmpResultType(LHS->getType()),
1009 Instruction::FCmp, pred, LHS, RHS, NameStr) {
1010 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1011 "Invalid FCmp predicate value");
1012 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1013 "Both operands to FCmp instruction are not of the same type!");
1014 // Check that the operands are the right type
1015 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1016 "Invalid operand types for FCmp instruction");
1019 /// @returns true if the predicate of this instruction is EQ or NE.
1020 /// @brief Determine if this is an equality predicate.
1021 bool isEquality() const {
1022 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
1023 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
1026 /// @returns true if the predicate of this instruction is commutative.
1027 /// @brief Determine if this is a commutative predicate.
1028 bool isCommutative() const {
1029 return isEquality() ||
1030 getPredicate() == FCMP_FALSE ||
1031 getPredicate() == FCMP_TRUE ||
1032 getPredicate() == FCMP_ORD ||
1033 getPredicate() == FCMP_UNO;
1036 /// @returns true if the predicate is relational (not EQ or NE).
1037 /// @brief Determine if this a relational predicate.
1038 bool isRelational() const { return !isEquality(); }
1040 /// Exchange the two operands to this instruction in such a way that it does
1041 /// not modify the semantics of the instruction. The predicate value may be
1042 /// changed to retain the same result if the predicate is order dependent
1044 /// @brief Swap operands and adjust predicate.
1045 void swapOperands() {
1046 setPredicate(getSwappedPredicate());
1047 Op<0>().swap(Op<1>());
1050 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1051 static inline bool classof(const FCmpInst *) { return true; }
1052 static inline bool classof(const Instruction *I) {
1053 return I->getOpcode() == Instruction::FCmp;
1055 static inline bool classof(const Value *V) {
1056 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1060 //===----------------------------------------------------------------------===//
1061 /// CallInst - This class represents a function call, abstracting a target
1062 /// machine's calling convention. This class uses low bit of the SubClassData
1063 /// field to indicate whether or not this is a tail call. The rest of the bits
1064 /// hold the calling convention of the call.
1066 class CallInst : public Instruction {
1067 AttrListPtr AttributeList; ///< parameter attributes for call
1068 CallInst(const CallInst &CI);
1069 void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
1070 void init(Value *Func, const Twine &NameStr);
1072 /// Construct a CallInst given a range of arguments.
1073 /// @brief Construct a CallInst from a range of arguments
1074 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1075 const Twine &NameStr, Instruction *InsertBefore);
1077 /// Construct a CallInst given a range of arguments.
1078 /// @brief Construct a CallInst from a range of arguments
1079 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1080 const Twine &NameStr, BasicBlock *InsertAtEnd);
1082 CallInst(Value *F, Value *Actual, const Twine &NameStr,
1083 Instruction *InsertBefore);
1084 CallInst(Value *F, Value *Actual, const Twine &NameStr,
1085 BasicBlock *InsertAtEnd);
1086 explicit CallInst(Value *F, const Twine &NameStr,
1087 Instruction *InsertBefore);
1088 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1090 virtual CallInst *clone_impl() const;
1092 static CallInst *Create(Value *Func,
1093 ArrayRef<Value *> Args,
1094 const Twine &NameStr = "",
1095 Instruction *InsertBefore = 0) {
1096 return new(unsigned(Args.size() + 1))
1097 CallInst(Func, Args, NameStr, InsertBefore);
1099 static CallInst *Create(Value *Func,
1100 ArrayRef<Value *> Args,
1101 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1102 return new(unsigned(Args.size() + 1))
1103 CallInst(Func, Args, NameStr, InsertAtEnd);
1105 static CallInst *Create(Value *F, const Twine &NameStr = "",
1106 Instruction *InsertBefore = 0) {
1107 return new(1) CallInst(F, NameStr, InsertBefore);
1109 static CallInst *Create(Value *F, const Twine &NameStr,
1110 BasicBlock *InsertAtEnd) {
1111 return new(1) CallInst(F, NameStr, InsertAtEnd);
1113 /// CreateMalloc - Generate the IR for a call to malloc:
1114 /// 1. Compute the malloc call's argument as the specified type's size,
1115 /// possibly multiplied by the array size if the array size is not
1117 /// 2. Call malloc with that argument.
1118 /// 3. Bitcast the result of the malloc call to the specified type.
1119 static Instruction *CreateMalloc(Instruction *InsertBefore,
1120 Type *IntPtrTy, Type *AllocTy,
1121 Value *AllocSize, Value *ArraySize = 0,
1122 Function* MallocF = 0,
1123 const Twine &Name = "");
1124 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1125 Type *IntPtrTy, Type *AllocTy,
1126 Value *AllocSize, Value *ArraySize = 0,
1127 Function* MallocF = 0,
1128 const Twine &Name = "");
1129 /// CreateFree - Generate the IR for a call to the builtin free function.
1130 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
1131 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
1135 bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
1136 void setTailCall(bool isTC = true) {
1137 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
1141 /// Provide fast operand accessors
1142 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1144 /// getNumArgOperands - Return the number of call arguments.
1146 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
1148 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1150 Value *getArgOperand(unsigned i) const { return getOperand(i); }
1151 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
1153 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1155 CallingConv::ID getCallingConv() const {
1156 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
1158 void setCallingConv(CallingConv::ID CC) {
1159 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
1160 (static_cast<unsigned>(CC) << 1));
1163 /// getAttributes - Return the parameter attributes for this call.
1165 const AttrListPtr &getAttributes() const { return AttributeList; }
1167 /// setAttributes - Set the parameter attributes for this call.
1169 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
1171 /// addAttribute - adds the attribute to the list of attributes.
1172 void addAttribute(unsigned i, Attributes attr);
1174 /// removeAttribute - removes the attribute from the list of attributes.
1175 void removeAttribute(unsigned i, Attributes attr);
1177 /// @brief Determine whether the call or the callee has the given attribute.
1178 bool paramHasAttr(unsigned i, Attributes attr) const;
1180 /// @brief Extract the alignment for a call or parameter (0=unknown).
1181 unsigned getParamAlignment(unsigned i) const {
1182 return AttributeList.getParamAlignment(i);
1185 /// @brief Return true if the call should not be inlined.
1186 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
1187 void setIsNoInline(bool Value = true) {
1188 if (Value) addAttribute(~0, Attribute::NoInline);
1189 else removeAttribute(~0, Attribute::NoInline);
1192 /// @brief Determine if the call does not access memory.
1193 bool doesNotAccessMemory() const {
1194 return paramHasAttr(~0, Attribute::ReadNone);
1196 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
1197 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
1198 else removeAttribute(~0, Attribute::ReadNone);
1201 /// @brief Determine if the call does not access or only reads memory.
1202 bool onlyReadsMemory() const {
1203 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
1205 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
1206 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
1207 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
1210 /// @brief Determine if the call cannot return.
1211 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
1212 void setDoesNotReturn(bool DoesNotReturn = true) {
1213 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
1214 else removeAttribute(~0, Attribute::NoReturn);
1217 /// @brief Determine if the call cannot unwind.
1218 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
1219 void setDoesNotThrow(bool DoesNotThrow = true) {
1220 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
1221 else removeAttribute(~0, Attribute::NoUnwind);
1224 /// @brief Determine if the call returns a structure through first
1225 /// pointer argument.
1226 bool hasStructRetAttr() const {
1227 // Be friendly and also check the callee.
1228 return paramHasAttr(1, Attribute::StructRet);
1231 /// @brief Determine if any call argument is an aggregate passed by value.
1232 bool hasByValArgument() const {
1233 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1236 /// getCalledFunction - Return the function called, or null if this is an
1237 /// indirect function invocation.
1239 Function *getCalledFunction() const {
1240 return dyn_cast<Function>(Op<-1>());
1243 /// getCalledValue - Get a pointer to the function that is invoked by this
1245 const Value *getCalledValue() const { return Op<-1>(); }
1246 Value *getCalledValue() { return Op<-1>(); }
1248 /// setCalledFunction - Set the function called.
1249 void setCalledFunction(Value* Fn) {
1253 /// isInlineAsm - Check if this call is an inline asm statement.
1254 bool isInlineAsm() const {
1255 return isa<InlineAsm>(Op<-1>());
1258 // Methods for support type inquiry through isa, cast, and dyn_cast:
1259 static inline bool classof(const CallInst *) { return true; }
1260 static inline bool classof(const Instruction *I) {
1261 return I->getOpcode() == Instruction::Call;
1263 static inline bool classof(const Value *V) {
1264 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1267 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1268 // method so that subclasses cannot accidentally use it.
1269 void setInstructionSubclassData(unsigned short D) {
1270 Instruction::setInstructionSubclassData(D);
1275 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1278 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1279 const Twine &NameStr, BasicBlock *InsertAtEnd)
1280 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1281 ->getElementType())->getReturnType(),
1283 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1284 unsigned(Args.size() + 1), InsertAtEnd) {
1285 init(Func, Args, NameStr);
1288 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1289 const Twine &NameStr, Instruction *InsertBefore)
1290 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1291 ->getElementType())->getReturnType(),
1293 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1294 unsigned(Args.size() + 1), InsertBefore) {
1295 init(Func, Args, NameStr);
1299 // Note: if you get compile errors about private methods then
1300 // please update your code to use the high-level operand
1301 // interfaces. See line 943 above.
1302 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1304 //===----------------------------------------------------------------------===//
1306 //===----------------------------------------------------------------------===//
1308 /// SelectInst - This class represents the LLVM 'select' instruction.
1310 class SelectInst : public Instruction {
1311 void init(Value *C, Value *S1, Value *S2) {
1312 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1318 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1319 Instruction *InsertBefore)
1320 : Instruction(S1->getType(), Instruction::Select,
1321 &Op<0>(), 3, InsertBefore) {
1325 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1326 BasicBlock *InsertAtEnd)
1327 : Instruction(S1->getType(), Instruction::Select,
1328 &Op<0>(), 3, InsertAtEnd) {
1333 virtual SelectInst *clone_impl() const;
1335 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1336 const Twine &NameStr = "",
1337 Instruction *InsertBefore = 0) {
1338 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1340 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1341 const Twine &NameStr,
1342 BasicBlock *InsertAtEnd) {
1343 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1346 const Value *getCondition() const { return Op<0>(); }
1347 const Value *getTrueValue() const { return Op<1>(); }
1348 const Value *getFalseValue() const { return Op<2>(); }
1349 Value *getCondition() { return Op<0>(); }
1350 Value *getTrueValue() { return Op<1>(); }
1351 Value *getFalseValue() { return Op<2>(); }
1353 /// areInvalidOperands - Return a string if the specified operands are invalid
1354 /// for a select operation, otherwise return null.
1355 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1357 /// Transparently provide more efficient getOperand methods.
1358 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1360 OtherOps getOpcode() const {
1361 return static_cast<OtherOps>(Instruction::getOpcode());
1364 // Methods for support type inquiry through isa, cast, and dyn_cast:
1365 static inline bool classof(const SelectInst *) { return true; }
1366 static inline bool classof(const Instruction *I) {
1367 return I->getOpcode() == Instruction::Select;
1369 static inline bool classof(const Value *V) {
1370 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1375 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1378 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1380 //===----------------------------------------------------------------------===//
1382 //===----------------------------------------------------------------------===//
1384 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1385 /// an argument of the specified type given a va_list and increments that list
1387 class VAArgInst : public UnaryInstruction {
1389 virtual VAArgInst *clone_impl() const;
1392 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1393 Instruction *InsertBefore = 0)
1394 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1397 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1398 BasicBlock *InsertAtEnd)
1399 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1403 Value *getPointerOperand() { return getOperand(0); }
1404 const Value *getPointerOperand() const { return getOperand(0); }
1405 static unsigned getPointerOperandIndex() { return 0U; }
1407 // Methods for support type inquiry through isa, cast, and dyn_cast:
1408 static inline bool classof(const VAArgInst *) { return true; }
1409 static inline bool classof(const Instruction *I) {
1410 return I->getOpcode() == VAArg;
1412 static inline bool classof(const Value *V) {
1413 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1417 //===----------------------------------------------------------------------===//
1418 // ExtractElementInst Class
1419 //===----------------------------------------------------------------------===//
1421 /// ExtractElementInst - This instruction extracts a single (scalar)
1422 /// element from a VectorType value
1424 class ExtractElementInst : public Instruction {
1425 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1426 Instruction *InsertBefore = 0);
1427 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1428 BasicBlock *InsertAtEnd);
1430 virtual ExtractElementInst *clone_impl() const;
1433 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1434 const Twine &NameStr = "",
1435 Instruction *InsertBefore = 0) {
1436 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1438 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1439 const Twine &NameStr,
1440 BasicBlock *InsertAtEnd) {
1441 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1444 /// isValidOperands - Return true if an extractelement instruction can be
1445 /// formed with the specified operands.
1446 static bool isValidOperands(const Value *Vec, const Value *Idx);
1448 Value *getVectorOperand() { return Op<0>(); }
1449 Value *getIndexOperand() { return Op<1>(); }
1450 const Value *getVectorOperand() const { return Op<0>(); }
1451 const Value *getIndexOperand() const { return Op<1>(); }
1453 VectorType *getVectorOperandType() const {
1454 return reinterpret_cast<VectorType*>(getVectorOperand()->getType());
1458 /// Transparently provide more efficient getOperand methods.
1459 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1461 // Methods for support type inquiry through isa, cast, and dyn_cast:
1462 static inline bool classof(const ExtractElementInst *) { return true; }
1463 static inline bool classof(const Instruction *I) {
1464 return I->getOpcode() == Instruction::ExtractElement;
1466 static inline bool classof(const Value *V) {
1467 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1472 struct OperandTraits<ExtractElementInst> :
1473 public FixedNumOperandTraits<ExtractElementInst, 2> {
1476 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1478 //===----------------------------------------------------------------------===//
1479 // InsertElementInst Class
1480 //===----------------------------------------------------------------------===//
1482 /// InsertElementInst - This instruction inserts a single (scalar)
1483 /// element into a VectorType value
1485 class InsertElementInst : public Instruction {
1486 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1487 const Twine &NameStr = "",
1488 Instruction *InsertBefore = 0);
1489 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1490 const Twine &NameStr, BasicBlock *InsertAtEnd);
1492 virtual InsertElementInst *clone_impl() const;
1495 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1496 const Twine &NameStr = "",
1497 Instruction *InsertBefore = 0) {
1498 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1500 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1501 const Twine &NameStr,
1502 BasicBlock *InsertAtEnd) {
1503 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1506 /// isValidOperands - Return true if an insertelement instruction can be
1507 /// formed with the specified operands.
1508 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1511 /// getType - Overload to return most specific vector type.
1513 VectorType *getType() const {
1514 return reinterpret_cast<VectorType*>(Instruction::getType());
1517 /// Transparently provide more efficient getOperand methods.
1518 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1520 // Methods for support type inquiry through isa, cast, and dyn_cast:
1521 static inline bool classof(const InsertElementInst *) { return true; }
1522 static inline bool classof(const Instruction *I) {
1523 return I->getOpcode() == Instruction::InsertElement;
1525 static inline bool classof(const Value *V) {
1526 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1531 struct OperandTraits<InsertElementInst> :
1532 public FixedNumOperandTraits<InsertElementInst, 3> {
1535 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1537 //===----------------------------------------------------------------------===//
1538 // ShuffleVectorInst Class
1539 //===----------------------------------------------------------------------===//
1541 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1544 class ShuffleVectorInst : public Instruction {
1546 virtual ShuffleVectorInst *clone_impl() const;
1549 // allocate space for exactly three operands
1550 void *operator new(size_t s) {
1551 return User::operator new(s, 3);
1553 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1554 const Twine &NameStr = "",
1555 Instruction *InsertBefor = 0);
1556 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1557 const Twine &NameStr, BasicBlock *InsertAtEnd);
1559 /// isValidOperands - Return true if a shufflevector instruction can be
1560 /// formed with the specified operands.
1561 static bool isValidOperands(const Value *V1, const Value *V2,
1564 /// getType - Overload to return most specific vector type.
1566 VectorType *getType() const {
1567 return reinterpret_cast<VectorType*>(Instruction::getType());
1570 /// Transparently provide more efficient getOperand methods.
1571 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1573 /// getMaskValue - Return the index from the shuffle mask for the specified
1574 /// output result. This is either -1 if the element is undef or a number less
1575 /// than 2*numelements.
1576 int getMaskValue(unsigned i) const;
1578 // Methods for support type inquiry through isa, cast, and dyn_cast:
1579 static inline bool classof(const ShuffleVectorInst *) { return true; }
1580 static inline bool classof(const Instruction *I) {
1581 return I->getOpcode() == Instruction::ShuffleVector;
1583 static inline bool classof(const Value *V) {
1584 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1589 struct OperandTraits<ShuffleVectorInst> :
1590 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1593 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1595 //===----------------------------------------------------------------------===//
1596 // ExtractValueInst Class
1597 //===----------------------------------------------------------------------===//
1599 /// ExtractValueInst - This instruction extracts a struct member or array
1600 /// element value from an aggregate value.
1602 class ExtractValueInst : public UnaryInstruction {
1603 SmallVector<unsigned, 4> Indices;
1605 ExtractValueInst(const ExtractValueInst &EVI);
1606 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1608 /// Constructors - Create a extractvalue instruction with a base aggregate
1609 /// value and a list of indices. The first ctor can optionally insert before
1610 /// an existing instruction, the second appends the new instruction to the
1611 /// specified BasicBlock.
1612 inline ExtractValueInst(Value *Agg,
1613 ArrayRef<unsigned> Idxs,
1614 const Twine &NameStr,
1615 Instruction *InsertBefore);
1616 inline ExtractValueInst(Value *Agg,
1617 ArrayRef<unsigned> Idxs,
1618 const Twine &NameStr, BasicBlock *InsertAtEnd);
1620 // allocate space for exactly one operand
1621 void *operator new(size_t s) {
1622 return User::operator new(s, 1);
1625 virtual ExtractValueInst *clone_impl() const;
1628 static ExtractValueInst *Create(Value *Agg,
1629 ArrayRef<unsigned> Idxs,
1630 const Twine &NameStr = "",
1631 Instruction *InsertBefore = 0) {
1633 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1635 static ExtractValueInst *Create(Value *Agg,
1636 ArrayRef<unsigned> Idxs,
1637 const Twine &NameStr,
1638 BasicBlock *InsertAtEnd) {
1639 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1642 /// getIndexedType - Returns the type of the element that would be extracted
1643 /// with an extractvalue instruction with the specified parameters.
1645 /// Null is returned if the indices are invalid for the specified type.
1646 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
1648 typedef const unsigned* idx_iterator;
1649 inline idx_iterator idx_begin() const { return Indices.begin(); }
1650 inline idx_iterator idx_end() const { return Indices.end(); }
1652 Value *getAggregateOperand() {
1653 return getOperand(0);
1655 const Value *getAggregateOperand() const {
1656 return getOperand(0);
1658 static unsigned getAggregateOperandIndex() {
1659 return 0U; // get index for modifying correct operand
1662 ArrayRef<unsigned> getIndices() const {
1666 unsigned getNumIndices() const {
1667 return (unsigned)Indices.size();
1670 bool hasIndices() const {
1674 // Methods for support type inquiry through isa, cast, and dyn_cast:
1675 static inline bool classof(const ExtractValueInst *) { return true; }
1676 static inline bool classof(const Instruction *I) {
1677 return I->getOpcode() == Instruction::ExtractValue;
1679 static inline bool classof(const Value *V) {
1680 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1684 ExtractValueInst::ExtractValueInst(Value *Agg,
1685 ArrayRef<unsigned> Idxs,
1686 const Twine &NameStr,
1687 Instruction *InsertBefore)
1688 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1689 ExtractValue, Agg, InsertBefore) {
1690 init(Idxs, NameStr);
1692 ExtractValueInst::ExtractValueInst(Value *Agg,
1693 ArrayRef<unsigned> Idxs,
1694 const Twine &NameStr,
1695 BasicBlock *InsertAtEnd)
1696 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1697 ExtractValue, Agg, InsertAtEnd) {
1698 init(Idxs, NameStr);
1702 //===----------------------------------------------------------------------===//
1703 // InsertValueInst Class
1704 //===----------------------------------------------------------------------===//
1706 /// InsertValueInst - This instruction inserts a struct field of array element
1707 /// value into an aggregate value.
1709 class InsertValueInst : public Instruction {
1710 SmallVector<unsigned, 4> Indices;
1712 void *operator new(size_t, unsigned); // Do not implement
1713 InsertValueInst(const InsertValueInst &IVI);
1714 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1715 const Twine &NameStr);
1717 /// Constructors - Create a insertvalue instruction with a base aggregate
1718 /// value, a value to insert, and a list of indices. The first ctor can
1719 /// optionally insert before an existing instruction, the second appends
1720 /// the new instruction to the specified BasicBlock.
1721 inline InsertValueInst(Value *Agg, Value *Val,
1722 ArrayRef<unsigned> Idxs,
1723 const Twine &NameStr,
1724 Instruction *InsertBefore);
1725 inline InsertValueInst(Value *Agg, Value *Val,
1726 ArrayRef<unsigned> Idxs,
1727 const Twine &NameStr, BasicBlock *InsertAtEnd);
1729 /// Constructors - These two constructors are convenience methods because one
1730 /// and two index insertvalue instructions are so common.
1731 InsertValueInst(Value *Agg, Value *Val,
1732 unsigned Idx, const Twine &NameStr = "",
1733 Instruction *InsertBefore = 0);
1734 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1735 const Twine &NameStr, BasicBlock *InsertAtEnd);
1737 virtual InsertValueInst *clone_impl() const;
1739 // allocate space for exactly two operands
1740 void *operator new(size_t s) {
1741 return User::operator new(s, 2);
1744 static InsertValueInst *Create(Value *Agg, Value *Val,
1745 ArrayRef<unsigned> Idxs,
1746 const Twine &NameStr = "",
1747 Instruction *InsertBefore = 0) {
1748 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1750 static InsertValueInst *Create(Value *Agg, Value *Val,
1751 ArrayRef<unsigned> Idxs,
1752 const Twine &NameStr,
1753 BasicBlock *InsertAtEnd) {
1754 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1757 /// Transparently provide more efficient getOperand methods.
1758 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1760 typedef const unsigned* idx_iterator;
1761 inline idx_iterator idx_begin() const { return Indices.begin(); }
1762 inline idx_iterator idx_end() const { return Indices.end(); }
1764 Value *getAggregateOperand() {
1765 return getOperand(0);
1767 const Value *getAggregateOperand() const {
1768 return getOperand(0);
1770 static unsigned getAggregateOperandIndex() {
1771 return 0U; // get index for modifying correct operand
1774 Value *getInsertedValueOperand() {
1775 return getOperand(1);
1777 const Value *getInsertedValueOperand() const {
1778 return getOperand(1);
1780 static unsigned getInsertedValueOperandIndex() {
1781 return 1U; // get index for modifying correct operand
1784 ArrayRef<unsigned> getIndices() const {
1788 unsigned getNumIndices() const {
1789 return (unsigned)Indices.size();
1792 bool hasIndices() const {
1796 // Methods for support type inquiry through isa, cast, and dyn_cast:
1797 static inline bool classof(const InsertValueInst *) { return true; }
1798 static inline bool classof(const Instruction *I) {
1799 return I->getOpcode() == Instruction::InsertValue;
1801 static inline bool classof(const Value *V) {
1802 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1807 struct OperandTraits<InsertValueInst> :
1808 public FixedNumOperandTraits<InsertValueInst, 2> {
1811 InsertValueInst::InsertValueInst(Value *Agg,
1813 ArrayRef<unsigned> Idxs,
1814 const Twine &NameStr,
1815 Instruction *InsertBefore)
1816 : Instruction(Agg->getType(), InsertValue,
1817 OperandTraits<InsertValueInst>::op_begin(this),
1819 init(Agg, Val, Idxs, NameStr);
1821 InsertValueInst::InsertValueInst(Value *Agg,
1823 ArrayRef<unsigned> Idxs,
1824 const Twine &NameStr,
1825 BasicBlock *InsertAtEnd)
1826 : Instruction(Agg->getType(), InsertValue,
1827 OperandTraits<InsertValueInst>::op_begin(this),
1829 init(Agg, Val, Idxs, NameStr);
1832 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1834 //===----------------------------------------------------------------------===//
1836 //===----------------------------------------------------------------------===//
1838 // PHINode - The PHINode class is used to represent the magical mystical PHI
1839 // node, that can not exist in nature, but can be synthesized in a computer
1840 // scientist's overactive imagination.
1842 class PHINode : public Instruction {
1843 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1844 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1845 /// the number actually in use.
1846 unsigned ReservedSpace;
1847 PHINode(const PHINode &PN);
1848 // allocate space for exactly zero operands
1849 void *operator new(size_t s) {
1850 return User::operator new(s, 0);
1852 explicit PHINode(Type *Ty, unsigned NumReservedValues,
1853 const Twine &NameStr = "", Instruction *InsertBefore = 0)
1854 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1855 ReservedSpace(NumReservedValues) {
1857 OperandList = allocHungoffUses(ReservedSpace);
1860 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
1861 BasicBlock *InsertAtEnd)
1862 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1863 ReservedSpace(NumReservedValues) {
1865 OperandList = allocHungoffUses(ReservedSpace);
1868 // allocHungoffUses - this is more complicated than the generic
1869 // User::allocHungoffUses, because we have to allocate Uses for the incoming
1870 // values and pointers to the incoming blocks, all in one allocation.
1871 Use *allocHungoffUses(unsigned) const;
1873 virtual PHINode *clone_impl() const;
1875 /// Constructors - NumReservedValues is a hint for the number of incoming
1876 /// edges that this phi node will have (use 0 if you really have no idea).
1877 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
1878 const Twine &NameStr = "",
1879 Instruction *InsertBefore = 0) {
1880 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
1882 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
1883 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1884 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
1888 /// Provide fast operand accessors
1889 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1891 // Block iterator interface. This provides access to the list of incoming
1892 // basic blocks, which parallels the list of incoming values.
1894 typedef BasicBlock **block_iterator;
1895 typedef BasicBlock * const *const_block_iterator;
1897 block_iterator block_begin() {
1899 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
1900 return reinterpret_cast<block_iterator>(ref + 1);
1903 const_block_iterator block_begin() const {
1904 const Use::UserRef *ref =
1905 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
1906 return reinterpret_cast<const_block_iterator>(ref + 1);
1909 block_iterator block_end() {
1910 return block_begin() + getNumOperands();
1913 const_block_iterator block_end() const {
1914 return block_begin() + getNumOperands();
1917 /// getNumIncomingValues - Return the number of incoming edges
1919 unsigned getNumIncomingValues() const { return getNumOperands(); }
1921 /// getIncomingValue - Return incoming value number x
1923 Value *getIncomingValue(unsigned i) const {
1924 return getOperand(i);
1926 void setIncomingValue(unsigned i, Value *V) {
1929 static unsigned getOperandNumForIncomingValue(unsigned i) {
1932 static unsigned getIncomingValueNumForOperand(unsigned i) {
1936 /// getIncomingBlock - Return incoming basic block number @p i.
1938 BasicBlock *getIncomingBlock(unsigned i) const {
1939 return block_begin()[i];
1942 /// getIncomingBlock - Return incoming basic block corresponding
1943 /// to an operand of the PHI.
1945 BasicBlock *getIncomingBlock(const Use &U) const {
1946 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
1947 return getIncomingBlock(unsigned(&U - op_begin()));
1950 /// getIncomingBlock - Return incoming basic block corresponding
1951 /// to value use iterator.
1953 template <typename U>
1954 BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
1955 return getIncomingBlock(I.getUse());
1958 void setIncomingBlock(unsigned i, BasicBlock *BB) {
1959 block_begin()[i] = BB;
1962 /// addIncoming - Add an incoming value to the end of the PHI list
1964 void addIncoming(Value *V, BasicBlock *BB) {
1965 assert(V && "PHI node got a null value!");
1966 assert(BB && "PHI node got a null basic block!");
1967 assert(getType() == V->getType() &&
1968 "All operands to PHI node must be the same type as the PHI node!");
1969 if (NumOperands == ReservedSpace)
1970 growOperands(); // Get more space!
1971 // Initialize some new operands.
1973 setIncomingValue(NumOperands - 1, V);
1974 setIncomingBlock(NumOperands - 1, BB);
1977 /// removeIncomingValue - Remove an incoming value. This is useful if a
1978 /// predecessor basic block is deleted. The value removed is returned.
1980 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1981 /// is true), the PHI node is destroyed and any uses of it are replaced with
1982 /// dummy values. The only time there should be zero incoming values to a PHI
1983 /// node is when the block is dead, so this strategy is sound.
1985 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1987 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
1988 int Idx = getBasicBlockIndex(BB);
1989 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1990 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1993 /// getBasicBlockIndex - Return the first index of the specified basic
1994 /// block in the value list for this PHI. Returns -1 if no instance.
1996 int getBasicBlockIndex(const BasicBlock *BB) const {
1997 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
1998 if (block_begin()[i] == BB)
2003 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2004 int Idx = getBasicBlockIndex(BB);
2005 assert(Idx >= 0 && "Invalid basic block argument!");
2006 return getIncomingValue(Idx);
2009 /// hasConstantValue - If the specified PHI node always merges together the
2010 /// same value, return the value, otherwise return null.
2011 Value *hasConstantValue() const;
2013 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2014 static inline bool classof(const PHINode *) { return true; }
2015 static inline bool classof(const Instruction *I) {
2016 return I->getOpcode() == Instruction::PHI;
2018 static inline bool classof(const Value *V) {
2019 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2022 void growOperands();
2026 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2029 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
2032 //===----------------------------------------------------------------------===//
2034 //===----------------------------------------------------------------------===//
2036 //===---------------------------------------------------------------------------
2037 /// ReturnInst - Return a value (possibly void), from a function. Execution
2038 /// does not continue in this function any longer.
2040 class ReturnInst : public TerminatorInst {
2041 ReturnInst(const ReturnInst &RI);
2044 // ReturnInst constructors:
2045 // ReturnInst() - 'ret void' instruction
2046 // ReturnInst( null) - 'ret void' instruction
2047 // ReturnInst(Value* X) - 'ret X' instruction
2048 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
2049 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
2050 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2051 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
2053 // NOTE: If the Value* passed is of type void then the constructor behaves as
2054 // if it was passed NULL.
2055 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
2056 Instruction *InsertBefore = 0);
2057 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2058 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2060 virtual ReturnInst *clone_impl() const;
2062 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
2063 Instruction *InsertBefore = 0) {
2064 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2066 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2067 BasicBlock *InsertAtEnd) {
2068 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2070 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2071 return new(0) ReturnInst(C, InsertAtEnd);
2073 virtual ~ReturnInst();
2075 /// Provide fast operand accessors
2076 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2078 /// Convenience accessor. Returns null if there is no return value.
2079 Value *getReturnValue() const {
2080 return getNumOperands() != 0 ? getOperand(0) : 0;
2083 unsigned getNumSuccessors() const { return 0; }
2085 // Methods for support type inquiry through isa, cast, and dyn_cast:
2086 static inline bool classof(const ReturnInst *) { return true; }
2087 static inline bool classof(const Instruction *I) {
2088 return (I->getOpcode() == Instruction::Ret);
2090 static inline bool classof(const Value *V) {
2091 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2094 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2095 virtual unsigned getNumSuccessorsV() const;
2096 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2100 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2103 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2105 //===----------------------------------------------------------------------===//
2107 //===----------------------------------------------------------------------===//
2109 //===---------------------------------------------------------------------------
2110 /// BranchInst - Conditional or Unconditional Branch instruction.
2112 class BranchInst : public TerminatorInst {
2113 /// Ops list - Branches are strange. The operands are ordered:
2114 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2115 /// they don't have to check for cond/uncond branchness. These are mostly
2116 /// accessed relative from op_end().
2117 BranchInst(const BranchInst &BI);
2119 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2120 // BranchInst(BB *B) - 'br B'
2121 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2122 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2123 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2124 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2125 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2126 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2127 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2128 Instruction *InsertBefore = 0);
2129 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2130 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2131 BasicBlock *InsertAtEnd);
2133 virtual BranchInst *clone_impl() const;
2135 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2136 return new(1) BranchInst(IfTrue, InsertBefore);
2138 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2139 Value *Cond, Instruction *InsertBefore = 0) {
2140 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2142 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2143 return new(1) BranchInst(IfTrue, InsertAtEnd);
2145 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2146 Value *Cond, BasicBlock *InsertAtEnd) {
2147 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2150 /// Transparently provide more efficient getOperand methods.
2151 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2153 bool isUnconditional() const { return getNumOperands() == 1; }
2154 bool isConditional() const { return getNumOperands() == 3; }
2156 Value *getCondition() const {
2157 assert(isConditional() && "Cannot get condition of an uncond branch!");
2161 void setCondition(Value *V) {
2162 assert(isConditional() && "Cannot set condition of unconditional branch!");
2166 unsigned getNumSuccessors() const { return 1+isConditional(); }
2168 BasicBlock *getSuccessor(unsigned i) const {
2169 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2170 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2173 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2174 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2175 *(&Op<-1>() - idx) = (Value*)NewSucc;
2178 // Methods for support type inquiry through isa, cast, and dyn_cast:
2179 static inline bool classof(const BranchInst *) { return true; }
2180 static inline bool classof(const Instruction *I) {
2181 return (I->getOpcode() == Instruction::Br);
2183 static inline bool classof(const Value *V) {
2184 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2187 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2188 virtual unsigned getNumSuccessorsV() const;
2189 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2193 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2196 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2198 //===----------------------------------------------------------------------===//
2200 //===----------------------------------------------------------------------===//
2202 //===---------------------------------------------------------------------------
2203 /// SwitchInst - Multiway switch
2205 class SwitchInst : public TerminatorInst {
2206 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2207 unsigned ReservedSpace;
2208 // Operand[0] = Value to switch on
2209 // Operand[1] = Default basic block destination
2210 // Operand[2n ] = Value to match
2211 // Operand[2n+1] = BasicBlock to go to on match
2212 SwitchInst(const SwitchInst &SI);
2213 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2214 void growOperands();
2215 // allocate space for exactly zero operands
2216 void *operator new(size_t s) {
2217 return User::operator new(s, 0);
2219 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2220 /// switch on and a default destination. The number of additional cases can
2221 /// be specified here to make memory allocation more efficient. This
2222 /// constructor can also autoinsert before another instruction.
2223 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2224 Instruction *InsertBefore);
2226 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2227 /// switch on and a default destination. The number of additional cases can
2228 /// be specified here to make memory allocation more efficient. This
2229 /// constructor also autoinserts at the end of the specified BasicBlock.
2230 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2231 BasicBlock *InsertAtEnd);
2233 virtual SwitchInst *clone_impl() const;
2235 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2236 unsigned NumCases, Instruction *InsertBefore = 0) {
2237 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2239 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2240 unsigned NumCases, BasicBlock *InsertAtEnd) {
2241 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2245 /// Provide fast operand accessors
2246 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2248 // Accessor Methods for Switch stmt
2249 Value *getCondition() const { return getOperand(0); }
2250 void setCondition(Value *V) { setOperand(0, V); }
2252 BasicBlock *getDefaultDest() const {
2253 return cast<BasicBlock>(getOperand(1));
2256 /// getNumCases - return the number of 'cases' in this switch instruction.
2257 /// Note that case #0 is always the default case.
2258 unsigned getNumCases() const {
2259 return getNumOperands()/2;
2262 /// getCaseValue - Return the specified case value. Note that case #0, the
2263 /// default destination, does not have a case value.
2264 ConstantInt *getCaseValue(unsigned i) {
2265 assert(i && i < getNumCases() && "Illegal case value to get!");
2266 return getSuccessorValue(i);
2269 /// getCaseValue - Return the specified case value. Note that case #0, the
2270 /// default destination, does not have a case value.
2271 const ConstantInt *getCaseValue(unsigned i) const {
2272 assert(i && i < getNumCases() && "Illegal case value to get!");
2273 return getSuccessorValue(i);
2276 /// findCaseValue - Search all of the case values for the specified constant.
2277 /// If it is explicitly handled, return the case number of it, otherwise
2278 /// return 0 to indicate that it is handled by the default handler.
2279 unsigned findCaseValue(const ConstantInt *C) const {
2280 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2281 if (getCaseValue(i) == C)
2286 /// findCaseDest - Finds the unique case value for a given successor. Returns
2287 /// null if the successor is not found, not unique, or is the default case.
2288 ConstantInt *findCaseDest(BasicBlock *BB) {
2289 if (BB == getDefaultDest()) return NULL;
2291 ConstantInt *CI = NULL;
2292 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2293 if (getSuccessor(i) == BB) {
2294 if (CI) return NULL; // Multiple cases lead to BB.
2295 else CI = getCaseValue(i);
2301 /// addCase - Add an entry to the switch instruction...
2303 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2305 /// removeCase - This method removes the specified successor from the switch
2306 /// instruction. Note that this cannot be used to remove the default
2307 /// destination (successor #0). Also note that this operation may reorder the
2308 /// remaining cases at index idx and above.
2310 void removeCase(unsigned idx);
2312 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2313 BasicBlock *getSuccessor(unsigned idx) const {
2314 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2315 return cast<BasicBlock>(getOperand(idx*2+1));
2317 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2318 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2319 setOperand(idx*2+1, (Value*)NewSucc);
2322 // getSuccessorValue - Return the value associated with the specified
2324 ConstantInt *getSuccessorValue(unsigned idx) const {
2325 assert(idx < getNumSuccessors() && "Successor # out of range!");
2326 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2329 // Methods for support type inquiry through isa, cast, and dyn_cast:
2330 static inline bool classof(const SwitchInst *) { return true; }
2331 static inline bool classof(const Instruction *I) {
2332 return I->getOpcode() == Instruction::Switch;
2334 static inline bool classof(const Value *V) {
2335 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2338 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2339 virtual unsigned getNumSuccessorsV() const;
2340 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2344 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2347 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2350 //===----------------------------------------------------------------------===//
2351 // IndirectBrInst Class
2352 //===----------------------------------------------------------------------===//
2354 //===---------------------------------------------------------------------------
2355 /// IndirectBrInst - Indirect Branch Instruction.
2357 class IndirectBrInst : public TerminatorInst {
2358 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2359 unsigned ReservedSpace;
2360 // Operand[0] = Value to switch on
2361 // Operand[1] = Default basic block destination
2362 // Operand[2n ] = Value to match
2363 // Operand[2n+1] = BasicBlock to go to on match
2364 IndirectBrInst(const IndirectBrInst &IBI);
2365 void init(Value *Address, unsigned NumDests);
2366 void growOperands();
2367 // allocate space for exactly zero operands
2368 void *operator new(size_t s) {
2369 return User::operator new(s, 0);
2371 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2372 /// Address to jump to. The number of expected destinations can be specified
2373 /// here to make memory allocation more efficient. This constructor can also
2374 /// autoinsert before another instruction.
2375 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2377 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2378 /// Address to jump to. The number of expected destinations can be specified
2379 /// here to make memory allocation more efficient. This constructor also
2380 /// autoinserts at the end of the specified BasicBlock.
2381 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2383 virtual IndirectBrInst *clone_impl() const;
2385 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2386 Instruction *InsertBefore = 0) {
2387 return new IndirectBrInst(Address, NumDests, InsertBefore);
2389 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2390 BasicBlock *InsertAtEnd) {
2391 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2395 /// Provide fast operand accessors.
2396 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2398 // Accessor Methods for IndirectBrInst instruction.
2399 Value *getAddress() { return getOperand(0); }
2400 const Value *getAddress() const { return getOperand(0); }
2401 void setAddress(Value *V) { setOperand(0, V); }
2404 /// getNumDestinations - return the number of possible destinations in this
2405 /// indirectbr instruction.
2406 unsigned getNumDestinations() const { return getNumOperands()-1; }
2408 /// getDestination - Return the specified destination.
2409 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2410 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2412 /// addDestination - Add a destination.
2414 void addDestination(BasicBlock *Dest);
2416 /// removeDestination - This method removes the specified successor from the
2417 /// indirectbr instruction.
2418 void removeDestination(unsigned i);
2420 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2421 BasicBlock *getSuccessor(unsigned i) const {
2422 return cast<BasicBlock>(getOperand(i+1));
2424 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2425 setOperand(i+1, (Value*)NewSucc);
2428 // Methods for support type inquiry through isa, cast, and dyn_cast:
2429 static inline bool classof(const IndirectBrInst *) { return true; }
2430 static inline bool classof(const Instruction *I) {
2431 return I->getOpcode() == Instruction::IndirectBr;
2433 static inline bool classof(const Value *V) {
2434 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2437 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2438 virtual unsigned getNumSuccessorsV() const;
2439 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2443 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2446 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2449 //===----------------------------------------------------------------------===//
2451 //===----------------------------------------------------------------------===//
2453 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2454 /// calling convention of the call.
2456 class InvokeInst : public TerminatorInst {
2457 AttrListPtr AttributeList;
2458 InvokeInst(const InvokeInst &BI);
2459 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2460 ArrayRef<Value *> Args, const Twine &NameStr);
2462 /// Construct an InvokeInst given a range of arguments.
2464 /// @brief Construct an InvokeInst from a range of arguments
2465 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2466 ArrayRef<Value *> Args, unsigned Values,
2467 const Twine &NameStr, Instruction *InsertBefore);
2469 /// Construct an InvokeInst given a range of arguments.
2471 /// @brief Construct an InvokeInst from a range of arguments
2472 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2473 ArrayRef<Value *> Args, unsigned Values,
2474 const Twine &NameStr, BasicBlock *InsertAtEnd);
2476 virtual InvokeInst *clone_impl() const;
2478 static InvokeInst *Create(Value *Func,
2479 BasicBlock *IfNormal, BasicBlock *IfException,
2480 ArrayRef<Value *> Args, const Twine &NameStr = "",
2481 Instruction *InsertBefore = 0) {
2482 unsigned Values = unsigned(Args.size()) + 3;
2483 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2484 Values, NameStr, InsertBefore);
2486 static InvokeInst *Create(Value *Func,
2487 BasicBlock *IfNormal, BasicBlock *IfException,
2488 ArrayRef<Value *> Args, const Twine &NameStr,
2489 BasicBlock *InsertAtEnd) {
2490 unsigned Values = unsigned(Args.size()) + 3;
2491 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2492 Values, NameStr, InsertAtEnd);
2495 /// Provide fast operand accessors
2496 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2498 /// getNumArgOperands - Return the number of invoke arguments.
2500 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2502 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2504 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2505 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2507 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2509 CallingConv::ID getCallingConv() const {
2510 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2512 void setCallingConv(CallingConv::ID CC) {
2513 setInstructionSubclassData(static_cast<unsigned>(CC));
2516 /// getAttributes - Return the parameter attributes for this invoke.
2518 const AttrListPtr &getAttributes() const { return AttributeList; }
2520 /// setAttributes - Set the parameter attributes for this invoke.
2522 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2524 /// addAttribute - adds the attribute to the list of attributes.
2525 void addAttribute(unsigned i, Attributes attr);
2527 /// removeAttribute - removes the attribute from the list of attributes.
2528 void removeAttribute(unsigned i, Attributes attr);
2530 /// @brief Determine whether the call or the callee has the given attribute.
2531 bool paramHasAttr(unsigned i, Attributes attr) const;
2533 /// @brief Extract the alignment for a call or parameter (0=unknown).
2534 unsigned getParamAlignment(unsigned i) const {
2535 return AttributeList.getParamAlignment(i);
2538 /// @brief Return true if the call should not be inlined.
2539 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2540 void setIsNoInline(bool Value = true) {
2541 if (Value) addAttribute(~0, Attribute::NoInline);
2542 else removeAttribute(~0, Attribute::NoInline);
2545 /// @brief Determine if the call does not access memory.
2546 bool doesNotAccessMemory() const {
2547 return paramHasAttr(~0, Attribute::ReadNone);
2549 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2550 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2551 else removeAttribute(~0, Attribute::ReadNone);
2554 /// @brief Determine if the call does not access or only reads memory.
2555 bool onlyReadsMemory() const {
2556 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2558 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2559 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2560 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2563 /// @brief Determine if the call cannot return.
2564 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
2565 void setDoesNotReturn(bool DoesNotReturn = true) {
2566 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2567 else removeAttribute(~0, Attribute::NoReturn);
2570 /// @brief Determine if the call cannot unwind.
2571 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
2572 void setDoesNotThrow(bool DoesNotThrow = true) {
2573 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2574 else removeAttribute(~0, Attribute::NoUnwind);
2577 /// @brief Determine if the call returns a structure through first
2578 /// pointer argument.
2579 bool hasStructRetAttr() const {
2580 // Be friendly and also check the callee.
2581 return paramHasAttr(1, Attribute::StructRet);
2584 /// @brief Determine if any call argument is an aggregate passed by value.
2585 bool hasByValArgument() const {
2586 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2589 /// getCalledFunction - Return the function called, or null if this is an
2590 /// indirect function invocation.
2592 Function *getCalledFunction() const {
2593 return dyn_cast<Function>(Op<-3>());
2596 /// getCalledValue - Get a pointer to the function that is invoked by this
2598 const Value *getCalledValue() const { return Op<-3>(); }
2599 Value *getCalledValue() { return Op<-3>(); }
2601 /// setCalledFunction - Set the function called.
2602 void setCalledFunction(Value* Fn) {
2606 // get*Dest - Return the destination basic blocks...
2607 BasicBlock *getNormalDest() const {
2608 return cast<BasicBlock>(Op<-2>());
2610 BasicBlock *getUnwindDest() const {
2611 return cast<BasicBlock>(Op<-1>());
2613 void setNormalDest(BasicBlock *B) {
2614 Op<-2>() = reinterpret_cast<Value*>(B);
2616 void setUnwindDest(BasicBlock *B) {
2617 Op<-1>() = reinterpret_cast<Value*>(B);
2620 BasicBlock *getSuccessor(unsigned i) const {
2621 assert(i < 2 && "Successor # out of range for invoke!");
2622 return i == 0 ? getNormalDest() : getUnwindDest();
2625 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2626 assert(idx < 2 && "Successor # out of range for invoke!");
2627 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2630 unsigned getNumSuccessors() const { return 2; }
2632 // Methods for support type inquiry through isa, cast, and dyn_cast:
2633 static inline bool classof(const InvokeInst *) { return true; }
2634 static inline bool classof(const Instruction *I) {
2635 return (I->getOpcode() == Instruction::Invoke);
2637 static inline bool classof(const Value *V) {
2638 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2642 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2643 virtual unsigned getNumSuccessorsV() const;
2644 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2646 // Shadow Instruction::setInstructionSubclassData with a private forwarding
2647 // method so that subclasses cannot accidentally use it.
2648 void setInstructionSubclassData(unsigned short D) {
2649 Instruction::setInstructionSubclassData(D);
2654 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
2657 InvokeInst::InvokeInst(Value *Func,
2658 BasicBlock *IfNormal, BasicBlock *IfException,
2659 ArrayRef<Value *> Args, unsigned Values,
2660 const Twine &NameStr, Instruction *InsertBefore)
2661 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2662 ->getElementType())->getReturnType(),
2663 Instruction::Invoke,
2664 OperandTraits<InvokeInst>::op_end(this) - Values,
2665 Values, InsertBefore) {
2666 init(Func, IfNormal, IfException, Args, NameStr);
2668 InvokeInst::InvokeInst(Value *Func,
2669 BasicBlock *IfNormal, BasicBlock *IfException,
2670 ArrayRef<Value *> Args, unsigned Values,
2671 const Twine &NameStr, BasicBlock *InsertAtEnd)
2672 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2673 ->getElementType())->getReturnType(),
2674 Instruction::Invoke,
2675 OperandTraits<InvokeInst>::op_end(this) - Values,
2676 Values, InsertAtEnd) {
2677 init(Func, IfNormal, IfException, Args, NameStr);
2680 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2682 //===----------------------------------------------------------------------===//
2684 //===----------------------------------------------------------------------===//
2686 //===---------------------------------------------------------------------------
2687 /// UnwindInst - Immediately exit the current function, unwinding the stack
2688 /// until an invoke instruction is found.
2690 class UnwindInst : public TerminatorInst {
2691 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2693 virtual UnwindInst *clone_impl() const;
2695 // allocate space for exactly zero operands
2696 void *operator new(size_t s) {
2697 return User::operator new(s, 0);
2699 explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2700 explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2702 unsigned getNumSuccessors() const { return 0; }
2704 // Methods for support type inquiry through isa, cast, and dyn_cast:
2705 static inline bool classof(const UnwindInst *) { return true; }
2706 static inline bool classof(const Instruction *I) {
2707 return I->getOpcode() == Instruction::Unwind;
2709 static inline bool classof(const Value *V) {
2710 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2713 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2714 virtual unsigned getNumSuccessorsV() const;
2715 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2718 //===----------------------------------------------------------------------===//
2720 //===----------------------------------------------------------------------===//
2722 //===---------------------------------------------------------------------------
2723 /// ResumeInst - Resume the propagation of an exception.
2725 class ResumeInst : public TerminatorInst {
2726 ResumeInst(const ResumeInst &RI);
2728 explicit ResumeInst(Value *Exn, Instruction *InsertBefore=0);
2729 ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
2731 virtual ResumeInst *clone_impl() const;
2733 static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = 0) {
2734 return new(1) ResumeInst(Exn, InsertBefore);
2736 static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
2737 return new(1) ResumeInst(Exn, InsertAtEnd);
2740 /// Provide fast operand accessors
2741 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2743 /// Convenience accessor.
2744 Value *getValue() const { return Op<0>(); }
2746 unsigned getNumSuccessors() const { return 0; }
2748 // Methods for support type inquiry through isa, cast, and dyn_cast:
2749 static inline bool classof(const ResumeInst *) { return true; }
2750 static inline bool classof(const Instruction *I) {
2751 return I->getOpcode() == Instruction::Resume;
2753 static inline bool classof(const Value *V) {
2754 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2757 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2758 virtual unsigned getNumSuccessorsV() const;
2759 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2763 struct OperandTraits<ResumeInst> :
2764 public FixedNumOperandTraits<ResumeInst, 1> {
2767 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
2769 //===----------------------------------------------------------------------===//
2770 // UnreachableInst Class
2771 //===----------------------------------------------------------------------===//
2773 //===---------------------------------------------------------------------------
2774 /// UnreachableInst - This function has undefined behavior. In particular, the
2775 /// presence of this instruction indicates some higher level knowledge that the
2776 /// end of the block cannot be reached.
2778 class UnreachableInst : public TerminatorInst {
2779 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2781 virtual UnreachableInst *clone_impl() const;
2784 // allocate space for exactly zero operands
2785 void *operator new(size_t s) {
2786 return User::operator new(s, 0);
2788 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2789 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2791 unsigned getNumSuccessors() const { return 0; }
2793 // Methods for support type inquiry through isa, cast, and dyn_cast:
2794 static inline bool classof(const UnreachableInst *) { return true; }
2795 static inline bool classof(const Instruction *I) {
2796 return I->getOpcode() == Instruction::Unreachable;
2798 static inline bool classof(const Value *V) {
2799 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2802 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2803 virtual unsigned getNumSuccessorsV() const;
2804 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2807 //===----------------------------------------------------------------------===//
2809 //===----------------------------------------------------------------------===//
2811 /// @brief This class represents a truncation of integer types.
2812 class TruncInst : public CastInst {
2814 /// @brief Clone an identical TruncInst
2815 virtual TruncInst *clone_impl() const;
2818 /// @brief Constructor with insert-before-instruction semantics
2820 Value *S, ///< The value to be truncated
2821 Type *Ty, ///< The (smaller) type to truncate to
2822 const Twine &NameStr = "", ///< A name for the new instruction
2823 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2826 /// @brief Constructor with insert-at-end-of-block semantics
2828 Value *S, ///< The value to be truncated
2829 Type *Ty, ///< The (smaller) type to truncate to
2830 const Twine &NameStr, ///< A name for the new instruction
2831 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2834 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2835 static inline bool classof(const TruncInst *) { return true; }
2836 static inline bool classof(const Instruction *I) {
2837 return I->getOpcode() == Trunc;
2839 static inline bool classof(const Value *V) {
2840 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2844 //===----------------------------------------------------------------------===//
2846 //===----------------------------------------------------------------------===//
2848 /// @brief This class represents zero extension of integer types.
2849 class ZExtInst : public CastInst {
2851 /// @brief Clone an identical ZExtInst
2852 virtual ZExtInst *clone_impl() const;
2855 /// @brief Constructor with insert-before-instruction semantics
2857 Value *S, ///< The value to be zero extended
2858 Type *Ty, ///< The type to zero extend to
2859 const Twine &NameStr = "", ///< A name for the new instruction
2860 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2863 /// @brief Constructor with insert-at-end semantics.
2865 Value *S, ///< The value to be zero extended
2866 Type *Ty, ///< The type to zero extend to
2867 const Twine &NameStr, ///< A name for the new instruction
2868 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2871 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2872 static inline bool classof(const ZExtInst *) { return true; }
2873 static inline bool classof(const Instruction *I) {
2874 return I->getOpcode() == ZExt;
2876 static inline bool classof(const Value *V) {
2877 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2881 //===----------------------------------------------------------------------===//
2883 //===----------------------------------------------------------------------===//
2885 /// @brief This class represents a sign extension of integer types.
2886 class SExtInst : public CastInst {
2888 /// @brief Clone an identical SExtInst
2889 virtual SExtInst *clone_impl() const;
2892 /// @brief Constructor with insert-before-instruction semantics
2894 Value *S, ///< The value to be sign extended
2895 Type *Ty, ///< The type to sign extend to
2896 const Twine &NameStr = "", ///< A name for the new instruction
2897 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2900 /// @brief Constructor with insert-at-end-of-block semantics
2902 Value *S, ///< The value to be sign extended
2903 Type *Ty, ///< The type to sign extend to
2904 const Twine &NameStr, ///< A name for the new instruction
2905 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2908 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2909 static inline bool classof(const SExtInst *) { return true; }
2910 static inline bool classof(const Instruction *I) {
2911 return I->getOpcode() == SExt;
2913 static inline bool classof(const Value *V) {
2914 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2918 //===----------------------------------------------------------------------===//
2919 // FPTruncInst Class
2920 //===----------------------------------------------------------------------===//
2922 /// @brief This class represents a truncation of floating point types.
2923 class FPTruncInst : public CastInst {
2925 /// @brief Clone an identical FPTruncInst
2926 virtual FPTruncInst *clone_impl() const;
2929 /// @brief Constructor with insert-before-instruction semantics
2931 Value *S, ///< The value to be truncated
2932 Type *Ty, ///< The type to truncate to
2933 const Twine &NameStr = "", ///< A name for the new instruction
2934 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2937 /// @brief Constructor with insert-before-instruction semantics
2939 Value *S, ///< The value to be truncated
2940 Type *Ty, ///< The type to truncate to
2941 const Twine &NameStr, ///< A name for the new instruction
2942 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2945 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2946 static inline bool classof(const FPTruncInst *) { return true; }
2947 static inline bool classof(const Instruction *I) {
2948 return I->getOpcode() == FPTrunc;
2950 static inline bool classof(const Value *V) {
2951 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2955 //===----------------------------------------------------------------------===//
2957 //===----------------------------------------------------------------------===//
2959 /// @brief This class represents an extension of floating point types.
2960 class FPExtInst : public CastInst {
2962 /// @brief Clone an identical FPExtInst
2963 virtual FPExtInst *clone_impl() const;
2966 /// @brief Constructor with insert-before-instruction semantics
2968 Value *S, ///< The value to be extended
2969 Type *Ty, ///< The type to extend to
2970 const Twine &NameStr = "", ///< A name for the new instruction
2971 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2974 /// @brief Constructor with insert-at-end-of-block semantics
2976 Value *S, ///< The value to be extended
2977 Type *Ty, ///< The type to extend to
2978 const Twine &NameStr, ///< A name for the new instruction
2979 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2982 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2983 static inline bool classof(const FPExtInst *) { return true; }
2984 static inline bool classof(const Instruction *I) {
2985 return I->getOpcode() == FPExt;
2987 static inline bool classof(const Value *V) {
2988 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2992 //===----------------------------------------------------------------------===//
2994 //===----------------------------------------------------------------------===//
2996 /// @brief This class represents a cast unsigned integer to floating point.
2997 class UIToFPInst : public CastInst {
2999 /// @brief Clone an identical UIToFPInst
3000 virtual UIToFPInst *clone_impl() const;
3003 /// @brief Constructor with insert-before-instruction semantics
3005 Value *S, ///< The value to be converted
3006 Type *Ty, ///< The type to convert to
3007 const Twine &NameStr = "", ///< A name for the new instruction
3008 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3011 /// @brief Constructor with insert-at-end-of-block semantics
3013 Value *S, ///< The value to be converted
3014 Type *Ty, ///< The type to convert to
3015 const Twine &NameStr, ///< A name for the new instruction
3016 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3019 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3020 static inline bool classof(const UIToFPInst *) { return true; }
3021 static inline bool classof(const Instruction *I) {
3022 return I->getOpcode() == UIToFP;
3024 static inline bool classof(const Value *V) {
3025 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3029 //===----------------------------------------------------------------------===//
3031 //===----------------------------------------------------------------------===//
3033 /// @brief This class represents a cast from signed integer to floating point.
3034 class SIToFPInst : public CastInst {
3036 /// @brief Clone an identical SIToFPInst
3037 virtual SIToFPInst *clone_impl() const;
3040 /// @brief Constructor with insert-before-instruction semantics
3042 Value *S, ///< The value to be converted
3043 Type *Ty, ///< The type to convert to
3044 const Twine &NameStr = "", ///< A name for the new instruction
3045 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3048 /// @brief Constructor with insert-at-end-of-block semantics
3050 Value *S, ///< The value to be converted
3051 Type *Ty, ///< The type to convert to
3052 const Twine &NameStr, ///< A name for the new instruction
3053 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3056 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3057 static inline bool classof(const SIToFPInst *) { return true; }
3058 static inline bool classof(const Instruction *I) {
3059 return I->getOpcode() == SIToFP;
3061 static inline bool classof(const Value *V) {
3062 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3066 //===----------------------------------------------------------------------===//
3068 //===----------------------------------------------------------------------===//
3070 /// @brief This class represents a cast from floating point to unsigned integer
3071 class FPToUIInst : public CastInst {
3073 /// @brief Clone an identical FPToUIInst
3074 virtual FPToUIInst *clone_impl() const;
3077 /// @brief Constructor with insert-before-instruction semantics
3079 Value *S, ///< The value to be converted
3080 Type *Ty, ///< The type to convert to
3081 const Twine &NameStr = "", ///< A name for the new instruction
3082 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3085 /// @brief Constructor with insert-at-end-of-block semantics
3087 Value *S, ///< The value to be converted
3088 Type *Ty, ///< The type to convert to
3089 const Twine &NameStr, ///< A name for the new instruction
3090 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3093 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3094 static inline bool classof(const FPToUIInst *) { return true; }
3095 static inline bool classof(const Instruction *I) {
3096 return I->getOpcode() == FPToUI;
3098 static inline bool classof(const Value *V) {
3099 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3103 //===----------------------------------------------------------------------===//
3105 //===----------------------------------------------------------------------===//
3107 /// @brief This class represents a cast from floating point to signed integer.
3108 class FPToSIInst : public CastInst {
3110 /// @brief Clone an identical FPToSIInst
3111 virtual FPToSIInst *clone_impl() const;
3114 /// @brief Constructor with insert-before-instruction semantics
3116 Value *S, ///< The value to be converted
3117 Type *Ty, ///< The type to convert to
3118 const Twine &NameStr = "", ///< A name for the new instruction
3119 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3122 /// @brief Constructor with insert-at-end-of-block semantics
3124 Value *S, ///< The value to be converted
3125 Type *Ty, ///< The type to convert to
3126 const Twine &NameStr, ///< A name for the new instruction
3127 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3130 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3131 static inline bool classof(const FPToSIInst *) { return true; }
3132 static inline bool classof(const Instruction *I) {
3133 return I->getOpcode() == FPToSI;
3135 static inline bool classof(const Value *V) {
3136 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3140 //===----------------------------------------------------------------------===//
3141 // IntToPtrInst Class
3142 //===----------------------------------------------------------------------===//
3144 /// @brief This class represents a cast from an integer to a pointer.
3145 class IntToPtrInst : public CastInst {
3147 /// @brief Constructor with insert-before-instruction semantics
3149 Value *S, ///< The value to be converted
3150 Type *Ty, ///< The type to convert to
3151 const Twine &NameStr = "", ///< A name for the new instruction
3152 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3155 /// @brief Constructor with insert-at-end-of-block semantics
3157 Value *S, ///< The value to be converted
3158 Type *Ty, ///< The type to convert to
3159 const Twine &NameStr, ///< A name for the new instruction
3160 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3163 /// @brief Clone an identical IntToPtrInst
3164 virtual IntToPtrInst *clone_impl() const;
3166 // Methods for support type inquiry through isa, cast, and dyn_cast:
3167 static inline bool classof(const IntToPtrInst *) { return true; }
3168 static inline bool classof(const Instruction *I) {
3169 return I->getOpcode() == IntToPtr;
3171 static inline bool classof(const Value *V) {
3172 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3176 //===----------------------------------------------------------------------===//
3177 // PtrToIntInst Class
3178 //===----------------------------------------------------------------------===//
3180 /// @brief This class represents a cast from a pointer to an integer
3181 class PtrToIntInst : public CastInst {
3183 /// @brief Clone an identical PtrToIntInst
3184 virtual PtrToIntInst *clone_impl() const;
3187 /// @brief Constructor with insert-before-instruction semantics
3189 Value *S, ///< The value to be converted
3190 Type *Ty, ///< The type to convert to
3191 const Twine &NameStr = "", ///< A name for the new instruction
3192 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3195 /// @brief Constructor with insert-at-end-of-block semantics
3197 Value *S, ///< The value to be converted
3198 Type *Ty, ///< The type to convert to
3199 const Twine &NameStr, ///< A name for the new instruction
3200 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3203 // Methods for support type inquiry through isa, cast, and dyn_cast:
3204 static inline bool classof(const PtrToIntInst *) { return true; }
3205 static inline bool classof(const Instruction *I) {
3206 return I->getOpcode() == PtrToInt;
3208 static inline bool classof(const Value *V) {
3209 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3213 //===----------------------------------------------------------------------===//
3214 // BitCastInst Class
3215 //===----------------------------------------------------------------------===//
3217 /// @brief This class represents a no-op cast from one type to another.
3218 class BitCastInst : public CastInst {
3220 /// @brief Clone an identical BitCastInst
3221 virtual BitCastInst *clone_impl() const;
3224 /// @brief Constructor with insert-before-instruction semantics
3226 Value *S, ///< The value to be casted
3227 Type *Ty, ///< The type to casted to
3228 const Twine &NameStr = "", ///< A name for the new instruction
3229 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3232 /// @brief Constructor with insert-at-end-of-block semantics
3234 Value *S, ///< The value to be casted
3235 Type *Ty, ///< The type to casted to
3236 const Twine &NameStr, ///< A name for the new instruction
3237 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3240 // Methods for support type inquiry through isa, cast, and dyn_cast:
3241 static inline bool classof(const BitCastInst *) { return true; }
3242 static inline bool classof(const Instruction *I) {
3243 return I->getOpcode() == BitCast;
3245 static inline bool classof(const Value *V) {
3246 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3250 } // End llvm namespace