1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the class definitions of all of the subclasses of the
11 // Instruction class. This is meant to be an easy way to get access to all
12 // instruction subclasses.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_INSTRUCTIONS_H
17 #define LLVM_INSTRUCTIONS_H
19 #include "llvm/InstrTypes.h"
20 #include "llvm/DerivedTypes.h"
21 #include "llvm/Attributes.h"
22 #include "llvm/CallingConv.h"
23 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/Support/ErrorHandling.h"
39 // Consume = 3, // Not specified yet.
43 SequentiallyConsistent = 7
46 enum SynchronizationScope {
51 //===----------------------------------------------------------------------===//
53 //===----------------------------------------------------------------------===//
55 /// AllocaInst - an instruction to allocate memory on the stack
57 class AllocaInst : public UnaryInstruction {
59 virtual AllocaInst *clone_impl() const;
61 explicit AllocaInst(Type *Ty, Value *ArraySize = 0,
62 const Twine &Name = "", Instruction *InsertBefore = 0);
63 AllocaInst(Type *Ty, Value *ArraySize,
64 const Twine &Name, BasicBlock *InsertAtEnd);
66 AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
67 AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
69 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
70 const Twine &Name = "", Instruction *InsertBefore = 0);
71 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
72 const Twine &Name, BasicBlock *InsertAtEnd);
74 // Out of line virtual method, so the vtable, etc. has a home.
75 virtual ~AllocaInst();
77 /// isArrayAllocation - Return true if there is an allocation size parameter
78 /// to the allocation instruction that is not 1.
80 bool isArrayAllocation() const;
82 /// getArraySize - Get the number of elements allocated. For a simple
83 /// allocation of a single element, this will return a constant 1 value.
85 const Value *getArraySize() const { return getOperand(0); }
86 Value *getArraySize() { return getOperand(0); }
88 /// getType - Overload to return most specific pointer type
90 PointerType *getType() const {
91 return reinterpret_cast<PointerType*>(Instruction::getType());
94 /// getAllocatedType - Return the type that is being allocated by the
97 Type *getAllocatedType() const;
99 /// getAlignment - Return the alignment of the memory that is being allocated
100 /// by the instruction.
102 unsigned getAlignment() const {
103 return (1u << getSubclassDataFromInstruction()) >> 1;
105 void setAlignment(unsigned Align);
107 /// isStaticAlloca - Return true if this alloca is in the entry block of the
108 /// function and is a constant size. If so, the code generator will fold it
109 /// into the prolog/epilog code, so it is basically free.
110 bool isStaticAlloca() const;
112 // Methods for support type inquiry through isa, cast, and dyn_cast:
113 static inline bool classof(const AllocaInst *) { return true; }
114 static inline bool classof(const Instruction *I) {
115 return (I->getOpcode() == Instruction::Alloca);
117 static inline bool classof(const Value *V) {
118 return isa<Instruction>(V) && classof(cast<Instruction>(V));
121 // Shadow Instruction::setInstructionSubclassData with a private forwarding
122 // method so that subclasses cannot accidentally use it.
123 void setInstructionSubclassData(unsigned short D) {
124 Instruction::setInstructionSubclassData(D);
129 //===----------------------------------------------------------------------===//
131 //===----------------------------------------------------------------------===//
133 /// LoadInst - an instruction for reading from memory. This uses the
134 /// SubclassData field in Value to store whether or not the load is volatile.
136 class LoadInst : public UnaryInstruction {
139 virtual LoadInst *clone_impl() const;
141 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
142 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
143 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
144 Instruction *InsertBefore = 0);
145 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
146 BasicBlock *InsertAtEnd);
147 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
148 unsigned Align, Instruction *InsertBefore = 0);
149 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
150 unsigned Align, BasicBlock *InsertAtEnd);
151 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
152 unsigned Align, AtomicOrdering Order,
153 SynchronizationScope SynchScope = CrossThread,
154 Instruction *InsertBefore = 0);
155 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
156 unsigned Align, AtomicOrdering Order,
157 SynchronizationScope SynchScope,
158 BasicBlock *InsertAtEnd);
160 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
161 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
162 explicit LoadInst(Value *Ptr, const char *NameStr = 0,
163 bool isVolatile = false, Instruction *InsertBefore = 0);
164 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
165 BasicBlock *InsertAtEnd);
167 /// isVolatile - Return true if this is a load from a volatile memory
170 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
172 /// setVolatile - Specify whether this is a volatile load or not.
174 void setVolatile(bool V) {
175 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
179 /// getAlignment - Return the alignment of the access that is being performed
181 unsigned getAlignment() const {
182 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
185 void setAlignment(unsigned Align);
187 /// Returns the ordering effect of this fence.
188 AtomicOrdering getOrdering() const {
189 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
192 /// Set the ordering constraint on this load. May not be Release or
194 void setOrdering(AtomicOrdering Ordering) {
195 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
199 SynchronizationScope getSynchScope() const {
200 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
203 /// Specify whether this load is ordered with respect to all
204 /// concurrently executing threads, or only with respect to signal handlers
205 /// executing in the same thread.
206 void setSynchScope(SynchronizationScope xthread) {
207 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
211 bool isAtomic() const { return getOrdering() != NotAtomic; }
212 void setAtomic(AtomicOrdering Ordering,
213 SynchronizationScope SynchScope = CrossThread) {
214 setOrdering(Ordering);
215 setSynchScope(SynchScope);
218 bool isSimple() const { return !isAtomic() && !isVolatile(); }
219 bool isUnordered() const {
220 return getOrdering() <= Unordered && !isVolatile();
223 Value *getPointerOperand() { return getOperand(0); }
224 const Value *getPointerOperand() const { return getOperand(0); }
225 static unsigned getPointerOperandIndex() { return 0U; }
227 unsigned getPointerAddressSpace() const {
228 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
232 // Methods for support type inquiry through isa, cast, and dyn_cast:
233 static inline bool classof(const LoadInst *) { return true; }
234 static inline bool classof(const Instruction *I) {
235 return I->getOpcode() == Instruction::Load;
237 static inline bool classof(const Value *V) {
238 return isa<Instruction>(V) && classof(cast<Instruction>(V));
241 // Shadow Instruction::setInstructionSubclassData with a private forwarding
242 // method so that subclasses cannot accidentally use it.
243 void setInstructionSubclassData(unsigned short D) {
244 Instruction::setInstructionSubclassData(D);
249 //===----------------------------------------------------------------------===//
251 //===----------------------------------------------------------------------===//
253 /// StoreInst - an instruction for storing to memory
255 class StoreInst : public Instruction {
256 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
259 virtual StoreInst *clone_impl() const;
261 // allocate space for exactly two operands
262 void *operator new(size_t s) {
263 return User::operator new(s, 2);
265 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
266 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
267 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
268 Instruction *InsertBefore = 0);
269 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
270 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
271 unsigned Align, Instruction *InsertBefore = 0);
272 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
273 unsigned Align, BasicBlock *InsertAtEnd);
274 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
275 unsigned Align, AtomicOrdering Order,
276 SynchronizationScope SynchScope = CrossThread,
277 Instruction *InsertBefore = 0);
278 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
279 unsigned Align, AtomicOrdering Order,
280 SynchronizationScope SynchScope,
281 BasicBlock *InsertAtEnd);
284 /// isVolatile - Return true if this is a store to a volatile memory
287 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
289 /// setVolatile - Specify whether this is a volatile store or not.
291 void setVolatile(bool V) {
292 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
296 /// Transparently provide more efficient getOperand methods.
297 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
299 /// getAlignment - Return the alignment of the access that is being performed
301 unsigned getAlignment() const {
302 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
305 void setAlignment(unsigned Align);
307 /// Returns the ordering effect of this store.
308 AtomicOrdering getOrdering() const {
309 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
312 /// Set the ordering constraint on this store. May not be Acquire or
314 void setOrdering(AtomicOrdering Ordering) {
315 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
319 SynchronizationScope getSynchScope() const {
320 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
323 /// Specify whether this store instruction is ordered with respect to all
324 /// concurrently executing threads, or only with respect to signal handlers
325 /// executing in the same thread.
326 void setSynchScope(SynchronizationScope xthread) {
327 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
331 bool isAtomic() const { return getOrdering() != NotAtomic; }
332 void setAtomic(AtomicOrdering Ordering,
333 SynchronizationScope SynchScope = CrossThread) {
334 setOrdering(Ordering);
335 setSynchScope(SynchScope);
338 bool isSimple() const { return !isAtomic() && !isVolatile(); }
339 bool isUnordered() const {
340 return getOrdering() <= Unordered && !isVolatile();
343 Value *getValueOperand() { return getOperand(0); }
344 const Value *getValueOperand() const { return getOperand(0); }
346 Value *getPointerOperand() { return getOperand(1); }
347 const Value *getPointerOperand() const { return getOperand(1); }
348 static unsigned getPointerOperandIndex() { return 1U; }
350 unsigned getPointerAddressSpace() const {
351 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
354 // Methods for support type inquiry through isa, cast, and dyn_cast:
355 static inline bool classof(const StoreInst *) { return true; }
356 static inline bool classof(const Instruction *I) {
357 return I->getOpcode() == Instruction::Store;
359 static inline bool classof(const Value *V) {
360 return isa<Instruction>(V) && classof(cast<Instruction>(V));
363 // Shadow Instruction::setInstructionSubclassData with a private forwarding
364 // method so that subclasses cannot accidentally use it.
365 void setInstructionSubclassData(unsigned short D) {
366 Instruction::setInstructionSubclassData(D);
371 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
374 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
376 //===----------------------------------------------------------------------===//
378 //===----------------------------------------------------------------------===//
380 /// FenceInst - an instruction for ordering other memory operations
382 class FenceInst : public Instruction {
383 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
384 void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
386 virtual FenceInst *clone_impl() const;
388 // allocate space for exactly zero operands
389 void *operator new(size_t s) {
390 return User::operator new(s, 0);
393 // Ordering may only be Acquire, Release, AcquireRelease, or
394 // SequentiallyConsistent.
395 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
396 SynchronizationScope SynchScope = CrossThread,
397 Instruction *InsertBefore = 0);
398 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
399 SynchronizationScope SynchScope,
400 BasicBlock *InsertAtEnd);
402 /// Returns the ordering effect of this fence.
403 AtomicOrdering getOrdering() const {
404 return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
407 /// Set the ordering constraint on this fence. May only be Acquire, Release,
408 /// AcquireRelease, or SequentiallyConsistent.
409 void setOrdering(AtomicOrdering Ordering) {
410 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
414 SynchronizationScope getSynchScope() const {
415 return SynchronizationScope(getSubclassDataFromInstruction() & 1);
418 /// Specify whether this fence orders other operations with respect to all
419 /// concurrently executing threads, or only with respect to signal handlers
420 /// executing in the same thread.
421 void setSynchScope(SynchronizationScope xthread) {
422 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
426 // Methods for support type inquiry through isa, cast, and dyn_cast:
427 static inline bool classof(const FenceInst *) { return true; }
428 static inline bool classof(const Instruction *I) {
429 return I->getOpcode() == Instruction::Fence;
431 static inline bool classof(const Value *V) {
432 return isa<Instruction>(V) && classof(cast<Instruction>(V));
435 // Shadow Instruction::setInstructionSubclassData with a private forwarding
436 // method so that subclasses cannot accidentally use it.
437 void setInstructionSubclassData(unsigned short D) {
438 Instruction::setInstructionSubclassData(D);
442 //===----------------------------------------------------------------------===//
443 // AtomicCmpXchgInst Class
444 //===----------------------------------------------------------------------===//
446 /// AtomicCmpXchgInst - an instruction that atomically checks whether a
447 /// specified value is in a memory location, and, if it is, stores a new value
448 /// there. Returns the value that was loaded.
450 class AtomicCmpXchgInst : public Instruction {
451 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
452 void Init(Value *Ptr, Value *Cmp, Value *NewVal,
453 AtomicOrdering Ordering, SynchronizationScope SynchScope);
455 virtual AtomicCmpXchgInst *clone_impl() const;
457 // allocate space for exactly three operands
458 void *operator new(size_t s) {
459 return User::operator new(s, 3);
461 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
462 AtomicOrdering Ordering, SynchronizationScope SynchScope,
463 Instruction *InsertBefore = 0);
464 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
465 AtomicOrdering Ordering, SynchronizationScope SynchScope,
466 BasicBlock *InsertAtEnd);
468 /// isVolatile - Return true if this is a cmpxchg from a volatile memory
471 bool isVolatile() const {
472 return getSubclassDataFromInstruction() & 1;
475 /// setVolatile - Specify whether this is a volatile cmpxchg.
477 void setVolatile(bool V) {
478 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
482 /// Transparently provide more efficient getOperand methods.
483 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
485 /// Set the ordering constraint on this cmpxchg.
486 void setOrdering(AtomicOrdering Ordering) {
487 assert(Ordering != NotAtomic &&
488 "CmpXchg instructions can only be atomic.");
489 setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
493 /// Specify whether this cmpxchg is atomic and orders other operations with
494 /// respect to all concurrently executing threads, or only with respect to
495 /// signal handlers executing in the same thread.
496 void setSynchScope(SynchronizationScope SynchScope) {
497 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
501 /// Returns the ordering constraint on this cmpxchg.
502 AtomicOrdering getOrdering() const {
503 return AtomicOrdering(getSubclassDataFromInstruction() >> 2);
506 /// Returns whether this cmpxchg is atomic between threads or only within a
508 SynchronizationScope getSynchScope() const {
509 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
512 Value *getPointerOperand() { return getOperand(0); }
513 const Value *getPointerOperand() const { return getOperand(0); }
514 static unsigned getPointerOperandIndex() { return 0U; }
516 Value *getCompareOperand() { return getOperand(1); }
517 const Value *getCompareOperand() const { return getOperand(1); }
519 Value *getNewValOperand() { return getOperand(2); }
520 const Value *getNewValOperand() const { return getOperand(2); }
522 unsigned getPointerAddressSpace() const {
523 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
526 // Methods for support type inquiry through isa, cast, and dyn_cast:
527 static inline bool classof(const AtomicCmpXchgInst *) { return true; }
528 static inline bool classof(const Instruction *I) {
529 return I->getOpcode() == Instruction::AtomicCmpXchg;
531 static inline bool classof(const Value *V) {
532 return isa<Instruction>(V) && classof(cast<Instruction>(V));
535 // Shadow Instruction::setInstructionSubclassData with a private forwarding
536 // method so that subclasses cannot accidentally use it.
537 void setInstructionSubclassData(unsigned short D) {
538 Instruction::setInstructionSubclassData(D);
543 struct OperandTraits<AtomicCmpXchgInst> :
544 public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
547 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)
549 //===----------------------------------------------------------------------===//
550 // AtomicRMWInst Class
551 //===----------------------------------------------------------------------===//
553 /// AtomicRMWInst - an instruction that atomically reads a memory location,
554 /// combines it with another value, and then stores the result back. Returns
557 class AtomicRMWInst : public Instruction {
558 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
560 virtual AtomicRMWInst *clone_impl() const;
562 /// This enumeration lists the possible modifications atomicrmw can make. In
563 /// the descriptions, 'p' is the pointer to the instruction's memory location,
564 /// 'old' is the initial value of *p, and 'v' is the other value passed to the
565 /// instruction. These instructions always return 'old'.
581 /// *p = old >signed v ? old : v
583 /// *p = old <signed v ? old : v
585 /// *p = old >unsigned v ? old : v
587 /// *p = old <unsigned v ? old : v
595 // allocate space for exactly two operands
596 void *operator new(size_t s) {
597 return User::operator new(s, 2);
599 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
600 AtomicOrdering Ordering, SynchronizationScope SynchScope,
601 Instruction *InsertBefore = 0);
602 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
603 AtomicOrdering Ordering, SynchronizationScope SynchScope,
604 BasicBlock *InsertAtEnd);
606 BinOp getOperation() const {
607 return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
610 void setOperation(BinOp Operation) {
611 unsigned short SubclassData = getSubclassDataFromInstruction();
612 setInstructionSubclassData((SubclassData & 31) |
616 /// isVolatile - Return true if this is a RMW on a volatile memory location.
618 bool isVolatile() const {
619 return getSubclassDataFromInstruction() & 1;
622 /// setVolatile - Specify whether this is a volatile RMW or not.
624 void setVolatile(bool V) {
625 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
629 /// Transparently provide more efficient getOperand methods.
630 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
632 /// Set the ordering constraint on this RMW.
633 void setOrdering(AtomicOrdering Ordering) {
634 assert(Ordering != NotAtomic &&
635 "atomicrmw instructions can only be atomic.");
636 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
640 /// Specify whether this RMW orders other operations with respect to all
641 /// concurrently executing threads, or only with respect to signal handlers
642 /// executing in the same thread.
643 void setSynchScope(SynchronizationScope SynchScope) {
644 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
648 /// Returns the ordering constraint on this RMW.
649 AtomicOrdering getOrdering() const {
650 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
653 /// Returns whether this RMW is atomic between threads or only within a
655 SynchronizationScope getSynchScope() const {
656 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
659 Value *getPointerOperand() { return getOperand(0); }
660 const Value *getPointerOperand() const { return getOperand(0); }
661 static unsigned getPointerOperandIndex() { return 0U; }
663 Value *getValOperand() { return getOperand(1); }
664 const Value *getValOperand() const { return getOperand(1); }
666 unsigned getPointerAddressSpace() const {
667 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
670 // Methods for support type inquiry through isa, cast, and dyn_cast:
671 static inline bool classof(const AtomicRMWInst *) { return true; }
672 static inline bool classof(const Instruction *I) {
673 return I->getOpcode() == Instruction::AtomicRMW;
675 static inline bool classof(const Value *V) {
676 return isa<Instruction>(V) && classof(cast<Instruction>(V));
679 void Init(BinOp Operation, Value *Ptr, Value *Val,
680 AtomicOrdering Ordering, SynchronizationScope SynchScope);
681 // Shadow Instruction::setInstructionSubclassData with a private forwarding
682 // method so that subclasses cannot accidentally use it.
683 void setInstructionSubclassData(unsigned short D) {
684 Instruction::setInstructionSubclassData(D);
689 struct OperandTraits<AtomicRMWInst>
690 : public FixedNumOperandTraits<AtomicRMWInst,2> {
693 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)
695 //===----------------------------------------------------------------------===//
696 // GetElementPtrInst Class
697 //===----------------------------------------------------------------------===//
699 // checkGEPType - Simple wrapper function to give a better assertion failure
700 // message on bad indexes for a gep instruction.
702 static inline Type *checkGEPType(Type *Ty) {
703 assert(Ty && "Invalid GetElementPtrInst indices for type!");
707 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
708 /// access elements of arrays and structs
710 class GetElementPtrInst : public Instruction {
711 GetElementPtrInst(const GetElementPtrInst &GEPI);
712 void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
714 /// Constructors - Create a getelementptr instruction with a base pointer an
715 /// list of indices. The first ctor can optionally insert before an existing
716 /// instruction, the second appends the new instruction to the specified
718 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
719 unsigned Values, const Twine &NameStr,
720 Instruction *InsertBefore);
721 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
722 unsigned Values, const Twine &NameStr,
723 BasicBlock *InsertAtEnd);
725 virtual GetElementPtrInst *clone_impl() const;
727 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
728 const Twine &NameStr = "",
729 Instruction *InsertBefore = 0) {
730 unsigned Values = 1 + unsigned(IdxList.size());
732 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
734 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
735 const Twine &NameStr,
736 BasicBlock *InsertAtEnd) {
737 unsigned Values = 1 + unsigned(IdxList.size());
739 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
742 /// Create an "inbounds" getelementptr. See the documentation for the
743 /// "inbounds" flag in LangRef.html for details.
744 static GetElementPtrInst *CreateInBounds(Value *Ptr,
745 ArrayRef<Value *> IdxList,
746 const Twine &NameStr = "",
747 Instruction *InsertBefore = 0) {
748 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
749 GEP->setIsInBounds(true);
752 static GetElementPtrInst *CreateInBounds(Value *Ptr,
753 ArrayRef<Value *> IdxList,
754 const Twine &NameStr,
755 BasicBlock *InsertAtEnd) {
756 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
757 GEP->setIsInBounds(true);
761 /// Transparently provide more efficient getOperand methods.
762 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
764 // getType - Overload to return most specific pointer type...
765 PointerType *getType() const {
766 return reinterpret_cast<PointerType*>(Instruction::getType());
769 /// getIndexedType - Returns the type of the element that would be loaded with
770 /// a load instruction with the specified parameters.
772 /// Null is returned if the indices are invalid for the specified
775 static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList);
776 static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList);
777 static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList);
779 /// getIndexedType - Returns the address space used by the GEP pointer.
781 static unsigned getAddressSpace(Value *Ptr);
783 inline op_iterator idx_begin() { return op_begin()+1; }
784 inline const_op_iterator idx_begin() const { return op_begin()+1; }
785 inline op_iterator idx_end() { return op_end(); }
786 inline const_op_iterator idx_end() const { return op_end(); }
788 Value *getPointerOperand() {
789 return getOperand(0);
791 const Value *getPointerOperand() const {
792 return getOperand(0);
794 static unsigned getPointerOperandIndex() {
795 return 0U; // get index for modifying correct operand.
798 unsigned getPointerAddressSpace() const {
799 return cast<PointerType>(getType())->getAddressSpace();
802 /// getPointerOperandType - Method to return the pointer operand as a
804 Type *getPointerOperandType() const {
805 return getPointerOperand()->getType();
808 /// GetGEPReturnType - Returns the pointer type returned by the GEP
809 /// instruction, which may be a vector of pointers.
810 static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
811 Type *PtrTy = PointerType::get(checkGEPType(
812 getIndexedType(Ptr->getType(), IdxList)),
813 getAddressSpace(Ptr));
815 if (Ptr->getType()->isVectorTy()) {
816 unsigned NumElem = cast<VectorType>(Ptr->getType())->getNumElements();
817 return VectorType::get(PtrTy, NumElem);
824 unsigned getNumIndices() const { // Note: always non-negative
825 return getNumOperands() - 1;
828 bool hasIndices() const {
829 return getNumOperands() > 1;
832 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
833 /// zeros. If so, the result pointer and the first operand have the same
834 /// value, just potentially different types.
835 bool hasAllZeroIndices() const;
837 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
838 /// constant integers. If so, the result pointer and the first operand have
839 /// a constant offset between them.
840 bool hasAllConstantIndices() const;
842 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
843 /// See LangRef.html for the meaning of inbounds on a getelementptr.
844 void setIsInBounds(bool b = true);
846 /// isInBounds - Determine whether the GEP has the inbounds flag.
847 bool isInBounds() const;
849 // Methods for support type inquiry through isa, cast, and dyn_cast:
850 static inline bool classof(const GetElementPtrInst *) { return true; }
851 static inline bool classof(const Instruction *I) {
852 return (I->getOpcode() == Instruction::GetElementPtr);
854 static inline bool classof(const Value *V) {
855 return isa<Instruction>(V) && classof(cast<Instruction>(V));
860 struct OperandTraits<GetElementPtrInst> :
861 public VariadicOperandTraits<GetElementPtrInst, 1> {
864 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
865 ArrayRef<Value *> IdxList,
867 const Twine &NameStr,
868 Instruction *InsertBefore)
869 : Instruction(getGEPReturnType(Ptr, IdxList),
871 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
872 Values, InsertBefore) {
873 init(Ptr, IdxList, NameStr);
875 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
876 ArrayRef<Value *> IdxList,
878 const Twine &NameStr,
879 BasicBlock *InsertAtEnd)
880 : Instruction(getGEPReturnType(Ptr, IdxList),
882 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
883 Values, InsertAtEnd) {
884 init(Ptr, IdxList, NameStr);
888 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
891 //===----------------------------------------------------------------------===//
893 //===----------------------------------------------------------------------===//
895 /// This instruction compares its operands according to the predicate given
896 /// to the constructor. It only operates on integers or pointers. The operands
897 /// must be identical types.
898 /// @brief Represent an integer comparison operator.
899 class ICmpInst: public CmpInst {
901 /// @brief Clone an identical ICmpInst
902 virtual ICmpInst *clone_impl() const;
904 /// @brief Constructor with insert-before-instruction semantics.
906 Instruction *InsertBefore, ///< Where to insert
907 Predicate pred, ///< The predicate to use for the comparison
908 Value *LHS, ///< The left-hand-side of the expression
909 Value *RHS, ///< The right-hand-side of the expression
910 const Twine &NameStr = "" ///< Name of the instruction
911 ) : CmpInst(makeCmpResultType(LHS->getType()),
912 Instruction::ICmp, pred, LHS, RHS, NameStr,
914 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
915 pred <= CmpInst::LAST_ICMP_PREDICATE &&
916 "Invalid ICmp predicate value");
917 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
918 "Both operands to ICmp instruction are not of the same type!");
919 // Check that the operands are the right type
920 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
921 getOperand(0)->getType()->getScalarType()->isPointerTy()) &&
922 "Invalid operand types for ICmp instruction");
925 /// @brief Constructor with insert-at-end semantics.
927 BasicBlock &InsertAtEnd, ///< Block to insert into.
928 Predicate pred, ///< The predicate to use for the comparison
929 Value *LHS, ///< The left-hand-side of the expression
930 Value *RHS, ///< The right-hand-side of the expression
931 const Twine &NameStr = "" ///< Name of the instruction
932 ) : CmpInst(makeCmpResultType(LHS->getType()),
933 Instruction::ICmp, pred, LHS, RHS, NameStr,
935 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
936 pred <= CmpInst::LAST_ICMP_PREDICATE &&
937 "Invalid ICmp predicate value");
938 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
939 "Both operands to ICmp instruction are not of the same type!");
940 // Check that the operands are the right type
941 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
942 getOperand(0)->getType()->isPointerTy()) &&
943 "Invalid operand types for ICmp instruction");
946 /// @brief Constructor with no-insertion semantics
948 Predicate pred, ///< The predicate to use for the comparison
949 Value *LHS, ///< The left-hand-side of the expression
950 Value *RHS, ///< The right-hand-side of the expression
951 const Twine &NameStr = "" ///< Name of the instruction
952 ) : CmpInst(makeCmpResultType(LHS->getType()),
953 Instruction::ICmp, pred, LHS, RHS, NameStr) {
954 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
955 pred <= CmpInst::LAST_ICMP_PREDICATE &&
956 "Invalid ICmp predicate value");
957 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
958 "Both operands to ICmp instruction are not of the same type!");
959 // Check that the operands are the right type
960 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
961 getOperand(0)->getType()->getScalarType()->isPointerTy()) &&
962 "Invalid operand types for ICmp instruction");
965 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
966 /// @returns the predicate that would be the result if the operand were
967 /// regarded as signed.
968 /// @brief Return the signed version of the predicate
969 Predicate getSignedPredicate() const {
970 return getSignedPredicate(getPredicate());
973 /// This is a static version that you can use without an instruction.
974 /// @brief Return the signed version of the predicate.
975 static Predicate getSignedPredicate(Predicate pred);
977 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
978 /// @returns the predicate that would be the result if the operand were
979 /// regarded as unsigned.
980 /// @brief Return the unsigned version of the predicate
981 Predicate getUnsignedPredicate() const {
982 return getUnsignedPredicate(getPredicate());
985 /// This is a static version that you can use without an instruction.
986 /// @brief Return the unsigned version of the predicate.
987 static Predicate getUnsignedPredicate(Predicate pred);
989 /// isEquality - Return true if this predicate is either EQ or NE. This also
990 /// tests for commutativity.
991 static bool isEquality(Predicate P) {
992 return P == ICMP_EQ || P == ICMP_NE;
995 /// isEquality - Return true if this predicate is either EQ or NE. This also
996 /// tests for commutativity.
997 bool isEquality() const {
998 return isEquality(getPredicate());
1001 /// @returns true if the predicate of this ICmpInst is commutative
1002 /// @brief Determine if this relation is commutative.
1003 bool isCommutative() const { return isEquality(); }
1005 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1007 bool isRelational() const {
1008 return !isEquality();
1011 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1013 static bool isRelational(Predicate P) {
1014 return !isEquality(P);
1017 /// Initialize a set of values that all satisfy the predicate with C.
1018 /// @brief Make a ConstantRange for a relation with a constant value.
1019 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
1021 /// Exchange the two operands to this instruction in such a way that it does
1022 /// not modify the semantics of the instruction. The predicate value may be
1023 /// changed to retain the same result if the predicate is order dependent
1025 /// @brief Swap operands and adjust predicate.
1026 void swapOperands() {
1027 setPredicate(getSwappedPredicate());
1028 Op<0>().swap(Op<1>());
1031 // Methods for support type inquiry through isa, cast, and dyn_cast:
1032 static inline bool classof(const ICmpInst *) { return true; }
1033 static inline bool classof(const Instruction *I) {
1034 return I->getOpcode() == Instruction::ICmp;
1036 static inline bool classof(const Value *V) {
1037 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1042 //===----------------------------------------------------------------------===//
1044 //===----------------------------------------------------------------------===//
1046 /// This instruction compares its operands according to the predicate given
1047 /// to the constructor. It only operates on floating point values or packed
1048 /// vectors of floating point values. The operands must be identical types.
1049 /// @brief Represents a floating point comparison operator.
1050 class FCmpInst: public CmpInst {
1052 /// @brief Clone an identical FCmpInst
1053 virtual FCmpInst *clone_impl() const;
1055 /// @brief Constructor with insert-before-instruction semantics.
1057 Instruction *InsertBefore, ///< Where to insert
1058 Predicate pred, ///< The predicate to use for the comparison
1059 Value *LHS, ///< The left-hand-side of the expression
1060 Value *RHS, ///< The right-hand-side of the expression
1061 const Twine &NameStr = "" ///< Name of the instruction
1062 ) : CmpInst(makeCmpResultType(LHS->getType()),
1063 Instruction::FCmp, pred, LHS, RHS, NameStr,
1065 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1066 "Invalid FCmp predicate value");
1067 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1068 "Both operands to FCmp instruction are not of the same type!");
1069 // Check that the operands are the right type
1070 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1071 "Invalid operand types for FCmp instruction");
1074 /// @brief Constructor with insert-at-end semantics.
1076 BasicBlock &InsertAtEnd, ///< Block to insert into.
1077 Predicate pred, ///< The predicate to use for the comparison
1078 Value *LHS, ///< The left-hand-side of the expression
1079 Value *RHS, ///< The right-hand-side of the expression
1080 const Twine &NameStr = "" ///< Name of the instruction
1081 ) : CmpInst(makeCmpResultType(LHS->getType()),
1082 Instruction::FCmp, pred, LHS, RHS, NameStr,
1084 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1085 "Invalid FCmp predicate value");
1086 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1087 "Both operands to FCmp instruction are not of the same type!");
1088 // Check that the operands are the right type
1089 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1090 "Invalid operand types for FCmp instruction");
1093 /// @brief Constructor with no-insertion semantics
1095 Predicate pred, ///< The predicate to use for the comparison
1096 Value *LHS, ///< The left-hand-side of the expression
1097 Value *RHS, ///< The right-hand-side of the expression
1098 const Twine &NameStr = "" ///< Name of the instruction
1099 ) : CmpInst(makeCmpResultType(LHS->getType()),
1100 Instruction::FCmp, pred, LHS, RHS, NameStr) {
1101 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1102 "Invalid FCmp predicate value");
1103 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1104 "Both operands to FCmp instruction are not of the same type!");
1105 // Check that the operands are the right type
1106 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1107 "Invalid operand types for FCmp instruction");
1110 /// @returns true if the predicate of this instruction is EQ or NE.
1111 /// @brief Determine if this is an equality predicate.
1112 bool isEquality() const {
1113 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
1114 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
1117 /// @returns true if the predicate of this instruction is commutative.
1118 /// @brief Determine if this is a commutative predicate.
1119 bool isCommutative() const {
1120 return isEquality() ||
1121 getPredicate() == FCMP_FALSE ||
1122 getPredicate() == FCMP_TRUE ||
1123 getPredicate() == FCMP_ORD ||
1124 getPredicate() == FCMP_UNO;
1127 /// @returns true if the predicate is relational (not EQ or NE).
1128 /// @brief Determine if this a relational predicate.
1129 bool isRelational() const { return !isEquality(); }
1131 /// Exchange the two operands to this instruction in such a way that it does
1132 /// not modify the semantics of the instruction. The predicate value may be
1133 /// changed to retain the same result if the predicate is order dependent
1135 /// @brief Swap operands and adjust predicate.
1136 void swapOperands() {
1137 setPredicate(getSwappedPredicate());
1138 Op<0>().swap(Op<1>());
1141 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1142 static inline bool classof(const FCmpInst *) { return true; }
1143 static inline bool classof(const Instruction *I) {
1144 return I->getOpcode() == Instruction::FCmp;
1146 static inline bool classof(const Value *V) {
1147 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1151 //===----------------------------------------------------------------------===//
1152 /// CallInst - This class represents a function call, abstracting a target
1153 /// machine's calling convention. This class uses low bit of the SubClassData
1154 /// field to indicate whether or not this is a tail call. The rest of the bits
1155 /// hold the calling convention of the call.
1157 class CallInst : public Instruction {
1158 AttrListPtr AttributeList; ///< parameter attributes for call
1159 CallInst(const CallInst &CI);
1160 void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
1161 void init(Value *Func, const Twine &NameStr);
1163 /// Construct a CallInst given a range of arguments.
1164 /// @brief Construct a CallInst from a range of arguments
1165 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1166 const Twine &NameStr, Instruction *InsertBefore);
1168 /// Construct a CallInst given a range of arguments.
1169 /// @brief Construct a CallInst from a range of arguments
1170 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1171 const Twine &NameStr, BasicBlock *InsertAtEnd);
1173 CallInst(Value *F, Value *Actual, const Twine &NameStr,
1174 Instruction *InsertBefore);
1175 CallInst(Value *F, Value *Actual, const Twine &NameStr,
1176 BasicBlock *InsertAtEnd);
1177 explicit CallInst(Value *F, const Twine &NameStr,
1178 Instruction *InsertBefore);
1179 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1181 virtual CallInst *clone_impl() const;
1183 static CallInst *Create(Value *Func,
1184 ArrayRef<Value *> Args,
1185 const Twine &NameStr = "",
1186 Instruction *InsertBefore = 0) {
1187 return new(unsigned(Args.size() + 1))
1188 CallInst(Func, Args, NameStr, InsertBefore);
1190 static CallInst *Create(Value *Func,
1191 ArrayRef<Value *> Args,
1192 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1193 return new(unsigned(Args.size() + 1))
1194 CallInst(Func, Args, NameStr, InsertAtEnd);
1196 static CallInst *Create(Value *F, const Twine &NameStr = "",
1197 Instruction *InsertBefore = 0) {
1198 return new(1) CallInst(F, NameStr, InsertBefore);
1200 static CallInst *Create(Value *F, const Twine &NameStr,
1201 BasicBlock *InsertAtEnd) {
1202 return new(1) CallInst(F, NameStr, InsertAtEnd);
1204 /// CreateMalloc - Generate the IR for a call to malloc:
1205 /// 1. Compute the malloc call's argument as the specified type's size,
1206 /// possibly multiplied by the array size if the array size is not
1208 /// 2. Call malloc with that argument.
1209 /// 3. Bitcast the result of the malloc call to the specified type.
1210 static Instruction *CreateMalloc(Instruction *InsertBefore,
1211 Type *IntPtrTy, Type *AllocTy,
1212 Value *AllocSize, Value *ArraySize = 0,
1213 Function* MallocF = 0,
1214 const Twine &Name = "");
1215 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1216 Type *IntPtrTy, Type *AllocTy,
1217 Value *AllocSize, Value *ArraySize = 0,
1218 Function* MallocF = 0,
1219 const Twine &Name = "");
1220 /// CreateFree - Generate the IR for a call to the builtin free function.
1221 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
1222 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
1226 bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
1227 void setTailCall(bool isTC = true) {
1228 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
1232 /// Provide fast operand accessors
1233 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1235 /// getNumArgOperands - Return the number of call arguments.
1237 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
1239 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1241 Value *getArgOperand(unsigned i) const { return getOperand(i); }
1242 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
1244 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1246 CallingConv::ID getCallingConv() const {
1247 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
1249 void setCallingConv(CallingConv::ID CC) {
1250 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
1251 (static_cast<unsigned>(CC) << 1));
1254 /// getAttributes - Return the parameter attributes for this call.
1256 const AttrListPtr &getAttributes() const { return AttributeList; }
1258 /// setAttributes - Set the parameter attributes for this call.
1260 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
1262 /// addAttribute - adds the attribute to the list of attributes.
1263 void addAttribute(unsigned i, Attributes attr);
1265 /// removeAttribute - removes the attribute from the list of attributes.
1266 void removeAttribute(unsigned i, Attributes attr);
1268 /// @brief Determine whether the call or the callee has the given attribute.
1269 bool paramHasAttr(unsigned i, Attributes attr) const;
1271 /// @brief Extract the alignment for a call or parameter (0=unknown).
1272 unsigned getParamAlignment(unsigned i) const {
1273 return AttributeList.getParamAlignment(i);
1276 /// @brief Return true if the call should not be inlined.
1277 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
1278 void setIsNoInline(bool Value = true) {
1279 if (Value) addAttribute(~0, Attribute::NoInline);
1280 else removeAttribute(~0, Attribute::NoInline);
1283 /// @brief Return true if the call can return twice
1284 bool canReturnTwice() const {
1285 return paramHasAttr(~0, Attribute::ReturnsTwice);
1287 void setCanReturnTwice(bool Value = true) {
1288 if (Value) addAttribute(~0, Attribute::ReturnsTwice);
1289 else removeAttribute(~0, Attribute::ReturnsTwice);
1292 /// @brief Determine if the call does not access memory.
1293 bool doesNotAccessMemory() const {
1294 return paramHasAttr(~0, Attribute::ReadNone);
1296 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
1297 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
1298 else removeAttribute(~0, Attribute::ReadNone);
1301 /// @brief Determine if the call does not access or only reads memory.
1302 bool onlyReadsMemory() const {
1303 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
1305 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
1306 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
1307 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
1310 /// @brief Determine if the call cannot return.
1311 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
1312 void setDoesNotReturn(bool DoesNotReturn = true) {
1313 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
1314 else removeAttribute(~0, Attribute::NoReturn);
1317 /// @brief Determine if the call cannot unwind.
1318 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
1319 void setDoesNotThrow(bool DoesNotThrow = true) {
1320 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
1321 else removeAttribute(~0, Attribute::NoUnwind);
1324 /// @brief Determine if the call returns a structure through first
1325 /// pointer argument.
1326 bool hasStructRetAttr() const {
1327 // Be friendly and also check the callee.
1328 return paramHasAttr(1, Attribute::StructRet);
1331 /// @brief Determine if any call argument is an aggregate passed by value.
1332 bool hasByValArgument() const {
1333 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1336 /// getCalledFunction - Return the function called, or null if this is an
1337 /// indirect function invocation.
1339 Function *getCalledFunction() const {
1340 return dyn_cast<Function>(Op<-1>());
1343 /// getCalledValue - Get a pointer to the function that is invoked by this
1345 const Value *getCalledValue() const { return Op<-1>(); }
1346 Value *getCalledValue() { return Op<-1>(); }
1348 /// setCalledFunction - Set the function called.
1349 void setCalledFunction(Value* Fn) {
1353 /// isInlineAsm - Check if this call is an inline asm statement.
1354 bool isInlineAsm() const {
1355 return isa<InlineAsm>(Op<-1>());
1358 // Methods for support type inquiry through isa, cast, and dyn_cast:
1359 static inline bool classof(const CallInst *) { return true; }
1360 static inline bool classof(const Instruction *I) {
1361 return I->getOpcode() == Instruction::Call;
1363 static inline bool classof(const Value *V) {
1364 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1367 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1368 // method so that subclasses cannot accidentally use it.
1369 void setInstructionSubclassData(unsigned short D) {
1370 Instruction::setInstructionSubclassData(D);
1375 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1378 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1379 const Twine &NameStr, BasicBlock *InsertAtEnd)
1380 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1381 ->getElementType())->getReturnType(),
1383 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1384 unsigned(Args.size() + 1), InsertAtEnd) {
1385 init(Func, Args, NameStr);
1388 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1389 const Twine &NameStr, Instruction *InsertBefore)
1390 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1391 ->getElementType())->getReturnType(),
1393 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1394 unsigned(Args.size() + 1), InsertBefore) {
1395 init(Func, Args, NameStr);
1399 // Note: if you get compile errors about private methods then
1400 // please update your code to use the high-level operand
1401 // interfaces. See line 943 above.
1402 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1404 //===----------------------------------------------------------------------===//
1406 //===----------------------------------------------------------------------===//
1408 /// SelectInst - This class represents the LLVM 'select' instruction.
1410 class SelectInst : public Instruction {
1411 void init(Value *C, Value *S1, Value *S2) {
1412 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1418 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1419 Instruction *InsertBefore)
1420 : Instruction(S1->getType(), Instruction::Select,
1421 &Op<0>(), 3, InsertBefore) {
1425 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1426 BasicBlock *InsertAtEnd)
1427 : Instruction(S1->getType(), Instruction::Select,
1428 &Op<0>(), 3, InsertAtEnd) {
1433 virtual SelectInst *clone_impl() const;
1435 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1436 const Twine &NameStr = "",
1437 Instruction *InsertBefore = 0) {
1438 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1440 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1441 const Twine &NameStr,
1442 BasicBlock *InsertAtEnd) {
1443 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1446 const Value *getCondition() const { return Op<0>(); }
1447 const Value *getTrueValue() const { return Op<1>(); }
1448 const Value *getFalseValue() const { return Op<2>(); }
1449 Value *getCondition() { return Op<0>(); }
1450 Value *getTrueValue() { return Op<1>(); }
1451 Value *getFalseValue() { return Op<2>(); }
1453 /// areInvalidOperands - Return a string if the specified operands are invalid
1454 /// for a select operation, otherwise return null.
1455 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1457 /// Transparently provide more efficient getOperand methods.
1458 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1460 OtherOps getOpcode() const {
1461 return static_cast<OtherOps>(Instruction::getOpcode());
1464 // Methods for support type inquiry through isa, cast, and dyn_cast:
1465 static inline bool classof(const SelectInst *) { return true; }
1466 static inline bool classof(const Instruction *I) {
1467 return I->getOpcode() == Instruction::Select;
1469 static inline bool classof(const Value *V) {
1470 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1475 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1478 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1480 //===----------------------------------------------------------------------===//
1482 //===----------------------------------------------------------------------===//
1484 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1485 /// an argument of the specified type given a va_list and increments that list
1487 class VAArgInst : public UnaryInstruction {
1489 virtual VAArgInst *clone_impl() const;
1492 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1493 Instruction *InsertBefore = 0)
1494 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1497 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1498 BasicBlock *InsertAtEnd)
1499 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1503 Value *getPointerOperand() { return getOperand(0); }
1504 const Value *getPointerOperand() const { return getOperand(0); }
1505 static unsigned getPointerOperandIndex() { return 0U; }
1507 // Methods for support type inquiry through isa, cast, and dyn_cast:
1508 static inline bool classof(const VAArgInst *) { return true; }
1509 static inline bool classof(const Instruction *I) {
1510 return I->getOpcode() == VAArg;
1512 static inline bool classof(const Value *V) {
1513 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1517 //===----------------------------------------------------------------------===//
1518 // ExtractElementInst Class
1519 //===----------------------------------------------------------------------===//
1521 /// ExtractElementInst - This instruction extracts a single (scalar)
1522 /// element from a VectorType value
1524 class ExtractElementInst : public Instruction {
1525 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1526 Instruction *InsertBefore = 0);
1527 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1528 BasicBlock *InsertAtEnd);
1530 virtual ExtractElementInst *clone_impl() const;
1533 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1534 const Twine &NameStr = "",
1535 Instruction *InsertBefore = 0) {
1536 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1538 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1539 const Twine &NameStr,
1540 BasicBlock *InsertAtEnd) {
1541 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1544 /// isValidOperands - Return true if an extractelement instruction can be
1545 /// formed with the specified operands.
1546 static bool isValidOperands(const Value *Vec, const Value *Idx);
1548 Value *getVectorOperand() { return Op<0>(); }
1549 Value *getIndexOperand() { return Op<1>(); }
1550 const Value *getVectorOperand() const { return Op<0>(); }
1551 const Value *getIndexOperand() const { return Op<1>(); }
1553 VectorType *getVectorOperandType() const {
1554 return reinterpret_cast<VectorType*>(getVectorOperand()->getType());
1558 /// Transparently provide more efficient getOperand methods.
1559 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1561 // Methods for support type inquiry through isa, cast, and dyn_cast:
1562 static inline bool classof(const ExtractElementInst *) { return true; }
1563 static inline bool classof(const Instruction *I) {
1564 return I->getOpcode() == Instruction::ExtractElement;
1566 static inline bool classof(const Value *V) {
1567 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1572 struct OperandTraits<ExtractElementInst> :
1573 public FixedNumOperandTraits<ExtractElementInst, 2> {
1576 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1578 //===----------------------------------------------------------------------===//
1579 // InsertElementInst Class
1580 //===----------------------------------------------------------------------===//
1582 /// InsertElementInst - This instruction inserts a single (scalar)
1583 /// element into a VectorType value
1585 class InsertElementInst : public Instruction {
1586 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1587 const Twine &NameStr = "",
1588 Instruction *InsertBefore = 0);
1589 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1590 const Twine &NameStr, BasicBlock *InsertAtEnd);
1592 virtual InsertElementInst *clone_impl() const;
1595 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1596 const Twine &NameStr = "",
1597 Instruction *InsertBefore = 0) {
1598 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1600 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1601 const Twine &NameStr,
1602 BasicBlock *InsertAtEnd) {
1603 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1606 /// isValidOperands - Return true if an insertelement instruction can be
1607 /// formed with the specified operands.
1608 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1611 /// getType - Overload to return most specific vector type.
1613 VectorType *getType() const {
1614 return reinterpret_cast<VectorType*>(Instruction::getType());
1617 /// Transparently provide more efficient getOperand methods.
1618 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1620 // Methods for support type inquiry through isa, cast, and dyn_cast:
1621 static inline bool classof(const InsertElementInst *) { return true; }
1622 static inline bool classof(const Instruction *I) {
1623 return I->getOpcode() == Instruction::InsertElement;
1625 static inline bool classof(const Value *V) {
1626 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1631 struct OperandTraits<InsertElementInst> :
1632 public FixedNumOperandTraits<InsertElementInst, 3> {
1635 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1637 //===----------------------------------------------------------------------===//
1638 // ShuffleVectorInst Class
1639 //===----------------------------------------------------------------------===//
1641 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1644 class ShuffleVectorInst : public Instruction {
1646 virtual ShuffleVectorInst *clone_impl() const;
1649 // allocate space for exactly three operands
1650 void *operator new(size_t s) {
1651 return User::operator new(s, 3);
1653 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1654 const Twine &NameStr = "",
1655 Instruction *InsertBefor = 0);
1656 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1657 const Twine &NameStr, BasicBlock *InsertAtEnd);
1659 /// isValidOperands - Return true if a shufflevector instruction can be
1660 /// formed with the specified operands.
1661 static bool isValidOperands(const Value *V1, const Value *V2,
1664 /// getType - Overload to return most specific vector type.
1666 VectorType *getType() const {
1667 return reinterpret_cast<VectorType*>(Instruction::getType());
1670 /// Transparently provide more efficient getOperand methods.
1671 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1673 Constant *getMask() const {
1674 return reinterpret_cast<Constant*>(getOperand(2));
1677 /// getMaskValue - Return the index from the shuffle mask for the specified
1678 /// output result. This is either -1 if the element is undef or a number less
1679 /// than 2*numelements.
1680 int getMaskValue(unsigned i) const;
1682 /// getShuffleMask - Return the full mask for this instruction, where each
1683 /// element is the element number and undef's are returned as -1.
1684 void getShuffleMask(SmallVectorImpl<int> &Mask) const;
1686 SmallVector<int, 16> getShuffleMask() const {
1687 SmallVector<int, 16> Mask;
1688 getShuffleMask(Mask);
1693 // Methods for support type inquiry through isa, cast, and dyn_cast:
1694 static inline bool classof(const ShuffleVectorInst *) { return true; }
1695 static inline bool classof(const Instruction *I) {
1696 return I->getOpcode() == Instruction::ShuffleVector;
1698 static inline bool classof(const Value *V) {
1699 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1704 struct OperandTraits<ShuffleVectorInst> :
1705 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1708 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1710 //===----------------------------------------------------------------------===//
1711 // ExtractValueInst Class
1712 //===----------------------------------------------------------------------===//
1714 /// ExtractValueInst - This instruction extracts a struct member or array
1715 /// element value from an aggregate value.
1717 class ExtractValueInst : public UnaryInstruction {
1718 SmallVector<unsigned, 4> Indices;
1720 ExtractValueInst(const ExtractValueInst &EVI);
1721 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1723 /// Constructors - Create a extractvalue instruction with a base aggregate
1724 /// value and a list of indices. The first ctor can optionally insert before
1725 /// an existing instruction, the second appends the new instruction to the
1726 /// specified BasicBlock.
1727 inline ExtractValueInst(Value *Agg,
1728 ArrayRef<unsigned> Idxs,
1729 const Twine &NameStr,
1730 Instruction *InsertBefore);
1731 inline ExtractValueInst(Value *Agg,
1732 ArrayRef<unsigned> Idxs,
1733 const Twine &NameStr, BasicBlock *InsertAtEnd);
1735 // allocate space for exactly one operand
1736 void *operator new(size_t s) {
1737 return User::operator new(s, 1);
1740 virtual ExtractValueInst *clone_impl() const;
1743 static ExtractValueInst *Create(Value *Agg,
1744 ArrayRef<unsigned> Idxs,
1745 const Twine &NameStr = "",
1746 Instruction *InsertBefore = 0) {
1748 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1750 static ExtractValueInst *Create(Value *Agg,
1751 ArrayRef<unsigned> Idxs,
1752 const Twine &NameStr,
1753 BasicBlock *InsertAtEnd) {
1754 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1757 /// getIndexedType - Returns the type of the element that would be extracted
1758 /// with an extractvalue instruction with the specified parameters.
1760 /// Null is returned if the indices are invalid for the specified type.
1761 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
1763 typedef const unsigned* idx_iterator;
1764 inline idx_iterator idx_begin() const { return Indices.begin(); }
1765 inline idx_iterator idx_end() const { return Indices.end(); }
1767 Value *getAggregateOperand() {
1768 return getOperand(0);
1770 const Value *getAggregateOperand() const {
1771 return getOperand(0);
1773 static unsigned getAggregateOperandIndex() {
1774 return 0U; // get index for modifying correct operand
1777 ArrayRef<unsigned> getIndices() const {
1781 unsigned getNumIndices() const {
1782 return (unsigned)Indices.size();
1785 bool hasIndices() const {
1789 // Methods for support type inquiry through isa, cast, and dyn_cast:
1790 static inline bool classof(const ExtractValueInst *) { return true; }
1791 static inline bool classof(const Instruction *I) {
1792 return I->getOpcode() == Instruction::ExtractValue;
1794 static inline bool classof(const Value *V) {
1795 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1799 ExtractValueInst::ExtractValueInst(Value *Agg,
1800 ArrayRef<unsigned> Idxs,
1801 const Twine &NameStr,
1802 Instruction *InsertBefore)
1803 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1804 ExtractValue, Agg, InsertBefore) {
1805 init(Idxs, NameStr);
1807 ExtractValueInst::ExtractValueInst(Value *Agg,
1808 ArrayRef<unsigned> Idxs,
1809 const Twine &NameStr,
1810 BasicBlock *InsertAtEnd)
1811 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1812 ExtractValue, Agg, InsertAtEnd) {
1813 init(Idxs, NameStr);
1817 //===----------------------------------------------------------------------===//
1818 // InsertValueInst Class
1819 //===----------------------------------------------------------------------===//
1821 /// InsertValueInst - This instruction inserts a struct field of array element
1822 /// value into an aggregate value.
1824 class InsertValueInst : public Instruction {
1825 SmallVector<unsigned, 4> Indices;
1827 void *operator new(size_t, unsigned); // Do not implement
1828 InsertValueInst(const InsertValueInst &IVI);
1829 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1830 const Twine &NameStr);
1832 /// Constructors - Create a insertvalue instruction with a base aggregate
1833 /// value, a value to insert, and a list of indices. The first ctor can
1834 /// optionally insert before an existing instruction, the second appends
1835 /// the new instruction to the specified BasicBlock.
1836 inline InsertValueInst(Value *Agg, Value *Val,
1837 ArrayRef<unsigned> Idxs,
1838 const Twine &NameStr,
1839 Instruction *InsertBefore);
1840 inline InsertValueInst(Value *Agg, Value *Val,
1841 ArrayRef<unsigned> Idxs,
1842 const Twine &NameStr, BasicBlock *InsertAtEnd);
1844 /// Constructors - These two constructors are convenience methods because one
1845 /// and two index insertvalue instructions are so common.
1846 InsertValueInst(Value *Agg, Value *Val,
1847 unsigned Idx, const Twine &NameStr = "",
1848 Instruction *InsertBefore = 0);
1849 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1850 const Twine &NameStr, BasicBlock *InsertAtEnd);
1852 virtual InsertValueInst *clone_impl() const;
1854 // allocate space for exactly two operands
1855 void *operator new(size_t s) {
1856 return User::operator new(s, 2);
1859 static InsertValueInst *Create(Value *Agg, Value *Val,
1860 ArrayRef<unsigned> Idxs,
1861 const Twine &NameStr = "",
1862 Instruction *InsertBefore = 0) {
1863 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1865 static InsertValueInst *Create(Value *Agg, Value *Val,
1866 ArrayRef<unsigned> Idxs,
1867 const Twine &NameStr,
1868 BasicBlock *InsertAtEnd) {
1869 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1872 /// Transparently provide more efficient getOperand methods.
1873 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1875 typedef const unsigned* idx_iterator;
1876 inline idx_iterator idx_begin() const { return Indices.begin(); }
1877 inline idx_iterator idx_end() const { return Indices.end(); }
1879 Value *getAggregateOperand() {
1880 return getOperand(0);
1882 const Value *getAggregateOperand() const {
1883 return getOperand(0);
1885 static unsigned getAggregateOperandIndex() {
1886 return 0U; // get index for modifying correct operand
1889 Value *getInsertedValueOperand() {
1890 return getOperand(1);
1892 const Value *getInsertedValueOperand() const {
1893 return getOperand(1);
1895 static unsigned getInsertedValueOperandIndex() {
1896 return 1U; // get index for modifying correct operand
1899 ArrayRef<unsigned> getIndices() const {
1903 unsigned getNumIndices() const {
1904 return (unsigned)Indices.size();
1907 bool hasIndices() const {
1911 // Methods for support type inquiry through isa, cast, and dyn_cast:
1912 static inline bool classof(const InsertValueInst *) { return true; }
1913 static inline bool classof(const Instruction *I) {
1914 return I->getOpcode() == Instruction::InsertValue;
1916 static inline bool classof(const Value *V) {
1917 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1922 struct OperandTraits<InsertValueInst> :
1923 public FixedNumOperandTraits<InsertValueInst, 2> {
1926 InsertValueInst::InsertValueInst(Value *Agg,
1928 ArrayRef<unsigned> Idxs,
1929 const Twine &NameStr,
1930 Instruction *InsertBefore)
1931 : Instruction(Agg->getType(), InsertValue,
1932 OperandTraits<InsertValueInst>::op_begin(this),
1934 init(Agg, Val, Idxs, NameStr);
1936 InsertValueInst::InsertValueInst(Value *Agg,
1938 ArrayRef<unsigned> Idxs,
1939 const Twine &NameStr,
1940 BasicBlock *InsertAtEnd)
1941 : Instruction(Agg->getType(), InsertValue,
1942 OperandTraits<InsertValueInst>::op_begin(this),
1944 init(Agg, Val, Idxs, NameStr);
1947 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1949 //===----------------------------------------------------------------------===//
1951 //===----------------------------------------------------------------------===//
1953 // PHINode - The PHINode class is used to represent the magical mystical PHI
1954 // node, that can not exist in nature, but can be synthesized in a computer
1955 // scientist's overactive imagination.
1957 class PHINode : public Instruction {
1958 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
1959 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1960 /// the number actually in use.
1961 unsigned ReservedSpace;
1962 PHINode(const PHINode &PN);
1963 // allocate space for exactly zero operands
1964 void *operator new(size_t s) {
1965 return User::operator new(s, 0);
1967 explicit PHINode(Type *Ty, unsigned NumReservedValues,
1968 const Twine &NameStr = "", Instruction *InsertBefore = 0)
1969 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1970 ReservedSpace(NumReservedValues) {
1972 OperandList = allocHungoffUses(ReservedSpace);
1975 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
1976 BasicBlock *InsertAtEnd)
1977 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1978 ReservedSpace(NumReservedValues) {
1980 OperandList = allocHungoffUses(ReservedSpace);
1983 // allocHungoffUses - this is more complicated than the generic
1984 // User::allocHungoffUses, because we have to allocate Uses for the incoming
1985 // values and pointers to the incoming blocks, all in one allocation.
1986 Use *allocHungoffUses(unsigned) const;
1988 virtual PHINode *clone_impl() const;
1990 /// Constructors - NumReservedValues is a hint for the number of incoming
1991 /// edges that this phi node will have (use 0 if you really have no idea).
1992 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
1993 const Twine &NameStr = "",
1994 Instruction *InsertBefore = 0) {
1995 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
1997 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
1998 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1999 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2003 /// Provide fast operand accessors
2004 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2006 // Block iterator interface. This provides access to the list of incoming
2007 // basic blocks, which parallels the list of incoming values.
2009 typedef BasicBlock **block_iterator;
2010 typedef BasicBlock * const *const_block_iterator;
2012 block_iterator block_begin() {
2014 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2015 return reinterpret_cast<block_iterator>(ref + 1);
2018 const_block_iterator block_begin() const {
2019 const Use::UserRef *ref =
2020 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2021 return reinterpret_cast<const_block_iterator>(ref + 1);
2024 block_iterator block_end() {
2025 return block_begin() + getNumOperands();
2028 const_block_iterator block_end() const {
2029 return block_begin() + getNumOperands();
2032 /// getNumIncomingValues - Return the number of incoming edges
2034 unsigned getNumIncomingValues() const { return getNumOperands(); }
2036 /// getIncomingValue - Return incoming value number x
2038 Value *getIncomingValue(unsigned i) const {
2039 return getOperand(i);
2041 void setIncomingValue(unsigned i, Value *V) {
2044 static unsigned getOperandNumForIncomingValue(unsigned i) {
2047 static unsigned getIncomingValueNumForOperand(unsigned i) {
2051 /// getIncomingBlock - Return incoming basic block number @p i.
2053 BasicBlock *getIncomingBlock(unsigned i) const {
2054 return block_begin()[i];
2057 /// getIncomingBlock - Return incoming basic block corresponding
2058 /// to an operand of the PHI.
2060 BasicBlock *getIncomingBlock(const Use &U) const {
2061 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2062 return getIncomingBlock(unsigned(&U - op_begin()));
2065 /// getIncomingBlock - Return incoming basic block corresponding
2066 /// to value use iterator.
2068 template <typename U>
2069 BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
2070 return getIncomingBlock(I.getUse());
2073 void setIncomingBlock(unsigned i, BasicBlock *BB) {
2074 block_begin()[i] = BB;
2077 /// addIncoming - Add an incoming value to the end of the PHI list
2079 void addIncoming(Value *V, BasicBlock *BB) {
2080 assert(V && "PHI node got a null value!");
2081 assert(BB && "PHI node got a null basic block!");
2082 assert(getType() == V->getType() &&
2083 "All operands to PHI node must be the same type as the PHI node!");
2084 if (NumOperands == ReservedSpace)
2085 growOperands(); // Get more space!
2086 // Initialize some new operands.
2088 setIncomingValue(NumOperands - 1, V);
2089 setIncomingBlock(NumOperands - 1, BB);
2092 /// removeIncomingValue - Remove an incoming value. This is useful if a
2093 /// predecessor basic block is deleted. The value removed is returned.
2095 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2096 /// is true), the PHI node is destroyed and any uses of it are replaced with
2097 /// dummy values. The only time there should be zero incoming values to a PHI
2098 /// node is when the block is dead, so this strategy is sound.
2100 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2102 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2103 int Idx = getBasicBlockIndex(BB);
2104 assert(Idx >= 0 && "Invalid basic block argument to remove!");
2105 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2108 /// getBasicBlockIndex - Return the first index of the specified basic
2109 /// block in the value list for this PHI. Returns -1 if no instance.
2111 int getBasicBlockIndex(const BasicBlock *BB) const {
2112 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2113 if (block_begin()[i] == BB)
2118 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2119 int Idx = getBasicBlockIndex(BB);
2120 assert(Idx >= 0 && "Invalid basic block argument!");
2121 return getIncomingValue(Idx);
2124 /// hasConstantValue - If the specified PHI node always merges together the
2125 /// same value, return the value, otherwise return null.
2126 Value *hasConstantValue() const;
2128 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2129 static inline bool classof(const PHINode *) { return true; }
2130 static inline bool classof(const Instruction *I) {
2131 return I->getOpcode() == Instruction::PHI;
2133 static inline bool classof(const Value *V) {
2134 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2137 void growOperands();
2141 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2144 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
2146 //===----------------------------------------------------------------------===//
2147 // LandingPadInst Class
2148 //===----------------------------------------------------------------------===//
2150 //===---------------------------------------------------------------------------
2151 /// LandingPadInst - The landingpad instruction holds all of the information
2152 /// necessary to generate correct exception handling. The landingpad instruction
2153 /// cannot be moved from the top of a landing pad block, which itself is
2154 /// accessible only from the 'unwind' edge of an invoke. This uses the
2155 /// SubclassData field in Value to store whether or not the landingpad is a
2158 class LandingPadInst : public Instruction {
2159 /// ReservedSpace - The number of operands actually allocated. NumOperands is
2160 /// the number actually in use.
2161 unsigned ReservedSpace;
2162 LandingPadInst(const LandingPadInst &LP);
2164 enum ClauseType { Catch, Filter };
2166 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2167 // Allocate space for exactly zero operands.
2168 void *operator new(size_t s) {
2169 return User::operator new(s, 0);
2171 void growOperands(unsigned Size);
2172 void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
2174 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2175 unsigned NumReservedValues, const Twine &NameStr,
2176 Instruction *InsertBefore);
2177 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2178 unsigned NumReservedValues, const Twine &NameStr,
2179 BasicBlock *InsertAtEnd);
2181 virtual LandingPadInst *clone_impl() const;
2183 /// Constructors - NumReservedClauses is a hint for the number of incoming
2184 /// clauses that this landingpad will have (use 0 if you really have no idea).
2185 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2186 unsigned NumReservedClauses,
2187 const Twine &NameStr = "",
2188 Instruction *InsertBefore = 0);
2189 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2190 unsigned NumReservedClauses,
2191 const Twine &NameStr, BasicBlock *InsertAtEnd);
2194 /// Provide fast operand accessors
2195 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2197 /// getPersonalityFn - Get the personality function associated with this
2199 Value *getPersonalityFn() const { return getOperand(0); }
2201 /// isCleanup - Return 'true' if this landingpad instruction is a
2202 /// cleanup. I.e., it should be run when unwinding even if its landing pad
2203 /// doesn't catch the exception.
2204 bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2206 /// setCleanup - Indicate that this landingpad instruction is a cleanup.
2207 void setCleanup(bool V) {
2208 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2212 /// addClause - Add a catch or filter clause to the landing pad.
2213 void addClause(Value *ClauseVal);
2215 /// getClause - Get the value of the clause at index Idx. Use isCatch/isFilter
2216 /// to determine what type of clause this is.
2217 Value *getClause(unsigned Idx) const { return OperandList[Idx + 1]; }
2219 /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
2220 bool isCatch(unsigned Idx) const {
2221 return !isa<ArrayType>(OperandList[Idx + 1]->getType());
2224 /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
2225 bool isFilter(unsigned Idx) const {
2226 return isa<ArrayType>(OperandList[Idx + 1]->getType());
2229 /// getNumClauses - Get the number of clauses for this landing pad.
2230 unsigned getNumClauses() const { return getNumOperands() - 1; }
2232 /// reserveClauses - Grow the size of the operand list to accomodate the new
2233 /// number of clauses.
2234 void reserveClauses(unsigned Size) { growOperands(Size); }
2236 // Methods for support type inquiry through isa, cast, and dyn_cast:
2237 static inline bool classof(const LandingPadInst *) { return true; }
2238 static inline bool classof(const Instruction *I) {
2239 return I->getOpcode() == Instruction::LandingPad;
2241 static inline bool classof(const Value *V) {
2242 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2247 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
2250 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
2252 //===----------------------------------------------------------------------===//
2254 //===----------------------------------------------------------------------===//
2256 //===---------------------------------------------------------------------------
2257 /// ReturnInst - Return a value (possibly void), from a function. Execution
2258 /// does not continue in this function any longer.
2260 class ReturnInst : public TerminatorInst {
2261 ReturnInst(const ReturnInst &RI);
2264 // ReturnInst constructors:
2265 // ReturnInst() - 'ret void' instruction
2266 // ReturnInst( null) - 'ret void' instruction
2267 // ReturnInst(Value* X) - 'ret X' instruction
2268 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
2269 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
2270 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2271 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
2273 // NOTE: If the Value* passed is of type void then the constructor behaves as
2274 // if it was passed NULL.
2275 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
2276 Instruction *InsertBefore = 0);
2277 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2278 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2280 virtual ReturnInst *clone_impl() const;
2282 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
2283 Instruction *InsertBefore = 0) {
2284 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2286 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2287 BasicBlock *InsertAtEnd) {
2288 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2290 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2291 return new(0) ReturnInst(C, InsertAtEnd);
2293 virtual ~ReturnInst();
2295 /// Provide fast operand accessors
2296 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2298 /// Convenience accessor. Returns null if there is no return value.
2299 Value *getReturnValue() const {
2300 return getNumOperands() != 0 ? getOperand(0) : 0;
2303 unsigned getNumSuccessors() const { return 0; }
2305 // Methods for support type inquiry through isa, cast, and dyn_cast:
2306 static inline bool classof(const ReturnInst *) { return true; }
2307 static inline bool classof(const Instruction *I) {
2308 return (I->getOpcode() == Instruction::Ret);
2310 static inline bool classof(const Value *V) {
2311 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2314 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2315 virtual unsigned getNumSuccessorsV() const;
2316 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2320 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2323 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2325 //===----------------------------------------------------------------------===//
2327 //===----------------------------------------------------------------------===//
2329 //===---------------------------------------------------------------------------
2330 /// BranchInst - Conditional or Unconditional Branch instruction.
2332 class BranchInst : public TerminatorInst {
2333 /// Ops list - Branches are strange. The operands are ordered:
2334 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2335 /// they don't have to check for cond/uncond branchness. These are mostly
2336 /// accessed relative from op_end().
2337 BranchInst(const BranchInst &BI);
2339 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2340 // BranchInst(BB *B) - 'br B'
2341 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2342 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2343 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2344 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2345 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2346 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2347 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2348 Instruction *InsertBefore = 0);
2349 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2350 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2351 BasicBlock *InsertAtEnd);
2353 virtual BranchInst *clone_impl() const;
2355 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2356 return new(1) BranchInst(IfTrue, InsertBefore);
2358 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2359 Value *Cond, Instruction *InsertBefore = 0) {
2360 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2362 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2363 return new(1) BranchInst(IfTrue, InsertAtEnd);
2365 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2366 Value *Cond, BasicBlock *InsertAtEnd) {
2367 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2370 /// Transparently provide more efficient getOperand methods.
2371 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2373 bool isUnconditional() const { return getNumOperands() == 1; }
2374 bool isConditional() const { return getNumOperands() == 3; }
2376 Value *getCondition() const {
2377 assert(isConditional() && "Cannot get condition of an uncond branch!");
2381 void setCondition(Value *V) {
2382 assert(isConditional() && "Cannot set condition of unconditional branch!");
2386 unsigned getNumSuccessors() const { return 1+isConditional(); }
2388 BasicBlock *getSuccessor(unsigned i) const {
2389 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2390 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2393 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2394 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2395 *(&Op<-1>() - idx) = (Value*)NewSucc;
2398 /// \brief Swap the successors of this branch instruction.
2400 /// Swaps the successors of the branch instruction. This also swaps any
2401 /// branch weight metadata associated with the instruction so that it
2402 /// continues to map correctly to each operand.
2403 void swapSuccessors();
2405 // Methods for support type inquiry through isa, cast, and dyn_cast:
2406 static inline bool classof(const BranchInst *) { return true; }
2407 static inline bool classof(const Instruction *I) {
2408 return (I->getOpcode() == Instruction::Br);
2410 static inline bool classof(const Value *V) {
2411 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2414 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2415 virtual unsigned getNumSuccessorsV() const;
2416 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2420 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2423 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2425 //===----------------------------------------------------------------------===//
2427 //===----------------------------------------------------------------------===//
2429 //===---------------------------------------------------------------------------
2430 /// SwitchInst - Multiway switch
2432 class SwitchInst : public TerminatorInst {
2433 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2434 unsigned ReservedSpace;
2435 // Operand[0] = Value to switch on
2436 // Operand[1] = Default basic block destination
2437 // Operand[2n ] = Value to match
2438 // Operand[2n+1] = BasicBlock to go to on match
2439 SwitchInst(const SwitchInst &SI);
2440 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2441 void growOperands();
2442 // allocate space for exactly zero operands
2443 void *operator new(size_t s) {
2444 return User::operator new(s, 0);
2446 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2447 /// switch on and a default destination. The number of additional cases can
2448 /// be specified here to make memory allocation more efficient. This
2449 /// constructor can also autoinsert before another instruction.
2450 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2451 Instruction *InsertBefore);
2453 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2454 /// switch on and a default destination. The number of additional cases can
2455 /// be specified here to make memory allocation more efficient. This
2456 /// constructor also autoinserts at the end of the specified BasicBlock.
2457 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2458 BasicBlock *InsertAtEnd);
2460 virtual SwitchInst *clone_impl() const;
2462 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2463 unsigned NumCases, Instruction *InsertBefore = 0) {
2464 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2466 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2467 unsigned NumCases, BasicBlock *InsertAtEnd) {
2468 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2472 /// Provide fast operand accessors
2473 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2475 // Accessor Methods for Switch stmt
2476 Value *getCondition() const { return getOperand(0); }
2477 void setCondition(Value *V) { setOperand(0, V); }
2479 BasicBlock *getDefaultDest() const {
2480 return cast<BasicBlock>(getOperand(1));
2483 /// getNumCases - return the number of 'cases' in this switch instruction.
2484 /// Note that case #0 is always the default case.
2485 unsigned getNumCases() const {
2486 return getNumOperands()/2;
2489 /// getCaseValue - Return the specified case value. Note that case #0, the
2490 /// default destination, does not have a case value.
2491 ConstantInt *getCaseValue(unsigned i) {
2492 assert(i && i < getNumCases() && "Illegal case value to get!");
2493 return getSuccessorValue(i);
2496 /// getCaseValue - Return the specified case value. Note that case #0, the
2497 /// default destination, does not have a case value.
2498 const ConstantInt *getCaseValue(unsigned i) const {
2499 assert(i && i < getNumCases() && "Illegal case value to get!");
2500 return getSuccessorValue(i);
2503 /// findCaseValue - Search all of the case values for the specified constant.
2504 /// If it is explicitly handled, return the case number of it, otherwise
2505 /// return 0 to indicate that it is handled by the default handler.
2506 unsigned findCaseValue(const ConstantInt *C) const {
2507 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2508 if (getCaseValue(i) == C)
2513 /// findCaseDest - Finds the unique case value for a given successor. Returns
2514 /// null if the successor is not found, not unique, or is the default case.
2515 ConstantInt *findCaseDest(BasicBlock *BB) {
2516 if (BB == getDefaultDest()) return NULL;
2518 ConstantInt *CI = NULL;
2519 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2520 if (getSuccessor(i) == BB) {
2521 if (CI) return NULL; // Multiple cases lead to BB.
2522 else CI = getCaseValue(i);
2528 /// addCase - Add an entry to the switch instruction...
2530 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2532 /// removeCase - This method removes the specified successor from the switch
2533 /// instruction. Note that this cannot be used to remove the default
2534 /// destination (successor #0). Also note that this operation may reorder the
2535 /// remaining cases at index idx and above.
2537 void removeCase(unsigned idx);
2539 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2540 BasicBlock *getSuccessor(unsigned idx) const {
2541 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2542 return cast<BasicBlock>(getOperand(idx*2+1));
2544 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2545 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2546 setOperand(idx*2+1, (Value*)NewSucc);
2549 // getSuccessorValue - Return the value associated with the specified
2551 ConstantInt *getSuccessorValue(unsigned idx) const {
2552 assert(idx < getNumSuccessors() && "Successor # out of range!");
2553 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2556 // setSuccessorValue - Updates the value associated with the specified
2558 void setSuccessorValue(unsigned idx, ConstantInt* SuccessorValue) {
2559 assert(idx < getNumSuccessors() && "Successor # out of range!");
2560 setOperand(idx*2, reinterpret_cast<Value*>(SuccessorValue));
2563 // Methods for support type inquiry through isa, cast, and dyn_cast:
2564 static inline bool classof(const SwitchInst *) { return true; }
2565 static inline bool classof(const Instruction *I) {
2566 return I->getOpcode() == Instruction::Switch;
2568 static inline bool classof(const Value *V) {
2569 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2572 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2573 virtual unsigned getNumSuccessorsV() const;
2574 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2578 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2581 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2584 //===----------------------------------------------------------------------===//
2585 // IndirectBrInst Class
2586 //===----------------------------------------------------------------------===//
2588 //===---------------------------------------------------------------------------
2589 /// IndirectBrInst - Indirect Branch Instruction.
2591 class IndirectBrInst : public TerminatorInst {
2592 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2593 unsigned ReservedSpace;
2594 // Operand[0] = Value to switch on
2595 // Operand[1] = Default basic block destination
2596 // Operand[2n ] = Value to match
2597 // Operand[2n+1] = BasicBlock to go to on match
2598 IndirectBrInst(const IndirectBrInst &IBI);
2599 void init(Value *Address, unsigned NumDests);
2600 void growOperands();
2601 // allocate space for exactly zero operands
2602 void *operator new(size_t s) {
2603 return User::operator new(s, 0);
2605 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2606 /// Address to jump to. The number of expected destinations can be specified
2607 /// here to make memory allocation more efficient. This constructor can also
2608 /// autoinsert before another instruction.
2609 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2611 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2612 /// Address to jump to. The number of expected destinations can be specified
2613 /// here to make memory allocation more efficient. This constructor also
2614 /// autoinserts at the end of the specified BasicBlock.
2615 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2617 virtual IndirectBrInst *clone_impl() const;
2619 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2620 Instruction *InsertBefore = 0) {
2621 return new IndirectBrInst(Address, NumDests, InsertBefore);
2623 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2624 BasicBlock *InsertAtEnd) {
2625 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2629 /// Provide fast operand accessors.
2630 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2632 // Accessor Methods for IndirectBrInst instruction.
2633 Value *getAddress() { return getOperand(0); }
2634 const Value *getAddress() const { return getOperand(0); }
2635 void setAddress(Value *V) { setOperand(0, V); }
2638 /// getNumDestinations - return the number of possible destinations in this
2639 /// indirectbr instruction.
2640 unsigned getNumDestinations() const { return getNumOperands()-1; }
2642 /// getDestination - Return the specified destination.
2643 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2644 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2646 /// addDestination - Add a destination.
2648 void addDestination(BasicBlock *Dest);
2650 /// removeDestination - This method removes the specified successor from the
2651 /// indirectbr instruction.
2652 void removeDestination(unsigned i);
2654 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2655 BasicBlock *getSuccessor(unsigned i) const {
2656 return cast<BasicBlock>(getOperand(i+1));
2658 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2659 setOperand(i+1, (Value*)NewSucc);
2662 // Methods for support type inquiry through isa, cast, and dyn_cast:
2663 static inline bool classof(const IndirectBrInst *) { return true; }
2664 static inline bool classof(const Instruction *I) {
2665 return I->getOpcode() == Instruction::IndirectBr;
2667 static inline bool classof(const Value *V) {
2668 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2671 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2672 virtual unsigned getNumSuccessorsV() const;
2673 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2677 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2680 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2683 //===----------------------------------------------------------------------===//
2685 //===----------------------------------------------------------------------===//
2687 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2688 /// calling convention of the call.
2690 class InvokeInst : public TerminatorInst {
2691 AttrListPtr AttributeList;
2692 InvokeInst(const InvokeInst &BI);
2693 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2694 ArrayRef<Value *> Args, const Twine &NameStr);
2696 /// Construct an InvokeInst given a range of arguments.
2698 /// @brief Construct an InvokeInst from a range of arguments
2699 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2700 ArrayRef<Value *> Args, unsigned Values,
2701 const Twine &NameStr, Instruction *InsertBefore);
2703 /// Construct an InvokeInst given a range of arguments.
2705 /// @brief Construct an InvokeInst from a range of arguments
2706 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2707 ArrayRef<Value *> Args, unsigned Values,
2708 const Twine &NameStr, BasicBlock *InsertAtEnd);
2710 virtual InvokeInst *clone_impl() const;
2712 static InvokeInst *Create(Value *Func,
2713 BasicBlock *IfNormal, BasicBlock *IfException,
2714 ArrayRef<Value *> Args, const Twine &NameStr = "",
2715 Instruction *InsertBefore = 0) {
2716 unsigned Values = unsigned(Args.size()) + 3;
2717 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2718 Values, NameStr, InsertBefore);
2720 static InvokeInst *Create(Value *Func,
2721 BasicBlock *IfNormal, BasicBlock *IfException,
2722 ArrayRef<Value *> Args, const Twine &NameStr,
2723 BasicBlock *InsertAtEnd) {
2724 unsigned Values = unsigned(Args.size()) + 3;
2725 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2726 Values, NameStr, InsertAtEnd);
2729 /// Provide fast operand accessors
2730 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2732 /// getNumArgOperands - Return the number of invoke arguments.
2734 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2736 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2738 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2739 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2741 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2743 CallingConv::ID getCallingConv() const {
2744 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2746 void setCallingConv(CallingConv::ID CC) {
2747 setInstructionSubclassData(static_cast<unsigned>(CC));
2750 /// getAttributes - Return the parameter attributes for this invoke.
2752 const AttrListPtr &getAttributes() const { return AttributeList; }
2754 /// setAttributes - Set the parameter attributes for this invoke.
2756 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2758 /// addAttribute - adds the attribute to the list of attributes.
2759 void addAttribute(unsigned i, Attributes attr);
2761 /// removeAttribute - removes the attribute from the list of attributes.
2762 void removeAttribute(unsigned i, Attributes attr);
2764 /// @brief Determine whether the call or the callee has the given attribute.
2765 bool paramHasAttr(unsigned i, Attributes attr) const;
2767 /// @brief Extract the alignment for a call or parameter (0=unknown).
2768 unsigned getParamAlignment(unsigned i) const {
2769 return AttributeList.getParamAlignment(i);
2772 /// @brief Return true if the call should not be inlined.
2773 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2774 void setIsNoInline(bool Value = true) {
2775 if (Value) addAttribute(~0, Attribute::NoInline);
2776 else removeAttribute(~0, Attribute::NoInline);
2779 /// @brief Determine if the call does not access memory.
2780 bool doesNotAccessMemory() const {
2781 return paramHasAttr(~0, Attribute::ReadNone);
2783 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2784 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2785 else removeAttribute(~0, Attribute::ReadNone);
2788 /// @brief Determine if the call does not access or only reads memory.
2789 bool onlyReadsMemory() const {
2790 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2792 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2793 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2794 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2797 /// @brief Determine if the call cannot return.
2798 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
2799 void setDoesNotReturn(bool DoesNotReturn = true) {
2800 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2801 else removeAttribute(~0, Attribute::NoReturn);
2804 /// @brief Determine if the call cannot unwind.
2805 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
2806 void setDoesNotThrow(bool DoesNotThrow = true) {
2807 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2808 else removeAttribute(~0, Attribute::NoUnwind);
2811 /// @brief Determine if the call returns a structure through first
2812 /// pointer argument.
2813 bool hasStructRetAttr() const {
2814 // Be friendly and also check the callee.
2815 return paramHasAttr(1, Attribute::StructRet);
2818 /// @brief Determine if any call argument is an aggregate passed by value.
2819 bool hasByValArgument() const {
2820 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2823 /// getCalledFunction - Return the function called, or null if this is an
2824 /// indirect function invocation.
2826 Function *getCalledFunction() const {
2827 return dyn_cast<Function>(Op<-3>());
2830 /// getCalledValue - Get a pointer to the function that is invoked by this
2832 const Value *getCalledValue() const { return Op<-3>(); }
2833 Value *getCalledValue() { return Op<-3>(); }
2835 /// setCalledFunction - Set the function called.
2836 void setCalledFunction(Value* Fn) {
2840 // get*Dest - Return the destination basic blocks...
2841 BasicBlock *getNormalDest() const {
2842 return cast<BasicBlock>(Op<-2>());
2844 BasicBlock *getUnwindDest() const {
2845 return cast<BasicBlock>(Op<-1>());
2847 void setNormalDest(BasicBlock *B) {
2848 Op<-2>() = reinterpret_cast<Value*>(B);
2850 void setUnwindDest(BasicBlock *B) {
2851 Op<-1>() = reinterpret_cast<Value*>(B);
2854 /// getLandingPadInst - Get the landingpad instruction from the landing pad
2855 /// block (the unwind destination).
2856 LandingPadInst *getLandingPadInst() const;
2858 BasicBlock *getSuccessor(unsigned i) const {
2859 assert(i < 2 && "Successor # out of range for invoke!");
2860 return i == 0 ? getNormalDest() : getUnwindDest();
2863 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2864 assert(idx < 2 && "Successor # out of range for invoke!");
2865 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2868 unsigned getNumSuccessors() const { return 2; }
2870 // Methods for support type inquiry through isa, cast, and dyn_cast:
2871 static inline bool classof(const InvokeInst *) { return true; }
2872 static inline bool classof(const Instruction *I) {
2873 return (I->getOpcode() == Instruction::Invoke);
2875 static inline bool classof(const Value *V) {
2876 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2880 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2881 virtual unsigned getNumSuccessorsV() const;
2882 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2884 // Shadow Instruction::setInstructionSubclassData with a private forwarding
2885 // method so that subclasses cannot accidentally use it.
2886 void setInstructionSubclassData(unsigned short D) {
2887 Instruction::setInstructionSubclassData(D);
2892 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
2895 InvokeInst::InvokeInst(Value *Func,
2896 BasicBlock *IfNormal, BasicBlock *IfException,
2897 ArrayRef<Value *> Args, unsigned Values,
2898 const Twine &NameStr, Instruction *InsertBefore)
2899 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2900 ->getElementType())->getReturnType(),
2901 Instruction::Invoke,
2902 OperandTraits<InvokeInst>::op_end(this) - Values,
2903 Values, InsertBefore) {
2904 init(Func, IfNormal, IfException, Args, NameStr);
2906 InvokeInst::InvokeInst(Value *Func,
2907 BasicBlock *IfNormal, BasicBlock *IfException,
2908 ArrayRef<Value *> Args, unsigned Values,
2909 const Twine &NameStr, BasicBlock *InsertAtEnd)
2910 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2911 ->getElementType())->getReturnType(),
2912 Instruction::Invoke,
2913 OperandTraits<InvokeInst>::op_end(this) - Values,
2914 Values, InsertAtEnd) {
2915 init(Func, IfNormal, IfException, Args, NameStr);
2918 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2920 //===----------------------------------------------------------------------===//
2922 //===----------------------------------------------------------------------===//
2924 //===---------------------------------------------------------------------------
2925 /// UnwindInst - Immediately exit the current function, unwinding the stack
2926 /// until an invoke instruction is found.
2928 class UnwindInst : public TerminatorInst {
2929 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2931 virtual UnwindInst *clone_impl() const;
2933 // allocate space for exactly zero operands
2934 void *operator new(size_t s) {
2935 return User::operator new(s, 0);
2937 explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2938 explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2940 unsigned getNumSuccessors() const { return 0; }
2942 // Methods for support type inquiry through isa, cast, and dyn_cast:
2943 static inline bool classof(const UnwindInst *) { return true; }
2944 static inline bool classof(const Instruction *I) {
2945 return I->getOpcode() == Instruction::Unwind;
2947 static inline bool classof(const Value *V) {
2948 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2951 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2952 virtual unsigned getNumSuccessorsV() const;
2953 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2956 //===----------------------------------------------------------------------===//
2958 //===----------------------------------------------------------------------===//
2960 //===---------------------------------------------------------------------------
2961 /// ResumeInst - Resume the propagation of an exception.
2963 class ResumeInst : public TerminatorInst {
2964 ResumeInst(const ResumeInst &RI);
2966 explicit ResumeInst(Value *Exn, Instruction *InsertBefore=0);
2967 ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
2969 virtual ResumeInst *clone_impl() const;
2971 static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = 0) {
2972 return new(1) ResumeInst(Exn, InsertBefore);
2974 static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
2975 return new(1) ResumeInst(Exn, InsertAtEnd);
2978 /// Provide fast operand accessors
2979 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2981 /// Convenience accessor.
2982 Value *getValue() const { return Op<0>(); }
2984 unsigned getNumSuccessors() const { return 0; }
2986 // Methods for support type inquiry through isa, cast, and dyn_cast:
2987 static inline bool classof(const ResumeInst *) { return true; }
2988 static inline bool classof(const Instruction *I) {
2989 return I->getOpcode() == Instruction::Resume;
2991 static inline bool classof(const Value *V) {
2992 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2995 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2996 virtual unsigned getNumSuccessorsV() const;
2997 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3001 struct OperandTraits<ResumeInst> :
3002 public FixedNumOperandTraits<ResumeInst, 1> {
3005 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
3007 //===----------------------------------------------------------------------===//
3008 // UnreachableInst Class
3009 //===----------------------------------------------------------------------===//
3011 //===---------------------------------------------------------------------------
3012 /// UnreachableInst - This function has undefined behavior. In particular, the
3013 /// presence of this instruction indicates some higher level knowledge that the
3014 /// end of the block cannot be reached.
3016 class UnreachableInst : public TerminatorInst {
3017 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
3019 virtual UnreachableInst *clone_impl() const;
3022 // allocate space for exactly zero operands
3023 void *operator new(size_t s) {
3024 return User::operator new(s, 0);
3026 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
3027 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
3029 unsigned getNumSuccessors() const { return 0; }
3031 // Methods for support type inquiry through isa, cast, and dyn_cast:
3032 static inline bool classof(const UnreachableInst *) { return true; }
3033 static inline bool classof(const Instruction *I) {
3034 return I->getOpcode() == Instruction::Unreachable;
3036 static inline bool classof(const Value *V) {
3037 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3040 virtual BasicBlock *getSuccessorV(unsigned idx) const;
3041 virtual unsigned getNumSuccessorsV() const;
3042 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3045 //===----------------------------------------------------------------------===//
3047 //===----------------------------------------------------------------------===//
3049 /// @brief This class represents a truncation of integer types.
3050 class TruncInst : public CastInst {
3052 /// @brief Clone an identical TruncInst
3053 virtual TruncInst *clone_impl() const;
3056 /// @brief Constructor with insert-before-instruction semantics
3058 Value *S, ///< The value to be truncated
3059 Type *Ty, ///< The (smaller) type to truncate to
3060 const Twine &NameStr = "", ///< A name for the new instruction
3061 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3064 /// @brief Constructor with insert-at-end-of-block semantics
3066 Value *S, ///< The value to be truncated
3067 Type *Ty, ///< The (smaller) type to truncate to
3068 const Twine &NameStr, ///< A name for the new instruction
3069 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3072 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3073 static inline bool classof(const TruncInst *) { return true; }
3074 static inline bool classof(const Instruction *I) {
3075 return I->getOpcode() == Trunc;
3077 static inline bool classof(const Value *V) {
3078 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3082 //===----------------------------------------------------------------------===//
3084 //===----------------------------------------------------------------------===//
3086 /// @brief This class represents zero extension of integer types.
3087 class ZExtInst : public CastInst {
3089 /// @brief Clone an identical ZExtInst
3090 virtual ZExtInst *clone_impl() const;
3093 /// @brief Constructor with insert-before-instruction semantics
3095 Value *S, ///< The value to be zero extended
3096 Type *Ty, ///< The type to zero extend to
3097 const Twine &NameStr = "", ///< A name for the new instruction
3098 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3101 /// @brief Constructor with insert-at-end semantics.
3103 Value *S, ///< The value to be zero extended
3104 Type *Ty, ///< The type to zero extend to
3105 const Twine &NameStr, ///< A name for the new instruction
3106 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3109 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3110 static inline bool classof(const ZExtInst *) { return true; }
3111 static inline bool classof(const Instruction *I) {
3112 return I->getOpcode() == ZExt;
3114 static inline bool classof(const Value *V) {
3115 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3119 //===----------------------------------------------------------------------===//
3121 //===----------------------------------------------------------------------===//
3123 /// @brief This class represents a sign extension of integer types.
3124 class SExtInst : public CastInst {
3126 /// @brief Clone an identical SExtInst
3127 virtual SExtInst *clone_impl() const;
3130 /// @brief Constructor with insert-before-instruction semantics
3132 Value *S, ///< The value to be sign extended
3133 Type *Ty, ///< The type to sign extend to
3134 const Twine &NameStr = "", ///< A name for the new instruction
3135 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3138 /// @brief Constructor with insert-at-end-of-block semantics
3140 Value *S, ///< The value to be sign extended
3141 Type *Ty, ///< The type to sign extend to
3142 const Twine &NameStr, ///< A name for the new instruction
3143 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3146 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3147 static inline bool classof(const SExtInst *) { return true; }
3148 static inline bool classof(const Instruction *I) {
3149 return I->getOpcode() == SExt;
3151 static inline bool classof(const Value *V) {
3152 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3156 //===----------------------------------------------------------------------===//
3157 // FPTruncInst Class
3158 //===----------------------------------------------------------------------===//
3160 /// @brief This class represents a truncation of floating point types.
3161 class FPTruncInst : public CastInst {
3163 /// @brief Clone an identical FPTruncInst
3164 virtual FPTruncInst *clone_impl() const;
3167 /// @brief Constructor with insert-before-instruction semantics
3169 Value *S, ///< The value to be truncated
3170 Type *Ty, ///< The type to truncate to
3171 const Twine &NameStr = "", ///< A name for the new instruction
3172 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3175 /// @brief Constructor with insert-before-instruction semantics
3177 Value *S, ///< The value to be truncated
3178 Type *Ty, ///< The type to truncate to
3179 const Twine &NameStr, ///< A name for the new instruction
3180 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3183 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3184 static inline bool classof(const FPTruncInst *) { return true; }
3185 static inline bool classof(const Instruction *I) {
3186 return I->getOpcode() == FPTrunc;
3188 static inline bool classof(const Value *V) {
3189 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3193 //===----------------------------------------------------------------------===//
3195 //===----------------------------------------------------------------------===//
3197 /// @brief This class represents an extension of floating point types.
3198 class FPExtInst : public CastInst {
3200 /// @brief Clone an identical FPExtInst
3201 virtual FPExtInst *clone_impl() const;
3204 /// @brief Constructor with insert-before-instruction semantics
3206 Value *S, ///< The value to be extended
3207 Type *Ty, ///< The type to extend to
3208 const Twine &NameStr = "", ///< A name for the new instruction
3209 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3212 /// @brief Constructor with insert-at-end-of-block semantics
3214 Value *S, ///< The value to be extended
3215 Type *Ty, ///< The type to extend to
3216 const Twine &NameStr, ///< A name for the new instruction
3217 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3220 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3221 static inline bool classof(const FPExtInst *) { return true; }
3222 static inline bool classof(const Instruction *I) {
3223 return I->getOpcode() == FPExt;
3225 static inline bool classof(const Value *V) {
3226 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3230 //===----------------------------------------------------------------------===//
3232 //===----------------------------------------------------------------------===//
3234 /// @brief This class represents a cast unsigned integer to floating point.
3235 class UIToFPInst : public CastInst {
3237 /// @brief Clone an identical UIToFPInst
3238 virtual UIToFPInst *clone_impl() const;
3241 /// @brief Constructor with insert-before-instruction semantics
3243 Value *S, ///< The value to be converted
3244 Type *Ty, ///< The type to convert to
3245 const Twine &NameStr = "", ///< A name for the new instruction
3246 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3249 /// @brief Constructor with insert-at-end-of-block semantics
3251 Value *S, ///< The value to be converted
3252 Type *Ty, ///< The type to convert to
3253 const Twine &NameStr, ///< A name for the new instruction
3254 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3257 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3258 static inline bool classof(const UIToFPInst *) { return true; }
3259 static inline bool classof(const Instruction *I) {
3260 return I->getOpcode() == UIToFP;
3262 static inline bool classof(const Value *V) {
3263 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3267 //===----------------------------------------------------------------------===//
3269 //===----------------------------------------------------------------------===//
3271 /// @brief This class represents a cast from signed integer to floating point.
3272 class SIToFPInst : public CastInst {
3274 /// @brief Clone an identical SIToFPInst
3275 virtual SIToFPInst *clone_impl() const;
3278 /// @brief Constructor with insert-before-instruction semantics
3280 Value *S, ///< The value to be converted
3281 Type *Ty, ///< The type to convert to
3282 const Twine &NameStr = "", ///< A name for the new instruction
3283 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3286 /// @brief Constructor with insert-at-end-of-block semantics
3288 Value *S, ///< The value to be converted
3289 Type *Ty, ///< The type to convert to
3290 const Twine &NameStr, ///< A name for the new instruction
3291 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3294 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3295 static inline bool classof(const SIToFPInst *) { return true; }
3296 static inline bool classof(const Instruction *I) {
3297 return I->getOpcode() == SIToFP;
3299 static inline bool classof(const Value *V) {
3300 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3304 //===----------------------------------------------------------------------===//
3306 //===----------------------------------------------------------------------===//
3308 /// @brief This class represents a cast from floating point to unsigned integer
3309 class FPToUIInst : public CastInst {
3311 /// @brief Clone an identical FPToUIInst
3312 virtual FPToUIInst *clone_impl() const;
3315 /// @brief Constructor with insert-before-instruction semantics
3317 Value *S, ///< The value to be converted
3318 Type *Ty, ///< The type to convert to
3319 const Twine &NameStr = "", ///< A name for the new instruction
3320 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3323 /// @brief Constructor with insert-at-end-of-block semantics
3325 Value *S, ///< The value to be converted
3326 Type *Ty, ///< The type to convert to
3327 const Twine &NameStr, ///< A name for the new instruction
3328 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3331 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3332 static inline bool classof(const FPToUIInst *) { return true; }
3333 static inline bool classof(const Instruction *I) {
3334 return I->getOpcode() == FPToUI;
3336 static inline bool classof(const Value *V) {
3337 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3341 //===----------------------------------------------------------------------===//
3343 //===----------------------------------------------------------------------===//
3345 /// @brief This class represents a cast from floating point to signed integer.
3346 class FPToSIInst : public CastInst {
3348 /// @brief Clone an identical FPToSIInst
3349 virtual FPToSIInst *clone_impl() const;
3352 /// @brief Constructor with insert-before-instruction semantics
3354 Value *S, ///< The value to be converted
3355 Type *Ty, ///< The type to convert to
3356 const Twine &NameStr = "", ///< A name for the new instruction
3357 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3360 /// @brief Constructor with insert-at-end-of-block semantics
3362 Value *S, ///< The value to be converted
3363 Type *Ty, ///< The type to convert to
3364 const Twine &NameStr, ///< A name for the new instruction
3365 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3368 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3369 static inline bool classof(const FPToSIInst *) { return true; }
3370 static inline bool classof(const Instruction *I) {
3371 return I->getOpcode() == FPToSI;
3373 static inline bool classof(const Value *V) {
3374 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3378 //===----------------------------------------------------------------------===//
3379 // IntToPtrInst Class
3380 //===----------------------------------------------------------------------===//
3382 /// @brief This class represents a cast from an integer to a pointer.
3383 class IntToPtrInst : public CastInst {
3385 /// @brief Constructor with insert-before-instruction semantics
3387 Value *S, ///< The value to be converted
3388 Type *Ty, ///< The type to convert to
3389 const Twine &NameStr = "", ///< A name for the new instruction
3390 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3393 /// @brief Constructor with insert-at-end-of-block semantics
3395 Value *S, ///< The value to be converted
3396 Type *Ty, ///< The type to convert to
3397 const Twine &NameStr, ///< A name for the new instruction
3398 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3401 /// @brief Clone an identical IntToPtrInst
3402 virtual IntToPtrInst *clone_impl() const;
3404 // Methods for support type inquiry through isa, cast, and dyn_cast:
3405 static inline bool classof(const IntToPtrInst *) { return true; }
3406 static inline bool classof(const Instruction *I) {
3407 return I->getOpcode() == IntToPtr;
3409 static inline bool classof(const Value *V) {
3410 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3414 //===----------------------------------------------------------------------===//
3415 // PtrToIntInst Class
3416 //===----------------------------------------------------------------------===//
3418 /// @brief This class represents a cast from a pointer to an integer
3419 class PtrToIntInst : public CastInst {
3421 /// @brief Clone an identical PtrToIntInst
3422 virtual PtrToIntInst *clone_impl() const;
3425 /// @brief Constructor with insert-before-instruction semantics
3427 Value *S, ///< The value to be converted
3428 Type *Ty, ///< The type to convert to
3429 const Twine &NameStr = "", ///< A name for the new instruction
3430 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3433 /// @brief Constructor with insert-at-end-of-block semantics
3435 Value *S, ///< The value to be converted
3436 Type *Ty, ///< The type to convert to
3437 const Twine &NameStr, ///< A name for the new instruction
3438 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3441 // Methods for support type inquiry through isa, cast, and dyn_cast:
3442 static inline bool classof(const PtrToIntInst *) { return true; }
3443 static inline bool classof(const Instruction *I) {
3444 return I->getOpcode() == PtrToInt;
3446 static inline bool classof(const Value *V) {
3447 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3451 //===----------------------------------------------------------------------===//
3452 // BitCastInst Class
3453 //===----------------------------------------------------------------------===//
3455 /// @brief This class represents a no-op cast from one type to another.
3456 class BitCastInst : public CastInst {
3458 /// @brief Clone an identical BitCastInst
3459 virtual BitCastInst *clone_impl() const;
3462 /// @brief Constructor with insert-before-instruction semantics
3464 Value *S, ///< The value to be casted
3465 Type *Ty, ///< The type to casted to
3466 const Twine &NameStr = "", ///< A name for the new instruction
3467 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3470 /// @brief Constructor with insert-at-end-of-block semantics
3472 Value *S, ///< The value to be casted
3473 Type *Ty, ///< The type to casted to
3474 const Twine &NameStr, ///< A name for the new instruction
3475 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3478 // Methods for support type inquiry through isa, cast, and dyn_cast:
3479 static inline bool classof(const BitCastInst *) { return true; }
3480 static inline bool classof(const Instruction *I) {
3481 return I->getOpcode() == BitCast;
3483 static inline bool classof(const Value *V) {
3484 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3488 } // End llvm namespace