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"
40 // Consume = 3, // Not specified yet.
44 SequentiallyConsistent = 7
47 enum SynchronizationScope {
52 //===----------------------------------------------------------------------===//
54 //===----------------------------------------------------------------------===//
56 /// AllocaInst - an instruction to allocate memory on the stack
58 class AllocaInst : public UnaryInstruction {
60 virtual AllocaInst *clone_impl() const;
62 explicit AllocaInst(Type *Ty, Value *ArraySize = 0,
63 const Twine &Name = "", Instruction *InsertBefore = 0);
64 AllocaInst(Type *Ty, Value *ArraySize,
65 const Twine &Name, BasicBlock *InsertAtEnd);
67 AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
68 AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
70 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
71 const Twine &Name = "", Instruction *InsertBefore = 0);
72 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
73 const Twine &Name, BasicBlock *InsertAtEnd);
75 // Out of line virtual method, so the vtable, etc. has a home.
76 virtual ~AllocaInst();
78 /// isArrayAllocation - Return true if there is an allocation size parameter
79 /// to the allocation instruction that is not 1.
81 bool isArrayAllocation() const;
83 /// getArraySize - Get the number of elements allocated. For a simple
84 /// allocation of a single element, this will return a constant 1 value.
86 const Value *getArraySize() const { return getOperand(0); }
87 Value *getArraySize() { return getOperand(0); }
89 /// getType - Overload to return most specific pointer type
91 PointerType *getType() const {
92 return reinterpret_cast<PointerType*>(Instruction::getType());
95 /// getAllocatedType - Return the type that is being allocated by the
98 Type *getAllocatedType() const;
100 /// getAlignment - Return the alignment of the memory that is being allocated
101 /// by the instruction.
103 unsigned getAlignment() const {
104 return (1u << getSubclassDataFromInstruction()) >> 1;
106 void setAlignment(unsigned Align);
108 /// isStaticAlloca - Return true if this alloca is in the entry block of the
109 /// function and is a constant size. If so, the code generator will fold it
110 /// into the prolog/epilog code, so it is basically free.
111 bool isStaticAlloca() const;
113 // Methods for support type inquiry through isa, cast, and dyn_cast:
114 static inline bool classof(const AllocaInst *) { return true; }
115 static inline bool classof(const Instruction *I) {
116 return (I->getOpcode() == Instruction::Alloca);
118 static inline bool classof(const Value *V) {
119 return isa<Instruction>(V) && classof(cast<Instruction>(V));
122 // Shadow Instruction::setInstructionSubclassData with a private forwarding
123 // method so that subclasses cannot accidentally use it.
124 void setInstructionSubclassData(unsigned short D) {
125 Instruction::setInstructionSubclassData(D);
130 //===----------------------------------------------------------------------===//
132 //===----------------------------------------------------------------------===//
134 /// LoadInst - an instruction for reading from memory. This uses the
135 /// SubclassData field in Value to store whether or not the load is volatile.
137 class LoadInst : public UnaryInstruction {
140 virtual LoadInst *clone_impl() const;
142 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
143 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
144 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
145 Instruction *InsertBefore = 0);
146 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
147 BasicBlock *InsertAtEnd);
148 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
149 unsigned Align, Instruction *InsertBefore = 0);
150 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
151 unsigned Align, BasicBlock *InsertAtEnd);
152 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
153 unsigned Align, AtomicOrdering Order,
154 SynchronizationScope SynchScope = CrossThread,
155 Instruction *InsertBefore = 0);
156 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
157 unsigned Align, AtomicOrdering Order,
158 SynchronizationScope SynchScope,
159 BasicBlock *InsertAtEnd);
161 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
162 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
163 explicit LoadInst(Value *Ptr, const char *NameStr = 0,
164 bool isVolatile = false, Instruction *InsertBefore = 0);
165 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
166 BasicBlock *InsertAtEnd);
168 /// isVolatile - Return true if this is a load from a volatile memory
171 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
173 /// setVolatile - Specify whether this is a volatile load or not.
175 void setVolatile(bool V) {
176 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
180 /// getAlignment - Return the alignment of the access that is being performed
182 unsigned getAlignment() const {
183 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
186 void setAlignment(unsigned Align);
188 /// Returns the ordering effect of this fence.
189 AtomicOrdering getOrdering() const {
190 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
193 /// Set the ordering constraint on this load. May not be Release or
195 void setOrdering(AtomicOrdering Ordering) {
196 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
200 SynchronizationScope getSynchScope() const {
201 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
204 /// Specify whether this load is ordered with respect to all
205 /// concurrently executing threads, or only with respect to signal handlers
206 /// executing in the same thread.
207 void setSynchScope(SynchronizationScope xthread) {
208 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
212 bool isAtomic() const { return getOrdering() != NotAtomic; }
213 void setAtomic(AtomicOrdering Ordering,
214 SynchronizationScope SynchScope = CrossThread) {
215 setOrdering(Ordering);
216 setSynchScope(SynchScope);
219 bool isSimple() const { return !isAtomic() && !isVolatile(); }
220 bool isUnordered() const {
221 return getOrdering() <= Unordered && !isVolatile();
224 Value *getPointerOperand() { return getOperand(0); }
225 const Value *getPointerOperand() const { return getOperand(0); }
226 static unsigned getPointerOperandIndex() { return 0U; }
228 unsigned getPointerAddressSpace() const {
229 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
233 // Methods for support type inquiry through isa, cast, and dyn_cast:
234 static inline bool classof(const LoadInst *) { return true; }
235 static inline bool classof(const Instruction *I) {
236 return I->getOpcode() == Instruction::Load;
238 static inline bool classof(const Value *V) {
239 return isa<Instruction>(V) && classof(cast<Instruction>(V));
242 // Shadow Instruction::setInstructionSubclassData with a private forwarding
243 // method so that subclasses cannot accidentally use it.
244 void setInstructionSubclassData(unsigned short D) {
245 Instruction::setInstructionSubclassData(D);
250 //===----------------------------------------------------------------------===//
252 //===----------------------------------------------------------------------===//
254 /// StoreInst - an instruction for storing to memory
256 class StoreInst : public Instruction {
257 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
260 virtual StoreInst *clone_impl() const;
262 // allocate space for exactly two operands
263 void *operator new(size_t s) {
264 return User::operator new(s, 2);
266 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
267 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
268 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
269 Instruction *InsertBefore = 0);
270 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
271 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
272 unsigned Align, Instruction *InsertBefore = 0);
273 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
274 unsigned Align, BasicBlock *InsertAtEnd);
275 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
276 unsigned Align, AtomicOrdering Order,
277 SynchronizationScope SynchScope = CrossThread,
278 Instruction *InsertBefore = 0);
279 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
280 unsigned Align, AtomicOrdering Order,
281 SynchronizationScope SynchScope,
282 BasicBlock *InsertAtEnd);
285 /// isVolatile - Return true if this is a store to a volatile memory
288 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
290 /// setVolatile - Specify whether this is a volatile store or not.
292 void setVolatile(bool V) {
293 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
297 /// Transparently provide more efficient getOperand methods.
298 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
300 /// getAlignment - Return the alignment of the access that is being performed
302 unsigned getAlignment() const {
303 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
306 void setAlignment(unsigned Align);
308 /// Returns the ordering effect of this store.
309 AtomicOrdering getOrdering() const {
310 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
313 /// Set the ordering constraint on this store. May not be Acquire or
315 void setOrdering(AtomicOrdering Ordering) {
316 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
320 SynchronizationScope getSynchScope() const {
321 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
324 /// Specify whether this store instruction is ordered with respect to all
325 /// concurrently executing threads, or only with respect to signal handlers
326 /// executing in the same thread.
327 void setSynchScope(SynchronizationScope xthread) {
328 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
332 bool isAtomic() const { return getOrdering() != NotAtomic; }
333 void setAtomic(AtomicOrdering Ordering,
334 SynchronizationScope SynchScope = CrossThread) {
335 setOrdering(Ordering);
336 setSynchScope(SynchScope);
339 bool isSimple() const { return !isAtomic() && !isVolatile(); }
340 bool isUnordered() const {
341 return getOrdering() <= Unordered && !isVolatile();
344 Value *getValueOperand() { return getOperand(0); }
345 const Value *getValueOperand() const { return getOperand(0); }
347 Value *getPointerOperand() { return getOperand(1); }
348 const Value *getPointerOperand() const { return getOperand(1); }
349 static unsigned getPointerOperandIndex() { return 1U; }
351 unsigned getPointerAddressSpace() const {
352 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
355 // Methods for support type inquiry through isa, cast, and dyn_cast:
356 static inline bool classof(const StoreInst *) { return true; }
357 static inline bool classof(const Instruction *I) {
358 return I->getOpcode() == Instruction::Store;
360 static inline bool classof(const Value *V) {
361 return isa<Instruction>(V) && classof(cast<Instruction>(V));
364 // Shadow Instruction::setInstructionSubclassData with a private forwarding
365 // method so that subclasses cannot accidentally use it.
366 void setInstructionSubclassData(unsigned short D) {
367 Instruction::setInstructionSubclassData(D);
372 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
375 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
377 //===----------------------------------------------------------------------===//
379 //===----------------------------------------------------------------------===//
381 /// FenceInst - an instruction for ordering other memory operations
383 class FenceInst : public Instruction {
384 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
385 void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
387 virtual FenceInst *clone_impl() const;
389 // allocate space for exactly zero operands
390 void *operator new(size_t s) {
391 return User::operator new(s, 0);
394 // Ordering may only be Acquire, Release, AcquireRelease, or
395 // SequentiallyConsistent.
396 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
397 SynchronizationScope SynchScope = CrossThread,
398 Instruction *InsertBefore = 0);
399 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
400 SynchronizationScope SynchScope,
401 BasicBlock *InsertAtEnd);
403 /// Returns the ordering effect of this fence.
404 AtomicOrdering getOrdering() const {
405 return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
408 /// Set the ordering constraint on this fence. May only be Acquire, Release,
409 /// AcquireRelease, or SequentiallyConsistent.
410 void setOrdering(AtomicOrdering Ordering) {
411 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
415 SynchronizationScope getSynchScope() const {
416 return SynchronizationScope(getSubclassDataFromInstruction() & 1);
419 /// Specify whether this fence orders other operations with respect to all
420 /// concurrently executing threads, or only with respect to signal handlers
421 /// executing in the same thread.
422 void setSynchScope(SynchronizationScope xthread) {
423 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
427 // Methods for support type inquiry through isa, cast, and dyn_cast:
428 static inline bool classof(const FenceInst *) { return true; }
429 static inline bool classof(const Instruction *I) {
430 return I->getOpcode() == Instruction::Fence;
432 static inline bool classof(const Value *V) {
433 return isa<Instruction>(V) && classof(cast<Instruction>(V));
436 // Shadow Instruction::setInstructionSubclassData with a private forwarding
437 // method so that subclasses cannot accidentally use it.
438 void setInstructionSubclassData(unsigned short D) {
439 Instruction::setInstructionSubclassData(D);
443 //===----------------------------------------------------------------------===//
444 // AtomicCmpXchgInst Class
445 //===----------------------------------------------------------------------===//
447 /// AtomicCmpXchgInst - an instruction that atomically checks whether a
448 /// specified value is in a memory location, and, if it is, stores a new value
449 /// there. Returns the value that was loaded.
451 class AtomicCmpXchgInst : public Instruction {
452 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
453 void Init(Value *Ptr, Value *Cmp, Value *NewVal,
454 AtomicOrdering Ordering, SynchronizationScope SynchScope);
456 virtual AtomicCmpXchgInst *clone_impl() const;
458 // allocate space for exactly three operands
459 void *operator new(size_t s) {
460 return User::operator new(s, 3);
462 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
463 AtomicOrdering Ordering, SynchronizationScope SynchScope,
464 Instruction *InsertBefore = 0);
465 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
466 AtomicOrdering Ordering, SynchronizationScope SynchScope,
467 BasicBlock *InsertAtEnd);
469 /// isVolatile - Return true if this is a cmpxchg from a volatile memory
472 bool isVolatile() const {
473 return getSubclassDataFromInstruction() & 1;
476 /// setVolatile - Specify whether this is a volatile cmpxchg.
478 void setVolatile(bool V) {
479 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
483 /// Transparently provide more efficient getOperand methods.
484 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
486 /// Set the ordering constraint on this cmpxchg.
487 void setOrdering(AtomicOrdering Ordering) {
488 assert(Ordering != NotAtomic &&
489 "CmpXchg instructions can only be atomic.");
490 setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
494 /// Specify whether this cmpxchg is atomic and orders other operations with
495 /// respect to all concurrently executing threads, or only with respect to
496 /// signal handlers executing in the same thread.
497 void setSynchScope(SynchronizationScope SynchScope) {
498 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
502 /// Returns the ordering constraint on this cmpxchg.
503 AtomicOrdering getOrdering() const {
504 return AtomicOrdering(getSubclassDataFromInstruction() >> 2);
507 /// Returns whether this cmpxchg is atomic between threads or only within a
509 SynchronizationScope getSynchScope() const {
510 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
513 Value *getPointerOperand() { return getOperand(0); }
514 const Value *getPointerOperand() const { return getOperand(0); }
515 static unsigned getPointerOperandIndex() { return 0U; }
517 Value *getCompareOperand() { return getOperand(1); }
518 const Value *getCompareOperand() const { return getOperand(1); }
520 Value *getNewValOperand() { return getOperand(2); }
521 const Value *getNewValOperand() const { return getOperand(2); }
523 unsigned getPointerAddressSpace() const {
524 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
527 // Methods for support type inquiry through isa, cast, and dyn_cast:
528 static inline bool classof(const AtomicCmpXchgInst *) { return true; }
529 static inline bool classof(const Instruction *I) {
530 return I->getOpcode() == Instruction::AtomicCmpXchg;
532 static inline bool classof(const Value *V) {
533 return isa<Instruction>(V) && classof(cast<Instruction>(V));
536 // Shadow Instruction::setInstructionSubclassData with a private forwarding
537 // method so that subclasses cannot accidentally use it.
538 void setInstructionSubclassData(unsigned short D) {
539 Instruction::setInstructionSubclassData(D);
544 struct OperandTraits<AtomicCmpXchgInst> :
545 public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
548 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)
550 //===----------------------------------------------------------------------===//
551 // AtomicRMWInst Class
552 //===----------------------------------------------------------------------===//
554 /// AtomicRMWInst - an instruction that atomically reads a memory location,
555 /// combines it with another value, and then stores the result back. Returns
558 class AtomicRMWInst : public Instruction {
559 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
561 virtual AtomicRMWInst *clone_impl() const;
563 /// This enumeration lists the possible modifications atomicrmw can make. In
564 /// the descriptions, 'p' is the pointer to the instruction's memory location,
565 /// 'old' is the initial value of *p, and 'v' is the other value passed to the
566 /// instruction. These instructions always return 'old'.
582 /// *p = old >signed v ? old : v
584 /// *p = old <signed v ? old : v
586 /// *p = old >unsigned v ? old : v
588 /// *p = old <unsigned v ? old : v
596 // allocate space for exactly two operands
597 void *operator new(size_t s) {
598 return User::operator new(s, 2);
600 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
601 AtomicOrdering Ordering, SynchronizationScope SynchScope,
602 Instruction *InsertBefore = 0);
603 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
604 AtomicOrdering Ordering, SynchronizationScope SynchScope,
605 BasicBlock *InsertAtEnd);
607 BinOp getOperation() const {
608 return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
611 void setOperation(BinOp Operation) {
612 unsigned short SubclassData = getSubclassDataFromInstruction();
613 setInstructionSubclassData((SubclassData & 31) |
617 /// isVolatile - Return true if this is a RMW on a volatile memory location.
619 bool isVolatile() const {
620 return getSubclassDataFromInstruction() & 1;
623 /// setVolatile - Specify whether this is a volatile RMW or not.
625 void setVolatile(bool V) {
626 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
630 /// Transparently provide more efficient getOperand methods.
631 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
633 /// Set the ordering constraint on this RMW.
634 void setOrdering(AtomicOrdering Ordering) {
635 assert(Ordering != NotAtomic &&
636 "atomicrmw instructions can only be atomic.");
637 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
641 /// Specify whether this RMW orders other operations with respect to all
642 /// concurrently executing threads, or only with respect to signal handlers
643 /// executing in the same thread.
644 void setSynchScope(SynchronizationScope SynchScope) {
645 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
649 /// Returns the ordering constraint on this RMW.
650 AtomicOrdering getOrdering() const {
651 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
654 /// Returns whether this RMW is atomic between threads or only within a
656 SynchronizationScope getSynchScope() const {
657 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
660 Value *getPointerOperand() { return getOperand(0); }
661 const Value *getPointerOperand() const { return getOperand(0); }
662 static unsigned getPointerOperandIndex() { return 0U; }
664 Value *getValOperand() { return getOperand(1); }
665 const Value *getValOperand() const { return getOperand(1); }
667 unsigned getPointerAddressSpace() const {
668 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
671 // Methods for support type inquiry through isa, cast, and dyn_cast:
672 static inline bool classof(const AtomicRMWInst *) { return true; }
673 static inline bool classof(const Instruction *I) {
674 return I->getOpcode() == Instruction::AtomicRMW;
676 static inline bool classof(const Value *V) {
677 return isa<Instruction>(V) && classof(cast<Instruction>(V));
680 void Init(BinOp Operation, Value *Ptr, Value *Val,
681 AtomicOrdering Ordering, SynchronizationScope SynchScope);
682 // Shadow Instruction::setInstructionSubclassData with a private forwarding
683 // method so that subclasses cannot accidentally use it.
684 void setInstructionSubclassData(unsigned short D) {
685 Instruction::setInstructionSubclassData(D);
690 struct OperandTraits<AtomicRMWInst>
691 : public FixedNumOperandTraits<AtomicRMWInst,2> {
694 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)
696 //===----------------------------------------------------------------------===//
697 // GetElementPtrInst Class
698 //===----------------------------------------------------------------------===//
700 // checkGEPType - Simple wrapper function to give a better assertion failure
701 // message on bad indexes for a gep instruction.
703 static inline Type *checkGEPType(Type *Ty) {
704 assert(Ty && "Invalid GetElementPtrInst indices for type!");
708 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
709 /// access elements of arrays and structs
711 class GetElementPtrInst : public Instruction {
712 GetElementPtrInst(const GetElementPtrInst &GEPI);
713 void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
715 /// Constructors - Create a getelementptr instruction with a base pointer an
716 /// list of indices. The first ctor can optionally insert before an existing
717 /// instruction, the second appends the new instruction to the specified
719 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
720 unsigned Values, const Twine &NameStr,
721 Instruction *InsertBefore);
722 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
723 unsigned Values, const Twine &NameStr,
724 BasicBlock *InsertAtEnd);
726 virtual GetElementPtrInst *clone_impl() const;
728 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
729 const Twine &NameStr = "",
730 Instruction *InsertBefore = 0) {
731 unsigned Values = 1 + unsigned(IdxList.size());
733 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
735 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
736 const Twine &NameStr,
737 BasicBlock *InsertAtEnd) {
738 unsigned Values = 1 + unsigned(IdxList.size());
740 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
743 /// Create an "inbounds" getelementptr. See the documentation for the
744 /// "inbounds" flag in LangRef.html for details.
745 static GetElementPtrInst *CreateInBounds(Value *Ptr,
746 ArrayRef<Value *> IdxList,
747 const Twine &NameStr = "",
748 Instruction *InsertBefore = 0) {
749 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
750 GEP->setIsInBounds(true);
753 static GetElementPtrInst *CreateInBounds(Value *Ptr,
754 ArrayRef<Value *> IdxList,
755 const Twine &NameStr,
756 BasicBlock *InsertAtEnd) {
757 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
758 GEP->setIsInBounds(true);
762 /// Transparently provide more efficient getOperand methods.
763 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
765 // getType - Overload to return most specific pointer type...
766 PointerType *getType() const {
767 return reinterpret_cast<PointerType*>(Instruction::getType());
770 /// getIndexedType - Returns the type of the element that would be loaded with
771 /// a load instruction with the specified parameters.
773 /// Null is returned if the indices are invalid for the specified
776 static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList);
777 static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList);
778 static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList);
780 /// getIndexedType - Returns the address space used by the GEP pointer.
782 static unsigned getAddressSpace(Value *Ptr);
784 inline op_iterator idx_begin() { return op_begin()+1; }
785 inline const_op_iterator idx_begin() const { return op_begin()+1; }
786 inline op_iterator idx_end() { return op_end(); }
787 inline const_op_iterator idx_end() const { return op_end(); }
789 Value *getPointerOperand() {
790 return getOperand(0);
792 const Value *getPointerOperand() const {
793 return getOperand(0);
795 static unsigned getPointerOperandIndex() {
796 return 0U; // get index for modifying correct operand.
799 unsigned getPointerAddressSpace() const {
800 return cast<PointerType>(getType())->getAddressSpace();
803 /// getPointerOperandType - Method to return the pointer operand as a
805 Type *getPointerOperandType() const {
806 return getPointerOperand()->getType();
809 /// GetGEPReturnType - Returns the pointer type returned by the GEP
810 /// instruction, which may be a vector of pointers.
811 static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
812 Type *PtrTy = PointerType::get(checkGEPType(
813 getIndexedType(Ptr->getType(), IdxList)),
814 getAddressSpace(Ptr));
816 if (Ptr->getType()->isVectorTy()) {
817 unsigned NumElem = cast<VectorType>(Ptr->getType())->getNumElements();
818 return VectorType::get(PtrTy, NumElem);
825 unsigned getNumIndices() const { // Note: always non-negative
826 return getNumOperands() - 1;
829 bool hasIndices() const {
830 return getNumOperands() > 1;
833 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
834 /// zeros. If so, the result pointer and the first operand have the same
835 /// value, just potentially different types.
836 bool hasAllZeroIndices() const;
838 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
839 /// constant integers. If so, the result pointer and the first operand have
840 /// a constant offset between them.
841 bool hasAllConstantIndices() const;
843 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
844 /// See LangRef.html for the meaning of inbounds on a getelementptr.
845 void setIsInBounds(bool b = true);
847 /// isInBounds - Determine whether the GEP has the inbounds flag.
848 bool isInBounds() const;
850 // Methods for support type inquiry through isa, cast, and dyn_cast:
851 static inline bool classof(const GetElementPtrInst *) { return true; }
852 static inline bool classof(const Instruction *I) {
853 return (I->getOpcode() == Instruction::GetElementPtr);
855 static inline bool classof(const Value *V) {
856 return isa<Instruction>(V) && classof(cast<Instruction>(V));
861 struct OperandTraits<GetElementPtrInst> :
862 public VariadicOperandTraits<GetElementPtrInst, 1> {
865 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
866 ArrayRef<Value *> IdxList,
868 const Twine &NameStr,
869 Instruction *InsertBefore)
870 : Instruction(getGEPReturnType(Ptr, IdxList),
872 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
873 Values, InsertBefore) {
874 init(Ptr, IdxList, NameStr);
876 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
877 ArrayRef<Value *> IdxList,
879 const Twine &NameStr,
880 BasicBlock *InsertAtEnd)
881 : Instruction(getGEPReturnType(Ptr, IdxList),
883 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
884 Values, InsertAtEnd) {
885 init(Ptr, IdxList, NameStr);
889 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
892 //===----------------------------------------------------------------------===//
894 //===----------------------------------------------------------------------===//
896 /// This instruction compares its operands according to the predicate given
897 /// to the constructor. It only operates on integers or pointers. The operands
898 /// must be identical types.
899 /// @brief Represent an integer comparison operator.
900 class ICmpInst: public CmpInst {
902 /// @brief Clone an identical ICmpInst
903 virtual ICmpInst *clone_impl() const;
905 /// @brief Constructor with insert-before-instruction semantics.
907 Instruction *InsertBefore, ///< Where to insert
908 Predicate pred, ///< The predicate to use for the comparison
909 Value *LHS, ///< The left-hand-side of the expression
910 Value *RHS, ///< The right-hand-side of the expression
911 const Twine &NameStr = "" ///< Name of the instruction
912 ) : CmpInst(makeCmpResultType(LHS->getType()),
913 Instruction::ICmp, pred, LHS, RHS, NameStr,
915 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
916 pred <= CmpInst::LAST_ICMP_PREDICATE &&
917 "Invalid ICmp predicate value");
918 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
919 "Both operands to ICmp instruction are not of the same type!");
920 // Check that the operands are the right type
921 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
922 getOperand(0)->getType()->getScalarType()->isPointerTy()) &&
923 "Invalid operand types for ICmp instruction");
926 /// @brief Constructor with insert-at-end semantics.
928 BasicBlock &InsertAtEnd, ///< Block to insert into.
929 Predicate pred, ///< The predicate to use for the comparison
930 Value *LHS, ///< The left-hand-side of the expression
931 Value *RHS, ///< The right-hand-side of the expression
932 const Twine &NameStr = "" ///< Name of the instruction
933 ) : CmpInst(makeCmpResultType(LHS->getType()),
934 Instruction::ICmp, pred, LHS, RHS, NameStr,
936 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
937 pred <= CmpInst::LAST_ICMP_PREDICATE &&
938 "Invalid ICmp predicate value");
939 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
940 "Both operands to ICmp instruction are not of the same type!");
941 // Check that the operands are the right type
942 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
943 getOperand(0)->getType()->isPointerTy()) &&
944 "Invalid operand types for ICmp instruction");
947 /// @brief Constructor with no-insertion semantics
949 Predicate pred, ///< The predicate to use for the comparison
950 Value *LHS, ///< The left-hand-side of the expression
951 Value *RHS, ///< The right-hand-side of the expression
952 const Twine &NameStr = "" ///< Name of the instruction
953 ) : CmpInst(makeCmpResultType(LHS->getType()),
954 Instruction::ICmp, pred, LHS, RHS, NameStr) {
955 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
956 pred <= CmpInst::LAST_ICMP_PREDICATE &&
957 "Invalid ICmp predicate value");
958 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
959 "Both operands to ICmp instruction are not of the same type!");
960 // Check that the operands are the right type
961 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
962 getOperand(0)->getType()->getScalarType()->isPointerTy()) &&
963 "Invalid operand types for ICmp instruction");
966 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
967 /// @returns the predicate that would be the result if the operand were
968 /// regarded as signed.
969 /// @brief Return the signed version of the predicate
970 Predicate getSignedPredicate() const {
971 return getSignedPredicate(getPredicate());
974 /// This is a static version that you can use without an instruction.
975 /// @brief Return the signed version of the predicate.
976 static Predicate getSignedPredicate(Predicate pred);
978 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
979 /// @returns the predicate that would be the result if the operand were
980 /// regarded as unsigned.
981 /// @brief Return the unsigned version of the predicate
982 Predicate getUnsignedPredicate() const {
983 return getUnsignedPredicate(getPredicate());
986 /// This is a static version that you can use without an instruction.
987 /// @brief Return the unsigned version of the predicate.
988 static Predicate getUnsignedPredicate(Predicate pred);
990 /// isEquality - Return true if this predicate is either EQ or NE. This also
991 /// tests for commutativity.
992 static bool isEquality(Predicate P) {
993 return P == ICMP_EQ || P == ICMP_NE;
996 /// isEquality - Return true if this predicate is either EQ or NE. This also
997 /// tests for commutativity.
998 bool isEquality() const {
999 return isEquality(getPredicate());
1002 /// @returns true if the predicate of this ICmpInst is commutative
1003 /// @brief Determine if this relation is commutative.
1004 bool isCommutative() const { return isEquality(); }
1006 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1008 bool isRelational() const {
1009 return !isEquality();
1012 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1014 static bool isRelational(Predicate P) {
1015 return !isEquality(P);
1018 /// Initialize a set of values that all satisfy the predicate with C.
1019 /// @brief Make a ConstantRange for a relation with a constant value.
1020 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
1022 /// Exchange the two operands to this instruction in such a way that it does
1023 /// not modify the semantics of the instruction. The predicate value may be
1024 /// changed to retain the same result if the predicate is order dependent
1026 /// @brief Swap operands and adjust predicate.
1027 void swapOperands() {
1028 setPredicate(getSwappedPredicate());
1029 Op<0>().swap(Op<1>());
1032 // Methods for support type inquiry through isa, cast, and dyn_cast:
1033 static inline bool classof(const ICmpInst *) { return true; }
1034 static inline bool classof(const Instruction *I) {
1035 return I->getOpcode() == Instruction::ICmp;
1037 static inline bool classof(const Value *V) {
1038 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1043 //===----------------------------------------------------------------------===//
1045 //===----------------------------------------------------------------------===//
1047 /// This instruction compares its operands according to the predicate given
1048 /// to the constructor. It only operates on floating point values or packed
1049 /// vectors of floating point values. The operands must be identical types.
1050 /// @brief Represents a floating point comparison operator.
1051 class FCmpInst: public CmpInst {
1053 /// @brief Clone an identical FCmpInst
1054 virtual FCmpInst *clone_impl() const;
1056 /// @brief Constructor with insert-before-instruction semantics.
1058 Instruction *InsertBefore, ///< Where to insert
1059 Predicate pred, ///< The predicate to use for the comparison
1060 Value *LHS, ///< The left-hand-side of the expression
1061 Value *RHS, ///< The right-hand-side of the expression
1062 const Twine &NameStr = "" ///< Name of the instruction
1063 ) : CmpInst(makeCmpResultType(LHS->getType()),
1064 Instruction::FCmp, pred, LHS, RHS, NameStr,
1066 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1067 "Invalid FCmp predicate value");
1068 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1069 "Both operands to FCmp instruction are not of the same type!");
1070 // Check that the operands are the right type
1071 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1072 "Invalid operand types for FCmp instruction");
1075 /// @brief Constructor with insert-at-end semantics.
1077 BasicBlock &InsertAtEnd, ///< Block to insert into.
1078 Predicate pred, ///< The predicate to use for the comparison
1079 Value *LHS, ///< The left-hand-side of the expression
1080 Value *RHS, ///< The right-hand-side of the expression
1081 const Twine &NameStr = "" ///< Name of the instruction
1082 ) : CmpInst(makeCmpResultType(LHS->getType()),
1083 Instruction::FCmp, pred, LHS, RHS, NameStr,
1085 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1086 "Invalid FCmp predicate value");
1087 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1088 "Both operands to FCmp instruction are not of the same type!");
1089 // Check that the operands are the right type
1090 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1091 "Invalid operand types for FCmp instruction");
1094 /// @brief Constructor with no-insertion semantics
1096 Predicate pred, ///< The predicate to use for the comparison
1097 Value *LHS, ///< The left-hand-side of the expression
1098 Value *RHS, ///< The right-hand-side of the expression
1099 const Twine &NameStr = "" ///< Name of the instruction
1100 ) : CmpInst(makeCmpResultType(LHS->getType()),
1101 Instruction::FCmp, pred, LHS, RHS, NameStr) {
1102 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1103 "Invalid FCmp predicate value");
1104 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1105 "Both operands to FCmp instruction are not of the same type!");
1106 // Check that the operands are the right type
1107 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1108 "Invalid operand types for FCmp instruction");
1111 /// @returns true if the predicate of this instruction is EQ or NE.
1112 /// @brief Determine if this is an equality predicate.
1113 bool isEquality() const {
1114 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
1115 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
1118 /// @returns true if the predicate of this instruction is commutative.
1119 /// @brief Determine if this is a commutative predicate.
1120 bool isCommutative() const {
1121 return isEquality() ||
1122 getPredicate() == FCMP_FALSE ||
1123 getPredicate() == FCMP_TRUE ||
1124 getPredicate() == FCMP_ORD ||
1125 getPredicate() == FCMP_UNO;
1128 /// @returns true if the predicate is relational (not EQ or NE).
1129 /// @brief Determine if this a relational predicate.
1130 bool isRelational() const { return !isEquality(); }
1132 /// Exchange the two operands to this instruction in such a way that it does
1133 /// not modify the semantics of the instruction. The predicate value may be
1134 /// changed to retain the same result if the predicate is order dependent
1136 /// @brief Swap operands and adjust predicate.
1137 void swapOperands() {
1138 setPredicate(getSwappedPredicate());
1139 Op<0>().swap(Op<1>());
1142 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1143 static inline bool classof(const FCmpInst *) { return true; }
1144 static inline bool classof(const Instruction *I) {
1145 return I->getOpcode() == Instruction::FCmp;
1147 static inline bool classof(const Value *V) {
1148 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1152 //===----------------------------------------------------------------------===//
1153 /// CallInst - This class represents a function call, abstracting a target
1154 /// machine's calling convention. This class uses low bit of the SubClassData
1155 /// field to indicate whether or not this is a tail call. The rest of the bits
1156 /// hold the calling convention of the call.
1158 class CallInst : public Instruction {
1159 AttrListPtr AttributeList; ///< parameter attributes for call
1160 CallInst(const CallInst &CI);
1161 void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
1162 void init(Value *Func, const Twine &NameStr);
1164 /// Construct a CallInst given a range of arguments.
1165 /// @brief Construct a CallInst from a range of arguments
1166 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1167 const Twine &NameStr, Instruction *InsertBefore);
1169 /// Construct a CallInst given a range of arguments.
1170 /// @brief Construct a CallInst from a range of arguments
1171 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1172 const Twine &NameStr, BasicBlock *InsertAtEnd);
1174 CallInst(Value *F, Value *Actual, const Twine &NameStr,
1175 Instruction *InsertBefore);
1176 CallInst(Value *F, Value *Actual, const Twine &NameStr,
1177 BasicBlock *InsertAtEnd);
1178 explicit CallInst(Value *F, const Twine &NameStr,
1179 Instruction *InsertBefore);
1180 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1182 virtual CallInst *clone_impl() const;
1184 static CallInst *Create(Value *Func,
1185 ArrayRef<Value *> Args,
1186 const Twine &NameStr = "",
1187 Instruction *InsertBefore = 0) {
1188 return new(unsigned(Args.size() + 1))
1189 CallInst(Func, Args, NameStr, InsertBefore);
1191 static CallInst *Create(Value *Func,
1192 ArrayRef<Value *> Args,
1193 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1194 return new(unsigned(Args.size() + 1))
1195 CallInst(Func, Args, NameStr, InsertAtEnd);
1197 static CallInst *Create(Value *F, const Twine &NameStr = "",
1198 Instruction *InsertBefore = 0) {
1199 return new(1) CallInst(F, NameStr, InsertBefore);
1201 static CallInst *Create(Value *F, const Twine &NameStr,
1202 BasicBlock *InsertAtEnd) {
1203 return new(1) CallInst(F, NameStr, InsertAtEnd);
1205 /// CreateMalloc - Generate the IR for a call to malloc:
1206 /// 1. Compute the malloc call's argument as the specified type's size,
1207 /// possibly multiplied by the array size if the array size is not
1209 /// 2. Call malloc with that argument.
1210 /// 3. Bitcast the result of the malloc call to the specified type.
1211 static Instruction *CreateMalloc(Instruction *InsertBefore,
1212 Type *IntPtrTy, Type *AllocTy,
1213 Value *AllocSize, Value *ArraySize = 0,
1214 Function* MallocF = 0,
1215 const Twine &Name = "");
1216 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1217 Type *IntPtrTy, Type *AllocTy,
1218 Value *AllocSize, Value *ArraySize = 0,
1219 Function* MallocF = 0,
1220 const Twine &Name = "");
1221 /// CreateFree - Generate the IR for a call to the builtin free function.
1222 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
1223 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
1227 bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
1228 void setTailCall(bool isTC = true) {
1229 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
1233 /// Provide fast operand accessors
1234 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1236 /// getNumArgOperands - Return the number of call arguments.
1238 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
1240 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1242 Value *getArgOperand(unsigned i) const { return getOperand(i); }
1243 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
1245 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1247 CallingConv::ID getCallingConv() const {
1248 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
1250 void setCallingConv(CallingConv::ID CC) {
1251 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
1252 (static_cast<unsigned>(CC) << 1));
1255 /// getAttributes - Return the parameter attributes for this call.
1257 const AttrListPtr &getAttributes() const { return AttributeList; }
1259 /// setAttributes - Set the parameter attributes for this call.
1261 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
1263 /// addAttribute - adds the attribute to the list of attributes.
1264 void addAttribute(unsigned i, Attributes attr);
1266 /// removeAttribute - removes the attribute from the list of attributes.
1267 void removeAttribute(unsigned i, Attributes attr);
1269 /// @brief Determine whether the call or the callee has the given attribute.
1270 bool paramHasAttr(unsigned i, Attributes attr) const;
1272 /// @brief Extract the alignment for a call or parameter (0=unknown).
1273 unsigned getParamAlignment(unsigned i) const {
1274 return AttributeList.getParamAlignment(i);
1277 /// @brief Return true if the call should not be inlined.
1278 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
1279 void setIsNoInline(bool Value = true) {
1280 if (Value) addAttribute(~0, Attribute::NoInline);
1281 else removeAttribute(~0, Attribute::NoInline);
1284 /// @brief Return true if the call can return twice
1285 bool canReturnTwice() const {
1286 return paramHasAttr(~0, Attribute::ReturnsTwice);
1288 void setCanReturnTwice(bool Value = true) {
1289 if (Value) addAttribute(~0, Attribute::ReturnsTwice);
1290 else removeAttribute(~0, Attribute::ReturnsTwice);
1293 /// @brief Determine if the call does not access memory.
1294 bool doesNotAccessMemory() const {
1295 return paramHasAttr(~0, Attribute::ReadNone);
1297 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
1298 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
1299 else removeAttribute(~0, Attribute::ReadNone);
1302 /// @brief Determine if the call does not access or only reads memory.
1303 bool onlyReadsMemory() const {
1304 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
1306 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
1307 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
1308 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
1311 /// @brief Determine if the call cannot return.
1312 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
1313 void setDoesNotReturn(bool DoesNotReturn = true) {
1314 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
1315 else removeAttribute(~0, Attribute::NoReturn);
1318 /// @brief Determine if the call cannot unwind.
1319 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
1320 void setDoesNotThrow(bool DoesNotThrow = true) {
1321 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
1322 else removeAttribute(~0, Attribute::NoUnwind);
1325 /// @brief Determine if the call returns a structure through first
1326 /// pointer argument.
1327 bool hasStructRetAttr() const {
1328 // Be friendly and also check the callee.
1329 return paramHasAttr(1, Attribute::StructRet);
1332 /// @brief Determine if any call argument is an aggregate passed by value.
1333 bool hasByValArgument() const {
1334 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1337 /// getCalledFunction - Return the function called, or null if this is an
1338 /// indirect function invocation.
1340 Function *getCalledFunction() const {
1341 return dyn_cast<Function>(Op<-1>());
1344 /// getCalledValue - Get a pointer to the function that is invoked by this
1346 const Value *getCalledValue() const { return Op<-1>(); }
1347 Value *getCalledValue() { return Op<-1>(); }
1349 /// setCalledFunction - Set the function called.
1350 void setCalledFunction(Value* Fn) {
1354 /// isInlineAsm - Check if this call is an inline asm statement.
1355 bool isInlineAsm() const {
1356 return isa<InlineAsm>(Op<-1>());
1359 // Methods for support type inquiry through isa, cast, and dyn_cast:
1360 static inline bool classof(const CallInst *) { return true; }
1361 static inline bool classof(const Instruction *I) {
1362 return I->getOpcode() == Instruction::Call;
1364 static inline bool classof(const Value *V) {
1365 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1368 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1369 // method so that subclasses cannot accidentally use it.
1370 void setInstructionSubclassData(unsigned short D) {
1371 Instruction::setInstructionSubclassData(D);
1376 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1379 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1380 const Twine &NameStr, BasicBlock *InsertAtEnd)
1381 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1382 ->getElementType())->getReturnType(),
1384 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1385 unsigned(Args.size() + 1), InsertAtEnd) {
1386 init(Func, Args, NameStr);
1389 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1390 const Twine &NameStr, Instruction *InsertBefore)
1391 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1392 ->getElementType())->getReturnType(),
1394 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1395 unsigned(Args.size() + 1), InsertBefore) {
1396 init(Func, Args, NameStr);
1400 // Note: if you get compile errors about private methods then
1401 // please update your code to use the high-level operand
1402 // interfaces. See line 943 above.
1403 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1405 //===----------------------------------------------------------------------===//
1407 //===----------------------------------------------------------------------===//
1409 /// SelectInst - This class represents the LLVM 'select' instruction.
1411 class SelectInst : public Instruction {
1412 void init(Value *C, Value *S1, Value *S2) {
1413 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1419 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1420 Instruction *InsertBefore)
1421 : Instruction(S1->getType(), Instruction::Select,
1422 &Op<0>(), 3, InsertBefore) {
1426 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1427 BasicBlock *InsertAtEnd)
1428 : Instruction(S1->getType(), Instruction::Select,
1429 &Op<0>(), 3, InsertAtEnd) {
1434 virtual SelectInst *clone_impl() const;
1436 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1437 const Twine &NameStr = "",
1438 Instruction *InsertBefore = 0) {
1439 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1441 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1442 const Twine &NameStr,
1443 BasicBlock *InsertAtEnd) {
1444 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1447 const Value *getCondition() const { return Op<0>(); }
1448 const Value *getTrueValue() const { return Op<1>(); }
1449 const Value *getFalseValue() const { return Op<2>(); }
1450 Value *getCondition() { return Op<0>(); }
1451 Value *getTrueValue() { return Op<1>(); }
1452 Value *getFalseValue() { return Op<2>(); }
1454 /// areInvalidOperands - Return a string if the specified operands are invalid
1455 /// for a select operation, otherwise return null.
1456 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1458 /// Transparently provide more efficient getOperand methods.
1459 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1461 OtherOps getOpcode() const {
1462 return static_cast<OtherOps>(Instruction::getOpcode());
1465 // Methods for support type inquiry through isa, cast, and dyn_cast:
1466 static inline bool classof(const SelectInst *) { return true; }
1467 static inline bool classof(const Instruction *I) {
1468 return I->getOpcode() == Instruction::Select;
1470 static inline bool classof(const Value *V) {
1471 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1476 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1479 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1481 //===----------------------------------------------------------------------===//
1483 //===----------------------------------------------------------------------===//
1485 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1486 /// an argument of the specified type given a va_list and increments that list
1488 class VAArgInst : public UnaryInstruction {
1490 virtual VAArgInst *clone_impl() const;
1493 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1494 Instruction *InsertBefore = 0)
1495 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1498 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1499 BasicBlock *InsertAtEnd)
1500 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1504 Value *getPointerOperand() { return getOperand(0); }
1505 const Value *getPointerOperand() const { return getOperand(0); }
1506 static unsigned getPointerOperandIndex() { return 0U; }
1508 // Methods for support type inquiry through isa, cast, and dyn_cast:
1509 static inline bool classof(const VAArgInst *) { return true; }
1510 static inline bool classof(const Instruction *I) {
1511 return I->getOpcode() == VAArg;
1513 static inline bool classof(const Value *V) {
1514 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1518 //===----------------------------------------------------------------------===//
1519 // ExtractElementInst Class
1520 //===----------------------------------------------------------------------===//
1522 /// ExtractElementInst - This instruction extracts a single (scalar)
1523 /// element from a VectorType value
1525 class ExtractElementInst : public Instruction {
1526 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1527 Instruction *InsertBefore = 0);
1528 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1529 BasicBlock *InsertAtEnd);
1531 virtual ExtractElementInst *clone_impl() const;
1534 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1535 const Twine &NameStr = "",
1536 Instruction *InsertBefore = 0) {
1537 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1539 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1540 const Twine &NameStr,
1541 BasicBlock *InsertAtEnd) {
1542 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1545 /// isValidOperands - Return true if an extractelement instruction can be
1546 /// formed with the specified operands.
1547 static bool isValidOperands(const Value *Vec, const Value *Idx);
1549 Value *getVectorOperand() { return Op<0>(); }
1550 Value *getIndexOperand() { return Op<1>(); }
1551 const Value *getVectorOperand() const { return Op<0>(); }
1552 const Value *getIndexOperand() const { return Op<1>(); }
1554 VectorType *getVectorOperandType() const {
1555 return reinterpret_cast<VectorType*>(getVectorOperand()->getType());
1559 /// Transparently provide more efficient getOperand methods.
1560 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1562 // Methods for support type inquiry through isa, cast, and dyn_cast:
1563 static inline bool classof(const ExtractElementInst *) { return true; }
1564 static inline bool classof(const Instruction *I) {
1565 return I->getOpcode() == Instruction::ExtractElement;
1567 static inline bool classof(const Value *V) {
1568 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1573 struct OperandTraits<ExtractElementInst> :
1574 public FixedNumOperandTraits<ExtractElementInst, 2> {
1577 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1579 //===----------------------------------------------------------------------===//
1580 // InsertElementInst Class
1581 //===----------------------------------------------------------------------===//
1583 /// InsertElementInst - This instruction inserts a single (scalar)
1584 /// element into a VectorType value
1586 class InsertElementInst : public Instruction {
1587 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1588 const Twine &NameStr = "",
1589 Instruction *InsertBefore = 0);
1590 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1591 const Twine &NameStr, BasicBlock *InsertAtEnd);
1593 virtual InsertElementInst *clone_impl() const;
1596 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1597 const Twine &NameStr = "",
1598 Instruction *InsertBefore = 0) {
1599 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1601 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1602 const Twine &NameStr,
1603 BasicBlock *InsertAtEnd) {
1604 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1607 /// isValidOperands - Return true if an insertelement instruction can be
1608 /// formed with the specified operands.
1609 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1612 /// getType - Overload to return most specific vector type.
1614 VectorType *getType() const {
1615 return reinterpret_cast<VectorType*>(Instruction::getType());
1618 /// Transparently provide more efficient getOperand methods.
1619 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1621 // Methods for support type inquiry through isa, cast, and dyn_cast:
1622 static inline bool classof(const InsertElementInst *) { return true; }
1623 static inline bool classof(const Instruction *I) {
1624 return I->getOpcode() == Instruction::InsertElement;
1626 static inline bool classof(const Value *V) {
1627 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1632 struct OperandTraits<InsertElementInst> :
1633 public FixedNumOperandTraits<InsertElementInst, 3> {
1636 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1638 //===----------------------------------------------------------------------===//
1639 // ShuffleVectorInst Class
1640 //===----------------------------------------------------------------------===//
1642 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1645 class ShuffleVectorInst : public Instruction {
1647 virtual ShuffleVectorInst *clone_impl() const;
1650 // allocate space for exactly three operands
1651 void *operator new(size_t s) {
1652 return User::operator new(s, 3);
1654 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1655 const Twine &NameStr = "",
1656 Instruction *InsertBefor = 0);
1657 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1658 const Twine &NameStr, BasicBlock *InsertAtEnd);
1660 /// isValidOperands - Return true if a shufflevector instruction can be
1661 /// formed with the specified operands.
1662 static bool isValidOperands(const Value *V1, const Value *V2,
1665 /// getType - Overload to return most specific vector type.
1667 VectorType *getType() const {
1668 return reinterpret_cast<VectorType*>(Instruction::getType());
1671 /// Transparently provide more efficient getOperand methods.
1672 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1674 Constant *getMask() const {
1675 return reinterpret_cast<Constant*>(getOperand(2));
1678 /// getMaskValue - Return the index from the shuffle mask for the specified
1679 /// output result. This is either -1 if the element is undef or a number less
1680 /// than 2*numelements.
1681 static int getMaskValue(Constant *Mask, unsigned i);
1683 int getMaskValue(unsigned i) const {
1684 return getMaskValue(getMask(), i);
1687 /// getShuffleMask - Return the full mask for this instruction, where each
1688 /// element is the element number and undef's are returned as -1.
1689 static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
1691 void getShuffleMask(SmallVectorImpl<int> &Result) const {
1692 return getShuffleMask(getMask(), Result);
1695 SmallVector<int, 16> getShuffleMask() const {
1696 SmallVector<int, 16> Mask;
1697 getShuffleMask(Mask);
1702 // Methods for support type inquiry through isa, cast, and dyn_cast:
1703 static inline bool classof(const ShuffleVectorInst *) { return true; }
1704 static inline bool classof(const Instruction *I) {
1705 return I->getOpcode() == Instruction::ShuffleVector;
1707 static inline bool classof(const Value *V) {
1708 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1713 struct OperandTraits<ShuffleVectorInst> :
1714 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1717 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1719 //===----------------------------------------------------------------------===//
1720 // ExtractValueInst Class
1721 //===----------------------------------------------------------------------===//
1723 /// ExtractValueInst - This instruction extracts a struct member or array
1724 /// element value from an aggregate value.
1726 class ExtractValueInst : public UnaryInstruction {
1727 SmallVector<unsigned, 4> Indices;
1729 ExtractValueInst(const ExtractValueInst &EVI);
1730 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1732 /// Constructors - Create a extractvalue instruction with a base aggregate
1733 /// value and a list of indices. The first ctor can optionally insert before
1734 /// an existing instruction, the second appends the new instruction to the
1735 /// specified BasicBlock.
1736 inline ExtractValueInst(Value *Agg,
1737 ArrayRef<unsigned> Idxs,
1738 const Twine &NameStr,
1739 Instruction *InsertBefore);
1740 inline ExtractValueInst(Value *Agg,
1741 ArrayRef<unsigned> Idxs,
1742 const Twine &NameStr, BasicBlock *InsertAtEnd);
1744 // allocate space for exactly one operand
1745 void *operator new(size_t s) {
1746 return User::operator new(s, 1);
1749 virtual ExtractValueInst *clone_impl() const;
1752 static ExtractValueInst *Create(Value *Agg,
1753 ArrayRef<unsigned> Idxs,
1754 const Twine &NameStr = "",
1755 Instruction *InsertBefore = 0) {
1757 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1759 static ExtractValueInst *Create(Value *Agg,
1760 ArrayRef<unsigned> Idxs,
1761 const Twine &NameStr,
1762 BasicBlock *InsertAtEnd) {
1763 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1766 /// getIndexedType - Returns the type of the element that would be extracted
1767 /// with an extractvalue instruction with the specified parameters.
1769 /// Null is returned if the indices are invalid for the specified type.
1770 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
1772 typedef const unsigned* idx_iterator;
1773 inline idx_iterator idx_begin() const { return Indices.begin(); }
1774 inline idx_iterator idx_end() const { return Indices.end(); }
1776 Value *getAggregateOperand() {
1777 return getOperand(0);
1779 const Value *getAggregateOperand() const {
1780 return getOperand(0);
1782 static unsigned getAggregateOperandIndex() {
1783 return 0U; // get index for modifying correct operand
1786 ArrayRef<unsigned> getIndices() const {
1790 unsigned getNumIndices() const {
1791 return (unsigned)Indices.size();
1794 bool hasIndices() const {
1798 // Methods for support type inquiry through isa, cast, and dyn_cast:
1799 static inline bool classof(const ExtractValueInst *) { return true; }
1800 static inline bool classof(const Instruction *I) {
1801 return I->getOpcode() == Instruction::ExtractValue;
1803 static inline bool classof(const Value *V) {
1804 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1808 ExtractValueInst::ExtractValueInst(Value *Agg,
1809 ArrayRef<unsigned> Idxs,
1810 const Twine &NameStr,
1811 Instruction *InsertBefore)
1812 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1813 ExtractValue, Agg, InsertBefore) {
1814 init(Idxs, NameStr);
1816 ExtractValueInst::ExtractValueInst(Value *Agg,
1817 ArrayRef<unsigned> Idxs,
1818 const Twine &NameStr,
1819 BasicBlock *InsertAtEnd)
1820 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1821 ExtractValue, Agg, InsertAtEnd) {
1822 init(Idxs, NameStr);
1826 //===----------------------------------------------------------------------===//
1827 // InsertValueInst Class
1828 //===----------------------------------------------------------------------===//
1830 /// InsertValueInst - This instruction inserts a struct field of array element
1831 /// value into an aggregate value.
1833 class InsertValueInst : public Instruction {
1834 SmallVector<unsigned, 4> Indices;
1836 void *operator new(size_t, unsigned); // Do not implement
1837 InsertValueInst(const InsertValueInst &IVI);
1838 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1839 const Twine &NameStr);
1841 /// Constructors - Create a insertvalue instruction with a base aggregate
1842 /// value, a value to insert, and a list of indices. The first ctor can
1843 /// optionally insert before an existing instruction, the second appends
1844 /// the new instruction to the specified BasicBlock.
1845 inline InsertValueInst(Value *Agg, Value *Val,
1846 ArrayRef<unsigned> Idxs,
1847 const Twine &NameStr,
1848 Instruction *InsertBefore);
1849 inline InsertValueInst(Value *Agg, Value *Val,
1850 ArrayRef<unsigned> Idxs,
1851 const Twine &NameStr, BasicBlock *InsertAtEnd);
1853 /// Constructors - These two constructors are convenience methods because one
1854 /// and two index insertvalue instructions are so common.
1855 InsertValueInst(Value *Agg, Value *Val,
1856 unsigned Idx, const Twine &NameStr = "",
1857 Instruction *InsertBefore = 0);
1858 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1859 const Twine &NameStr, BasicBlock *InsertAtEnd);
1861 virtual InsertValueInst *clone_impl() const;
1863 // allocate space for exactly two operands
1864 void *operator new(size_t s) {
1865 return User::operator new(s, 2);
1868 static InsertValueInst *Create(Value *Agg, Value *Val,
1869 ArrayRef<unsigned> Idxs,
1870 const Twine &NameStr = "",
1871 Instruction *InsertBefore = 0) {
1872 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1874 static InsertValueInst *Create(Value *Agg, Value *Val,
1875 ArrayRef<unsigned> Idxs,
1876 const Twine &NameStr,
1877 BasicBlock *InsertAtEnd) {
1878 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1881 /// Transparently provide more efficient getOperand methods.
1882 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1884 typedef const unsigned* idx_iterator;
1885 inline idx_iterator idx_begin() const { return Indices.begin(); }
1886 inline idx_iterator idx_end() const { return Indices.end(); }
1888 Value *getAggregateOperand() {
1889 return getOperand(0);
1891 const Value *getAggregateOperand() const {
1892 return getOperand(0);
1894 static unsigned getAggregateOperandIndex() {
1895 return 0U; // get index for modifying correct operand
1898 Value *getInsertedValueOperand() {
1899 return getOperand(1);
1901 const Value *getInsertedValueOperand() const {
1902 return getOperand(1);
1904 static unsigned getInsertedValueOperandIndex() {
1905 return 1U; // get index for modifying correct operand
1908 ArrayRef<unsigned> getIndices() const {
1912 unsigned getNumIndices() const {
1913 return (unsigned)Indices.size();
1916 bool hasIndices() const {
1920 // Methods for support type inquiry through isa, cast, and dyn_cast:
1921 static inline bool classof(const InsertValueInst *) { return true; }
1922 static inline bool classof(const Instruction *I) {
1923 return I->getOpcode() == Instruction::InsertValue;
1925 static inline bool classof(const Value *V) {
1926 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1931 struct OperandTraits<InsertValueInst> :
1932 public FixedNumOperandTraits<InsertValueInst, 2> {
1935 InsertValueInst::InsertValueInst(Value *Agg,
1937 ArrayRef<unsigned> Idxs,
1938 const Twine &NameStr,
1939 Instruction *InsertBefore)
1940 : Instruction(Agg->getType(), InsertValue,
1941 OperandTraits<InsertValueInst>::op_begin(this),
1943 init(Agg, Val, Idxs, NameStr);
1945 InsertValueInst::InsertValueInst(Value *Agg,
1947 ArrayRef<unsigned> Idxs,
1948 const Twine &NameStr,
1949 BasicBlock *InsertAtEnd)
1950 : Instruction(Agg->getType(), InsertValue,
1951 OperandTraits<InsertValueInst>::op_begin(this),
1953 init(Agg, Val, Idxs, NameStr);
1956 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1958 //===----------------------------------------------------------------------===//
1960 //===----------------------------------------------------------------------===//
1962 // PHINode - The PHINode class is used to represent the magical mystical PHI
1963 // node, that can not exist in nature, but can be synthesized in a computer
1964 // scientist's overactive imagination.
1966 class PHINode : public Instruction {
1967 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1968 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1969 /// the number actually in use.
1970 unsigned ReservedSpace;
1971 PHINode(const PHINode &PN);
1972 // allocate space for exactly zero operands
1973 void *operator new(size_t s) {
1974 return User::operator new(s, 0);
1976 explicit PHINode(Type *Ty, unsigned NumReservedValues,
1977 const Twine &NameStr = "", Instruction *InsertBefore = 0)
1978 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1979 ReservedSpace(NumReservedValues) {
1981 OperandList = allocHungoffUses(ReservedSpace);
1984 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
1985 BasicBlock *InsertAtEnd)
1986 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1987 ReservedSpace(NumReservedValues) {
1989 OperandList = allocHungoffUses(ReservedSpace);
1992 // allocHungoffUses - this is more complicated than the generic
1993 // User::allocHungoffUses, because we have to allocate Uses for the incoming
1994 // values and pointers to the incoming blocks, all in one allocation.
1995 Use *allocHungoffUses(unsigned) const;
1997 virtual PHINode *clone_impl() const;
1999 /// Constructors - NumReservedValues is a hint for the number of incoming
2000 /// edges that this phi node will have (use 0 if you really have no idea).
2001 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2002 const Twine &NameStr = "",
2003 Instruction *InsertBefore = 0) {
2004 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2006 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2007 const Twine &NameStr, BasicBlock *InsertAtEnd) {
2008 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2012 /// Provide fast operand accessors
2013 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2015 // Block iterator interface. This provides access to the list of incoming
2016 // basic blocks, which parallels the list of incoming values.
2018 typedef BasicBlock **block_iterator;
2019 typedef BasicBlock * const *const_block_iterator;
2021 block_iterator block_begin() {
2023 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2024 return reinterpret_cast<block_iterator>(ref + 1);
2027 const_block_iterator block_begin() const {
2028 const Use::UserRef *ref =
2029 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2030 return reinterpret_cast<const_block_iterator>(ref + 1);
2033 block_iterator block_end() {
2034 return block_begin() + getNumOperands();
2037 const_block_iterator block_end() const {
2038 return block_begin() + getNumOperands();
2041 /// getNumIncomingValues - Return the number of incoming edges
2043 unsigned getNumIncomingValues() const { return getNumOperands(); }
2045 /// getIncomingValue - Return incoming value number x
2047 Value *getIncomingValue(unsigned i) const {
2048 return getOperand(i);
2050 void setIncomingValue(unsigned i, Value *V) {
2053 static unsigned getOperandNumForIncomingValue(unsigned i) {
2056 static unsigned getIncomingValueNumForOperand(unsigned i) {
2060 /// getIncomingBlock - Return incoming basic block number @p i.
2062 BasicBlock *getIncomingBlock(unsigned i) const {
2063 return block_begin()[i];
2066 /// getIncomingBlock - Return incoming basic block corresponding
2067 /// to an operand of the PHI.
2069 BasicBlock *getIncomingBlock(const Use &U) const {
2070 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2071 return getIncomingBlock(unsigned(&U - op_begin()));
2074 /// getIncomingBlock - Return incoming basic block corresponding
2075 /// to value use iterator.
2077 template <typename U>
2078 BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
2079 return getIncomingBlock(I.getUse());
2082 void setIncomingBlock(unsigned i, BasicBlock *BB) {
2083 block_begin()[i] = BB;
2086 /// addIncoming - Add an incoming value to the end of the PHI list
2088 void addIncoming(Value *V, BasicBlock *BB) {
2089 assert(V && "PHI node got a null value!");
2090 assert(BB && "PHI node got a null basic block!");
2091 assert(getType() == V->getType() &&
2092 "All operands to PHI node must be the same type as the PHI node!");
2093 if (NumOperands == ReservedSpace)
2094 growOperands(); // Get more space!
2095 // Initialize some new operands.
2097 setIncomingValue(NumOperands - 1, V);
2098 setIncomingBlock(NumOperands - 1, BB);
2101 /// removeIncomingValue - Remove an incoming value. This is useful if a
2102 /// predecessor basic block is deleted. The value removed is returned.
2104 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2105 /// is true), the PHI node is destroyed and any uses of it are replaced with
2106 /// dummy values. The only time there should be zero incoming values to a PHI
2107 /// node is when the block is dead, so this strategy is sound.
2109 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2111 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2112 int Idx = getBasicBlockIndex(BB);
2113 assert(Idx >= 0 && "Invalid basic block argument to remove!");
2114 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2117 /// getBasicBlockIndex - Return the first index of the specified basic
2118 /// block in the value list for this PHI. Returns -1 if no instance.
2120 int getBasicBlockIndex(const BasicBlock *BB) const {
2121 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2122 if (block_begin()[i] == BB)
2127 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2128 int Idx = getBasicBlockIndex(BB);
2129 assert(Idx >= 0 && "Invalid basic block argument!");
2130 return getIncomingValue(Idx);
2133 /// hasConstantValue - If the specified PHI node always merges together the
2134 /// same value, return the value, otherwise return null.
2135 Value *hasConstantValue() const;
2137 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2138 static inline bool classof(const PHINode *) { return true; }
2139 static inline bool classof(const Instruction *I) {
2140 return I->getOpcode() == Instruction::PHI;
2142 static inline bool classof(const Value *V) {
2143 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2146 void growOperands();
2150 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2153 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
2155 //===----------------------------------------------------------------------===//
2156 // LandingPadInst Class
2157 //===----------------------------------------------------------------------===//
2159 //===---------------------------------------------------------------------------
2160 /// LandingPadInst - The landingpad instruction holds all of the information
2161 /// necessary to generate correct exception handling. The landingpad instruction
2162 /// cannot be moved from the top of a landing pad block, which itself is
2163 /// accessible only from the 'unwind' edge of an invoke. This uses the
2164 /// SubclassData field in Value to store whether or not the landingpad is a
2167 class LandingPadInst : public Instruction {
2168 /// ReservedSpace - The number of operands actually allocated. NumOperands is
2169 /// the number actually in use.
2170 unsigned ReservedSpace;
2171 LandingPadInst(const LandingPadInst &LP);
2173 enum ClauseType { Catch, Filter };
2175 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2176 // Allocate space for exactly zero operands.
2177 void *operator new(size_t s) {
2178 return User::operator new(s, 0);
2180 void growOperands(unsigned Size);
2181 void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
2183 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2184 unsigned NumReservedValues, const Twine &NameStr,
2185 Instruction *InsertBefore);
2186 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2187 unsigned NumReservedValues, const Twine &NameStr,
2188 BasicBlock *InsertAtEnd);
2190 virtual LandingPadInst *clone_impl() const;
2192 /// Constructors - NumReservedClauses is a hint for the number of incoming
2193 /// clauses that this landingpad will have (use 0 if you really have no idea).
2194 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2195 unsigned NumReservedClauses,
2196 const Twine &NameStr = "",
2197 Instruction *InsertBefore = 0);
2198 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2199 unsigned NumReservedClauses,
2200 const Twine &NameStr, BasicBlock *InsertAtEnd);
2203 /// Provide fast operand accessors
2204 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2206 /// getPersonalityFn - Get the personality function associated with this
2208 Value *getPersonalityFn() const { return getOperand(0); }
2210 /// isCleanup - Return 'true' if this landingpad instruction is a
2211 /// cleanup. I.e., it should be run when unwinding even if its landing pad
2212 /// doesn't catch the exception.
2213 bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2215 /// setCleanup - Indicate that this landingpad instruction is a cleanup.
2216 void setCleanup(bool V) {
2217 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2221 /// addClause - Add a catch or filter clause to the landing pad.
2222 void addClause(Value *ClauseVal);
2224 /// getClause - Get the value of the clause at index Idx. Use isCatch/isFilter
2225 /// to determine what type of clause this is.
2226 Value *getClause(unsigned Idx) const { return OperandList[Idx + 1]; }
2228 /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
2229 bool isCatch(unsigned Idx) const {
2230 return !isa<ArrayType>(OperandList[Idx + 1]->getType());
2233 /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
2234 bool isFilter(unsigned Idx) const {
2235 return isa<ArrayType>(OperandList[Idx + 1]->getType());
2238 /// getNumClauses - Get the number of clauses for this landing pad.
2239 unsigned getNumClauses() const { return getNumOperands() - 1; }
2241 /// reserveClauses - Grow the size of the operand list to accomodate the new
2242 /// number of clauses.
2243 void reserveClauses(unsigned Size) { growOperands(Size); }
2245 // Methods for support type inquiry through isa, cast, and dyn_cast:
2246 static inline bool classof(const LandingPadInst *) { return true; }
2247 static inline bool classof(const Instruction *I) {
2248 return I->getOpcode() == Instruction::LandingPad;
2250 static inline bool classof(const Value *V) {
2251 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2256 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
2259 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
2261 //===----------------------------------------------------------------------===//
2263 //===----------------------------------------------------------------------===//
2265 //===---------------------------------------------------------------------------
2266 /// ReturnInst - Return a value (possibly void), from a function. Execution
2267 /// does not continue in this function any longer.
2269 class ReturnInst : public TerminatorInst {
2270 ReturnInst(const ReturnInst &RI);
2273 // ReturnInst constructors:
2274 // ReturnInst() - 'ret void' instruction
2275 // ReturnInst( null) - 'ret void' instruction
2276 // ReturnInst(Value* X) - 'ret X' instruction
2277 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
2278 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
2279 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2280 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
2282 // NOTE: If the Value* passed is of type void then the constructor behaves as
2283 // if it was passed NULL.
2284 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
2285 Instruction *InsertBefore = 0);
2286 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2287 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2289 virtual ReturnInst *clone_impl() const;
2291 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
2292 Instruction *InsertBefore = 0) {
2293 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2295 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2296 BasicBlock *InsertAtEnd) {
2297 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2299 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2300 return new(0) ReturnInst(C, InsertAtEnd);
2302 virtual ~ReturnInst();
2304 /// Provide fast operand accessors
2305 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2307 /// Convenience accessor. Returns null if there is no return value.
2308 Value *getReturnValue() const {
2309 return getNumOperands() != 0 ? getOperand(0) : 0;
2312 unsigned getNumSuccessors() const { return 0; }
2314 // Methods for support type inquiry through isa, cast, and dyn_cast:
2315 static inline bool classof(const ReturnInst *) { return true; }
2316 static inline bool classof(const Instruction *I) {
2317 return (I->getOpcode() == Instruction::Ret);
2319 static inline bool classof(const Value *V) {
2320 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2323 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2324 virtual unsigned getNumSuccessorsV() const;
2325 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2329 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2332 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2334 //===----------------------------------------------------------------------===//
2336 //===----------------------------------------------------------------------===//
2338 //===---------------------------------------------------------------------------
2339 /// BranchInst - Conditional or Unconditional Branch instruction.
2341 class BranchInst : public TerminatorInst {
2342 /// Ops list - Branches are strange. The operands are ordered:
2343 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2344 /// they don't have to check for cond/uncond branchness. These are mostly
2345 /// accessed relative from op_end().
2346 BranchInst(const BranchInst &BI);
2348 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2349 // BranchInst(BB *B) - 'br B'
2350 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2351 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2352 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2353 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2354 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2355 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2356 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2357 Instruction *InsertBefore = 0);
2358 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2359 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2360 BasicBlock *InsertAtEnd);
2362 virtual BranchInst *clone_impl() const;
2364 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2365 return new(1) BranchInst(IfTrue, InsertBefore);
2367 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2368 Value *Cond, Instruction *InsertBefore = 0) {
2369 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2371 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2372 return new(1) BranchInst(IfTrue, InsertAtEnd);
2374 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2375 Value *Cond, BasicBlock *InsertAtEnd) {
2376 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2379 /// Transparently provide more efficient getOperand methods.
2380 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2382 bool isUnconditional() const { return getNumOperands() == 1; }
2383 bool isConditional() const { return getNumOperands() == 3; }
2385 Value *getCondition() const {
2386 assert(isConditional() && "Cannot get condition of an uncond branch!");
2390 void setCondition(Value *V) {
2391 assert(isConditional() && "Cannot set condition of unconditional branch!");
2395 unsigned getNumSuccessors() const { return 1+isConditional(); }
2397 BasicBlock *getSuccessor(unsigned i) const {
2398 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2399 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2402 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2403 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2404 *(&Op<-1>() - idx) = (Value*)NewSucc;
2407 /// \brief Swap the successors of this branch instruction.
2409 /// Swaps the successors of the branch instruction. This also swaps any
2410 /// branch weight metadata associated with the instruction so that it
2411 /// continues to map correctly to each operand.
2412 void swapSuccessors();
2414 // Methods for support type inquiry through isa, cast, and dyn_cast:
2415 static inline bool classof(const BranchInst *) { return true; }
2416 static inline bool classof(const Instruction *I) {
2417 return (I->getOpcode() == Instruction::Br);
2419 static inline bool classof(const Value *V) {
2420 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2423 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2424 virtual unsigned getNumSuccessorsV() const;
2425 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2429 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2432 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2434 //===----------------------------------------------------------------------===//
2436 //===----------------------------------------------------------------------===//
2438 //===---------------------------------------------------------------------------
2439 /// SwitchInst - Multiway switch
2441 class SwitchInst : public TerminatorInst {
2442 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2443 unsigned ReservedSpace;
2444 // Operand[0] = Value to switch on
2445 // Operand[1] = Default basic block destination
2446 // Operand[2n ] = Value to match
2447 // Operand[2n+1] = BasicBlock to go to on match
2448 SwitchInst(const SwitchInst &SI);
2449 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2450 void growOperands();
2451 // allocate space for exactly zero operands
2452 void *operator new(size_t s) {
2453 return User::operator new(s, 0);
2455 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2456 /// switch on and a default destination. The number of additional cases can
2457 /// be specified here to make memory allocation more efficient. This
2458 /// constructor can also autoinsert before another instruction.
2459 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2460 Instruction *InsertBefore);
2462 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2463 /// switch on and a default destination. The number of additional cases can
2464 /// be specified here to make memory allocation more efficient. This
2465 /// constructor also autoinserts at the end of the specified BasicBlock.
2466 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2467 BasicBlock *InsertAtEnd);
2469 virtual SwitchInst *clone_impl() const;
2472 enum { ErrorIndex = UINT_MAX };
2474 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2475 unsigned NumCases, Instruction *InsertBefore = 0) {
2476 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2478 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2479 unsigned NumCases, BasicBlock *InsertAtEnd) {
2480 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2484 /// Provide fast operand accessors
2485 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2487 // Accessor Methods for Switch stmt
2488 Value *getCondition() const { return getOperand(0); }
2489 void setCondition(Value *V) { setOperand(0, V); }
2491 BasicBlock *getDefaultDest() const {
2492 return cast<BasicBlock>(getOperand(1));
2495 void setDefaultDest(BasicBlock *DefaultCase) {
2496 setOperand(1, reinterpret_cast<Value*>(DefaultCase));
2499 /// getNumCases - return the number of 'cases' in this switch instruction,
2500 /// except the default case
2501 unsigned getNumCases() const {
2502 return getNumOperands()/2 - 1;
2505 /// getCaseValue - Return the specified case value. Note that case #0, means
2506 /// first case, not a default case.
2507 ConstantInt *getCaseValue(unsigned i) {
2508 assert(i < getNumCases() && "Illegal case value to get!");
2509 return reinterpret_cast<ConstantInt*>(getOperand(2 + i*2));
2512 /// getCaseValue - Return the specified case value. Note that case #0, means
2513 /// first case, not a default case.
2514 const ConstantInt *getCaseValue(unsigned i) const {
2515 assert(i < getNumCases() && "Illegal case value to get!");
2516 return reinterpret_cast<const ConstantInt*>(getOperand(2 + i*2));
2519 // setSuccessorValue - Updates the value associated with the specified
2521 void setCaseValue(unsigned i, ConstantInt *CaseValue) {
2522 assert(i < getNumCases() && "Case index # out of range!");
2523 setOperand(2 + i*2, reinterpret_cast<Value*>(CaseValue));
2526 /// findCaseValue - Search all of the case values for the specified constant.
2527 /// If it is explicitly handled, return the case number of it, otherwise
2528 /// return ErrorIndex to indicate that it is handled by the default handler.
2529 unsigned findCaseValue(const ConstantInt *C) const {
2530 for (unsigned i = 0, e = getNumCases(); i != e; ++i)
2531 if (getCaseValue(i) == C)
2536 /// resolveSuccessorIndex - Converts case index to index of its successor
2537 /// index in TerminatorInst successors collection.
2538 /// If CaseIndex == ErrorIndex, "default" successor will returned then.
2539 unsigned resolveSuccessorIndex(unsigned CaseIndex) const {
2540 assert((CaseIndex == ErrorIndex || CaseIndex < getNumCases()) &&
2541 "Case index # out of range!");
2542 return CaseIndex != ErrorIndex ? CaseIndex + 1 : 0;
2545 /// resolveCaseIndex - Converts index of successor in TerminatorInst
2546 /// collection to index of case that corresponds to this successor.
2547 unsigned resolveCaseIndex(unsigned SuccessorIndex) const {
2548 assert(SuccessorIndex < getNumSuccessors() &&
2549 "Successor index # out of range!");
2550 return SuccessorIndex != 0 ? SuccessorIndex - 1 : ErrorIndex;
2553 /// findCaseDest - Finds the unique case value for a given successor. Returns
2554 /// null if the successor is not found, not unique, or is the default case.
2555 ConstantInt *findCaseDest(BasicBlock *BB) {
2556 if (BB == getDefaultDest()) return NULL;
2558 ConstantInt *CI = NULL;
2559 for (unsigned i = 0, e = getNumCases(); i != e; ++i) {
2560 if (getSuccessor(i + 1) == BB) {
2561 if (CI) return NULL; // Multiple cases lead to BB.
2562 else CI = getCaseValue(i);
2568 /// addCase - Add an entry to the switch instruction...
2570 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2572 /// removeCase - This method removes the specified case and its successor
2573 /// from the switch instruction. Note that this operation may reorder the
2574 /// remaining cases at index idx and above.
2576 void removeCase(unsigned idx);
2578 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2579 BasicBlock *getSuccessor(unsigned idx) const {
2580 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2581 return cast<BasicBlock>(getOperand(idx*2+1));
2583 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2584 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2585 setOperand(idx*2+1, (Value*)NewSucc);
2588 /// Resolves successor for idx-th case.
2589 /// Use getCaseSuccessor instead of TerminatorInst::getSuccessor,
2590 /// since internal SwitchInst organization of operands/successors is
2591 /// hidden and may be changed in any moment.
2592 BasicBlock *getCaseSuccessor(unsigned idx) const {
2593 return getSuccessor(resolveSuccessorIndex(idx));
2596 /// Set new successor for idx-th case.
2597 /// Use setCaseSuccessor instead of TerminatorInst::setSuccessor,
2598 /// since internal SwitchInst organization of operands/successors is
2599 /// hidden and may be changed in any moment.
2600 void setCaseSuccessor(unsigned idx, BasicBlock *NewSucc) {
2601 setSuccessor(resolveSuccessorIndex(idx), NewSucc);
2604 // getSuccessorValue - Return the value associated with the specified
2606 ConstantInt *getSuccessorValue(unsigned idx) const {
2607 assert(idx < getNumSuccessors() && "Successor # out of range!");
2608 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2611 // setSuccessorValue - Updates the value associated with the specified
2613 void setSuccessorValue(unsigned idx, ConstantInt* SuccessorValue) {
2614 assert(idx < getNumSuccessors() && "Successor # out of range!");
2615 setOperand(idx*2, reinterpret_cast<Value*>(SuccessorValue));
2618 // Methods for support type inquiry through isa, cast, and dyn_cast:
2619 static inline bool classof(const SwitchInst *) { return true; }
2620 static inline bool classof(const Instruction *I) {
2621 return I->getOpcode() == Instruction::Switch;
2623 static inline bool classof(const Value *V) {
2624 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2627 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2628 virtual unsigned getNumSuccessorsV() const;
2629 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2633 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2636 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2639 //===----------------------------------------------------------------------===//
2640 // IndirectBrInst Class
2641 //===----------------------------------------------------------------------===//
2643 //===---------------------------------------------------------------------------
2644 /// IndirectBrInst - Indirect Branch Instruction.
2646 class IndirectBrInst : public TerminatorInst {
2647 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2648 unsigned ReservedSpace;
2649 // Operand[0] = Value to switch on
2650 // Operand[1] = Default basic block destination
2651 // Operand[2n ] = Value to match
2652 // Operand[2n+1] = BasicBlock to go to on match
2653 IndirectBrInst(const IndirectBrInst &IBI);
2654 void init(Value *Address, unsigned NumDests);
2655 void growOperands();
2656 // allocate space for exactly zero operands
2657 void *operator new(size_t s) {
2658 return User::operator new(s, 0);
2660 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2661 /// Address to jump to. The number of expected destinations can be specified
2662 /// here to make memory allocation more efficient. This constructor can also
2663 /// autoinsert before another instruction.
2664 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2666 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2667 /// Address to jump to. The number of expected destinations can be specified
2668 /// here to make memory allocation more efficient. This constructor also
2669 /// autoinserts at the end of the specified BasicBlock.
2670 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2672 virtual IndirectBrInst *clone_impl() const;
2674 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2675 Instruction *InsertBefore = 0) {
2676 return new IndirectBrInst(Address, NumDests, InsertBefore);
2678 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2679 BasicBlock *InsertAtEnd) {
2680 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2684 /// Provide fast operand accessors.
2685 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2687 // Accessor Methods for IndirectBrInst instruction.
2688 Value *getAddress() { return getOperand(0); }
2689 const Value *getAddress() const { return getOperand(0); }
2690 void setAddress(Value *V) { setOperand(0, V); }
2693 /// getNumDestinations - return the number of possible destinations in this
2694 /// indirectbr instruction.
2695 unsigned getNumDestinations() const { return getNumOperands()-1; }
2697 /// getDestination - Return the specified destination.
2698 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2699 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2701 /// addDestination - Add a destination.
2703 void addDestination(BasicBlock *Dest);
2705 /// removeDestination - This method removes the specified successor from the
2706 /// indirectbr instruction.
2707 void removeDestination(unsigned i);
2709 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2710 BasicBlock *getSuccessor(unsigned i) const {
2711 return cast<BasicBlock>(getOperand(i+1));
2713 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2714 setOperand(i+1, (Value*)NewSucc);
2717 // Methods for support type inquiry through isa, cast, and dyn_cast:
2718 static inline bool classof(const IndirectBrInst *) { return true; }
2719 static inline bool classof(const Instruction *I) {
2720 return I->getOpcode() == Instruction::IndirectBr;
2722 static inline bool classof(const Value *V) {
2723 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2726 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2727 virtual unsigned getNumSuccessorsV() const;
2728 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2732 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2735 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2738 //===----------------------------------------------------------------------===//
2740 //===----------------------------------------------------------------------===//
2742 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2743 /// calling convention of the call.
2745 class InvokeInst : public TerminatorInst {
2746 AttrListPtr AttributeList;
2747 InvokeInst(const InvokeInst &BI);
2748 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2749 ArrayRef<Value *> Args, const Twine &NameStr);
2751 /// Construct an InvokeInst given a range of arguments.
2753 /// @brief Construct an InvokeInst from a range of arguments
2754 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2755 ArrayRef<Value *> Args, unsigned Values,
2756 const Twine &NameStr, Instruction *InsertBefore);
2758 /// Construct an InvokeInst given a range of arguments.
2760 /// @brief Construct an InvokeInst from a range of arguments
2761 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2762 ArrayRef<Value *> Args, unsigned Values,
2763 const Twine &NameStr, BasicBlock *InsertAtEnd);
2765 virtual InvokeInst *clone_impl() const;
2767 static InvokeInst *Create(Value *Func,
2768 BasicBlock *IfNormal, BasicBlock *IfException,
2769 ArrayRef<Value *> Args, const Twine &NameStr = "",
2770 Instruction *InsertBefore = 0) {
2771 unsigned Values = unsigned(Args.size()) + 3;
2772 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2773 Values, NameStr, InsertBefore);
2775 static InvokeInst *Create(Value *Func,
2776 BasicBlock *IfNormal, BasicBlock *IfException,
2777 ArrayRef<Value *> Args, const Twine &NameStr,
2778 BasicBlock *InsertAtEnd) {
2779 unsigned Values = unsigned(Args.size()) + 3;
2780 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2781 Values, NameStr, InsertAtEnd);
2784 /// Provide fast operand accessors
2785 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2787 /// getNumArgOperands - Return the number of invoke arguments.
2789 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2791 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2793 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2794 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2796 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2798 CallingConv::ID getCallingConv() const {
2799 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2801 void setCallingConv(CallingConv::ID CC) {
2802 setInstructionSubclassData(static_cast<unsigned>(CC));
2805 /// getAttributes - Return the parameter attributes for this invoke.
2807 const AttrListPtr &getAttributes() const { return AttributeList; }
2809 /// setAttributes - Set the parameter attributes for this invoke.
2811 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2813 /// addAttribute - adds the attribute to the list of attributes.
2814 void addAttribute(unsigned i, Attributes attr);
2816 /// removeAttribute - removes the attribute from the list of attributes.
2817 void removeAttribute(unsigned i, Attributes attr);
2819 /// @brief Determine whether the call or the callee has the given attribute.
2820 bool paramHasAttr(unsigned i, Attributes attr) const;
2822 /// @brief Extract the alignment for a call or parameter (0=unknown).
2823 unsigned getParamAlignment(unsigned i) const {
2824 return AttributeList.getParamAlignment(i);
2827 /// @brief Return true if the call should not be inlined.
2828 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2829 void setIsNoInline(bool Value = true) {
2830 if (Value) addAttribute(~0, Attribute::NoInline);
2831 else removeAttribute(~0, Attribute::NoInline);
2834 /// @brief Determine if the call does not access memory.
2835 bool doesNotAccessMemory() const {
2836 return paramHasAttr(~0, Attribute::ReadNone);
2838 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2839 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2840 else removeAttribute(~0, Attribute::ReadNone);
2843 /// @brief Determine if the call does not access or only reads memory.
2844 bool onlyReadsMemory() const {
2845 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2847 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2848 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2849 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2852 /// @brief Determine if the call cannot return.
2853 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
2854 void setDoesNotReturn(bool DoesNotReturn = true) {
2855 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2856 else removeAttribute(~0, Attribute::NoReturn);
2859 /// @brief Determine if the call cannot unwind.
2860 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
2861 void setDoesNotThrow(bool DoesNotThrow = true) {
2862 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2863 else removeAttribute(~0, Attribute::NoUnwind);
2866 /// @brief Determine if the call returns a structure through first
2867 /// pointer argument.
2868 bool hasStructRetAttr() const {
2869 // Be friendly and also check the callee.
2870 return paramHasAttr(1, Attribute::StructRet);
2873 /// @brief Determine if any call argument is an aggregate passed by value.
2874 bool hasByValArgument() const {
2875 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2878 /// getCalledFunction - Return the function called, or null if this is an
2879 /// indirect function invocation.
2881 Function *getCalledFunction() const {
2882 return dyn_cast<Function>(Op<-3>());
2885 /// getCalledValue - Get a pointer to the function that is invoked by this
2887 const Value *getCalledValue() const { return Op<-3>(); }
2888 Value *getCalledValue() { return Op<-3>(); }
2890 /// setCalledFunction - Set the function called.
2891 void setCalledFunction(Value* Fn) {
2895 // get*Dest - Return the destination basic blocks...
2896 BasicBlock *getNormalDest() const {
2897 return cast<BasicBlock>(Op<-2>());
2899 BasicBlock *getUnwindDest() const {
2900 return cast<BasicBlock>(Op<-1>());
2902 void setNormalDest(BasicBlock *B) {
2903 Op<-2>() = reinterpret_cast<Value*>(B);
2905 void setUnwindDest(BasicBlock *B) {
2906 Op<-1>() = reinterpret_cast<Value*>(B);
2909 /// getLandingPadInst - Get the landingpad instruction from the landing pad
2910 /// block (the unwind destination).
2911 LandingPadInst *getLandingPadInst() const;
2913 BasicBlock *getSuccessor(unsigned i) const {
2914 assert(i < 2 && "Successor # out of range for invoke!");
2915 return i == 0 ? getNormalDest() : getUnwindDest();
2918 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2919 assert(idx < 2 && "Successor # out of range for invoke!");
2920 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2923 unsigned getNumSuccessors() const { return 2; }
2925 // Methods for support type inquiry through isa, cast, and dyn_cast:
2926 static inline bool classof(const InvokeInst *) { return true; }
2927 static inline bool classof(const Instruction *I) {
2928 return (I->getOpcode() == Instruction::Invoke);
2930 static inline bool classof(const Value *V) {
2931 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2935 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2936 virtual unsigned getNumSuccessorsV() const;
2937 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2939 // Shadow Instruction::setInstructionSubclassData with a private forwarding
2940 // method so that subclasses cannot accidentally use it.
2941 void setInstructionSubclassData(unsigned short D) {
2942 Instruction::setInstructionSubclassData(D);
2947 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
2950 InvokeInst::InvokeInst(Value *Func,
2951 BasicBlock *IfNormal, BasicBlock *IfException,
2952 ArrayRef<Value *> Args, unsigned Values,
2953 const Twine &NameStr, Instruction *InsertBefore)
2954 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2955 ->getElementType())->getReturnType(),
2956 Instruction::Invoke,
2957 OperandTraits<InvokeInst>::op_end(this) - Values,
2958 Values, InsertBefore) {
2959 init(Func, IfNormal, IfException, Args, NameStr);
2961 InvokeInst::InvokeInst(Value *Func,
2962 BasicBlock *IfNormal, BasicBlock *IfException,
2963 ArrayRef<Value *> Args, unsigned Values,
2964 const Twine &NameStr, BasicBlock *InsertAtEnd)
2965 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2966 ->getElementType())->getReturnType(),
2967 Instruction::Invoke,
2968 OperandTraits<InvokeInst>::op_end(this) - Values,
2969 Values, InsertAtEnd) {
2970 init(Func, IfNormal, IfException, Args, NameStr);
2973 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2975 //===----------------------------------------------------------------------===//
2977 //===----------------------------------------------------------------------===//
2979 //===---------------------------------------------------------------------------
2980 /// ResumeInst - Resume the propagation of an exception.
2982 class ResumeInst : public TerminatorInst {
2983 ResumeInst(const ResumeInst &RI);
2985 explicit ResumeInst(Value *Exn, Instruction *InsertBefore=0);
2986 ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
2988 virtual ResumeInst *clone_impl() const;
2990 static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = 0) {
2991 return new(1) ResumeInst(Exn, InsertBefore);
2993 static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
2994 return new(1) ResumeInst(Exn, InsertAtEnd);
2997 /// Provide fast operand accessors
2998 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3000 /// Convenience accessor.
3001 Value *getValue() const { return Op<0>(); }
3003 unsigned getNumSuccessors() const { return 0; }
3005 // Methods for support type inquiry through isa, cast, and dyn_cast:
3006 static inline bool classof(const ResumeInst *) { return true; }
3007 static inline bool classof(const Instruction *I) {
3008 return I->getOpcode() == Instruction::Resume;
3010 static inline bool classof(const Value *V) {
3011 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3014 virtual BasicBlock *getSuccessorV(unsigned idx) const;
3015 virtual unsigned getNumSuccessorsV() const;
3016 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3020 struct OperandTraits<ResumeInst> :
3021 public FixedNumOperandTraits<ResumeInst, 1> {
3024 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
3026 //===----------------------------------------------------------------------===//
3027 // UnreachableInst Class
3028 //===----------------------------------------------------------------------===//
3030 //===---------------------------------------------------------------------------
3031 /// UnreachableInst - This function has undefined behavior. In particular, the
3032 /// presence of this instruction indicates some higher level knowledge that the
3033 /// end of the block cannot be reached.
3035 class UnreachableInst : public TerminatorInst {
3036 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
3038 virtual UnreachableInst *clone_impl() const;
3041 // allocate space for exactly zero operands
3042 void *operator new(size_t s) {
3043 return User::operator new(s, 0);
3045 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
3046 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
3048 unsigned getNumSuccessors() const { return 0; }
3050 // Methods for support type inquiry through isa, cast, and dyn_cast:
3051 static inline bool classof(const UnreachableInst *) { return true; }
3052 static inline bool classof(const Instruction *I) {
3053 return I->getOpcode() == Instruction::Unreachable;
3055 static inline bool classof(const Value *V) {
3056 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3059 virtual BasicBlock *getSuccessorV(unsigned idx) const;
3060 virtual unsigned getNumSuccessorsV() const;
3061 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3064 //===----------------------------------------------------------------------===//
3066 //===----------------------------------------------------------------------===//
3068 /// @brief This class represents a truncation of integer types.
3069 class TruncInst : public CastInst {
3071 /// @brief Clone an identical TruncInst
3072 virtual TruncInst *clone_impl() const;
3075 /// @brief Constructor with insert-before-instruction semantics
3077 Value *S, ///< The value to be truncated
3078 Type *Ty, ///< The (smaller) type to truncate to
3079 const Twine &NameStr = "", ///< A name for the new instruction
3080 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3083 /// @brief Constructor with insert-at-end-of-block semantics
3085 Value *S, ///< The value to be truncated
3086 Type *Ty, ///< The (smaller) type to truncate to
3087 const Twine &NameStr, ///< A name for the new instruction
3088 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3091 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3092 static inline bool classof(const TruncInst *) { return true; }
3093 static inline bool classof(const Instruction *I) {
3094 return I->getOpcode() == Trunc;
3096 static inline bool classof(const Value *V) {
3097 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3101 //===----------------------------------------------------------------------===//
3103 //===----------------------------------------------------------------------===//
3105 /// @brief This class represents zero extension of integer types.
3106 class ZExtInst : public CastInst {
3108 /// @brief Clone an identical ZExtInst
3109 virtual ZExtInst *clone_impl() const;
3112 /// @brief Constructor with insert-before-instruction semantics
3114 Value *S, ///< The value to be zero extended
3115 Type *Ty, ///< The type to zero extend to
3116 const Twine &NameStr = "", ///< A name for the new instruction
3117 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3120 /// @brief Constructor with insert-at-end semantics.
3122 Value *S, ///< The value to be zero extended
3123 Type *Ty, ///< The type to zero extend to
3124 const Twine &NameStr, ///< A name for the new instruction
3125 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3128 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3129 static inline bool classof(const ZExtInst *) { return true; }
3130 static inline bool classof(const Instruction *I) {
3131 return I->getOpcode() == ZExt;
3133 static inline bool classof(const Value *V) {
3134 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3138 //===----------------------------------------------------------------------===//
3140 //===----------------------------------------------------------------------===//
3142 /// @brief This class represents a sign extension of integer types.
3143 class SExtInst : public CastInst {
3145 /// @brief Clone an identical SExtInst
3146 virtual SExtInst *clone_impl() const;
3149 /// @brief Constructor with insert-before-instruction semantics
3151 Value *S, ///< The value to be sign extended
3152 Type *Ty, ///< The type to sign extend to
3153 const Twine &NameStr = "", ///< A name for the new instruction
3154 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3157 /// @brief Constructor with insert-at-end-of-block semantics
3159 Value *S, ///< The value to be sign extended
3160 Type *Ty, ///< The type to sign extend to
3161 const Twine &NameStr, ///< A name for the new instruction
3162 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3165 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3166 static inline bool classof(const SExtInst *) { return true; }
3167 static inline bool classof(const Instruction *I) {
3168 return I->getOpcode() == SExt;
3170 static inline bool classof(const Value *V) {
3171 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3175 //===----------------------------------------------------------------------===//
3176 // FPTruncInst Class
3177 //===----------------------------------------------------------------------===//
3179 /// @brief This class represents a truncation of floating point types.
3180 class FPTruncInst : public CastInst {
3182 /// @brief Clone an identical FPTruncInst
3183 virtual FPTruncInst *clone_impl() const;
3186 /// @brief Constructor with insert-before-instruction semantics
3188 Value *S, ///< The value to be truncated
3189 Type *Ty, ///< The type to truncate to
3190 const Twine &NameStr = "", ///< A name for the new instruction
3191 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3194 /// @brief Constructor with insert-before-instruction semantics
3196 Value *S, ///< The value to be truncated
3197 Type *Ty, ///< The type to truncate to
3198 const Twine &NameStr, ///< A name for the new instruction
3199 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3202 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3203 static inline bool classof(const FPTruncInst *) { return true; }
3204 static inline bool classof(const Instruction *I) {
3205 return I->getOpcode() == FPTrunc;
3207 static inline bool classof(const Value *V) {
3208 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3212 //===----------------------------------------------------------------------===//
3214 //===----------------------------------------------------------------------===//
3216 /// @brief This class represents an extension of floating point types.
3217 class FPExtInst : public CastInst {
3219 /// @brief Clone an identical FPExtInst
3220 virtual FPExtInst *clone_impl() const;
3223 /// @brief Constructor with insert-before-instruction semantics
3225 Value *S, ///< The value to be extended
3226 Type *Ty, ///< The type to extend to
3227 const Twine &NameStr = "", ///< A name for the new instruction
3228 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3231 /// @brief Constructor with insert-at-end-of-block semantics
3233 Value *S, ///< The value to be extended
3234 Type *Ty, ///< The type to extend to
3235 const Twine &NameStr, ///< A name for the new instruction
3236 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3239 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3240 static inline bool classof(const FPExtInst *) { return true; }
3241 static inline bool classof(const Instruction *I) {
3242 return I->getOpcode() == FPExt;
3244 static inline bool classof(const Value *V) {
3245 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3249 //===----------------------------------------------------------------------===//
3251 //===----------------------------------------------------------------------===//
3253 /// @brief This class represents a cast unsigned integer to floating point.
3254 class UIToFPInst : public CastInst {
3256 /// @brief Clone an identical UIToFPInst
3257 virtual UIToFPInst *clone_impl() const;
3260 /// @brief Constructor with insert-before-instruction semantics
3262 Value *S, ///< The value to be converted
3263 Type *Ty, ///< The type to convert to
3264 const Twine &NameStr = "", ///< A name for the new instruction
3265 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3268 /// @brief Constructor with insert-at-end-of-block semantics
3270 Value *S, ///< The value to be converted
3271 Type *Ty, ///< The type to convert to
3272 const Twine &NameStr, ///< A name for the new instruction
3273 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3276 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3277 static inline bool classof(const UIToFPInst *) { return true; }
3278 static inline bool classof(const Instruction *I) {
3279 return I->getOpcode() == UIToFP;
3281 static inline bool classof(const Value *V) {
3282 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3286 //===----------------------------------------------------------------------===//
3288 //===----------------------------------------------------------------------===//
3290 /// @brief This class represents a cast from signed integer to floating point.
3291 class SIToFPInst : public CastInst {
3293 /// @brief Clone an identical SIToFPInst
3294 virtual SIToFPInst *clone_impl() const;
3297 /// @brief Constructor with insert-before-instruction semantics
3299 Value *S, ///< The value to be converted
3300 Type *Ty, ///< The type to convert to
3301 const Twine &NameStr = "", ///< A name for the new instruction
3302 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3305 /// @brief Constructor with insert-at-end-of-block semantics
3307 Value *S, ///< The value to be converted
3308 Type *Ty, ///< The type to convert to
3309 const Twine &NameStr, ///< A name for the new instruction
3310 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3313 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3314 static inline bool classof(const SIToFPInst *) { return true; }
3315 static inline bool classof(const Instruction *I) {
3316 return I->getOpcode() == SIToFP;
3318 static inline bool classof(const Value *V) {
3319 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3323 //===----------------------------------------------------------------------===//
3325 //===----------------------------------------------------------------------===//
3327 /// @brief This class represents a cast from floating point to unsigned integer
3328 class FPToUIInst : public CastInst {
3330 /// @brief Clone an identical FPToUIInst
3331 virtual FPToUIInst *clone_impl() const;
3334 /// @brief Constructor with insert-before-instruction semantics
3336 Value *S, ///< The value to be converted
3337 Type *Ty, ///< The type to convert to
3338 const Twine &NameStr = "", ///< A name for the new instruction
3339 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3342 /// @brief Constructor with insert-at-end-of-block semantics
3344 Value *S, ///< The value to be converted
3345 Type *Ty, ///< The type to convert to
3346 const Twine &NameStr, ///< A name for the new instruction
3347 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3350 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3351 static inline bool classof(const FPToUIInst *) { return true; }
3352 static inline bool classof(const Instruction *I) {
3353 return I->getOpcode() == FPToUI;
3355 static inline bool classof(const Value *V) {
3356 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3360 //===----------------------------------------------------------------------===//
3362 //===----------------------------------------------------------------------===//
3364 /// @brief This class represents a cast from floating point to signed integer.
3365 class FPToSIInst : public CastInst {
3367 /// @brief Clone an identical FPToSIInst
3368 virtual FPToSIInst *clone_impl() const;
3371 /// @brief Constructor with insert-before-instruction semantics
3373 Value *S, ///< The value to be converted
3374 Type *Ty, ///< The type to convert to
3375 const Twine &NameStr = "", ///< A name for the new instruction
3376 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3379 /// @brief Constructor with insert-at-end-of-block semantics
3381 Value *S, ///< The value to be converted
3382 Type *Ty, ///< The type to convert to
3383 const Twine &NameStr, ///< A name for the new instruction
3384 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3387 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3388 static inline bool classof(const FPToSIInst *) { return true; }
3389 static inline bool classof(const Instruction *I) {
3390 return I->getOpcode() == FPToSI;
3392 static inline bool classof(const Value *V) {
3393 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3397 //===----------------------------------------------------------------------===//
3398 // IntToPtrInst Class
3399 //===----------------------------------------------------------------------===//
3401 /// @brief This class represents a cast from an integer to a pointer.
3402 class IntToPtrInst : public CastInst {
3404 /// @brief Constructor with insert-before-instruction semantics
3406 Value *S, ///< The value to be converted
3407 Type *Ty, ///< The type to convert to
3408 const Twine &NameStr = "", ///< A name for the new instruction
3409 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3412 /// @brief Constructor with insert-at-end-of-block semantics
3414 Value *S, ///< The value to be converted
3415 Type *Ty, ///< The type to convert to
3416 const Twine &NameStr, ///< A name for the new instruction
3417 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3420 /// @brief Clone an identical IntToPtrInst
3421 virtual IntToPtrInst *clone_impl() const;
3423 // Methods for support type inquiry through isa, cast, and dyn_cast:
3424 static inline bool classof(const IntToPtrInst *) { return true; }
3425 static inline bool classof(const Instruction *I) {
3426 return I->getOpcode() == IntToPtr;
3428 static inline bool classof(const Value *V) {
3429 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3433 //===----------------------------------------------------------------------===//
3434 // PtrToIntInst Class
3435 //===----------------------------------------------------------------------===//
3437 /// @brief This class represents a cast from a pointer to an integer
3438 class PtrToIntInst : public CastInst {
3440 /// @brief Clone an identical PtrToIntInst
3441 virtual PtrToIntInst *clone_impl() const;
3444 /// @brief Constructor with insert-before-instruction semantics
3446 Value *S, ///< The value to be converted
3447 Type *Ty, ///< The type to convert to
3448 const Twine &NameStr = "", ///< A name for the new instruction
3449 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3452 /// @brief Constructor with insert-at-end-of-block semantics
3454 Value *S, ///< The value to be converted
3455 Type *Ty, ///< The type to convert to
3456 const Twine &NameStr, ///< A name for the new instruction
3457 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3460 // Methods for support type inquiry through isa, cast, and dyn_cast:
3461 static inline bool classof(const PtrToIntInst *) { return true; }
3462 static inline bool classof(const Instruction *I) {
3463 return I->getOpcode() == PtrToInt;
3465 static inline bool classof(const Value *V) {
3466 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3470 //===----------------------------------------------------------------------===//
3471 // BitCastInst Class
3472 //===----------------------------------------------------------------------===//
3474 /// @brief This class represents a no-op cast from one type to another.
3475 class BitCastInst : public CastInst {
3477 /// @brief Clone an identical BitCastInst
3478 virtual BitCastInst *clone_impl() const;
3481 /// @brief Constructor with insert-before-instruction semantics
3483 Value *S, ///< The value to be casted
3484 Type *Ty, ///< The type to casted to
3485 const Twine &NameStr = "", ///< A name for the new instruction
3486 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3489 /// @brief Constructor with insert-at-end-of-block semantics
3491 Value *S, ///< The value to be casted
3492 Type *Ty, ///< The type to casted to
3493 const Twine &NameStr, ///< A name for the new instruction
3494 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3497 // Methods for support type inquiry through isa, cast, and dyn_cast:
3498 static inline bool classof(const BitCastInst *) { return true; }
3499 static inline bool classof(const Instruction *I) {
3500 return I->getOpcode() == BitCast;
3502 static inline bool classof(const Value *V) {
3503 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3507 } // End llvm namespace