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)
2031 //===----------------------------------------------------------------------===//
2032 // LandingPadInst Class
2033 //===----------------------------------------------------------------------===//
2035 //===---------------------------------------------------------------------------
2036 /// LandingPadInst - The landingpad instruction holds all of the information
2037 /// necessary to generate correct exception handling. The landingpad instruction
2038 /// cannot be moved from the top of a landing pad block, which itself is
2039 /// accessible only from the 'unwind' edge of an invoke.
2041 class LandingPadInst : public Instruction {
2042 /// ReservedSpace - The number of operands actually allocated. NumOperands is
2043 /// the number actually in use.
2044 unsigned ReservedSpace;
2046 /// IsCleanup - True if the landingpad instruction is also a cleanup.
2048 LandingPadInst(const LandingPadInst &LP);
2050 enum ClauseType { Catch, Filter };
2052 /// ClauseIdxs - This indexes into the OperandList, indicating what the
2053 /// values are at a given index.
2054 SmallVector<ClauseType, 8> ClauseIdxs;
2056 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2057 // Allocate space for exactly zero operands.
2058 void *operator new(size_t s) {
2059 return User::operator new(s, 0);
2061 void growOperands();
2062 void init(Function *PersFn, unsigned NumReservedValues, const Twine &NameStr);
2064 explicit LandingPadInst(Type *RetTy, Function *PersonalityFn,
2065 unsigned NumReservedValues, const Twine &NameStr,
2066 Instruction *InsertBefore)
2067 : Instruction(RetTy, Instruction::LandingPad, 0, 0, InsertBefore),
2069 init(PersonalityFn, 1 + NumReservedValues, NameStr);
2071 explicit LandingPadInst(Type *RetTy, Function *PersonalityFn,
2072 unsigned NumReservedValues, const Twine &NameStr,
2073 BasicBlock *InsertAtEnd)
2074 : Instruction(RetTy, Instruction::LandingPad, 0, 0, InsertAtEnd),
2076 init(PersonalityFn, 1 + NumReservedValues, NameStr);
2079 virtual LandingPadInst *clone_impl() const;
2081 static LandingPadInst *Create(Type *RetTy, Function *PersonalityFn,
2082 unsigned NumReservedValues,
2083 const Twine &NameStr = "",
2084 Instruction *InsertBefore = 0) {
2085 return new LandingPadInst(RetTy, PersonalityFn, NumReservedValues, NameStr,
2088 static LandingPadInst *Create(Type *RetTy, Function *PersonalityFn,
2089 unsigned NumReservedValues,
2090 const Twine &NameStr, BasicBlock *InsertAtEnd) {
2091 return new LandingPadInst(RetTy, PersonalityFn, NumReservedValues, NameStr,
2096 /// Provide fast operand accessors
2097 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2099 /// getPersonalityFn - Get the personality function associated with this
2101 const Function *getPersonalityFn() const {
2102 return cast<Function>(getOperand(0));
2105 // Simple accessors.
2106 bool isCleanup() const { return IsCleanup; }
2107 void setCleanup(bool Val) { IsCleanup = Val; }
2109 /// addClause - Add a clause to the landing pad.
2110 void addClause(ClauseType CT, Constant *ClauseVal);
2112 /// getClauseType - Return the type of the clause at this index. The two
2113 /// supported clauses are Catch and Filter.
2114 ClauseType getClauseType(unsigned I) const {
2115 assert(I < ClauseIdxs.size() && "Index too large!");
2116 return ClauseIdxs[I];
2119 /// getClauseValue - Return the value of the clause at this index.
2120 Constant *getClauseValue(unsigned I) const {
2121 assert(I + 1 < getNumOperands() && "Index too large!");
2122 return cast<Constant>(OperandList[I + 1]);
2125 /// getNumClauses - Get the number of clauses for this landing pad.
2126 unsigned getNumClauses() const { return getNumOperands() - 1; }
2128 /// reserveClauses - Grow the size of the operand list to accomodate the new
2129 /// number of clauses.
2130 void reserveClauses(unsigned Size);
2132 // Methods for support type inquiry through isa, cast, and dyn_cast:
2133 static inline bool classof(const LandingPadInst *) { return true; }
2134 static inline bool classof(const Instruction *I) {
2135 return I->getOpcode() == Instruction::LandingPad;
2137 static inline bool classof(const Value *V) {
2138 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2143 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
2146 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
2148 //===----------------------------------------------------------------------===//
2150 //===----------------------------------------------------------------------===//
2152 //===---------------------------------------------------------------------------
2153 /// ReturnInst - Return a value (possibly void), from a function. Execution
2154 /// does not continue in this function any longer.
2156 class ReturnInst : public TerminatorInst {
2157 ReturnInst(const ReturnInst &RI);
2160 // ReturnInst constructors:
2161 // ReturnInst() - 'ret void' instruction
2162 // ReturnInst( null) - 'ret void' instruction
2163 // ReturnInst(Value* X) - 'ret X' instruction
2164 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
2165 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
2166 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2167 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
2169 // NOTE: If the Value* passed is of type void then the constructor behaves as
2170 // if it was passed NULL.
2171 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
2172 Instruction *InsertBefore = 0);
2173 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2174 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2176 virtual ReturnInst *clone_impl() const;
2178 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
2179 Instruction *InsertBefore = 0) {
2180 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2182 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2183 BasicBlock *InsertAtEnd) {
2184 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2186 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2187 return new(0) ReturnInst(C, InsertAtEnd);
2189 virtual ~ReturnInst();
2191 /// Provide fast operand accessors
2192 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2194 /// Convenience accessor. Returns null if there is no return value.
2195 Value *getReturnValue() const {
2196 return getNumOperands() != 0 ? getOperand(0) : 0;
2199 unsigned getNumSuccessors() const { return 0; }
2201 // Methods for support type inquiry through isa, cast, and dyn_cast:
2202 static inline bool classof(const ReturnInst *) { return true; }
2203 static inline bool classof(const Instruction *I) {
2204 return (I->getOpcode() == Instruction::Ret);
2206 static inline bool classof(const Value *V) {
2207 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2210 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2211 virtual unsigned getNumSuccessorsV() const;
2212 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2216 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2219 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2221 //===----------------------------------------------------------------------===//
2223 //===----------------------------------------------------------------------===//
2225 //===---------------------------------------------------------------------------
2226 /// BranchInst - Conditional or Unconditional Branch instruction.
2228 class BranchInst : public TerminatorInst {
2229 /// Ops list - Branches are strange. The operands are ordered:
2230 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2231 /// they don't have to check for cond/uncond branchness. These are mostly
2232 /// accessed relative from op_end().
2233 BranchInst(const BranchInst &BI);
2235 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2236 // BranchInst(BB *B) - 'br B'
2237 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2238 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2239 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2240 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2241 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2242 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2243 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2244 Instruction *InsertBefore = 0);
2245 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2246 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2247 BasicBlock *InsertAtEnd);
2249 virtual BranchInst *clone_impl() const;
2251 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2252 return new(1) BranchInst(IfTrue, InsertBefore);
2254 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2255 Value *Cond, Instruction *InsertBefore = 0) {
2256 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2258 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2259 return new(1) BranchInst(IfTrue, InsertAtEnd);
2261 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2262 Value *Cond, BasicBlock *InsertAtEnd) {
2263 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2266 /// Transparently provide more efficient getOperand methods.
2267 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2269 bool isUnconditional() const { return getNumOperands() == 1; }
2270 bool isConditional() const { return getNumOperands() == 3; }
2272 Value *getCondition() const {
2273 assert(isConditional() && "Cannot get condition of an uncond branch!");
2277 void setCondition(Value *V) {
2278 assert(isConditional() && "Cannot set condition of unconditional branch!");
2282 unsigned getNumSuccessors() const { return 1+isConditional(); }
2284 BasicBlock *getSuccessor(unsigned i) const {
2285 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2286 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2289 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2290 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2291 *(&Op<-1>() - idx) = (Value*)NewSucc;
2294 // Methods for support type inquiry through isa, cast, and dyn_cast:
2295 static inline bool classof(const BranchInst *) { return true; }
2296 static inline bool classof(const Instruction *I) {
2297 return (I->getOpcode() == Instruction::Br);
2299 static inline bool classof(const Value *V) {
2300 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2303 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2304 virtual unsigned getNumSuccessorsV() const;
2305 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2309 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2312 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2314 //===----------------------------------------------------------------------===//
2316 //===----------------------------------------------------------------------===//
2318 //===---------------------------------------------------------------------------
2319 /// SwitchInst - Multiway switch
2321 class SwitchInst : public TerminatorInst {
2322 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2323 unsigned ReservedSpace;
2324 // Operand[0] = Value to switch on
2325 // Operand[1] = Default basic block destination
2326 // Operand[2n ] = Value to match
2327 // Operand[2n+1] = BasicBlock to go to on match
2328 SwitchInst(const SwitchInst &SI);
2329 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2330 void growOperands();
2331 // allocate space for exactly zero operands
2332 void *operator new(size_t s) {
2333 return User::operator new(s, 0);
2335 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2336 /// switch on and a default destination. The number of additional cases can
2337 /// be specified here to make memory allocation more efficient. This
2338 /// constructor can also autoinsert before another instruction.
2339 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2340 Instruction *InsertBefore);
2342 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2343 /// switch on and a default destination. The number of additional cases can
2344 /// be specified here to make memory allocation more efficient. This
2345 /// constructor also autoinserts at the end of the specified BasicBlock.
2346 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2347 BasicBlock *InsertAtEnd);
2349 virtual SwitchInst *clone_impl() const;
2351 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2352 unsigned NumCases, Instruction *InsertBefore = 0) {
2353 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2355 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2356 unsigned NumCases, BasicBlock *InsertAtEnd) {
2357 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2361 /// Provide fast operand accessors
2362 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2364 // Accessor Methods for Switch stmt
2365 Value *getCondition() const { return getOperand(0); }
2366 void setCondition(Value *V) { setOperand(0, V); }
2368 BasicBlock *getDefaultDest() const {
2369 return cast<BasicBlock>(getOperand(1));
2372 /// getNumCases - return the number of 'cases' in this switch instruction.
2373 /// Note that case #0 is always the default case.
2374 unsigned getNumCases() const {
2375 return getNumOperands()/2;
2378 /// getCaseValue - Return the specified case value. Note that case #0, the
2379 /// default destination, does not have a case value.
2380 ConstantInt *getCaseValue(unsigned i) {
2381 assert(i && i < getNumCases() && "Illegal case value to get!");
2382 return getSuccessorValue(i);
2385 /// getCaseValue - Return the specified case value. Note that case #0, the
2386 /// default destination, does not have a case value.
2387 const ConstantInt *getCaseValue(unsigned i) const {
2388 assert(i && i < getNumCases() && "Illegal case value to get!");
2389 return getSuccessorValue(i);
2392 /// findCaseValue - Search all of the case values for the specified constant.
2393 /// If it is explicitly handled, return the case number of it, otherwise
2394 /// return 0 to indicate that it is handled by the default handler.
2395 unsigned findCaseValue(const ConstantInt *C) const {
2396 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2397 if (getCaseValue(i) == C)
2402 /// findCaseDest - Finds the unique case value for a given successor. Returns
2403 /// null if the successor is not found, not unique, or is the default case.
2404 ConstantInt *findCaseDest(BasicBlock *BB) {
2405 if (BB == getDefaultDest()) return NULL;
2407 ConstantInt *CI = NULL;
2408 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2409 if (getSuccessor(i) == BB) {
2410 if (CI) return NULL; // Multiple cases lead to BB.
2411 else CI = getCaseValue(i);
2417 /// addCase - Add an entry to the switch instruction...
2419 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2421 /// removeCase - This method removes the specified successor from the switch
2422 /// instruction. Note that this cannot be used to remove the default
2423 /// destination (successor #0). Also note that this operation may reorder the
2424 /// remaining cases at index idx and above.
2426 void removeCase(unsigned idx);
2428 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2429 BasicBlock *getSuccessor(unsigned idx) const {
2430 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2431 return cast<BasicBlock>(getOperand(idx*2+1));
2433 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2434 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2435 setOperand(idx*2+1, (Value*)NewSucc);
2438 // getSuccessorValue - Return the value associated with the specified
2440 ConstantInt *getSuccessorValue(unsigned idx) const {
2441 assert(idx < getNumSuccessors() && "Successor # out of range!");
2442 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2445 // Methods for support type inquiry through isa, cast, and dyn_cast:
2446 static inline bool classof(const SwitchInst *) { return true; }
2447 static inline bool classof(const Instruction *I) {
2448 return I->getOpcode() == Instruction::Switch;
2450 static inline bool classof(const Value *V) {
2451 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2454 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2455 virtual unsigned getNumSuccessorsV() const;
2456 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2460 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2463 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2466 //===----------------------------------------------------------------------===//
2467 // IndirectBrInst Class
2468 //===----------------------------------------------------------------------===//
2470 //===---------------------------------------------------------------------------
2471 /// IndirectBrInst - Indirect Branch Instruction.
2473 class IndirectBrInst : public TerminatorInst {
2474 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2475 unsigned ReservedSpace;
2476 // Operand[0] = Value to switch on
2477 // Operand[1] = Default basic block destination
2478 // Operand[2n ] = Value to match
2479 // Operand[2n+1] = BasicBlock to go to on match
2480 IndirectBrInst(const IndirectBrInst &IBI);
2481 void init(Value *Address, unsigned NumDests);
2482 void growOperands();
2483 // allocate space for exactly zero operands
2484 void *operator new(size_t s) {
2485 return User::operator new(s, 0);
2487 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2488 /// Address to jump to. The number of expected destinations can be specified
2489 /// here to make memory allocation more efficient. This constructor can also
2490 /// autoinsert before another instruction.
2491 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2493 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2494 /// Address to jump to. The number of expected destinations can be specified
2495 /// here to make memory allocation more efficient. This constructor also
2496 /// autoinserts at the end of the specified BasicBlock.
2497 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2499 virtual IndirectBrInst *clone_impl() const;
2501 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2502 Instruction *InsertBefore = 0) {
2503 return new IndirectBrInst(Address, NumDests, InsertBefore);
2505 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2506 BasicBlock *InsertAtEnd) {
2507 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2511 /// Provide fast operand accessors.
2512 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2514 // Accessor Methods for IndirectBrInst instruction.
2515 Value *getAddress() { return getOperand(0); }
2516 const Value *getAddress() const { return getOperand(0); }
2517 void setAddress(Value *V) { setOperand(0, V); }
2520 /// getNumDestinations - return the number of possible destinations in this
2521 /// indirectbr instruction.
2522 unsigned getNumDestinations() const { return getNumOperands()-1; }
2524 /// getDestination - Return the specified destination.
2525 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2526 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2528 /// addDestination - Add a destination.
2530 void addDestination(BasicBlock *Dest);
2532 /// removeDestination - This method removes the specified successor from the
2533 /// indirectbr instruction.
2534 void removeDestination(unsigned i);
2536 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2537 BasicBlock *getSuccessor(unsigned i) const {
2538 return cast<BasicBlock>(getOperand(i+1));
2540 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2541 setOperand(i+1, (Value*)NewSucc);
2544 // Methods for support type inquiry through isa, cast, and dyn_cast:
2545 static inline bool classof(const IndirectBrInst *) { return true; }
2546 static inline bool classof(const Instruction *I) {
2547 return I->getOpcode() == Instruction::IndirectBr;
2549 static inline bool classof(const Value *V) {
2550 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2553 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2554 virtual unsigned getNumSuccessorsV() const;
2555 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2559 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2562 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2565 //===----------------------------------------------------------------------===//
2567 //===----------------------------------------------------------------------===//
2569 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2570 /// calling convention of the call.
2572 class InvokeInst : public TerminatorInst {
2573 AttrListPtr AttributeList;
2574 InvokeInst(const InvokeInst &BI);
2575 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2576 ArrayRef<Value *> Args, const Twine &NameStr);
2578 /// Construct an InvokeInst given a range of arguments.
2580 /// @brief Construct an InvokeInst from a range of arguments
2581 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2582 ArrayRef<Value *> Args, unsigned Values,
2583 const Twine &NameStr, Instruction *InsertBefore);
2585 /// Construct an InvokeInst given a range of arguments.
2587 /// @brief Construct an InvokeInst from a range of arguments
2588 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2589 ArrayRef<Value *> Args, unsigned Values,
2590 const Twine &NameStr, BasicBlock *InsertAtEnd);
2592 virtual InvokeInst *clone_impl() const;
2594 static InvokeInst *Create(Value *Func,
2595 BasicBlock *IfNormal, BasicBlock *IfException,
2596 ArrayRef<Value *> Args, const Twine &NameStr = "",
2597 Instruction *InsertBefore = 0) {
2598 unsigned Values = unsigned(Args.size()) + 3;
2599 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2600 Values, NameStr, InsertBefore);
2602 static InvokeInst *Create(Value *Func,
2603 BasicBlock *IfNormal, BasicBlock *IfException,
2604 ArrayRef<Value *> Args, const Twine &NameStr,
2605 BasicBlock *InsertAtEnd) {
2606 unsigned Values = unsigned(Args.size()) + 3;
2607 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2608 Values, NameStr, InsertAtEnd);
2611 /// Provide fast operand accessors
2612 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2614 /// getNumArgOperands - Return the number of invoke arguments.
2616 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2618 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2620 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2621 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2623 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2625 CallingConv::ID getCallingConv() const {
2626 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2628 void setCallingConv(CallingConv::ID CC) {
2629 setInstructionSubclassData(static_cast<unsigned>(CC));
2632 /// getAttributes - Return the parameter attributes for this invoke.
2634 const AttrListPtr &getAttributes() const { return AttributeList; }
2636 /// setAttributes - Set the parameter attributes for this invoke.
2638 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2640 /// addAttribute - adds the attribute to the list of attributes.
2641 void addAttribute(unsigned i, Attributes attr);
2643 /// removeAttribute - removes the attribute from the list of attributes.
2644 void removeAttribute(unsigned i, Attributes attr);
2646 /// @brief Determine whether the call or the callee has the given attribute.
2647 bool paramHasAttr(unsigned i, Attributes attr) const;
2649 /// @brief Extract the alignment for a call or parameter (0=unknown).
2650 unsigned getParamAlignment(unsigned i) const {
2651 return AttributeList.getParamAlignment(i);
2654 /// @brief Return true if the call should not be inlined.
2655 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2656 void setIsNoInline(bool Value = true) {
2657 if (Value) addAttribute(~0, Attribute::NoInline);
2658 else removeAttribute(~0, Attribute::NoInline);
2661 /// @brief Determine if the call does not access memory.
2662 bool doesNotAccessMemory() const {
2663 return paramHasAttr(~0, Attribute::ReadNone);
2665 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2666 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2667 else removeAttribute(~0, Attribute::ReadNone);
2670 /// @brief Determine if the call does not access or only reads memory.
2671 bool onlyReadsMemory() const {
2672 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2674 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2675 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2676 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2679 /// @brief Determine if the call cannot return.
2680 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
2681 void setDoesNotReturn(bool DoesNotReturn = true) {
2682 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2683 else removeAttribute(~0, Attribute::NoReturn);
2686 /// @brief Determine if the call cannot unwind.
2687 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
2688 void setDoesNotThrow(bool DoesNotThrow = true) {
2689 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2690 else removeAttribute(~0, Attribute::NoUnwind);
2693 /// @brief Determine if the call returns a structure through first
2694 /// pointer argument.
2695 bool hasStructRetAttr() const {
2696 // Be friendly and also check the callee.
2697 return paramHasAttr(1, Attribute::StructRet);
2700 /// @brief Determine if any call argument is an aggregate passed by value.
2701 bool hasByValArgument() const {
2702 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2705 /// getCalledFunction - Return the function called, or null if this is an
2706 /// indirect function invocation.
2708 Function *getCalledFunction() const {
2709 return dyn_cast<Function>(Op<-3>());
2712 /// getCalledValue - Get a pointer to the function that is invoked by this
2714 const Value *getCalledValue() const { return Op<-3>(); }
2715 Value *getCalledValue() { return Op<-3>(); }
2717 /// setCalledFunction - Set the function called.
2718 void setCalledFunction(Value* Fn) {
2722 // get*Dest - Return the destination basic blocks...
2723 BasicBlock *getNormalDest() const {
2724 return cast<BasicBlock>(Op<-2>());
2726 BasicBlock *getUnwindDest() const {
2727 return cast<BasicBlock>(Op<-1>());
2729 void setNormalDest(BasicBlock *B) {
2730 Op<-2>() = reinterpret_cast<Value*>(B);
2732 void setUnwindDest(BasicBlock *B) {
2733 Op<-1>() = reinterpret_cast<Value*>(B);
2736 // getLandingPad - Get the landingpad instruction from the landing pad block
2737 // (the unwind destination).
2738 LandingPadInst *getLandingPad() const;
2740 BasicBlock *getSuccessor(unsigned i) const {
2741 assert(i < 2 && "Successor # out of range for invoke!");
2742 return i == 0 ? getNormalDest() : getUnwindDest();
2745 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2746 assert(idx < 2 && "Successor # out of range for invoke!");
2747 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2750 unsigned getNumSuccessors() const { return 2; }
2752 // Methods for support type inquiry through isa, cast, and dyn_cast:
2753 static inline bool classof(const InvokeInst *) { return true; }
2754 static inline bool classof(const Instruction *I) {
2755 return (I->getOpcode() == Instruction::Invoke);
2757 static inline bool classof(const Value *V) {
2758 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2762 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2763 virtual unsigned getNumSuccessorsV() const;
2764 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2766 // Shadow Instruction::setInstructionSubclassData with a private forwarding
2767 // method so that subclasses cannot accidentally use it.
2768 void setInstructionSubclassData(unsigned short D) {
2769 Instruction::setInstructionSubclassData(D);
2774 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
2777 InvokeInst::InvokeInst(Value *Func,
2778 BasicBlock *IfNormal, BasicBlock *IfException,
2779 ArrayRef<Value *> Args, unsigned Values,
2780 const Twine &NameStr, Instruction *InsertBefore)
2781 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2782 ->getElementType())->getReturnType(),
2783 Instruction::Invoke,
2784 OperandTraits<InvokeInst>::op_end(this) - Values,
2785 Values, InsertBefore) {
2786 init(Func, IfNormal, IfException, Args, NameStr);
2788 InvokeInst::InvokeInst(Value *Func,
2789 BasicBlock *IfNormal, BasicBlock *IfException,
2790 ArrayRef<Value *> Args, unsigned Values,
2791 const Twine &NameStr, BasicBlock *InsertAtEnd)
2792 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2793 ->getElementType())->getReturnType(),
2794 Instruction::Invoke,
2795 OperandTraits<InvokeInst>::op_end(this) - Values,
2796 Values, InsertAtEnd) {
2797 init(Func, IfNormal, IfException, Args, NameStr);
2800 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2802 //===----------------------------------------------------------------------===//
2804 //===----------------------------------------------------------------------===//
2806 //===---------------------------------------------------------------------------
2807 /// UnwindInst - Immediately exit the current function, unwinding the stack
2808 /// until an invoke instruction is found.
2810 class UnwindInst : public TerminatorInst {
2811 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2813 virtual UnwindInst *clone_impl() const;
2815 // allocate space for exactly zero operands
2816 void *operator new(size_t s) {
2817 return User::operator new(s, 0);
2819 explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2820 explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2822 unsigned getNumSuccessors() const { return 0; }
2824 // Methods for support type inquiry through isa, cast, and dyn_cast:
2825 static inline bool classof(const UnwindInst *) { return true; }
2826 static inline bool classof(const Instruction *I) {
2827 return I->getOpcode() == Instruction::Unwind;
2829 static inline bool classof(const Value *V) {
2830 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2833 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2834 virtual unsigned getNumSuccessorsV() const;
2835 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2838 //===----------------------------------------------------------------------===//
2840 //===----------------------------------------------------------------------===//
2842 //===---------------------------------------------------------------------------
2843 /// ResumeInst - Resume the propagation of an exception.
2845 class ResumeInst : public TerminatorInst {
2846 ResumeInst(const ResumeInst &RI);
2848 explicit ResumeInst(LLVMContext &C, Value *Exn, Instruction *InsertBefore=0);
2849 ResumeInst(LLVMContext &C, Value *Exn, BasicBlock *InsertAtEnd);
2851 virtual ResumeInst *clone_impl() const;
2853 static ResumeInst *Create(LLVMContext &C, Value *Exn,
2854 Instruction *InsertBefore = 0) {
2855 return new(1) ResumeInst(C, Exn, InsertBefore);
2857 static ResumeInst *Create(LLVMContext &C, Value *Exn,
2858 BasicBlock *InsertAtEnd) {
2859 return new(1) ResumeInst(C, Exn, InsertAtEnd);
2862 /// Provide fast operand accessors
2863 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2865 /// Convenience accessor.
2866 Value *getResumeValue() const { return Op<0>(); }
2868 unsigned getNumSuccessors() const { return 0; }
2870 // Methods for support type inquiry through isa, cast, and dyn_cast:
2871 static inline bool classof(const ResumeInst *) { return true; }
2872 static inline bool classof(const Instruction *I) {
2873 return I->getOpcode() == Instruction::Resume;
2875 static inline bool classof(const Value *V) {
2876 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2879 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2880 virtual unsigned getNumSuccessorsV() const;
2881 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2885 struct OperandTraits<ResumeInst> :
2886 public FixedNumOperandTraits<ResumeInst, 1> {
2889 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
2891 //===----------------------------------------------------------------------===//
2892 // UnreachableInst Class
2893 //===----------------------------------------------------------------------===//
2895 //===---------------------------------------------------------------------------
2896 /// UnreachableInst - This function has undefined behavior. In particular, the
2897 /// presence of this instruction indicates some higher level knowledge that the
2898 /// end of the block cannot be reached.
2900 class UnreachableInst : public TerminatorInst {
2901 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2903 virtual UnreachableInst *clone_impl() const;
2906 // allocate space for exactly zero operands
2907 void *operator new(size_t s) {
2908 return User::operator new(s, 0);
2910 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2911 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2913 unsigned getNumSuccessors() const { return 0; }
2915 // Methods for support type inquiry through isa, cast, and dyn_cast:
2916 static inline bool classof(const UnreachableInst *) { return true; }
2917 static inline bool classof(const Instruction *I) {
2918 return I->getOpcode() == Instruction::Unreachable;
2920 static inline bool classof(const Value *V) {
2921 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2924 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2925 virtual unsigned getNumSuccessorsV() const;
2926 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2929 //===----------------------------------------------------------------------===//
2931 //===----------------------------------------------------------------------===//
2933 /// @brief This class represents a truncation of integer types.
2934 class TruncInst : public CastInst {
2936 /// @brief Clone an identical TruncInst
2937 virtual TruncInst *clone_impl() const;
2940 /// @brief Constructor with insert-before-instruction semantics
2942 Value *S, ///< The value to be truncated
2943 Type *Ty, ///< The (smaller) type to truncate to
2944 const Twine &NameStr = "", ///< A name for the new instruction
2945 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2948 /// @brief Constructor with insert-at-end-of-block semantics
2950 Value *S, ///< The value to be truncated
2951 Type *Ty, ///< The (smaller) type to truncate to
2952 const Twine &NameStr, ///< A name for the new instruction
2953 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2956 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2957 static inline bool classof(const TruncInst *) { return true; }
2958 static inline bool classof(const Instruction *I) {
2959 return I->getOpcode() == Trunc;
2961 static inline bool classof(const Value *V) {
2962 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2966 //===----------------------------------------------------------------------===//
2968 //===----------------------------------------------------------------------===//
2970 /// @brief This class represents zero extension of integer types.
2971 class ZExtInst : public CastInst {
2973 /// @brief Clone an identical ZExtInst
2974 virtual ZExtInst *clone_impl() const;
2977 /// @brief Constructor with insert-before-instruction semantics
2979 Value *S, ///< The value to be zero extended
2980 Type *Ty, ///< The type to zero extend to
2981 const Twine &NameStr = "", ///< A name for the new instruction
2982 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2985 /// @brief Constructor with insert-at-end semantics.
2987 Value *S, ///< The value to be zero extended
2988 Type *Ty, ///< The type to zero extend to
2989 const Twine &NameStr, ///< A name for the new instruction
2990 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2993 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2994 static inline bool classof(const ZExtInst *) { return true; }
2995 static inline bool classof(const Instruction *I) {
2996 return I->getOpcode() == ZExt;
2998 static inline bool classof(const Value *V) {
2999 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3003 //===----------------------------------------------------------------------===//
3005 //===----------------------------------------------------------------------===//
3007 /// @brief This class represents a sign extension of integer types.
3008 class SExtInst : public CastInst {
3010 /// @brief Clone an identical SExtInst
3011 virtual SExtInst *clone_impl() const;
3014 /// @brief Constructor with insert-before-instruction semantics
3016 Value *S, ///< The value to be sign extended
3017 Type *Ty, ///< The type to sign extend to
3018 const Twine &NameStr = "", ///< A name for the new instruction
3019 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3022 /// @brief Constructor with insert-at-end-of-block semantics
3024 Value *S, ///< The value to be sign extended
3025 Type *Ty, ///< The type to sign extend to
3026 const Twine &NameStr, ///< A name for the new instruction
3027 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3030 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3031 static inline bool classof(const SExtInst *) { return true; }
3032 static inline bool classof(const Instruction *I) {
3033 return I->getOpcode() == SExt;
3035 static inline bool classof(const Value *V) {
3036 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3040 //===----------------------------------------------------------------------===//
3041 // FPTruncInst Class
3042 //===----------------------------------------------------------------------===//
3044 /// @brief This class represents a truncation of floating point types.
3045 class FPTruncInst : public CastInst {
3047 /// @brief Clone an identical FPTruncInst
3048 virtual FPTruncInst *clone_impl() const;
3051 /// @brief Constructor with insert-before-instruction semantics
3053 Value *S, ///< The value to be truncated
3054 Type *Ty, ///< The type to truncate to
3055 const Twine &NameStr = "", ///< A name for the new instruction
3056 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3059 /// @brief Constructor with insert-before-instruction semantics
3061 Value *S, ///< The value to be truncated
3062 Type *Ty, ///< The type to truncate to
3063 const Twine &NameStr, ///< A name for the new instruction
3064 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3067 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3068 static inline bool classof(const FPTruncInst *) { return true; }
3069 static inline bool classof(const Instruction *I) {
3070 return I->getOpcode() == FPTrunc;
3072 static inline bool classof(const Value *V) {
3073 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3077 //===----------------------------------------------------------------------===//
3079 //===----------------------------------------------------------------------===//
3081 /// @brief This class represents an extension of floating point types.
3082 class FPExtInst : public CastInst {
3084 /// @brief Clone an identical FPExtInst
3085 virtual FPExtInst *clone_impl() const;
3088 /// @brief Constructor with insert-before-instruction semantics
3090 Value *S, ///< The value to be extended
3091 Type *Ty, ///< The type to extend to
3092 const Twine &NameStr = "", ///< A name for the new instruction
3093 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3096 /// @brief Constructor with insert-at-end-of-block semantics
3098 Value *S, ///< The value to be extended
3099 Type *Ty, ///< The type to extend to
3100 const Twine &NameStr, ///< A name for the new instruction
3101 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3104 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3105 static inline bool classof(const FPExtInst *) { return true; }
3106 static inline bool classof(const Instruction *I) {
3107 return I->getOpcode() == FPExt;
3109 static inline bool classof(const Value *V) {
3110 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3114 //===----------------------------------------------------------------------===//
3116 //===----------------------------------------------------------------------===//
3118 /// @brief This class represents a cast unsigned integer to floating point.
3119 class UIToFPInst : public CastInst {
3121 /// @brief Clone an identical UIToFPInst
3122 virtual UIToFPInst *clone_impl() const;
3125 /// @brief Constructor with insert-before-instruction semantics
3127 Value *S, ///< The value to be converted
3128 Type *Ty, ///< The type to convert to
3129 const Twine &NameStr = "", ///< A name for the new instruction
3130 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3133 /// @brief Constructor with insert-at-end-of-block semantics
3135 Value *S, ///< The value to be converted
3136 Type *Ty, ///< The type to convert to
3137 const Twine &NameStr, ///< A name for the new instruction
3138 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3141 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3142 static inline bool classof(const UIToFPInst *) { return true; }
3143 static inline bool classof(const Instruction *I) {
3144 return I->getOpcode() == UIToFP;
3146 static inline bool classof(const Value *V) {
3147 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3151 //===----------------------------------------------------------------------===//
3153 //===----------------------------------------------------------------------===//
3155 /// @brief This class represents a cast from signed integer to floating point.
3156 class SIToFPInst : public CastInst {
3158 /// @brief Clone an identical SIToFPInst
3159 virtual SIToFPInst *clone_impl() const;
3162 /// @brief Constructor with insert-before-instruction semantics
3164 Value *S, ///< The value to be converted
3165 Type *Ty, ///< The type to convert to
3166 const Twine &NameStr = "", ///< A name for the new instruction
3167 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3170 /// @brief Constructor with insert-at-end-of-block semantics
3172 Value *S, ///< The value to be converted
3173 Type *Ty, ///< The type to convert to
3174 const Twine &NameStr, ///< A name for the new instruction
3175 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3178 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3179 static inline bool classof(const SIToFPInst *) { return true; }
3180 static inline bool classof(const Instruction *I) {
3181 return I->getOpcode() == SIToFP;
3183 static inline bool classof(const Value *V) {
3184 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3188 //===----------------------------------------------------------------------===//
3190 //===----------------------------------------------------------------------===//
3192 /// @brief This class represents a cast from floating point to unsigned integer
3193 class FPToUIInst : public CastInst {
3195 /// @brief Clone an identical FPToUIInst
3196 virtual FPToUIInst *clone_impl() const;
3199 /// @brief Constructor with insert-before-instruction semantics
3201 Value *S, ///< The value to be converted
3202 Type *Ty, ///< The type to convert to
3203 const Twine &NameStr = "", ///< A name for the new instruction
3204 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3207 /// @brief Constructor with insert-at-end-of-block semantics
3209 Value *S, ///< The value to be converted
3210 Type *Ty, ///< The type to convert to
3211 const Twine &NameStr, ///< A name for the new instruction
3212 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3215 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3216 static inline bool classof(const FPToUIInst *) { return true; }
3217 static inline bool classof(const Instruction *I) {
3218 return I->getOpcode() == FPToUI;
3220 static inline bool classof(const Value *V) {
3221 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3225 //===----------------------------------------------------------------------===//
3227 //===----------------------------------------------------------------------===//
3229 /// @brief This class represents a cast from floating point to signed integer.
3230 class FPToSIInst : public CastInst {
3232 /// @brief Clone an identical FPToSIInst
3233 virtual FPToSIInst *clone_impl() const;
3236 /// @brief Constructor with insert-before-instruction semantics
3238 Value *S, ///< The value to be converted
3239 Type *Ty, ///< The type to convert to
3240 const Twine &NameStr = "", ///< A name for the new instruction
3241 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3244 /// @brief Constructor with insert-at-end-of-block semantics
3246 Value *S, ///< The value to be converted
3247 Type *Ty, ///< The type to convert to
3248 const Twine &NameStr, ///< A name for the new instruction
3249 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3252 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3253 static inline bool classof(const FPToSIInst *) { return true; }
3254 static inline bool classof(const Instruction *I) {
3255 return I->getOpcode() == FPToSI;
3257 static inline bool classof(const Value *V) {
3258 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3262 //===----------------------------------------------------------------------===//
3263 // IntToPtrInst Class
3264 //===----------------------------------------------------------------------===//
3266 /// @brief This class represents a cast from an integer to a pointer.
3267 class IntToPtrInst : public CastInst {
3269 /// @brief Constructor with insert-before-instruction semantics
3271 Value *S, ///< The value to be converted
3272 Type *Ty, ///< The type to convert to
3273 const Twine &NameStr = "", ///< A name for the new instruction
3274 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3277 /// @brief Constructor with insert-at-end-of-block semantics
3279 Value *S, ///< The value to be converted
3280 Type *Ty, ///< The type to convert to
3281 const Twine &NameStr, ///< A name for the new instruction
3282 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3285 /// @brief Clone an identical IntToPtrInst
3286 virtual IntToPtrInst *clone_impl() const;
3288 // Methods for support type inquiry through isa, cast, and dyn_cast:
3289 static inline bool classof(const IntToPtrInst *) { return true; }
3290 static inline bool classof(const Instruction *I) {
3291 return I->getOpcode() == IntToPtr;
3293 static inline bool classof(const Value *V) {
3294 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3298 //===----------------------------------------------------------------------===//
3299 // PtrToIntInst Class
3300 //===----------------------------------------------------------------------===//
3302 /// @brief This class represents a cast from a pointer to an integer
3303 class PtrToIntInst : public CastInst {
3305 /// @brief Clone an identical PtrToIntInst
3306 virtual PtrToIntInst *clone_impl() const;
3309 /// @brief Constructor with insert-before-instruction semantics
3311 Value *S, ///< The value to be converted
3312 Type *Ty, ///< The type to convert to
3313 const Twine &NameStr = "", ///< A name for the new instruction
3314 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3317 /// @brief Constructor with insert-at-end-of-block semantics
3319 Value *S, ///< The value to be converted
3320 Type *Ty, ///< The type to convert to
3321 const Twine &NameStr, ///< A name for the new instruction
3322 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3325 // Methods for support type inquiry through isa, cast, and dyn_cast:
3326 static inline bool classof(const PtrToIntInst *) { return true; }
3327 static inline bool classof(const Instruction *I) {
3328 return I->getOpcode() == PtrToInt;
3330 static inline bool classof(const Value *V) {
3331 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3335 //===----------------------------------------------------------------------===//
3336 // BitCastInst Class
3337 //===----------------------------------------------------------------------===//
3339 /// @brief This class represents a no-op cast from one type to another.
3340 class BitCastInst : public CastInst {
3342 /// @brief Clone an identical BitCastInst
3343 virtual BitCastInst *clone_impl() const;
3346 /// @brief Constructor with insert-before-instruction semantics
3348 Value *S, ///< The value to be casted
3349 Type *Ty, ///< The type to casted to
3350 const Twine &NameStr = "", ///< A name for the new instruction
3351 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3354 /// @brief Constructor with insert-at-end-of-block semantics
3356 Value *S, ///< The value to be casted
3357 Type *Ty, ///< The type to casted to
3358 const Twine &NameStr, ///< A name for the new instruction
3359 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3362 // Methods for support type inquiry through isa, cast, and dyn_cast:
3363 static inline bool classof(const BitCastInst *) { return true; }
3364 static inline bool classof(const Instruction *I) {
3365 return I->getOpcode() == BitCast;
3367 static inline bool classof(const Value *V) {
3368 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3372 } // End llvm namespace