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_IR_INSTRUCTIONS_H
17 #define LLVM_IR_INSTRUCTIONS_H
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/IR/Attributes.h"
22 #include "llvm/IR/CallingConv.h"
23 #include "llvm/IR/DerivedTypes.h"
24 #include "llvm/IR/InstrTypes.h"
25 #include "llvm/Support/ErrorHandling.h"
40 // Consume = 3, // Not specified yet.
44 SequentiallyConsistent = 7
47 enum SynchronizationScope {
52 //===----------------------------------------------------------------------===//
54 //===----------------------------------------------------------------------===//
56 /// AllocaInst - an instruction to allocate memory on the stack
58 class AllocaInst : public UnaryInstruction {
60 virtual AllocaInst *clone_impl() const;
62 explicit AllocaInst(Type *Ty, Value *ArraySize = 0,
63 const Twine &Name = "", Instruction *InsertBefore = 0);
64 AllocaInst(Type *Ty, Value *ArraySize,
65 const Twine &Name, BasicBlock *InsertAtEnd);
67 AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
68 AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
70 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
71 const Twine &Name = "", Instruction *InsertBefore = 0);
72 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
73 const Twine &Name, BasicBlock *InsertAtEnd);
75 // Out of line virtual method, so the vtable, etc. has a home.
76 virtual ~AllocaInst();
78 /// isArrayAllocation - Return true if there is an allocation size parameter
79 /// to the allocation instruction that is not 1.
81 bool isArrayAllocation() const;
83 /// getArraySize - Get the number of elements allocated. For a simple
84 /// allocation of a single element, this will return a constant 1 value.
86 const Value *getArraySize() const { return getOperand(0); }
87 Value *getArraySize() { return getOperand(0); }
89 /// getType - Overload to return most specific pointer type
91 PointerType *getType() const {
92 return cast<PointerType>(Instruction::getType());
95 /// getAllocatedType - Return the type that is being allocated by the
98 Type *getAllocatedType() const;
100 /// getAlignment - Return the alignment of the memory that is being allocated
101 /// by the instruction.
103 unsigned getAlignment() const {
104 return (1u << getSubclassDataFromInstruction()) >> 1;
106 void setAlignment(unsigned Align);
108 /// isStaticAlloca - Return true if this alloca is in the entry block of the
109 /// function and is a constant size. If so, the code generator will fold it
110 /// into the prolog/epilog code, so it is basically free.
111 bool isStaticAlloca() const;
113 // Methods for support type inquiry through isa, cast, and dyn_cast:
114 static inline bool classof(const 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 /// \brief Returns the address space of the pointer operand.
228 unsigned getPointerAddressSpace() const {
229 return getPointerOperand()->getType()->getPointerAddressSpace();
233 // Methods for support type inquiry through isa, cast, and dyn_cast:
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) LLVM_DELETED_FUNCTION;
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 /// \brief Returns the address space of the pointer operand.
351 unsigned getPointerAddressSpace() const {
352 return getPointerOperand()->getType()->getPointerAddressSpace();
355 // Methods for support type inquiry through isa, cast, and dyn_cast:
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) LLVM_DELETED_FUNCTION;
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 Instruction *I) {
428 return I->getOpcode() == Instruction::Fence;
430 static inline bool classof(const Value *V) {
431 return isa<Instruction>(V) && classof(cast<Instruction>(V));
434 // Shadow Instruction::setInstructionSubclassData with a private forwarding
435 // method so that subclasses cannot accidentally use it.
436 void setInstructionSubclassData(unsigned short D) {
437 Instruction::setInstructionSubclassData(D);
441 //===----------------------------------------------------------------------===//
442 // AtomicCmpXchgInst Class
443 //===----------------------------------------------------------------------===//
445 /// AtomicCmpXchgInst - an instruction that atomically checks whether a
446 /// specified value is in a memory location, and, if it is, stores a new value
447 /// there. Returns the value that was loaded.
449 class AtomicCmpXchgInst : public Instruction {
450 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
451 void Init(Value *Ptr, Value *Cmp, Value *NewVal,
452 AtomicOrdering Ordering, SynchronizationScope SynchScope);
454 virtual AtomicCmpXchgInst *clone_impl() const;
456 // allocate space for exactly three operands
457 void *operator new(size_t s) {
458 return User::operator new(s, 3);
460 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
461 AtomicOrdering Ordering, SynchronizationScope SynchScope,
462 Instruction *InsertBefore = 0);
463 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
464 AtomicOrdering Ordering, SynchronizationScope SynchScope,
465 BasicBlock *InsertAtEnd);
467 /// isVolatile - Return true if this is a cmpxchg from a volatile memory
470 bool isVolatile() const {
471 return getSubclassDataFromInstruction() & 1;
474 /// setVolatile - Specify whether this is a volatile cmpxchg.
476 void setVolatile(bool V) {
477 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
481 /// Transparently provide more efficient getOperand methods.
482 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
484 /// Set the ordering constraint on this cmpxchg.
485 void setOrdering(AtomicOrdering Ordering) {
486 assert(Ordering != NotAtomic &&
487 "CmpXchg instructions can only be atomic.");
488 setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
492 /// Specify whether this cmpxchg is atomic and orders other operations with
493 /// respect to all concurrently executing threads, or only with respect to
494 /// signal handlers executing in the same thread.
495 void setSynchScope(SynchronizationScope SynchScope) {
496 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
500 /// Returns the ordering constraint on this cmpxchg.
501 AtomicOrdering getOrdering() const {
502 return AtomicOrdering(getSubclassDataFromInstruction() >> 2);
505 /// Returns whether this cmpxchg is atomic between threads or only within a
507 SynchronizationScope getSynchScope() const {
508 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
511 Value *getPointerOperand() { return getOperand(0); }
512 const Value *getPointerOperand() const { return getOperand(0); }
513 static unsigned getPointerOperandIndex() { return 0U; }
515 Value *getCompareOperand() { return getOperand(1); }
516 const Value *getCompareOperand() const { return getOperand(1); }
518 Value *getNewValOperand() { return getOperand(2); }
519 const Value *getNewValOperand() const { return getOperand(2); }
521 /// \brief Returns the address space of the pointer operand.
522 unsigned getPointerAddressSpace() const {
523 return getPointerOperand()->getType()->getPointerAddressSpace();
526 // Methods for support type inquiry through isa, cast, and dyn_cast:
527 static inline bool classof(const Instruction *I) {
528 return I->getOpcode() == Instruction::AtomicCmpXchg;
530 static inline bool classof(const Value *V) {
531 return isa<Instruction>(V) && classof(cast<Instruction>(V));
534 // Shadow Instruction::setInstructionSubclassData with a private forwarding
535 // method so that subclasses cannot accidentally use it.
536 void setInstructionSubclassData(unsigned short D) {
537 Instruction::setInstructionSubclassData(D);
542 struct OperandTraits<AtomicCmpXchgInst> :
543 public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
546 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)
548 //===----------------------------------------------------------------------===//
549 // AtomicRMWInst Class
550 //===----------------------------------------------------------------------===//
552 /// AtomicRMWInst - an instruction that atomically reads a memory location,
553 /// combines it with another value, and then stores the result back. Returns
556 class AtomicRMWInst : public Instruction {
557 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
559 virtual AtomicRMWInst *clone_impl() const;
561 /// This enumeration lists the possible modifications atomicrmw can make. In
562 /// the descriptions, 'p' is the pointer to the instruction's memory location,
563 /// 'old' is the initial value of *p, and 'v' is the other value passed to the
564 /// instruction. These instructions always return 'old'.
580 /// *p = old >signed v ? old : v
582 /// *p = old <signed v ? old : v
584 /// *p = old >unsigned v ? old : v
586 /// *p = old <unsigned v ? old : v
594 // allocate space for exactly two operands
595 void *operator new(size_t s) {
596 return User::operator new(s, 2);
598 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
599 AtomicOrdering Ordering, SynchronizationScope SynchScope,
600 Instruction *InsertBefore = 0);
601 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
602 AtomicOrdering Ordering, SynchronizationScope SynchScope,
603 BasicBlock *InsertAtEnd);
605 BinOp getOperation() const {
606 return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
609 void setOperation(BinOp Operation) {
610 unsigned short SubclassData = getSubclassDataFromInstruction();
611 setInstructionSubclassData((SubclassData & 31) |
615 /// isVolatile - Return true if this is a RMW on a volatile memory location.
617 bool isVolatile() const {
618 return getSubclassDataFromInstruction() & 1;
621 /// setVolatile - Specify whether this is a volatile RMW or not.
623 void setVolatile(bool V) {
624 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
628 /// Transparently provide more efficient getOperand methods.
629 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
631 /// Set the ordering constraint on this RMW.
632 void setOrdering(AtomicOrdering Ordering) {
633 assert(Ordering != NotAtomic &&
634 "atomicrmw instructions can only be atomic.");
635 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
639 /// Specify whether this RMW orders other operations with respect to all
640 /// concurrently executing threads, or only with respect to signal handlers
641 /// executing in the same thread.
642 void setSynchScope(SynchronizationScope SynchScope) {
643 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
647 /// Returns the ordering constraint on this RMW.
648 AtomicOrdering getOrdering() const {
649 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
652 /// Returns whether this RMW is atomic between threads or only within a
654 SynchronizationScope getSynchScope() const {
655 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
658 Value *getPointerOperand() { return getOperand(0); }
659 const Value *getPointerOperand() const { return getOperand(0); }
660 static unsigned getPointerOperandIndex() { return 0U; }
662 Value *getValOperand() { return getOperand(1); }
663 const Value *getValOperand() const { return getOperand(1); }
665 /// \brief Returns the address space of the pointer operand.
666 unsigned getPointerAddressSpace() const {
667 return getPointerOperand()->getType()->getPointerAddressSpace();
670 // Methods for support type inquiry through isa, cast, and dyn_cast:
671 static inline bool classof(const Instruction *I) {
672 return I->getOpcode() == Instruction::AtomicRMW;
674 static inline bool classof(const Value *V) {
675 return isa<Instruction>(V) && classof(cast<Instruction>(V));
678 void Init(BinOp Operation, Value *Ptr, Value *Val,
679 AtomicOrdering Ordering, SynchronizationScope SynchScope);
680 // Shadow Instruction::setInstructionSubclassData with a private forwarding
681 // method so that subclasses cannot accidentally use it.
682 void setInstructionSubclassData(unsigned short D) {
683 Instruction::setInstructionSubclassData(D);
688 struct OperandTraits<AtomicRMWInst>
689 : public FixedNumOperandTraits<AtomicRMWInst,2> {
692 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)
694 //===----------------------------------------------------------------------===//
695 // GetElementPtrInst Class
696 //===----------------------------------------------------------------------===//
698 // checkGEPType - Simple wrapper function to give a better assertion failure
699 // message on bad indexes for a gep instruction.
701 inline Type *checkGEPType(Type *Ty) {
702 assert(Ty && "Invalid GetElementPtrInst indices for type!");
706 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
707 /// access elements of arrays and structs
709 class GetElementPtrInst : public Instruction {
710 GetElementPtrInst(const GetElementPtrInst &GEPI);
711 void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
713 /// Constructors - Create a getelementptr instruction with a base pointer an
714 /// list of indices. The first ctor can optionally insert before an existing
715 /// instruction, the second appends the new instruction to the specified
717 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
718 unsigned Values, const Twine &NameStr,
719 Instruction *InsertBefore);
720 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
721 unsigned Values, const Twine &NameStr,
722 BasicBlock *InsertAtEnd);
724 virtual GetElementPtrInst *clone_impl() const;
726 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
727 const Twine &NameStr = "",
728 Instruction *InsertBefore = 0) {
729 unsigned Values = 1 + unsigned(IdxList.size());
731 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
733 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
734 const Twine &NameStr,
735 BasicBlock *InsertAtEnd) {
736 unsigned Values = 1 + unsigned(IdxList.size());
738 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
741 /// Create an "inbounds" getelementptr. See the documentation for the
742 /// "inbounds" flag in LangRef.html for details.
743 static GetElementPtrInst *CreateInBounds(Value *Ptr,
744 ArrayRef<Value *> IdxList,
745 const Twine &NameStr = "",
746 Instruction *InsertBefore = 0) {
747 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
748 GEP->setIsInBounds(true);
751 static GetElementPtrInst *CreateInBounds(Value *Ptr,
752 ArrayRef<Value *> IdxList,
753 const Twine &NameStr,
754 BasicBlock *InsertAtEnd) {
755 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
756 GEP->setIsInBounds(true);
760 /// Transparently provide more efficient getOperand methods.
761 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
763 // getType - Overload to return most specific sequential type.
764 SequentialType *getType() const {
765 return cast<SequentialType>(Instruction::getType());
768 /// \brief Returns the address space of this instruction's pointer type.
769 unsigned getAddressSpace() const {
770 // Note that this is always the same as the pointer operand's address space
771 // and that is cheaper to compute, so cheat here.
772 return getPointerAddressSpace();
775 /// getIndexedType - Returns the type of the element that would be loaded with
776 /// a load instruction with the specified parameters.
778 /// Null is returned if the indices are invalid for the specified
781 static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList);
782 static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList);
783 static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList);
785 inline op_iterator idx_begin() { return op_begin()+1; }
786 inline const_op_iterator idx_begin() const { return op_begin()+1; }
787 inline op_iterator idx_end() { return op_end(); }
788 inline const_op_iterator idx_end() const { return op_end(); }
790 Value *getPointerOperand() {
791 return getOperand(0);
793 const Value *getPointerOperand() const {
794 return getOperand(0);
796 static unsigned getPointerOperandIndex() {
797 return 0U; // get index for modifying correct operand.
800 /// getPointerOperandType - Method to return the pointer operand as a
802 Type *getPointerOperandType() const {
803 return getPointerOperand()->getType();
806 /// \brief Returns the address space of the pointer operand.
807 unsigned getPointerAddressSpace() const {
808 return getPointerOperandType()->getPointerAddressSpace();
811 /// GetGEPReturnType - Returns the pointer type returned by the GEP
812 /// instruction, which may be a vector of pointers.
813 static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
814 Type *PtrTy = PointerType::get(checkGEPType(
815 getIndexedType(Ptr->getType(), IdxList)),
816 Ptr->getType()->getPointerAddressSpace());
818 if (Ptr->getType()->isVectorTy()) {
819 unsigned NumElem = cast<VectorType>(Ptr->getType())->getNumElements();
820 return VectorType::get(PtrTy, NumElem);
827 unsigned getNumIndices() const { // Note: always non-negative
828 return getNumOperands() - 1;
831 bool hasIndices() const {
832 return getNumOperands() > 1;
835 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
836 /// zeros. If so, the result pointer and the first operand have the same
837 /// value, just potentially different types.
838 bool hasAllZeroIndices() const;
840 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
841 /// constant integers. If so, the result pointer and the first operand have
842 /// a constant offset between them.
843 bool hasAllConstantIndices() const;
845 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
846 /// See LangRef.html for the meaning of inbounds on a getelementptr.
847 void setIsInBounds(bool b = true);
849 /// isInBounds - Determine whether the GEP has the inbounds flag.
850 bool isInBounds() const;
852 /// \brief Accumulate the constant address offset of this GEP if possible.
854 /// This routine accepts an APInt into which it will accumulate the constant
855 /// offset of this GEP if the GEP is in fact constant. If the GEP is not
856 /// all-constant, it returns false and the value of the offset APInt is
857 /// undefined (it is *not* preserved!). The APInt passed into this routine
858 /// must be at least as wide as the IntPtr type for the address space of
859 /// the base GEP pointer.
860 bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
862 // Methods for support type inquiry through isa, cast, and dyn_cast:
863 static inline bool classof(const Instruction *I) {
864 return (I->getOpcode() == Instruction::GetElementPtr);
866 static inline bool classof(const Value *V) {
867 return isa<Instruction>(V) && classof(cast<Instruction>(V));
872 struct OperandTraits<GetElementPtrInst> :
873 public VariadicOperandTraits<GetElementPtrInst, 1> {
876 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
877 ArrayRef<Value *> IdxList,
879 const Twine &NameStr,
880 Instruction *InsertBefore)
881 : Instruction(getGEPReturnType(Ptr, IdxList),
883 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
884 Values, InsertBefore) {
885 init(Ptr, IdxList, NameStr);
887 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
888 ArrayRef<Value *> IdxList,
890 const Twine &NameStr,
891 BasicBlock *InsertAtEnd)
892 : Instruction(getGEPReturnType(Ptr, IdxList),
894 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
895 Values, InsertAtEnd) {
896 init(Ptr, IdxList, NameStr);
900 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
903 //===----------------------------------------------------------------------===//
905 //===----------------------------------------------------------------------===//
907 /// This instruction compares its operands according to the predicate given
908 /// to the constructor. It only operates on integers or pointers. The operands
909 /// must be identical types.
910 /// \brief Represent an integer comparison operator.
911 class ICmpInst: public CmpInst {
913 assert(getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE &&
914 getPredicate() <= CmpInst::LAST_ICMP_PREDICATE &&
915 "Invalid ICmp predicate value");
916 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
917 "Both operands to ICmp instruction are not of the same type!");
918 // Check that the operands are the right type
919 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
920 getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
921 "Invalid operand types for ICmp instruction");
925 /// \brief Clone an identical ICmpInst
926 virtual ICmpInst *clone_impl() const;
928 /// \brief Constructor with insert-before-instruction semantics.
930 Instruction *InsertBefore, ///< Where to insert
931 Predicate pred, ///< The predicate to use for the comparison
932 Value *LHS, ///< The left-hand-side of the expression
933 Value *RHS, ///< The right-hand-side of the expression
934 const Twine &NameStr = "" ///< Name of the instruction
935 ) : CmpInst(makeCmpResultType(LHS->getType()),
936 Instruction::ICmp, pred, LHS, RHS, NameStr,
943 /// \brief Constructor with insert-at-end semantics.
945 BasicBlock &InsertAtEnd, ///< Block to insert into.
946 Predicate pred, ///< The predicate to use for the comparison
947 Value *LHS, ///< The left-hand-side of the expression
948 Value *RHS, ///< The right-hand-side of the expression
949 const Twine &NameStr = "" ///< Name of the instruction
950 ) : CmpInst(makeCmpResultType(LHS->getType()),
951 Instruction::ICmp, pred, LHS, RHS, NameStr,
958 /// \brief Constructor with no-insertion semantics
960 Predicate pred, ///< The predicate to use for the comparison
961 Value *LHS, ///< The left-hand-side of the expression
962 Value *RHS, ///< The right-hand-side of the expression
963 const Twine &NameStr = "" ///< Name of the instruction
964 ) : CmpInst(makeCmpResultType(LHS->getType()),
965 Instruction::ICmp, pred, LHS, RHS, NameStr) {
971 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
972 /// @returns the predicate that would be the result if the operand were
973 /// regarded as signed.
974 /// \brief Return the signed version of the predicate
975 Predicate getSignedPredicate() const {
976 return getSignedPredicate(getPredicate());
979 /// This is a static version that you can use without an instruction.
980 /// \brief Return the signed version of the predicate.
981 static Predicate getSignedPredicate(Predicate pred);
983 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
984 /// @returns the predicate that would be the result if the operand were
985 /// regarded as unsigned.
986 /// \brief Return the unsigned version of the predicate
987 Predicate getUnsignedPredicate() const {
988 return getUnsignedPredicate(getPredicate());
991 /// This is a static version that you can use without an instruction.
992 /// \brief Return the unsigned version of the predicate.
993 static Predicate getUnsignedPredicate(Predicate pred);
995 /// isEquality - Return true if this predicate is either EQ or NE. This also
996 /// tests for commutativity.
997 static bool isEquality(Predicate P) {
998 return P == ICMP_EQ || P == ICMP_NE;
1001 /// isEquality - Return true if this predicate is either EQ or NE. This also
1002 /// tests for commutativity.
1003 bool isEquality() const {
1004 return isEquality(getPredicate());
1007 /// @returns true if the predicate of this ICmpInst is commutative
1008 /// \brief Determine if this relation is commutative.
1009 bool isCommutative() const { return isEquality(); }
1011 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1013 bool isRelational() const {
1014 return !isEquality();
1017 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1019 static bool isRelational(Predicate P) {
1020 return !isEquality(P);
1023 /// Initialize a set of values that all satisfy the predicate with C.
1024 /// \brief Make a ConstantRange for a relation with a constant value.
1025 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
1027 /// Exchange the two operands to this instruction in such a way that it does
1028 /// not modify the semantics of the instruction. The predicate value may be
1029 /// changed to retain the same result if the predicate is order dependent
1031 /// \brief Swap operands and adjust predicate.
1032 void swapOperands() {
1033 setPredicate(getSwappedPredicate());
1034 Op<0>().swap(Op<1>());
1037 // Methods for support type inquiry through isa, cast, and dyn_cast:
1038 static inline bool classof(const Instruction *I) {
1039 return I->getOpcode() == Instruction::ICmp;
1041 static inline bool classof(const Value *V) {
1042 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1047 //===----------------------------------------------------------------------===//
1049 //===----------------------------------------------------------------------===//
1051 /// This instruction compares its operands according to the predicate given
1052 /// to the constructor. It only operates on floating point values or packed
1053 /// vectors of floating point values. The operands must be identical types.
1054 /// \brief Represents a floating point comparison operator.
1055 class FCmpInst: public CmpInst {
1057 /// \brief Clone an identical FCmpInst
1058 virtual FCmpInst *clone_impl() const;
1060 /// \brief Constructor with insert-before-instruction semantics.
1062 Instruction *InsertBefore, ///< Where to insert
1063 Predicate pred, ///< The predicate to use for the comparison
1064 Value *LHS, ///< The left-hand-side of the expression
1065 Value *RHS, ///< The right-hand-side of the expression
1066 const Twine &NameStr = "" ///< Name of the instruction
1067 ) : CmpInst(makeCmpResultType(LHS->getType()),
1068 Instruction::FCmp, pred, LHS, RHS, NameStr,
1070 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1071 "Invalid FCmp predicate value");
1072 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1073 "Both operands to FCmp instruction are not of the same type!");
1074 // Check that the operands are the right type
1075 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1076 "Invalid operand types for FCmp instruction");
1079 /// \brief Constructor with insert-at-end semantics.
1081 BasicBlock &InsertAtEnd, ///< Block to insert into.
1082 Predicate pred, ///< The predicate to use for the comparison
1083 Value *LHS, ///< The left-hand-side of the expression
1084 Value *RHS, ///< The right-hand-side of the expression
1085 const Twine &NameStr = "" ///< Name of the instruction
1086 ) : CmpInst(makeCmpResultType(LHS->getType()),
1087 Instruction::FCmp, pred, LHS, RHS, NameStr,
1089 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1090 "Invalid FCmp predicate value");
1091 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1092 "Both operands to FCmp instruction are not of the same type!");
1093 // Check that the operands are the right type
1094 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1095 "Invalid operand types for FCmp instruction");
1098 /// \brief Constructor with no-insertion semantics
1100 Predicate pred, ///< The predicate to use for the comparison
1101 Value *LHS, ///< The left-hand-side of the expression
1102 Value *RHS, ///< The right-hand-side of the expression
1103 const Twine &NameStr = "" ///< Name of the instruction
1104 ) : CmpInst(makeCmpResultType(LHS->getType()),
1105 Instruction::FCmp, pred, LHS, RHS, NameStr) {
1106 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1107 "Invalid FCmp predicate value");
1108 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1109 "Both operands to FCmp instruction are not of the same type!");
1110 // Check that the operands are the right type
1111 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1112 "Invalid operand types for FCmp instruction");
1115 /// @returns true if the predicate of this instruction is EQ or NE.
1116 /// \brief Determine if this is an equality predicate.
1117 bool isEquality() const {
1118 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
1119 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
1122 /// @returns true if the predicate of this instruction is commutative.
1123 /// \brief Determine if this is a commutative predicate.
1124 bool isCommutative() const {
1125 return isEquality() ||
1126 getPredicate() == FCMP_FALSE ||
1127 getPredicate() == FCMP_TRUE ||
1128 getPredicate() == FCMP_ORD ||
1129 getPredicate() == FCMP_UNO;
1132 /// @returns true if the predicate is relational (not EQ or NE).
1133 /// \brief Determine if this a relational predicate.
1134 bool isRelational() const { return !isEquality(); }
1136 /// Exchange the two operands to this instruction in such a way that it does
1137 /// not modify the semantics of the instruction. The predicate value may be
1138 /// changed to retain the same result if the predicate is order dependent
1140 /// \brief Swap operands and adjust predicate.
1141 void swapOperands() {
1142 setPredicate(getSwappedPredicate());
1143 Op<0>().swap(Op<1>());
1146 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
1147 static inline bool classof(const Instruction *I) {
1148 return I->getOpcode() == Instruction::FCmp;
1150 static inline bool classof(const Value *V) {
1151 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1155 //===----------------------------------------------------------------------===//
1156 /// CallInst - This class represents a function call, abstracting a target
1157 /// machine's calling convention. This class uses low bit of the SubClassData
1158 /// field to indicate whether or not this is a tail call. The rest of the bits
1159 /// hold the calling convention of the call.
1161 class CallInst : public Instruction {
1162 AttributeSet AttributeList; ///< parameter attributes for call
1163 CallInst(const CallInst &CI);
1164 void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
1165 void init(Value *Func, const Twine &NameStr);
1167 /// Construct a CallInst given a range of arguments.
1168 /// \brief Construct a CallInst from a range of arguments
1169 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1170 const Twine &NameStr, Instruction *InsertBefore);
1172 /// Construct a CallInst given a range of arguments.
1173 /// \brief Construct a CallInst from a range of arguments
1174 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1175 const Twine &NameStr, BasicBlock *InsertAtEnd);
1177 CallInst(Value *F, Value *Actual, const Twine &NameStr,
1178 Instruction *InsertBefore);
1179 CallInst(Value *F, Value *Actual, const Twine &NameStr,
1180 BasicBlock *InsertAtEnd);
1181 explicit CallInst(Value *F, const Twine &NameStr,
1182 Instruction *InsertBefore);
1183 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1185 virtual CallInst *clone_impl() const;
1187 static CallInst *Create(Value *Func,
1188 ArrayRef<Value *> Args,
1189 const Twine &NameStr = "",
1190 Instruction *InsertBefore = 0) {
1191 return new(unsigned(Args.size() + 1))
1192 CallInst(Func, Args, NameStr, InsertBefore);
1194 static CallInst *Create(Value *Func,
1195 ArrayRef<Value *> Args,
1196 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1197 return new(unsigned(Args.size() + 1))
1198 CallInst(Func, Args, NameStr, InsertAtEnd);
1200 static CallInst *Create(Value *F, const Twine &NameStr = "",
1201 Instruction *InsertBefore = 0) {
1202 return new(1) CallInst(F, NameStr, InsertBefore);
1204 static CallInst *Create(Value *F, const Twine &NameStr,
1205 BasicBlock *InsertAtEnd) {
1206 return new(1) CallInst(F, NameStr, InsertAtEnd);
1208 /// CreateMalloc - Generate the IR for a call to malloc:
1209 /// 1. Compute the malloc call's argument as the specified type's size,
1210 /// possibly multiplied by the array size if the array size is not
1212 /// 2. Call malloc with that argument.
1213 /// 3. Bitcast the result of the malloc call to the specified type.
1214 static Instruction *CreateMalloc(Instruction *InsertBefore,
1215 Type *IntPtrTy, Type *AllocTy,
1216 Value *AllocSize, Value *ArraySize = 0,
1217 Function* MallocF = 0,
1218 const Twine &Name = "");
1219 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1220 Type *IntPtrTy, Type *AllocTy,
1221 Value *AllocSize, Value *ArraySize = 0,
1222 Function* MallocF = 0,
1223 const Twine &Name = "");
1224 /// CreateFree - Generate the IR for a call to the builtin free function.
1225 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
1226 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
1230 bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
1231 void setTailCall(bool isTC = true) {
1232 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
1236 /// Provide fast operand accessors
1237 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1239 /// getNumArgOperands - Return the number of call arguments.
1241 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
1243 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1245 Value *getArgOperand(unsigned i) const { return getOperand(i); }
1246 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
1248 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1250 CallingConv::ID getCallingConv() const {
1251 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
1253 void setCallingConv(CallingConv::ID CC) {
1254 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
1255 (static_cast<unsigned>(CC) << 1));
1258 /// getAttributes - Return the parameter attributes for this call.
1260 const AttributeSet &getAttributes() const { return AttributeList; }
1262 /// setAttributes - Set the parameter attributes for this call.
1264 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
1266 /// addAttribute - adds the attribute to the list of attributes.
1267 void addAttribute(unsigned i, Attribute::AttrKind attr);
1269 /// removeAttribute - removes the attribute from the list of attributes.
1270 void removeAttribute(unsigned i, Attribute attr);
1272 /// \brief Determine whether this call has the given attribute.
1273 bool hasFnAttr(Attribute::AttrKind A) const {
1274 assert(A != Attribute::NoBuiltin &&
1275 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
1276 return hasFnAttrImpl(A);
1279 /// \brief Determine whether the call or the callee has the given attributes.
1280 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
1282 /// \brief Extract the alignment for a call or parameter (0=unknown).
1283 unsigned getParamAlignment(unsigned i) const {
1284 return AttributeList.getParamAlignment(i);
1287 /// \brief Return true if the call should not be treated as a call to a
1289 bool isNoBuiltin() const {
1290 return hasFnAttrImpl(Attribute::NoBuiltin) &&
1291 !hasFnAttrImpl(Attribute::Builtin);
1294 /// \brief Return true if the call should not be inlined.
1295 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
1296 void setIsNoInline() {
1297 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
1300 /// \brief Return true if the call can return twice
1301 bool canReturnTwice() const {
1302 return hasFnAttr(Attribute::ReturnsTwice);
1304 void setCanReturnTwice() {
1305 addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice);
1308 /// \brief Determine if the call does not access memory.
1309 bool doesNotAccessMemory() const {
1310 return hasFnAttr(Attribute::ReadNone);
1312 void setDoesNotAccessMemory() {
1313 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
1316 /// \brief Determine if the call does not access or only reads memory.
1317 bool onlyReadsMemory() const {
1318 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
1320 void setOnlyReadsMemory() {
1321 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
1324 /// \brief Determine if the call cannot return.
1325 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
1326 void setDoesNotReturn() {
1327 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
1330 /// \brief Determine if the call cannot unwind.
1331 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
1332 void setDoesNotThrow() {
1333 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
1336 /// \brief Determine if the call cannot be duplicated.
1337 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
1338 void setCannotDuplicate() {
1339 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
1342 /// \brief Determine if the call returns a structure through first
1343 /// pointer argument.
1344 bool hasStructRetAttr() const {
1345 // Be friendly and also check the callee.
1346 return paramHasAttr(1, Attribute::StructRet);
1349 /// \brief Determine if any call argument is an aggregate passed by value.
1350 bool hasByValArgument() const {
1351 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1354 /// getCalledFunction - Return the function called, or null if this is an
1355 /// indirect function invocation.
1357 Function *getCalledFunction() const {
1358 return dyn_cast<Function>(Op<-1>());
1361 /// getCalledValue - Get a pointer to the function that is invoked by this
1363 const Value *getCalledValue() const { return Op<-1>(); }
1364 Value *getCalledValue() { return Op<-1>(); }
1366 /// setCalledFunction - Set the function called.
1367 void setCalledFunction(Value* Fn) {
1371 /// isInlineAsm - Check if this call is an inline asm statement.
1372 bool isInlineAsm() const {
1373 return isa<InlineAsm>(Op<-1>());
1376 // Methods for support type inquiry through isa, cast, and dyn_cast:
1377 static inline bool classof(const Instruction *I) {
1378 return I->getOpcode() == Instruction::Call;
1380 static inline bool classof(const Value *V) {
1381 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1385 bool hasFnAttrImpl(Attribute::AttrKind A) const;
1387 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1388 // method so that subclasses cannot accidentally use it.
1389 void setInstructionSubclassData(unsigned short D) {
1390 Instruction::setInstructionSubclassData(D);
1395 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1398 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1399 const Twine &NameStr, BasicBlock *InsertAtEnd)
1400 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1401 ->getElementType())->getReturnType(),
1403 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1404 unsigned(Args.size() + 1), InsertAtEnd) {
1405 init(Func, Args, NameStr);
1408 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1409 const Twine &NameStr, Instruction *InsertBefore)
1410 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1411 ->getElementType())->getReturnType(),
1413 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1414 unsigned(Args.size() + 1), InsertBefore) {
1415 init(Func, Args, NameStr);
1419 // Note: if you get compile errors about private methods then
1420 // please update your code to use the high-level operand
1421 // interfaces. See line 943 above.
1422 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1424 //===----------------------------------------------------------------------===//
1426 //===----------------------------------------------------------------------===//
1428 /// SelectInst - This class represents the LLVM 'select' instruction.
1430 class SelectInst : public Instruction {
1431 void init(Value *C, Value *S1, Value *S2) {
1432 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1438 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1439 Instruction *InsertBefore)
1440 : Instruction(S1->getType(), Instruction::Select,
1441 &Op<0>(), 3, InsertBefore) {
1445 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1446 BasicBlock *InsertAtEnd)
1447 : Instruction(S1->getType(), Instruction::Select,
1448 &Op<0>(), 3, InsertAtEnd) {
1453 virtual SelectInst *clone_impl() const;
1455 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1456 const Twine &NameStr = "",
1457 Instruction *InsertBefore = 0) {
1458 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1460 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1461 const Twine &NameStr,
1462 BasicBlock *InsertAtEnd) {
1463 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1466 const Value *getCondition() const { return Op<0>(); }
1467 const Value *getTrueValue() const { return Op<1>(); }
1468 const Value *getFalseValue() const { return Op<2>(); }
1469 Value *getCondition() { return Op<0>(); }
1470 Value *getTrueValue() { return Op<1>(); }
1471 Value *getFalseValue() { return Op<2>(); }
1473 /// areInvalidOperands - Return a string if the specified operands are invalid
1474 /// for a select operation, otherwise return null.
1475 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1477 /// Transparently provide more efficient getOperand methods.
1478 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1480 OtherOps getOpcode() const {
1481 return static_cast<OtherOps>(Instruction::getOpcode());
1484 // Methods for support type inquiry through isa, cast, and dyn_cast:
1485 static inline bool classof(const Instruction *I) {
1486 return I->getOpcode() == Instruction::Select;
1488 static inline bool classof(const Value *V) {
1489 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1494 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1497 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1499 //===----------------------------------------------------------------------===//
1501 //===----------------------------------------------------------------------===//
1503 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1504 /// an argument of the specified type given a va_list and increments that list
1506 class VAArgInst : public UnaryInstruction {
1508 virtual VAArgInst *clone_impl() const;
1511 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1512 Instruction *InsertBefore = 0)
1513 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1516 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1517 BasicBlock *InsertAtEnd)
1518 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1522 Value *getPointerOperand() { return getOperand(0); }
1523 const Value *getPointerOperand() const { return getOperand(0); }
1524 static unsigned getPointerOperandIndex() { return 0U; }
1526 // Methods for support type inquiry through isa, cast, and dyn_cast:
1527 static inline bool classof(const Instruction *I) {
1528 return I->getOpcode() == VAArg;
1530 static inline bool classof(const Value *V) {
1531 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1535 //===----------------------------------------------------------------------===//
1536 // ExtractElementInst Class
1537 //===----------------------------------------------------------------------===//
1539 /// ExtractElementInst - This instruction extracts a single (scalar)
1540 /// element from a VectorType value
1542 class ExtractElementInst : public Instruction {
1543 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1544 Instruction *InsertBefore = 0);
1545 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1546 BasicBlock *InsertAtEnd);
1548 virtual ExtractElementInst *clone_impl() const;
1551 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1552 const Twine &NameStr = "",
1553 Instruction *InsertBefore = 0) {
1554 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1556 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1557 const Twine &NameStr,
1558 BasicBlock *InsertAtEnd) {
1559 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1562 /// isValidOperands - Return true if an extractelement instruction can be
1563 /// formed with the specified operands.
1564 static bool isValidOperands(const Value *Vec, const Value *Idx);
1566 Value *getVectorOperand() { return Op<0>(); }
1567 Value *getIndexOperand() { return Op<1>(); }
1568 const Value *getVectorOperand() const { return Op<0>(); }
1569 const Value *getIndexOperand() const { return Op<1>(); }
1571 VectorType *getVectorOperandType() const {
1572 return cast<VectorType>(getVectorOperand()->getType());
1576 /// Transparently provide more efficient getOperand methods.
1577 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1579 // Methods for support type inquiry through isa, cast, and dyn_cast:
1580 static inline bool classof(const Instruction *I) {
1581 return I->getOpcode() == Instruction::ExtractElement;
1583 static inline bool classof(const Value *V) {
1584 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1589 struct OperandTraits<ExtractElementInst> :
1590 public FixedNumOperandTraits<ExtractElementInst, 2> {
1593 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1595 //===----------------------------------------------------------------------===//
1596 // InsertElementInst Class
1597 //===----------------------------------------------------------------------===//
1599 /// InsertElementInst - This instruction inserts a single (scalar)
1600 /// element into a VectorType value
1602 class InsertElementInst : public Instruction {
1603 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1604 const Twine &NameStr = "",
1605 Instruction *InsertBefore = 0);
1606 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1607 const Twine &NameStr, BasicBlock *InsertAtEnd);
1609 virtual InsertElementInst *clone_impl() const;
1612 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1613 const Twine &NameStr = "",
1614 Instruction *InsertBefore = 0) {
1615 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1617 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1618 const Twine &NameStr,
1619 BasicBlock *InsertAtEnd) {
1620 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1623 /// isValidOperands - Return true if an insertelement instruction can be
1624 /// formed with the specified operands.
1625 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1628 /// getType - Overload to return most specific vector type.
1630 VectorType *getType() const {
1631 return cast<VectorType>(Instruction::getType());
1634 /// Transparently provide more efficient getOperand methods.
1635 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1637 // Methods for support type inquiry through isa, cast, and dyn_cast:
1638 static inline bool classof(const Instruction *I) {
1639 return I->getOpcode() == Instruction::InsertElement;
1641 static inline bool classof(const Value *V) {
1642 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1647 struct OperandTraits<InsertElementInst> :
1648 public FixedNumOperandTraits<InsertElementInst, 3> {
1651 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1653 //===----------------------------------------------------------------------===//
1654 // ShuffleVectorInst Class
1655 //===----------------------------------------------------------------------===//
1657 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1660 class ShuffleVectorInst : public Instruction {
1662 virtual ShuffleVectorInst *clone_impl() const;
1665 // allocate space for exactly three operands
1666 void *operator new(size_t s) {
1667 return User::operator new(s, 3);
1669 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1670 const Twine &NameStr = "",
1671 Instruction *InsertBefor = 0);
1672 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1673 const Twine &NameStr, BasicBlock *InsertAtEnd);
1675 /// isValidOperands - Return true if a shufflevector instruction can be
1676 /// formed with the specified operands.
1677 static bool isValidOperands(const Value *V1, const Value *V2,
1680 /// getType - Overload to return most specific vector type.
1682 VectorType *getType() const {
1683 return cast<VectorType>(Instruction::getType());
1686 /// Transparently provide more efficient getOperand methods.
1687 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1689 Constant *getMask() const {
1690 return cast<Constant>(getOperand(2));
1693 /// getMaskValue - Return the index from the shuffle mask for the specified
1694 /// output result. This is either -1 if the element is undef or a number less
1695 /// than 2*numelements.
1696 static int getMaskValue(Constant *Mask, unsigned i);
1698 int getMaskValue(unsigned i) const {
1699 return getMaskValue(getMask(), i);
1702 /// getShuffleMask - Return the full mask for this instruction, where each
1703 /// element is the element number and undef's are returned as -1.
1704 static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
1706 void getShuffleMask(SmallVectorImpl<int> &Result) const {
1707 return getShuffleMask(getMask(), Result);
1710 SmallVector<int, 16> getShuffleMask() const {
1711 SmallVector<int, 16> Mask;
1712 getShuffleMask(Mask);
1717 // Methods for support type inquiry through isa, cast, and dyn_cast:
1718 static inline bool classof(const Instruction *I) {
1719 return I->getOpcode() == Instruction::ShuffleVector;
1721 static inline bool classof(const Value *V) {
1722 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1727 struct OperandTraits<ShuffleVectorInst> :
1728 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1731 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1733 //===----------------------------------------------------------------------===//
1734 // ExtractValueInst Class
1735 //===----------------------------------------------------------------------===//
1737 /// ExtractValueInst - This instruction extracts a struct member or array
1738 /// element value from an aggregate value.
1740 class ExtractValueInst : public UnaryInstruction {
1741 SmallVector<unsigned, 4> Indices;
1743 ExtractValueInst(const ExtractValueInst &EVI);
1744 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1746 /// Constructors - Create a extractvalue instruction with a base aggregate
1747 /// value and a list of indices. The first ctor can optionally insert before
1748 /// an existing instruction, the second appends the new instruction to the
1749 /// specified BasicBlock.
1750 inline ExtractValueInst(Value *Agg,
1751 ArrayRef<unsigned> Idxs,
1752 const Twine &NameStr,
1753 Instruction *InsertBefore);
1754 inline ExtractValueInst(Value *Agg,
1755 ArrayRef<unsigned> Idxs,
1756 const Twine &NameStr, BasicBlock *InsertAtEnd);
1758 // allocate space for exactly one operand
1759 void *operator new(size_t s) {
1760 return User::operator new(s, 1);
1763 virtual ExtractValueInst *clone_impl() const;
1766 static ExtractValueInst *Create(Value *Agg,
1767 ArrayRef<unsigned> Idxs,
1768 const Twine &NameStr = "",
1769 Instruction *InsertBefore = 0) {
1771 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1773 static ExtractValueInst *Create(Value *Agg,
1774 ArrayRef<unsigned> Idxs,
1775 const Twine &NameStr,
1776 BasicBlock *InsertAtEnd) {
1777 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1780 /// getIndexedType - Returns the type of the element that would be extracted
1781 /// with an extractvalue instruction with the specified parameters.
1783 /// Null is returned if the indices are invalid for the specified type.
1784 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
1786 typedef const unsigned* idx_iterator;
1787 inline idx_iterator idx_begin() const { return Indices.begin(); }
1788 inline idx_iterator idx_end() const { return Indices.end(); }
1790 Value *getAggregateOperand() {
1791 return getOperand(0);
1793 const Value *getAggregateOperand() const {
1794 return getOperand(0);
1796 static unsigned getAggregateOperandIndex() {
1797 return 0U; // get index for modifying correct operand
1800 ArrayRef<unsigned> getIndices() const {
1804 unsigned getNumIndices() const {
1805 return (unsigned)Indices.size();
1808 bool hasIndices() const {
1812 // Methods for support type inquiry through isa, cast, and dyn_cast:
1813 static inline bool classof(const Instruction *I) {
1814 return I->getOpcode() == Instruction::ExtractValue;
1816 static inline bool classof(const Value *V) {
1817 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1821 ExtractValueInst::ExtractValueInst(Value *Agg,
1822 ArrayRef<unsigned> Idxs,
1823 const Twine &NameStr,
1824 Instruction *InsertBefore)
1825 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1826 ExtractValue, Agg, InsertBefore) {
1827 init(Idxs, NameStr);
1829 ExtractValueInst::ExtractValueInst(Value *Agg,
1830 ArrayRef<unsigned> Idxs,
1831 const Twine &NameStr,
1832 BasicBlock *InsertAtEnd)
1833 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1834 ExtractValue, Agg, InsertAtEnd) {
1835 init(Idxs, NameStr);
1839 //===----------------------------------------------------------------------===//
1840 // InsertValueInst Class
1841 //===----------------------------------------------------------------------===//
1843 /// InsertValueInst - This instruction inserts a struct field of array element
1844 /// value into an aggregate value.
1846 class InsertValueInst : public Instruction {
1847 SmallVector<unsigned, 4> Indices;
1849 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1850 InsertValueInst(const InsertValueInst &IVI);
1851 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1852 const Twine &NameStr);
1854 /// Constructors - Create a insertvalue instruction with a base aggregate
1855 /// value, a value to insert, and a list of indices. The first ctor can
1856 /// optionally insert before an existing instruction, the second appends
1857 /// the new instruction to the specified BasicBlock.
1858 inline InsertValueInst(Value *Agg, Value *Val,
1859 ArrayRef<unsigned> Idxs,
1860 const Twine &NameStr,
1861 Instruction *InsertBefore);
1862 inline InsertValueInst(Value *Agg, Value *Val,
1863 ArrayRef<unsigned> Idxs,
1864 const Twine &NameStr, BasicBlock *InsertAtEnd);
1866 /// Constructors - These two constructors are convenience methods because one
1867 /// and two index insertvalue instructions are so common.
1868 InsertValueInst(Value *Agg, Value *Val,
1869 unsigned Idx, const Twine &NameStr = "",
1870 Instruction *InsertBefore = 0);
1871 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1872 const Twine &NameStr, BasicBlock *InsertAtEnd);
1874 virtual InsertValueInst *clone_impl() const;
1876 // allocate space for exactly two operands
1877 void *operator new(size_t s) {
1878 return User::operator new(s, 2);
1881 static InsertValueInst *Create(Value *Agg, Value *Val,
1882 ArrayRef<unsigned> Idxs,
1883 const Twine &NameStr = "",
1884 Instruction *InsertBefore = 0) {
1885 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1887 static InsertValueInst *Create(Value *Agg, Value *Val,
1888 ArrayRef<unsigned> Idxs,
1889 const Twine &NameStr,
1890 BasicBlock *InsertAtEnd) {
1891 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1894 /// Transparently provide more efficient getOperand methods.
1895 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1897 typedef const unsigned* idx_iterator;
1898 inline idx_iterator idx_begin() const { return Indices.begin(); }
1899 inline idx_iterator idx_end() const { return Indices.end(); }
1901 Value *getAggregateOperand() {
1902 return getOperand(0);
1904 const Value *getAggregateOperand() const {
1905 return getOperand(0);
1907 static unsigned getAggregateOperandIndex() {
1908 return 0U; // get index for modifying correct operand
1911 Value *getInsertedValueOperand() {
1912 return getOperand(1);
1914 const Value *getInsertedValueOperand() const {
1915 return getOperand(1);
1917 static unsigned getInsertedValueOperandIndex() {
1918 return 1U; // get index for modifying correct operand
1921 ArrayRef<unsigned> getIndices() const {
1925 unsigned getNumIndices() const {
1926 return (unsigned)Indices.size();
1929 bool hasIndices() const {
1933 // Methods for support type inquiry through isa, cast, and dyn_cast:
1934 static inline bool classof(const Instruction *I) {
1935 return I->getOpcode() == Instruction::InsertValue;
1937 static inline bool classof(const Value *V) {
1938 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1943 struct OperandTraits<InsertValueInst> :
1944 public FixedNumOperandTraits<InsertValueInst, 2> {
1947 InsertValueInst::InsertValueInst(Value *Agg,
1949 ArrayRef<unsigned> Idxs,
1950 const Twine &NameStr,
1951 Instruction *InsertBefore)
1952 : Instruction(Agg->getType(), InsertValue,
1953 OperandTraits<InsertValueInst>::op_begin(this),
1955 init(Agg, Val, Idxs, NameStr);
1957 InsertValueInst::InsertValueInst(Value *Agg,
1959 ArrayRef<unsigned> Idxs,
1960 const Twine &NameStr,
1961 BasicBlock *InsertAtEnd)
1962 : Instruction(Agg->getType(), InsertValue,
1963 OperandTraits<InsertValueInst>::op_begin(this),
1965 init(Agg, Val, Idxs, NameStr);
1968 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1970 //===----------------------------------------------------------------------===//
1972 //===----------------------------------------------------------------------===//
1974 // PHINode - The PHINode class is used to represent the magical mystical PHI
1975 // node, that can not exist in nature, but can be synthesized in a computer
1976 // scientist's overactive imagination.
1978 class PHINode : public Instruction {
1979 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1980 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1981 /// the number actually in use.
1982 unsigned ReservedSpace;
1983 PHINode(const PHINode &PN);
1984 // allocate space for exactly zero operands
1985 void *operator new(size_t s) {
1986 return User::operator new(s, 0);
1988 explicit PHINode(Type *Ty, unsigned NumReservedValues,
1989 const Twine &NameStr = "", Instruction *InsertBefore = 0)
1990 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1991 ReservedSpace(NumReservedValues) {
1993 OperandList = allocHungoffUses(ReservedSpace);
1996 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
1997 BasicBlock *InsertAtEnd)
1998 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1999 ReservedSpace(NumReservedValues) {
2001 OperandList = allocHungoffUses(ReservedSpace);
2004 // allocHungoffUses - this is more complicated than the generic
2005 // User::allocHungoffUses, because we have to allocate Uses for the incoming
2006 // values and pointers to the incoming blocks, all in one allocation.
2007 Use *allocHungoffUses(unsigned) const;
2009 virtual PHINode *clone_impl() const;
2011 /// Constructors - NumReservedValues is a hint for the number of incoming
2012 /// edges that this phi node will have (use 0 if you really have no idea).
2013 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2014 const Twine &NameStr = "",
2015 Instruction *InsertBefore = 0) {
2016 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2018 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2019 const Twine &NameStr, BasicBlock *InsertAtEnd) {
2020 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2024 /// Provide fast operand accessors
2025 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2027 // Block iterator interface. This provides access to the list of incoming
2028 // basic blocks, which parallels the list of incoming values.
2030 typedef BasicBlock **block_iterator;
2031 typedef BasicBlock * const *const_block_iterator;
2033 block_iterator block_begin() {
2035 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2036 return reinterpret_cast<block_iterator>(ref + 1);
2039 const_block_iterator block_begin() const {
2040 const Use::UserRef *ref =
2041 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2042 return reinterpret_cast<const_block_iterator>(ref + 1);
2045 block_iterator block_end() {
2046 return block_begin() + getNumOperands();
2049 const_block_iterator block_end() const {
2050 return block_begin() + getNumOperands();
2053 /// getNumIncomingValues - Return the number of incoming edges
2055 unsigned getNumIncomingValues() const { return getNumOperands(); }
2057 /// getIncomingValue - Return incoming value number x
2059 Value *getIncomingValue(unsigned i) const {
2060 return getOperand(i);
2062 void setIncomingValue(unsigned i, Value *V) {
2065 static unsigned getOperandNumForIncomingValue(unsigned i) {
2068 static unsigned getIncomingValueNumForOperand(unsigned i) {
2072 /// getIncomingBlock - Return incoming basic block number @p i.
2074 BasicBlock *getIncomingBlock(unsigned i) const {
2075 return block_begin()[i];
2078 /// getIncomingBlock - Return incoming basic block corresponding
2079 /// to an operand of the PHI.
2081 BasicBlock *getIncomingBlock(const Use &U) const {
2082 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2083 return getIncomingBlock(unsigned(&U - op_begin()));
2086 /// getIncomingBlock - Return incoming basic block corresponding
2087 /// to value use iterator.
2089 template <typename U>
2090 BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
2091 return getIncomingBlock(I.getUse());
2094 void setIncomingBlock(unsigned i, BasicBlock *BB) {
2095 block_begin()[i] = BB;
2098 /// addIncoming - Add an incoming value to the end of the PHI list
2100 void addIncoming(Value *V, BasicBlock *BB) {
2101 assert(V && "PHI node got a null value!");
2102 assert(BB && "PHI node got a null basic block!");
2103 assert(getType() == V->getType() &&
2104 "All operands to PHI node must be the same type as the PHI node!");
2105 if (NumOperands == ReservedSpace)
2106 growOperands(); // Get more space!
2107 // Initialize some new operands.
2109 setIncomingValue(NumOperands - 1, V);
2110 setIncomingBlock(NumOperands - 1, BB);
2113 /// removeIncomingValue - Remove an incoming value. This is useful if a
2114 /// predecessor basic block is deleted. The value removed is returned.
2116 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2117 /// is true), the PHI node is destroyed and any uses of it are replaced with
2118 /// dummy values. The only time there should be zero incoming values to a PHI
2119 /// node is when the block is dead, so this strategy is sound.
2121 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2123 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2124 int Idx = getBasicBlockIndex(BB);
2125 assert(Idx >= 0 && "Invalid basic block argument to remove!");
2126 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2129 /// getBasicBlockIndex - Return the first index of the specified basic
2130 /// block in the value list for this PHI. Returns -1 if no instance.
2132 int getBasicBlockIndex(const BasicBlock *BB) const {
2133 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2134 if (block_begin()[i] == BB)
2139 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2140 int Idx = getBasicBlockIndex(BB);
2141 assert(Idx >= 0 && "Invalid basic block argument!");
2142 return getIncomingValue(Idx);
2145 /// hasConstantValue - If the specified PHI node always merges together the
2146 /// same value, return the value, otherwise return null.
2147 Value *hasConstantValue() const;
2149 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2150 static inline bool classof(const Instruction *I) {
2151 return I->getOpcode() == Instruction::PHI;
2153 static inline bool classof(const Value *V) {
2154 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2157 void growOperands();
2161 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2164 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
2166 //===----------------------------------------------------------------------===//
2167 // LandingPadInst Class
2168 //===----------------------------------------------------------------------===//
2170 //===---------------------------------------------------------------------------
2171 /// LandingPadInst - The landingpad instruction holds all of the information
2172 /// necessary to generate correct exception handling. The landingpad instruction
2173 /// cannot be moved from the top of a landing pad block, which itself is
2174 /// accessible only from the 'unwind' edge of an invoke. This uses the
2175 /// SubclassData field in Value to store whether or not the landingpad is a
2178 class LandingPadInst : public Instruction {
2179 /// ReservedSpace - The number of operands actually allocated. NumOperands is
2180 /// the number actually in use.
2181 unsigned ReservedSpace;
2182 LandingPadInst(const LandingPadInst &LP);
2184 enum ClauseType { Catch, Filter };
2186 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2187 // Allocate space for exactly zero operands.
2188 void *operator new(size_t s) {
2189 return User::operator new(s, 0);
2191 void growOperands(unsigned Size);
2192 void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
2194 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2195 unsigned NumReservedValues, const Twine &NameStr,
2196 Instruction *InsertBefore);
2197 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2198 unsigned NumReservedValues, const Twine &NameStr,
2199 BasicBlock *InsertAtEnd);
2201 virtual LandingPadInst *clone_impl() const;
2203 /// Constructors - NumReservedClauses is a hint for the number of incoming
2204 /// clauses that this landingpad will have (use 0 if you really have no idea).
2205 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2206 unsigned NumReservedClauses,
2207 const Twine &NameStr = "",
2208 Instruction *InsertBefore = 0);
2209 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2210 unsigned NumReservedClauses,
2211 const Twine &NameStr, BasicBlock *InsertAtEnd);
2214 /// Provide fast operand accessors
2215 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2217 /// getPersonalityFn - Get the personality function associated with this
2219 Value *getPersonalityFn() const { return getOperand(0); }
2221 /// isCleanup - Return 'true' if this landingpad instruction is a
2222 /// cleanup. I.e., it should be run when unwinding even if its landing pad
2223 /// doesn't catch the exception.
2224 bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2226 /// setCleanup - Indicate that this landingpad instruction is a cleanup.
2227 void setCleanup(bool V) {
2228 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2232 /// addClause - Add a catch or filter clause to the landing pad.
2233 void addClause(Value *ClauseVal);
2235 /// getClause - Get the value of the clause at index Idx. Use isCatch/isFilter
2236 /// to determine what type of clause this is.
2237 Value *getClause(unsigned Idx) const { return OperandList[Idx + 1]; }
2239 /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
2240 bool isCatch(unsigned Idx) const {
2241 return !isa<ArrayType>(OperandList[Idx + 1]->getType());
2244 /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
2245 bool isFilter(unsigned Idx) const {
2246 return isa<ArrayType>(OperandList[Idx + 1]->getType());
2249 /// getNumClauses - Get the number of clauses for this landing pad.
2250 unsigned getNumClauses() const { return getNumOperands() - 1; }
2252 /// reserveClauses - Grow the size of the operand list to accommodate the new
2253 /// number of clauses.
2254 void reserveClauses(unsigned Size) { growOperands(Size); }
2256 // Methods for support type inquiry through isa, cast, and dyn_cast:
2257 static inline bool classof(const Instruction *I) {
2258 return I->getOpcode() == Instruction::LandingPad;
2260 static inline bool classof(const Value *V) {
2261 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2266 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
2269 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
2271 //===----------------------------------------------------------------------===//
2273 //===----------------------------------------------------------------------===//
2275 //===---------------------------------------------------------------------------
2276 /// ReturnInst - Return a value (possibly void), from a function. Execution
2277 /// does not continue in this function any longer.
2279 class ReturnInst : public TerminatorInst {
2280 ReturnInst(const ReturnInst &RI);
2283 // ReturnInst constructors:
2284 // ReturnInst() - 'ret void' instruction
2285 // ReturnInst( null) - 'ret void' instruction
2286 // ReturnInst(Value* X) - 'ret X' instruction
2287 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
2288 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
2289 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2290 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
2292 // NOTE: If the Value* passed is of type void then the constructor behaves as
2293 // if it was passed NULL.
2294 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
2295 Instruction *InsertBefore = 0);
2296 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2297 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2299 virtual ReturnInst *clone_impl() const;
2301 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
2302 Instruction *InsertBefore = 0) {
2303 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2305 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2306 BasicBlock *InsertAtEnd) {
2307 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2309 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2310 return new(0) ReturnInst(C, InsertAtEnd);
2312 virtual ~ReturnInst();
2314 /// Provide fast operand accessors
2315 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2317 /// Convenience accessor. Returns null if there is no return value.
2318 Value *getReturnValue() const {
2319 return getNumOperands() != 0 ? getOperand(0) : 0;
2322 unsigned getNumSuccessors() const { return 0; }
2324 // Methods for support type inquiry through isa, cast, and dyn_cast:
2325 static inline bool classof(const Instruction *I) {
2326 return (I->getOpcode() == Instruction::Ret);
2328 static inline bool classof(const Value *V) {
2329 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2332 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2333 virtual unsigned getNumSuccessorsV() const;
2334 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2338 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2341 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2343 //===----------------------------------------------------------------------===//
2345 //===----------------------------------------------------------------------===//
2347 //===---------------------------------------------------------------------------
2348 /// BranchInst - Conditional or Unconditional Branch instruction.
2350 class BranchInst : public TerminatorInst {
2351 /// Ops list - Branches are strange. The operands are ordered:
2352 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2353 /// they don't have to check for cond/uncond branchness. These are mostly
2354 /// accessed relative from op_end().
2355 BranchInst(const BranchInst &BI);
2357 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2358 // BranchInst(BB *B) - 'br B'
2359 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2360 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2361 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2362 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2363 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2364 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2365 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2366 Instruction *InsertBefore = 0);
2367 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2368 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2369 BasicBlock *InsertAtEnd);
2371 virtual BranchInst *clone_impl() const;
2373 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2374 return new(1) BranchInst(IfTrue, InsertBefore);
2376 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2377 Value *Cond, Instruction *InsertBefore = 0) {
2378 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2380 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2381 return new(1) BranchInst(IfTrue, InsertAtEnd);
2383 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2384 Value *Cond, BasicBlock *InsertAtEnd) {
2385 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2388 /// Transparently provide more efficient getOperand methods.
2389 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2391 bool isUnconditional() const { return getNumOperands() == 1; }
2392 bool isConditional() const { return getNumOperands() == 3; }
2394 Value *getCondition() const {
2395 assert(isConditional() && "Cannot get condition of an uncond branch!");
2399 void setCondition(Value *V) {
2400 assert(isConditional() && "Cannot set condition of unconditional branch!");
2404 unsigned getNumSuccessors() const { return 1+isConditional(); }
2406 BasicBlock *getSuccessor(unsigned i) const {
2407 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2408 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2411 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2412 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2413 *(&Op<-1>() - idx) = (Value*)NewSucc;
2416 /// \brief Swap the successors of this branch instruction.
2418 /// Swaps the successors of the branch instruction. This also swaps any
2419 /// branch weight metadata associated with the instruction so that it
2420 /// continues to map correctly to each operand.
2421 void swapSuccessors();
2423 // Methods for support type inquiry through isa, cast, and dyn_cast:
2424 static inline bool classof(const Instruction *I) {
2425 return (I->getOpcode() == Instruction::Br);
2427 static inline bool classof(const Value *V) {
2428 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2431 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2432 virtual unsigned getNumSuccessorsV() const;
2433 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2437 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2440 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2442 //===----------------------------------------------------------------------===//
2444 //===----------------------------------------------------------------------===//
2446 //===---------------------------------------------------------------------------
2447 /// SwitchInst - Multiway switch
2449 class SwitchInst : public TerminatorInst {
2450 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2451 unsigned ReservedSpace;
2452 // Operand[0] = Value to switch on
2453 // Operand[1] = Default basic block destination
2454 // Operand[2n ] = Value to match
2455 // Operand[2n+1] = BasicBlock to go to on match
2456 SwitchInst(const SwitchInst &SI);
2457 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2458 void growOperands();
2459 // allocate space for exactly zero operands
2460 void *operator new(size_t s) {
2461 return User::operator new(s, 0);
2463 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2464 /// switch on and a default destination. The number of additional cases can
2465 /// be specified here to make memory allocation more efficient. This
2466 /// constructor can also autoinsert before another instruction.
2467 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2468 Instruction *InsertBefore);
2470 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2471 /// switch on and a default destination. The number of additional cases can
2472 /// be specified here to make memory allocation more efficient. This
2473 /// constructor also autoinserts at the end of the specified BasicBlock.
2474 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2475 BasicBlock *InsertAtEnd);
2477 virtual SwitchInst *clone_impl() const;
2481 static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
2483 template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy>
2484 class CaseIteratorT {
2492 typedef CaseIteratorT<SwitchInstTy, ConstantIntTy, BasicBlockTy> Self;
2494 /// Initializes case iterator for given SwitchInst and for given
2496 CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
2501 /// Initializes case iterator for given SwitchInst and for given
2502 /// TerminatorInst's successor index.
2503 static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
2504 assert(SuccessorIndex < SI->getNumSuccessors() &&
2505 "Successor index # out of range!");
2506 return SuccessorIndex != 0 ?
2507 Self(SI, SuccessorIndex - 1) :
2508 Self(SI, DefaultPseudoIndex);
2511 /// Resolves case value for current case.
2512 ConstantIntTy *getCaseValue() {
2513 assert(Index < SI->getNumCases() && "Index out the number of cases.");
2514 return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2));
2517 /// Resolves successor for current case.
2518 BasicBlockTy *getCaseSuccessor() {
2519 assert((Index < SI->getNumCases() ||
2520 Index == DefaultPseudoIndex) &&
2521 "Index out the number of cases.");
2522 return SI->getSuccessor(getSuccessorIndex());
2525 /// Returns number of current case.
2526 unsigned getCaseIndex() const { return Index; }
2528 /// Returns TerminatorInst's successor index for current case successor.
2529 unsigned getSuccessorIndex() const {
2530 assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
2531 "Index out the number of cases.");
2532 return Index != DefaultPseudoIndex ? Index + 1 : 0;
2536 // Check index correctness after increment.
2537 // Note: Index == getNumCases() means end().
2538 assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
2542 Self operator++(int) {
2548 // Check index correctness after decrement.
2549 // Note: Index == getNumCases() means end().
2550 // Also allow "-1" iterator here. That will became valid after ++.
2551 assert((Index == 0 || Index-1 <= SI->getNumCases()) &&
2552 "Index out the number of cases.");
2556 Self operator--(int) {
2561 bool operator==(const Self& RHS) const {
2562 assert(RHS.SI == SI && "Incompatible operators.");
2563 return RHS.Index == Index;
2565 bool operator!=(const Self& RHS) const {
2566 assert(RHS.SI == SI && "Incompatible operators.");
2567 return RHS.Index != Index;
2571 typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock>
2574 class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> {
2576 typedef CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> ParentTy;
2580 CaseIt(const ParentTy& Src) : ParentTy(Src) {}
2581 CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
2583 /// Sets the new value for current case.
2584 void setValue(ConstantInt *V) {
2585 assert(Index < SI->getNumCases() && "Index out the number of cases.");
2586 SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V));
2589 /// Sets the new successor for current case.
2590 void setSuccessor(BasicBlock *S) {
2591 SI->setSuccessor(getSuccessorIndex(), S);
2595 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2596 unsigned NumCases, Instruction *InsertBefore = 0) {
2597 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2599 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2600 unsigned NumCases, BasicBlock *InsertAtEnd) {
2601 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2606 /// Provide fast operand accessors
2607 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2609 // Accessor Methods for Switch stmt
2610 Value *getCondition() const { return getOperand(0); }
2611 void setCondition(Value *V) { setOperand(0, V); }
2613 BasicBlock *getDefaultDest() const {
2614 return cast<BasicBlock>(getOperand(1));
2617 void setDefaultDest(BasicBlock *DefaultCase) {
2618 setOperand(1, reinterpret_cast<Value*>(DefaultCase));
2621 /// getNumCases - return the number of 'cases' in this switch instruction,
2622 /// except the default case
2623 unsigned getNumCases() const {
2624 return getNumOperands()/2 - 1;
2627 /// Returns a read/write iterator that points to the first
2628 /// case in SwitchInst.
2629 CaseIt case_begin() {
2630 return CaseIt(this, 0);
2632 /// Returns a read-only iterator that points to the first
2633 /// case in the SwitchInst.
2634 ConstCaseIt case_begin() const {
2635 return ConstCaseIt(this, 0);
2638 /// Returns a read/write iterator that points one past the last
2639 /// in the SwitchInst.
2641 return CaseIt(this, getNumCases());
2643 /// Returns a read-only iterator that points one past the last
2644 /// in the SwitchInst.
2645 ConstCaseIt case_end() const {
2646 return ConstCaseIt(this, getNumCases());
2648 /// Returns an iterator that points to the default case.
2649 /// Note: this iterator allows to resolve successor only. Attempt
2650 /// to resolve case value causes an assertion.
2651 /// Also note, that increment and decrement also causes an assertion and
2652 /// makes iterator invalid.
2653 CaseIt case_default() {
2654 return CaseIt(this, DefaultPseudoIndex);
2656 ConstCaseIt case_default() const {
2657 return ConstCaseIt(this, DefaultPseudoIndex);
2660 /// findCaseValue - Search all of the case values for the specified constant.
2661 /// If it is explicitly handled, return the case iterator of it, otherwise
2662 /// return default case iterator to indicate
2663 /// that it is handled by the default handler.
2664 CaseIt findCaseValue(const ConstantInt *C) {
2665 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
2666 if (i.getCaseValue() == C)
2668 return case_default();
2670 ConstCaseIt findCaseValue(const ConstantInt *C) const {
2671 for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
2672 if (i.getCaseValue() == C)
2674 return case_default();
2677 /// findCaseDest - Finds the unique case value for a given successor. Returns
2678 /// null if the successor is not found, not unique, or is the default case.
2679 ConstantInt *findCaseDest(BasicBlock *BB) {
2680 if (BB == getDefaultDest()) return NULL;
2682 ConstantInt *CI = NULL;
2683 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
2684 if (i.getCaseSuccessor() == BB) {
2685 if (CI) return NULL; // Multiple cases lead to BB.
2686 else CI = i.getCaseValue();
2692 /// addCase - Add an entry to the switch instruction...
2694 /// This action invalidates case_end(). Old case_end() iterator will
2695 /// point to the added case.
2696 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2698 /// removeCase - This method removes the specified case and its successor
2699 /// from the switch instruction. Note that this operation may reorder the
2700 /// remaining cases at index idx and above.
2702 /// This action invalidates iterators for all cases following the one removed,
2703 /// including the case_end() iterator.
2704 void removeCase(CaseIt i);
2706 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2707 BasicBlock *getSuccessor(unsigned idx) const {
2708 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2709 return cast<BasicBlock>(getOperand(idx*2+1));
2711 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2712 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2713 setOperand(idx*2+1, (Value*)NewSucc);
2716 // Methods for support type inquiry through isa, cast, and dyn_cast:
2717 static inline bool classof(const Instruction *I) {
2718 return I->getOpcode() == Instruction::Switch;
2720 static inline bool classof(const Value *V) {
2721 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2724 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2725 virtual unsigned getNumSuccessorsV() const;
2726 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2730 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2733 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2736 //===----------------------------------------------------------------------===//
2737 // IndirectBrInst Class
2738 //===----------------------------------------------------------------------===//
2740 //===---------------------------------------------------------------------------
2741 /// IndirectBrInst - Indirect Branch Instruction.
2743 class IndirectBrInst : public TerminatorInst {
2744 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2745 unsigned ReservedSpace;
2746 // Operand[0] = Value to switch on
2747 // Operand[1] = Default basic block destination
2748 // Operand[2n ] = Value to match
2749 // Operand[2n+1] = BasicBlock to go to on match
2750 IndirectBrInst(const IndirectBrInst &IBI);
2751 void init(Value *Address, unsigned NumDests);
2752 void growOperands();
2753 // allocate space for exactly zero operands
2754 void *operator new(size_t s) {
2755 return User::operator new(s, 0);
2757 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2758 /// Address to jump to. The number of expected destinations can be specified
2759 /// here to make memory allocation more efficient. This constructor can also
2760 /// autoinsert before another instruction.
2761 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2763 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2764 /// Address to jump to. The number of expected destinations can be specified
2765 /// here to make memory allocation more efficient. This constructor also
2766 /// autoinserts at the end of the specified BasicBlock.
2767 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2769 virtual IndirectBrInst *clone_impl() const;
2771 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2772 Instruction *InsertBefore = 0) {
2773 return new IndirectBrInst(Address, NumDests, InsertBefore);
2775 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2776 BasicBlock *InsertAtEnd) {
2777 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2781 /// Provide fast operand accessors.
2782 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2784 // Accessor Methods for IndirectBrInst instruction.
2785 Value *getAddress() { return getOperand(0); }
2786 const Value *getAddress() const { return getOperand(0); }
2787 void setAddress(Value *V) { setOperand(0, V); }
2790 /// getNumDestinations - return the number of possible destinations in this
2791 /// indirectbr instruction.
2792 unsigned getNumDestinations() const { return getNumOperands()-1; }
2794 /// getDestination - Return the specified destination.
2795 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2796 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2798 /// addDestination - Add a destination.
2800 void addDestination(BasicBlock *Dest);
2802 /// removeDestination - This method removes the specified successor from the
2803 /// indirectbr instruction.
2804 void removeDestination(unsigned i);
2806 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2807 BasicBlock *getSuccessor(unsigned i) const {
2808 return cast<BasicBlock>(getOperand(i+1));
2810 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2811 setOperand(i+1, (Value*)NewSucc);
2814 // Methods for support type inquiry through isa, cast, and dyn_cast:
2815 static inline bool classof(const Instruction *I) {
2816 return I->getOpcode() == Instruction::IndirectBr;
2818 static inline bool classof(const Value *V) {
2819 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2822 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2823 virtual unsigned getNumSuccessorsV() const;
2824 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2828 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2831 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2834 //===----------------------------------------------------------------------===//
2836 //===----------------------------------------------------------------------===//
2838 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2839 /// calling convention of the call.
2841 class InvokeInst : public TerminatorInst {
2842 AttributeSet AttributeList;
2843 InvokeInst(const InvokeInst &BI);
2844 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2845 ArrayRef<Value *> Args, const Twine &NameStr);
2847 /// Construct an InvokeInst given a range of arguments.
2849 /// \brief Construct an InvokeInst from a range of arguments
2850 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2851 ArrayRef<Value *> Args, unsigned Values,
2852 const Twine &NameStr, Instruction *InsertBefore);
2854 /// Construct an InvokeInst given a range of arguments.
2856 /// \brief Construct an InvokeInst from a range of arguments
2857 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2858 ArrayRef<Value *> Args, unsigned Values,
2859 const Twine &NameStr, BasicBlock *InsertAtEnd);
2861 virtual InvokeInst *clone_impl() const;
2863 static InvokeInst *Create(Value *Func,
2864 BasicBlock *IfNormal, BasicBlock *IfException,
2865 ArrayRef<Value *> Args, const Twine &NameStr = "",
2866 Instruction *InsertBefore = 0) {
2867 unsigned Values = unsigned(Args.size()) + 3;
2868 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2869 Values, NameStr, InsertBefore);
2871 static InvokeInst *Create(Value *Func,
2872 BasicBlock *IfNormal, BasicBlock *IfException,
2873 ArrayRef<Value *> Args, const Twine &NameStr,
2874 BasicBlock *InsertAtEnd) {
2875 unsigned Values = unsigned(Args.size()) + 3;
2876 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2877 Values, NameStr, InsertAtEnd);
2880 /// Provide fast operand accessors
2881 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2883 /// getNumArgOperands - Return the number of invoke arguments.
2885 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2887 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2889 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2890 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2892 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2894 CallingConv::ID getCallingConv() const {
2895 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2897 void setCallingConv(CallingConv::ID CC) {
2898 setInstructionSubclassData(static_cast<unsigned>(CC));
2901 /// getAttributes - Return the parameter attributes for this invoke.
2903 const AttributeSet &getAttributes() const { return AttributeList; }
2905 /// setAttributes - Set the parameter attributes for this invoke.
2907 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
2909 /// addAttribute - adds the attribute to the list of attributes.
2910 void addAttribute(unsigned i, Attribute::AttrKind attr);
2912 /// removeAttribute - removes the attribute from the list of attributes.
2913 void removeAttribute(unsigned i, Attribute attr);
2915 /// \brief Determine whether this call has the NoAlias attribute.
2916 bool hasFnAttr(Attribute::AttrKind A) const {
2917 assert(A != Attribute::NoBuiltin &&
2918 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
2919 return hasFnAttrImpl(A);
2922 /// \brief Determine whether the call or the callee has the given attributes.
2923 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
2925 /// \brief Extract the alignment for a call or parameter (0=unknown).
2926 unsigned getParamAlignment(unsigned i) const {
2927 return AttributeList.getParamAlignment(i);
2930 /// \brief Return true if the call should not be treated as a call to a
2932 bool isNoBuiltin() const {
2933 // We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have
2934 // to check it by hand.
2935 return hasFnAttrImpl(Attribute::NoBuiltin) &&
2936 !hasFnAttrImpl(Attribute::Builtin);
2939 /// \brief Return true if the call should not be inlined.
2940 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
2941 void setIsNoInline() {
2942 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
2945 /// \brief Determine if the call does not access memory.
2946 bool doesNotAccessMemory() const {
2947 return hasFnAttr(Attribute::ReadNone);
2949 void setDoesNotAccessMemory() {
2950 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
2953 /// \brief Determine if the call does not access or only reads memory.
2954 bool onlyReadsMemory() const {
2955 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
2957 void setOnlyReadsMemory() {
2958 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
2961 /// \brief Determine if the call cannot return.
2962 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
2963 void setDoesNotReturn() {
2964 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
2967 /// \brief Determine if the call cannot unwind.
2968 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
2969 void setDoesNotThrow() {
2970 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
2973 /// \brief Determine if the call returns a structure through first
2974 /// pointer argument.
2975 bool hasStructRetAttr() const {
2976 // Be friendly and also check the callee.
2977 return paramHasAttr(1, Attribute::StructRet);
2980 /// \brief Determine if any call argument is an aggregate passed by value.
2981 bool hasByValArgument() const {
2982 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2985 /// getCalledFunction - Return the function called, or null if this is an
2986 /// indirect function invocation.
2988 Function *getCalledFunction() const {
2989 return dyn_cast<Function>(Op<-3>());
2992 /// getCalledValue - Get a pointer to the function that is invoked by this
2994 const Value *getCalledValue() const { return Op<-3>(); }
2995 Value *getCalledValue() { return Op<-3>(); }
2997 /// setCalledFunction - Set the function called.
2998 void setCalledFunction(Value* Fn) {
3002 // get*Dest - Return the destination basic blocks...
3003 BasicBlock *getNormalDest() const {
3004 return cast<BasicBlock>(Op<-2>());
3006 BasicBlock *getUnwindDest() const {
3007 return cast<BasicBlock>(Op<-1>());
3009 void setNormalDest(BasicBlock *B) {
3010 Op<-2>() = reinterpret_cast<Value*>(B);
3012 void setUnwindDest(BasicBlock *B) {
3013 Op<-1>() = reinterpret_cast<Value*>(B);
3016 /// getLandingPadInst - Get the landingpad instruction from the landing pad
3017 /// block (the unwind destination).
3018 LandingPadInst *getLandingPadInst() const;
3020 BasicBlock *getSuccessor(unsigned i) const {
3021 assert(i < 2 && "Successor # out of range for invoke!");
3022 return i == 0 ? getNormalDest() : getUnwindDest();
3025 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3026 assert(idx < 2 && "Successor # out of range for invoke!");
3027 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
3030 unsigned getNumSuccessors() const { return 2; }
3032 // Methods for support type inquiry through isa, cast, and dyn_cast:
3033 static inline bool classof(const Instruction *I) {
3034 return (I->getOpcode() == Instruction::Invoke);
3036 static inline bool classof(const Value *V) {
3037 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3041 virtual BasicBlock *getSuccessorV(unsigned idx) const;
3042 virtual unsigned getNumSuccessorsV() const;
3043 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3045 bool hasFnAttrImpl(Attribute::AttrKind A) const;
3047 // Shadow Instruction::setInstructionSubclassData with a private forwarding
3048 // method so that subclasses cannot accidentally use it.
3049 void setInstructionSubclassData(unsigned short D) {
3050 Instruction::setInstructionSubclassData(D);
3055 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
3058 InvokeInst::InvokeInst(Value *Func,
3059 BasicBlock *IfNormal, BasicBlock *IfException,
3060 ArrayRef<Value *> Args, unsigned Values,
3061 const Twine &NameStr, Instruction *InsertBefore)
3062 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3063 ->getElementType())->getReturnType(),
3064 Instruction::Invoke,
3065 OperandTraits<InvokeInst>::op_end(this) - Values,
3066 Values, InsertBefore) {
3067 init(Func, IfNormal, IfException, Args, NameStr);
3069 InvokeInst::InvokeInst(Value *Func,
3070 BasicBlock *IfNormal, BasicBlock *IfException,
3071 ArrayRef<Value *> Args, unsigned Values,
3072 const Twine &NameStr, BasicBlock *InsertAtEnd)
3073 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3074 ->getElementType())->getReturnType(),
3075 Instruction::Invoke,
3076 OperandTraits<InvokeInst>::op_end(this) - Values,
3077 Values, InsertAtEnd) {
3078 init(Func, IfNormal, IfException, Args, NameStr);
3081 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
3083 //===----------------------------------------------------------------------===//
3085 //===----------------------------------------------------------------------===//
3087 //===---------------------------------------------------------------------------
3088 /// ResumeInst - Resume the propagation of an exception.
3090 class ResumeInst : public TerminatorInst {
3091 ResumeInst(const ResumeInst &RI);
3093 explicit ResumeInst(Value *Exn, Instruction *InsertBefore=0);
3094 ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
3096 virtual ResumeInst *clone_impl() const;
3098 static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = 0) {
3099 return new(1) ResumeInst(Exn, InsertBefore);
3101 static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
3102 return new(1) ResumeInst(Exn, InsertAtEnd);
3105 /// Provide fast operand accessors
3106 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3108 /// Convenience accessor.
3109 Value *getValue() const { return Op<0>(); }
3111 unsigned getNumSuccessors() const { return 0; }
3113 // Methods for support type inquiry through isa, cast, and dyn_cast:
3114 static inline bool classof(const Instruction *I) {
3115 return I->getOpcode() == Instruction::Resume;
3117 static inline bool classof(const Value *V) {
3118 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3121 virtual BasicBlock *getSuccessorV(unsigned idx) const;
3122 virtual unsigned getNumSuccessorsV() const;
3123 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3127 struct OperandTraits<ResumeInst> :
3128 public FixedNumOperandTraits<ResumeInst, 1> {
3131 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
3133 //===----------------------------------------------------------------------===//
3134 // UnreachableInst Class
3135 //===----------------------------------------------------------------------===//
3137 //===---------------------------------------------------------------------------
3138 /// UnreachableInst - This function has undefined behavior. In particular, the
3139 /// presence of this instruction indicates some higher level knowledge that the
3140 /// end of the block cannot be reached.
3142 class UnreachableInst : public TerminatorInst {
3143 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
3145 virtual UnreachableInst *clone_impl() const;
3148 // allocate space for exactly zero operands
3149 void *operator new(size_t s) {
3150 return User::operator new(s, 0);
3152 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
3153 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
3155 unsigned getNumSuccessors() const { return 0; }
3157 // Methods for support type inquiry through isa, cast, and dyn_cast:
3158 static inline bool classof(const Instruction *I) {
3159 return I->getOpcode() == Instruction::Unreachable;
3161 static inline bool classof(const Value *V) {
3162 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3165 virtual BasicBlock *getSuccessorV(unsigned idx) const;
3166 virtual unsigned getNumSuccessorsV() const;
3167 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3170 //===----------------------------------------------------------------------===//
3172 //===----------------------------------------------------------------------===//
3174 /// \brief This class represents a truncation of integer types.
3175 class TruncInst : public CastInst {
3177 /// \brief Clone an identical TruncInst
3178 virtual TruncInst *clone_impl() const;
3181 /// \brief Constructor with insert-before-instruction semantics
3183 Value *S, ///< The value to be truncated
3184 Type *Ty, ///< The (smaller) type to truncate to
3185 const Twine &NameStr = "", ///< A name for the new instruction
3186 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3189 /// \brief Constructor with insert-at-end-of-block semantics
3191 Value *S, ///< The value to be truncated
3192 Type *Ty, ///< The (smaller) type to truncate to
3193 const Twine &NameStr, ///< A name for the new instruction
3194 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3197 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3198 static inline bool classof(const Instruction *I) {
3199 return I->getOpcode() == Trunc;
3201 static inline bool classof(const Value *V) {
3202 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3206 //===----------------------------------------------------------------------===//
3208 //===----------------------------------------------------------------------===//
3210 /// \brief This class represents zero extension of integer types.
3211 class ZExtInst : public CastInst {
3213 /// \brief Clone an identical ZExtInst
3214 virtual ZExtInst *clone_impl() const;
3217 /// \brief Constructor with insert-before-instruction semantics
3219 Value *S, ///< The value to be zero extended
3220 Type *Ty, ///< The type to zero extend to
3221 const Twine &NameStr = "", ///< A name for the new instruction
3222 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3225 /// \brief Constructor with insert-at-end semantics.
3227 Value *S, ///< The value to be zero extended
3228 Type *Ty, ///< The type to zero extend to
3229 const Twine &NameStr, ///< A name for the new instruction
3230 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3233 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3234 static inline bool classof(const Instruction *I) {
3235 return I->getOpcode() == ZExt;
3237 static inline bool classof(const Value *V) {
3238 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3242 //===----------------------------------------------------------------------===//
3244 //===----------------------------------------------------------------------===//
3246 /// \brief This class represents a sign extension of integer types.
3247 class SExtInst : public CastInst {
3249 /// \brief Clone an identical SExtInst
3250 virtual SExtInst *clone_impl() const;
3253 /// \brief Constructor with insert-before-instruction semantics
3255 Value *S, ///< The value to be sign extended
3256 Type *Ty, ///< The type to sign extend to
3257 const Twine &NameStr = "", ///< A name for the new instruction
3258 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3261 /// \brief Constructor with insert-at-end-of-block semantics
3263 Value *S, ///< The value to be sign extended
3264 Type *Ty, ///< The type to sign extend to
3265 const Twine &NameStr, ///< A name for the new instruction
3266 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3269 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3270 static inline bool classof(const Instruction *I) {
3271 return I->getOpcode() == SExt;
3273 static inline bool classof(const Value *V) {
3274 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3278 //===----------------------------------------------------------------------===//
3279 // FPTruncInst Class
3280 //===----------------------------------------------------------------------===//
3282 /// \brief This class represents a truncation of floating point types.
3283 class FPTruncInst : public CastInst {
3285 /// \brief Clone an identical FPTruncInst
3286 virtual FPTruncInst *clone_impl() const;
3289 /// \brief Constructor with insert-before-instruction semantics
3291 Value *S, ///< The value to be truncated
3292 Type *Ty, ///< The type to truncate to
3293 const Twine &NameStr = "", ///< A name for the new instruction
3294 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3297 /// \brief Constructor with insert-before-instruction semantics
3299 Value *S, ///< The value to be truncated
3300 Type *Ty, ///< The type to truncate to
3301 const Twine &NameStr, ///< A name for the new instruction
3302 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3305 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3306 static inline bool classof(const Instruction *I) {
3307 return I->getOpcode() == FPTrunc;
3309 static inline bool classof(const Value *V) {
3310 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3314 //===----------------------------------------------------------------------===//
3316 //===----------------------------------------------------------------------===//
3318 /// \brief This class represents an extension of floating point types.
3319 class FPExtInst : public CastInst {
3321 /// \brief Clone an identical FPExtInst
3322 virtual FPExtInst *clone_impl() const;
3325 /// \brief Constructor with insert-before-instruction semantics
3327 Value *S, ///< The value to be extended
3328 Type *Ty, ///< The type to extend to
3329 const Twine &NameStr = "", ///< A name for the new instruction
3330 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3333 /// \brief Constructor with insert-at-end-of-block semantics
3335 Value *S, ///< The value to be extended
3336 Type *Ty, ///< The type to extend to
3337 const Twine &NameStr, ///< A name for the new instruction
3338 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3341 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3342 static inline bool classof(const Instruction *I) {
3343 return I->getOpcode() == FPExt;
3345 static inline bool classof(const Value *V) {
3346 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3350 //===----------------------------------------------------------------------===//
3352 //===----------------------------------------------------------------------===//
3354 /// \brief This class represents a cast unsigned integer to floating point.
3355 class UIToFPInst : public CastInst {
3357 /// \brief Clone an identical UIToFPInst
3358 virtual UIToFPInst *clone_impl() const;
3361 /// \brief Constructor with insert-before-instruction semantics
3363 Value *S, ///< The value to be converted
3364 Type *Ty, ///< The type to convert to
3365 const Twine &NameStr = "", ///< A name for the new instruction
3366 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3369 /// \brief Constructor with insert-at-end-of-block semantics
3371 Value *S, ///< The value to be converted
3372 Type *Ty, ///< The type to convert to
3373 const Twine &NameStr, ///< A name for the new instruction
3374 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3377 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3378 static inline bool classof(const Instruction *I) {
3379 return I->getOpcode() == UIToFP;
3381 static inline bool classof(const Value *V) {
3382 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3386 //===----------------------------------------------------------------------===//
3388 //===----------------------------------------------------------------------===//
3390 /// \brief This class represents a cast from signed integer to floating point.
3391 class SIToFPInst : public CastInst {
3393 /// \brief Clone an identical SIToFPInst
3394 virtual SIToFPInst *clone_impl() const;
3397 /// \brief Constructor with insert-before-instruction semantics
3399 Value *S, ///< The value to be converted
3400 Type *Ty, ///< The type to convert to
3401 const Twine &NameStr = "", ///< A name for the new instruction
3402 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3405 /// \brief Constructor with insert-at-end-of-block semantics
3407 Value *S, ///< The value to be converted
3408 Type *Ty, ///< The type to convert to
3409 const Twine &NameStr, ///< A name for the new instruction
3410 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3413 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3414 static inline bool classof(const Instruction *I) {
3415 return I->getOpcode() == SIToFP;
3417 static inline bool classof(const Value *V) {
3418 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3422 //===----------------------------------------------------------------------===//
3424 //===----------------------------------------------------------------------===//
3426 /// \brief This class represents a cast from floating point to unsigned integer
3427 class FPToUIInst : public CastInst {
3429 /// \brief Clone an identical FPToUIInst
3430 virtual FPToUIInst *clone_impl() const;
3433 /// \brief Constructor with insert-before-instruction 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 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3441 /// \brief Constructor with insert-at-end-of-block semantics
3443 Value *S, ///< The value to be converted
3444 Type *Ty, ///< The type to convert to
3445 const Twine &NameStr, ///< A name for the new instruction
3446 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3449 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3450 static inline bool classof(const Instruction *I) {
3451 return I->getOpcode() == FPToUI;
3453 static inline bool classof(const Value *V) {
3454 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3458 //===----------------------------------------------------------------------===//
3460 //===----------------------------------------------------------------------===//
3462 /// \brief This class represents a cast from floating point to signed integer.
3463 class FPToSIInst : public CastInst {
3465 /// \brief Clone an identical FPToSIInst
3466 virtual FPToSIInst *clone_impl() const;
3469 /// \brief Constructor with insert-before-instruction semantics
3471 Value *S, ///< The value to be converted
3472 Type *Ty, ///< The type to convert to
3473 const Twine &NameStr = "", ///< A name for the new instruction
3474 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3477 /// \brief Constructor with insert-at-end-of-block semantics
3479 Value *S, ///< The value to be converted
3480 Type *Ty, ///< The type to convert to
3481 const Twine &NameStr, ///< A name for the new instruction
3482 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3485 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3486 static inline bool classof(const Instruction *I) {
3487 return I->getOpcode() == FPToSI;
3489 static inline bool classof(const Value *V) {
3490 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3494 //===----------------------------------------------------------------------===//
3495 // IntToPtrInst Class
3496 //===----------------------------------------------------------------------===//
3498 /// \brief This class represents a cast from an integer to a pointer.
3499 class IntToPtrInst : public CastInst {
3501 /// \brief Constructor with insert-before-instruction semantics
3503 Value *S, ///< The value to be converted
3504 Type *Ty, ///< The type to convert to
3505 const Twine &NameStr = "", ///< A name for the new instruction
3506 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3509 /// \brief Constructor with insert-at-end-of-block semantics
3511 Value *S, ///< The value to be converted
3512 Type *Ty, ///< The type to convert to
3513 const Twine &NameStr, ///< A name for the new instruction
3514 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3517 /// \brief Clone an identical IntToPtrInst
3518 virtual IntToPtrInst *clone_impl() const;
3520 /// \brief Returns the address space of this instruction's pointer type.
3521 unsigned getAddressSpace() const {
3522 return getType()->getPointerAddressSpace();
3525 // Methods for support type inquiry through isa, cast, and dyn_cast:
3526 static inline bool classof(const Instruction *I) {
3527 return I->getOpcode() == IntToPtr;
3529 static inline bool classof(const Value *V) {
3530 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3534 //===----------------------------------------------------------------------===//
3535 // PtrToIntInst Class
3536 //===----------------------------------------------------------------------===//
3538 /// \brief This class represents a cast from a pointer to an integer
3539 class PtrToIntInst : public CastInst {
3541 /// \brief Clone an identical PtrToIntInst
3542 virtual PtrToIntInst *clone_impl() const;
3545 /// \brief Constructor with insert-before-instruction semantics
3547 Value *S, ///< The value to be converted
3548 Type *Ty, ///< The type to convert to
3549 const Twine &NameStr = "", ///< A name for the new instruction
3550 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3553 /// \brief Constructor with insert-at-end-of-block semantics
3555 Value *S, ///< The value to be converted
3556 Type *Ty, ///< The type to convert to
3557 const Twine &NameStr, ///< A name for the new instruction
3558 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3561 /// \brief Gets the pointer operand.
3562 Value *getPointerOperand() { return getOperand(0); }
3563 /// \brief Gets the pointer operand.
3564 const Value *getPointerOperand() const { return getOperand(0); }
3565 /// \brief Gets the operand index of the pointer operand.
3566 static unsigned getPointerOperandIndex() { return 0U; }
3568 /// \brief Returns the address space of the pointer operand.
3569 unsigned getPointerAddressSpace() const {
3570 return getPointerOperand()->getType()->getPointerAddressSpace();
3573 // Methods for support type inquiry through isa, cast, and dyn_cast:
3574 static inline bool classof(const Instruction *I) {
3575 return I->getOpcode() == PtrToInt;
3577 static inline bool classof(const Value *V) {
3578 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3582 //===----------------------------------------------------------------------===//
3583 // BitCastInst Class
3584 //===----------------------------------------------------------------------===//
3586 /// \brief This class represents a no-op cast from one type to another.
3587 class BitCastInst : public CastInst {
3589 /// \brief Clone an identical BitCastInst
3590 virtual BitCastInst *clone_impl() const;
3593 /// \brief Constructor with insert-before-instruction semantics
3595 Value *S, ///< The value to be casted
3596 Type *Ty, ///< The type to casted to
3597 const Twine &NameStr = "", ///< A name for the new instruction
3598 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3601 /// \brief Constructor with insert-at-end-of-block semantics
3603 Value *S, ///< The value to be casted
3604 Type *Ty, ///< The type to casted to
3605 const Twine &NameStr, ///< A name for the new instruction
3606 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3609 // Methods for support type inquiry through isa, cast, and dyn_cast:
3610 static inline bool classof(const Instruction *I) {
3611 return I->getOpcode() == BitCast;
3613 static inline bool classof(const Value *V) {
3614 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3618 } // End llvm namespace