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 /// \brief Clone an identical ICmpInst
914 virtual ICmpInst *clone_impl() const;
916 /// \brief Constructor with insert-before-instruction semantics.
918 Instruction *InsertBefore, ///< Where to insert
919 Predicate pred, ///< The predicate to use for the comparison
920 Value *LHS, ///< The left-hand-side of the expression
921 Value *RHS, ///< The right-hand-side of the expression
922 const Twine &NameStr = "" ///< Name of the instruction
923 ) : CmpInst(makeCmpResultType(LHS->getType()),
924 Instruction::ICmp, pred, LHS, RHS, NameStr,
926 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
927 pred <= CmpInst::LAST_ICMP_PREDICATE &&
928 "Invalid ICmp predicate value");
929 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
930 "Both operands to ICmp instruction are not of the same type!");
931 // Check that the operands are the right type
932 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
933 getOperand(0)->getType()->getScalarType()->isPointerTy()) &&
934 "Invalid operand types for ICmp instruction");
937 /// \brief Constructor with insert-at-end semantics.
939 BasicBlock &InsertAtEnd, ///< Block to insert into.
940 Predicate pred, ///< The predicate to use for the comparison
941 Value *LHS, ///< The left-hand-side of the expression
942 Value *RHS, ///< The right-hand-side of the expression
943 const Twine &NameStr = "" ///< Name of the instruction
944 ) : CmpInst(makeCmpResultType(LHS->getType()),
945 Instruction::ICmp, pred, LHS, RHS, NameStr,
947 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
948 pred <= CmpInst::LAST_ICMP_PREDICATE &&
949 "Invalid ICmp predicate value");
950 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
951 "Both operands to ICmp instruction are not of the same type!");
952 // Check that the operands are the right type
953 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
954 getOperand(0)->getType()->getScalarType()->isPointerTy()) &&
955 "Invalid operand types for ICmp instruction");
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) {
966 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
967 pred <= CmpInst::LAST_ICMP_PREDICATE &&
968 "Invalid ICmp predicate value");
969 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
970 "Both operands to ICmp instruction are not of the same type!");
971 // Check that the operands are the right type
972 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
973 getOperand(0)->getType()->getScalarType()->isPointerTy()) &&
974 "Invalid operand types for ICmp instruction");
977 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
978 /// @returns the predicate that would be the result if the operand were
979 /// regarded as signed.
980 /// \brief Return the signed version of the predicate
981 Predicate getSignedPredicate() const {
982 return getSignedPredicate(getPredicate());
985 /// This is a static version that you can use without an instruction.
986 /// \brief Return the signed version of the predicate.
987 static Predicate getSignedPredicate(Predicate pred);
989 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
990 /// @returns the predicate that would be the result if the operand were
991 /// regarded as unsigned.
992 /// \brief Return the unsigned version of the predicate
993 Predicate getUnsignedPredicate() const {
994 return getUnsignedPredicate(getPredicate());
997 /// This is a static version that you can use without an instruction.
998 /// \brief Return the unsigned version of the predicate.
999 static Predicate getUnsignedPredicate(Predicate pred);
1001 /// isEquality - Return true if this predicate is either EQ or NE. This also
1002 /// tests for commutativity.
1003 static bool isEquality(Predicate P) {
1004 return P == ICMP_EQ || P == ICMP_NE;
1007 /// isEquality - Return true if this predicate is either EQ or NE. This also
1008 /// tests for commutativity.
1009 bool isEquality() const {
1010 return isEquality(getPredicate());
1013 /// @returns true if the predicate of this ICmpInst is commutative
1014 /// \brief Determine if this relation is commutative.
1015 bool isCommutative() const { return isEquality(); }
1017 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1019 bool isRelational() const {
1020 return !isEquality();
1023 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1025 static bool isRelational(Predicate P) {
1026 return !isEquality(P);
1029 /// Initialize a set of values that all satisfy the predicate with C.
1030 /// \brief Make a ConstantRange for a relation with a constant value.
1031 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
1033 /// Exchange the two operands to this instruction in such a way that it does
1034 /// not modify the semantics of the instruction. The predicate value may be
1035 /// changed to retain the same result if the predicate is order dependent
1037 /// \brief Swap operands and adjust predicate.
1038 void swapOperands() {
1039 setPredicate(getSwappedPredicate());
1040 Op<0>().swap(Op<1>());
1043 // Methods for support type inquiry through isa, cast, and dyn_cast:
1044 static inline bool classof(const Instruction *I) {
1045 return I->getOpcode() == Instruction::ICmp;
1047 static inline bool classof(const Value *V) {
1048 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1053 //===----------------------------------------------------------------------===//
1055 //===----------------------------------------------------------------------===//
1057 /// This instruction compares its operands according to the predicate given
1058 /// to the constructor. It only operates on floating point values or packed
1059 /// vectors of floating point values. The operands must be identical types.
1060 /// \brief Represents a floating point comparison operator.
1061 class FCmpInst: public CmpInst {
1063 /// \brief Clone an identical FCmpInst
1064 virtual FCmpInst *clone_impl() const;
1066 /// \brief Constructor with insert-before-instruction semantics.
1068 Instruction *InsertBefore, ///< Where to insert
1069 Predicate pred, ///< The predicate to use for the comparison
1070 Value *LHS, ///< The left-hand-side of the expression
1071 Value *RHS, ///< The right-hand-side of the expression
1072 const Twine &NameStr = "" ///< Name of the instruction
1073 ) : CmpInst(makeCmpResultType(LHS->getType()),
1074 Instruction::FCmp, pred, LHS, RHS, NameStr,
1076 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1077 "Invalid FCmp predicate value");
1078 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1079 "Both operands to FCmp instruction are not of the same type!");
1080 // Check that the operands are the right type
1081 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1082 "Invalid operand types for FCmp instruction");
1085 /// \brief Constructor with insert-at-end semantics.
1087 BasicBlock &InsertAtEnd, ///< Block to insert into.
1088 Predicate pred, ///< The predicate to use for the comparison
1089 Value *LHS, ///< The left-hand-side of the expression
1090 Value *RHS, ///< The right-hand-side of the expression
1091 const Twine &NameStr = "" ///< Name of the instruction
1092 ) : CmpInst(makeCmpResultType(LHS->getType()),
1093 Instruction::FCmp, pred, LHS, RHS, NameStr,
1095 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1096 "Invalid FCmp predicate value");
1097 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1098 "Both operands to FCmp instruction are not of the same type!");
1099 // Check that the operands are the right type
1100 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1101 "Invalid operand types for FCmp instruction");
1104 /// \brief Constructor with no-insertion semantics
1106 Predicate pred, ///< The predicate to use for the comparison
1107 Value *LHS, ///< The left-hand-side of the expression
1108 Value *RHS, ///< The right-hand-side of the expression
1109 const Twine &NameStr = "" ///< Name of the instruction
1110 ) : CmpInst(makeCmpResultType(LHS->getType()),
1111 Instruction::FCmp, pred, LHS, RHS, NameStr) {
1112 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1113 "Invalid FCmp predicate value");
1114 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1115 "Both operands to FCmp instruction are not of the same type!");
1116 // Check that the operands are the right type
1117 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1118 "Invalid operand types for FCmp instruction");
1121 /// @returns true if the predicate of this instruction is EQ or NE.
1122 /// \brief Determine if this is an equality predicate.
1123 bool isEquality() const {
1124 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
1125 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
1128 /// @returns true if the predicate of this instruction is commutative.
1129 /// \brief Determine if this is a commutative predicate.
1130 bool isCommutative() const {
1131 return isEquality() ||
1132 getPredicate() == FCMP_FALSE ||
1133 getPredicate() == FCMP_TRUE ||
1134 getPredicate() == FCMP_ORD ||
1135 getPredicate() == FCMP_UNO;
1138 /// @returns true if the predicate is relational (not EQ or NE).
1139 /// \brief Determine if this a relational predicate.
1140 bool isRelational() const { return !isEquality(); }
1142 /// Exchange the two operands to this instruction in such a way that it does
1143 /// not modify the semantics of the instruction. The predicate value may be
1144 /// changed to retain the same result if the predicate is order dependent
1146 /// \brief Swap operands and adjust predicate.
1147 void swapOperands() {
1148 setPredicate(getSwappedPredicate());
1149 Op<0>().swap(Op<1>());
1152 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
1153 static inline bool classof(const Instruction *I) {
1154 return I->getOpcode() == Instruction::FCmp;
1156 static inline bool classof(const Value *V) {
1157 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1161 //===----------------------------------------------------------------------===//
1162 /// CallInst - This class represents a function call, abstracting a target
1163 /// machine's calling convention. This class uses low bit of the SubClassData
1164 /// field to indicate whether or not this is a tail call. The rest of the bits
1165 /// hold the calling convention of the call.
1167 class CallInst : public Instruction {
1168 AttributeSet AttributeList; ///< parameter attributes for call
1169 CallInst(const CallInst &CI);
1170 void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
1171 void init(Value *Func, const Twine &NameStr);
1173 /// Construct a CallInst given a range of arguments.
1174 /// \brief Construct a CallInst from a range of arguments
1175 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1176 const Twine &NameStr, Instruction *InsertBefore);
1178 /// Construct a CallInst given a range of arguments.
1179 /// \brief Construct a CallInst from a range of arguments
1180 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1181 const Twine &NameStr, BasicBlock *InsertAtEnd);
1183 CallInst(Value *F, Value *Actual, const Twine &NameStr,
1184 Instruction *InsertBefore);
1185 CallInst(Value *F, Value *Actual, const Twine &NameStr,
1186 BasicBlock *InsertAtEnd);
1187 explicit CallInst(Value *F, const Twine &NameStr,
1188 Instruction *InsertBefore);
1189 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1191 virtual CallInst *clone_impl() const;
1193 static CallInst *Create(Value *Func,
1194 ArrayRef<Value *> Args,
1195 const Twine &NameStr = "",
1196 Instruction *InsertBefore = 0) {
1197 return new(unsigned(Args.size() + 1))
1198 CallInst(Func, Args, NameStr, InsertBefore);
1200 static CallInst *Create(Value *Func,
1201 ArrayRef<Value *> Args,
1202 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1203 return new(unsigned(Args.size() + 1))
1204 CallInst(Func, Args, NameStr, InsertAtEnd);
1206 static CallInst *Create(Value *F, const Twine &NameStr = "",
1207 Instruction *InsertBefore = 0) {
1208 return new(1) CallInst(F, NameStr, InsertBefore);
1210 static CallInst *Create(Value *F, const Twine &NameStr,
1211 BasicBlock *InsertAtEnd) {
1212 return new(1) CallInst(F, NameStr, InsertAtEnd);
1214 /// CreateMalloc - Generate the IR for a call to malloc:
1215 /// 1. Compute the malloc call's argument as the specified type's size,
1216 /// possibly multiplied by the array size if the array size is not
1218 /// 2. Call malloc with that argument.
1219 /// 3. Bitcast the result of the malloc call to the specified type.
1220 static Instruction *CreateMalloc(Instruction *InsertBefore,
1221 Type *IntPtrTy, Type *AllocTy,
1222 Value *AllocSize, Value *ArraySize = 0,
1223 Function* MallocF = 0,
1224 const Twine &Name = "");
1225 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1226 Type *IntPtrTy, Type *AllocTy,
1227 Value *AllocSize, Value *ArraySize = 0,
1228 Function* MallocF = 0,
1229 const Twine &Name = "");
1230 /// CreateFree - Generate the IR for a call to the builtin free function.
1231 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
1232 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
1236 bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
1237 void setTailCall(bool isTC = true) {
1238 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
1242 /// Provide fast operand accessors
1243 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1245 /// getNumArgOperands - Return the number of call arguments.
1247 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
1249 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1251 Value *getArgOperand(unsigned i) const { return getOperand(i); }
1252 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
1254 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1256 CallingConv::ID getCallingConv() const {
1257 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
1259 void setCallingConv(CallingConv::ID CC) {
1260 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
1261 (static_cast<unsigned>(CC) << 1));
1264 /// getAttributes - Return the parameter attributes for this call.
1266 const AttributeSet &getAttributes() const { return AttributeList; }
1268 /// setAttributes - Set the parameter attributes for this call.
1270 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
1272 /// addAttribute - adds the attribute to the list of attributes.
1273 void addAttribute(unsigned i, Attribute::AttrKind attr);
1275 /// removeAttribute - removes the attribute from the list of attributes.
1276 void removeAttribute(unsigned i, Attribute attr);
1278 /// \brief Determine whether this call has the given attribute.
1279 bool hasFnAttr(Attribute::AttrKind A) const {
1280 assert(A != Attribute::NoBuiltin &&
1281 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
1282 return hasFnAttrImpl(A);
1285 /// \brief Determine whether the call or the callee has the given attributes.
1286 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
1288 /// \brief Extract the alignment for a call or parameter (0=unknown).
1289 unsigned getParamAlignment(unsigned i) const {
1290 return AttributeList.getParamAlignment(i);
1293 /// \brief Return true if the call should not be treated as a call to a
1295 bool isNoBuiltin() const {
1296 return hasFnAttrImpl(Attribute::NoBuiltin) &&
1297 !hasFnAttrImpl(Attribute::Builtin);
1300 /// \brief Return true if the call should not be inlined.
1301 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
1302 void setIsNoInline() {
1303 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
1306 /// \brief Return true if the call can return twice
1307 bool canReturnTwice() const {
1308 return hasFnAttr(Attribute::ReturnsTwice);
1310 void setCanReturnTwice() {
1311 addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice);
1314 /// \brief Determine if the call does not access memory.
1315 bool doesNotAccessMemory() const {
1316 return hasFnAttr(Attribute::ReadNone);
1318 void setDoesNotAccessMemory() {
1319 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
1322 /// \brief Determine if the call does not access or only reads memory.
1323 bool onlyReadsMemory() const {
1324 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
1326 void setOnlyReadsMemory() {
1327 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
1330 /// \brief Determine if the call cannot return.
1331 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
1332 void setDoesNotReturn() {
1333 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
1336 /// \brief Determine if the call cannot unwind.
1337 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
1338 void setDoesNotThrow() {
1339 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
1342 /// \brief Determine if the call cannot be duplicated.
1343 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
1344 void setCannotDuplicate() {
1345 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
1348 /// \brief Determine if the call returns a structure through first
1349 /// pointer argument.
1350 bool hasStructRetAttr() const {
1351 // Be friendly and also check the callee.
1352 return paramHasAttr(1, Attribute::StructRet);
1355 /// \brief Determine if any call argument is an aggregate passed by value.
1356 bool hasByValArgument() const {
1357 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1360 /// getCalledFunction - Return the function called, or null if this is an
1361 /// indirect function invocation.
1363 Function *getCalledFunction() const {
1364 return dyn_cast<Function>(Op<-1>());
1367 /// getCalledValue - Get a pointer to the function that is invoked by this
1369 const Value *getCalledValue() const { return Op<-1>(); }
1370 Value *getCalledValue() { return Op<-1>(); }
1372 /// setCalledFunction - Set the function called.
1373 void setCalledFunction(Value* Fn) {
1377 /// isInlineAsm - Check if this call is an inline asm statement.
1378 bool isInlineAsm() const {
1379 return isa<InlineAsm>(Op<-1>());
1382 // Methods for support type inquiry through isa, cast, and dyn_cast:
1383 static inline bool classof(const Instruction *I) {
1384 return I->getOpcode() == Instruction::Call;
1386 static inline bool classof(const Value *V) {
1387 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1391 bool hasFnAttrImpl(Attribute::AttrKind A) const;
1393 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1394 // method so that subclasses cannot accidentally use it.
1395 void setInstructionSubclassData(unsigned short D) {
1396 Instruction::setInstructionSubclassData(D);
1401 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1404 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1405 const Twine &NameStr, BasicBlock *InsertAtEnd)
1406 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1407 ->getElementType())->getReturnType(),
1409 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1410 unsigned(Args.size() + 1), InsertAtEnd) {
1411 init(Func, Args, NameStr);
1414 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1415 const Twine &NameStr, Instruction *InsertBefore)
1416 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1417 ->getElementType())->getReturnType(),
1419 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1420 unsigned(Args.size() + 1), InsertBefore) {
1421 init(Func, Args, NameStr);
1425 // Note: if you get compile errors about private methods then
1426 // please update your code to use the high-level operand
1427 // interfaces. See line 943 above.
1428 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1430 //===----------------------------------------------------------------------===//
1432 //===----------------------------------------------------------------------===//
1434 /// SelectInst - This class represents the LLVM 'select' instruction.
1436 class SelectInst : public Instruction {
1437 void init(Value *C, Value *S1, Value *S2) {
1438 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1444 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1445 Instruction *InsertBefore)
1446 : Instruction(S1->getType(), Instruction::Select,
1447 &Op<0>(), 3, InsertBefore) {
1451 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1452 BasicBlock *InsertAtEnd)
1453 : Instruction(S1->getType(), Instruction::Select,
1454 &Op<0>(), 3, InsertAtEnd) {
1459 virtual SelectInst *clone_impl() const;
1461 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1462 const Twine &NameStr = "",
1463 Instruction *InsertBefore = 0) {
1464 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1466 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1467 const Twine &NameStr,
1468 BasicBlock *InsertAtEnd) {
1469 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1472 const Value *getCondition() const { return Op<0>(); }
1473 const Value *getTrueValue() const { return Op<1>(); }
1474 const Value *getFalseValue() const { return Op<2>(); }
1475 Value *getCondition() { return Op<0>(); }
1476 Value *getTrueValue() { return Op<1>(); }
1477 Value *getFalseValue() { return Op<2>(); }
1479 /// areInvalidOperands - Return a string if the specified operands are invalid
1480 /// for a select operation, otherwise return null.
1481 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1483 /// Transparently provide more efficient getOperand methods.
1484 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1486 OtherOps getOpcode() const {
1487 return static_cast<OtherOps>(Instruction::getOpcode());
1490 // Methods for support type inquiry through isa, cast, and dyn_cast:
1491 static inline bool classof(const Instruction *I) {
1492 return I->getOpcode() == Instruction::Select;
1494 static inline bool classof(const Value *V) {
1495 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1500 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1503 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1505 //===----------------------------------------------------------------------===//
1507 //===----------------------------------------------------------------------===//
1509 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1510 /// an argument of the specified type given a va_list and increments that list
1512 class VAArgInst : public UnaryInstruction {
1514 virtual VAArgInst *clone_impl() const;
1517 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1518 Instruction *InsertBefore = 0)
1519 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1522 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1523 BasicBlock *InsertAtEnd)
1524 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1528 Value *getPointerOperand() { return getOperand(0); }
1529 const Value *getPointerOperand() const { return getOperand(0); }
1530 static unsigned getPointerOperandIndex() { return 0U; }
1532 // Methods for support type inquiry through isa, cast, and dyn_cast:
1533 static inline bool classof(const Instruction *I) {
1534 return I->getOpcode() == VAArg;
1536 static inline bool classof(const Value *V) {
1537 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1541 //===----------------------------------------------------------------------===//
1542 // ExtractElementInst Class
1543 //===----------------------------------------------------------------------===//
1545 /// ExtractElementInst - This instruction extracts a single (scalar)
1546 /// element from a VectorType value
1548 class ExtractElementInst : public Instruction {
1549 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1550 Instruction *InsertBefore = 0);
1551 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1552 BasicBlock *InsertAtEnd);
1554 virtual ExtractElementInst *clone_impl() const;
1557 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1558 const Twine &NameStr = "",
1559 Instruction *InsertBefore = 0) {
1560 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1562 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1563 const Twine &NameStr,
1564 BasicBlock *InsertAtEnd) {
1565 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1568 /// isValidOperands - Return true if an extractelement instruction can be
1569 /// formed with the specified operands.
1570 static bool isValidOperands(const Value *Vec, const Value *Idx);
1572 Value *getVectorOperand() { return Op<0>(); }
1573 Value *getIndexOperand() { return Op<1>(); }
1574 const Value *getVectorOperand() const { return Op<0>(); }
1575 const Value *getIndexOperand() const { return Op<1>(); }
1577 VectorType *getVectorOperandType() const {
1578 return cast<VectorType>(getVectorOperand()->getType());
1582 /// Transparently provide more efficient getOperand methods.
1583 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1585 // Methods for support type inquiry through isa, cast, and dyn_cast:
1586 static inline bool classof(const Instruction *I) {
1587 return I->getOpcode() == Instruction::ExtractElement;
1589 static inline bool classof(const Value *V) {
1590 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1595 struct OperandTraits<ExtractElementInst> :
1596 public FixedNumOperandTraits<ExtractElementInst, 2> {
1599 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1601 //===----------------------------------------------------------------------===//
1602 // InsertElementInst Class
1603 //===----------------------------------------------------------------------===//
1605 /// InsertElementInst - This instruction inserts a single (scalar)
1606 /// element into a VectorType value
1608 class InsertElementInst : public Instruction {
1609 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1610 const Twine &NameStr = "",
1611 Instruction *InsertBefore = 0);
1612 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1613 const Twine &NameStr, BasicBlock *InsertAtEnd);
1615 virtual InsertElementInst *clone_impl() const;
1618 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1619 const Twine &NameStr = "",
1620 Instruction *InsertBefore = 0) {
1621 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1623 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1624 const Twine &NameStr,
1625 BasicBlock *InsertAtEnd) {
1626 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1629 /// isValidOperands - Return true if an insertelement instruction can be
1630 /// formed with the specified operands.
1631 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1634 /// getType - Overload to return most specific vector type.
1636 VectorType *getType() const {
1637 return cast<VectorType>(Instruction::getType());
1640 /// Transparently provide more efficient getOperand methods.
1641 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1643 // Methods for support type inquiry through isa, cast, and dyn_cast:
1644 static inline bool classof(const Instruction *I) {
1645 return I->getOpcode() == Instruction::InsertElement;
1647 static inline bool classof(const Value *V) {
1648 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1653 struct OperandTraits<InsertElementInst> :
1654 public FixedNumOperandTraits<InsertElementInst, 3> {
1657 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1659 //===----------------------------------------------------------------------===//
1660 // ShuffleVectorInst Class
1661 //===----------------------------------------------------------------------===//
1663 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1666 class ShuffleVectorInst : public Instruction {
1668 virtual ShuffleVectorInst *clone_impl() const;
1671 // allocate space for exactly three operands
1672 void *operator new(size_t s) {
1673 return User::operator new(s, 3);
1675 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1676 const Twine &NameStr = "",
1677 Instruction *InsertBefor = 0);
1678 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1679 const Twine &NameStr, BasicBlock *InsertAtEnd);
1681 /// isValidOperands - Return true if a shufflevector instruction can be
1682 /// formed with the specified operands.
1683 static bool isValidOperands(const Value *V1, const Value *V2,
1686 /// getType - Overload to return most specific vector type.
1688 VectorType *getType() const {
1689 return cast<VectorType>(Instruction::getType());
1692 /// Transparently provide more efficient getOperand methods.
1693 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1695 Constant *getMask() const {
1696 return cast<Constant>(getOperand(2));
1699 /// getMaskValue - Return the index from the shuffle mask for the specified
1700 /// output result. This is either -1 if the element is undef or a number less
1701 /// than 2*numelements.
1702 static int getMaskValue(Constant *Mask, unsigned i);
1704 int getMaskValue(unsigned i) const {
1705 return getMaskValue(getMask(), i);
1708 /// getShuffleMask - Return the full mask for this instruction, where each
1709 /// element is the element number and undef's are returned as -1.
1710 static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
1712 void getShuffleMask(SmallVectorImpl<int> &Result) const {
1713 return getShuffleMask(getMask(), Result);
1716 SmallVector<int, 16> getShuffleMask() const {
1717 SmallVector<int, 16> Mask;
1718 getShuffleMask(Mask);
1723 // Methods for support type inquiry through isa, cast, and dyn_cast:
1724 static inline bool classof(const Instruction *I) {
1725 return I->getOpcode() == Instruction::ShuffleVector;
1727 static inline bool classof(const Value *V) {
1728 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1733 struct OperandTraits<ShuffleVectorInst> :
1734 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1737 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1739 //===----------------------------------------------------------------------===//
1740 // ExtractValueInst Class
1741 //===----------------------------------------------------------------------===//
1743 /// ExtractValueInst - This instruction extracts a struct member or array
1744 /// element value from an aggregate value.
1746 class ExtractValueInst : public UnaryInstruction {
1747 SmallVector<unsigned, 4> Indices;
1749 ExtractValueInst(const ExtractValueInst &EVI);
1750 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1752 /// Constructors - Create a extractvalue instruction with a base aggregate
1753 /// value and a list of indices. The first ctor can optionally insert before
1754 /// an existing instruction, the second appends the new instruction to the
1755 /// specified BasicBlock.
1756 inline ExtractValueInst(Value *Agg,
1757 ArrayRef<unsigned> Idxs,
1758 const Twine &NameStr,
1759 Instruction *InsertBefore);
1760 inline ExtractValueInst(Value *Agg,
1761 ArrayRef<unsigned> Idxs,
1762 const Twine &NameStr, BasicBlock *InsertAtEnd);
1764 // allocate space for exactly one operand
1765 void *operator new(size_t s) {
1766 return User::operator new(s, 1);
1769 virtual ExtractValueInst *clone_impl() const;
1772 static ExtractValueInst *Create(Value *Agg,
1773 ArrayRef<unsigned> Idxs,
1774 const Twine &NameStr = "",
1775 Instruction *InsertBefore = 0) {
1777 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1779 static ExtractValueInst *Create(Value *Agg,
1780 ArrayRef<unsigned> Idxs,
1781 const Twine &NameStr,
1782 BasicBlock *InsertAtEnd) {
1783 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1786 /// getIndexedType - Returns the type of the element that would be extracted
1787 /// with an extractvalue instruction with the specified parameters.
1789 /// Null is returned if the indices are invalid for the specified type.
1790 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
1792 typedef const unsigned* idx_iterator;
1793 inline idx_iterator idx_begin() const { return Indices.begin(); }
1794 inline idx_iterator idx_end() const { return Indices.end(); }
1796 Value *getAggregateOperand() {
1797 return getOperand(0);
1799 const Value *getAggregateOperand() const {
1800 return getOperand(0);
1802 static unsigned getAggregateOperandIndex() {
1803 return 0U; // get index for modifying correct operand
1806 ArrayRef<unsigned> getIndices() const {
1810 unsigned getNumIndices() const {
1811 return (unsigned)Indices.size();
1814 bool hasIndices() const {
1818 // Methods for support type inquiry through isa, cast, and dyn_cast:
1819 static inline bool classof(const Instruction *I) {
1820 return I->getOpcode() == Instruction::ExtractValue;
1822 static inline bool classof(const Value *V) {
1823 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1827 ExtractValueInst::ExtractValueInst(Value *Agg,
1828 ArrayRef<unsigned> Idxs,
1829 const Twine &NameStr,
1830 Instruction *InsertBefore)
1831 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1832 ExtractValue, Agg, InsertBefore) {
1833 init(Idxs, NameStr);
1835 ExtractValueInst::ExtractValueInst(Value *Agg,
1836 ArrayRef<unsigned> Idxs,
1837 const Twine &NameStr,
1838 BasicBlock *InsertAtEnd)
1839 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1840 ExtractValue, Agg, InsertAtEnd) {
1841 init(Idxs, NameStr);
1845 //===----------------------------------------------------------------------===//
1846 // InsertValueInst Class
1847 //===----------------------------------------------------------------------===//
1849 /// InsertValueInst - This instruction inserts a struct field of array element
1850 /// value into an aggregate value.
1852 class InsertValueInst : public Instruction {
1853 SmallVector<unsigned, 4> Indices;
1855 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1856 InsertValueInst(const InsertValueInst &IVI);
1857 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1858 const Twine &NameStr);
1860 /// Constructors - Create a insertvalue instruction with a base aggregate
1861 /// value, a value to insert, and a list of indices. The first ctor can
1862 /// optionally insert before an existing instruction, the second appends
1863 /// the new instruction to the specified BasicBlock.
1864 inline InsertValueInst(Value *Agg, Value *Val,
1865 ArrayRef<unsigned> Idxs,
1866 const Twine &NameStr,
1867 Instruction *InsertBefore);
1868 inline InsertValueInst(Value *Agg, Value *Val,
1869 ArrayRef<unsigned> Idxs,
1870 const Twine &NameStr, BasicBlock *InsertAtEnd);
1872 /// Constructors - These two constructors are convenience methods because one
1873 /// and two index insertvalue instructions are so common.
1874 InsertValueInst(Value *Agg, Value *Val,
1875 unsigned Idx, const Twine &NameStr = "",
1876 Instruction *InsertBefore = 0);
1877 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1878 const Twine &NameStr, BasicBlock *InsertAtEnd);
1880 virtual InsertValueInst *clone_impl() const;
1882 // allocate space for exactly two operands
1883 void *operator new(size_t s) {
1884 return User::operator new(s, 2);
1887 static InsertValueInst *Create(Value *Agg, Value *Val,
1888 ArrayRef<unsigned> Idxs,
1889 const Twine &NameStr = "",
1890 Instruction *InsertBefore = 0) {
1891 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1893 static InsertValueInst *Create(Value *Agg, Value *Val,
1894 ArrayRef<unsigned> Idxs,
1895 const Twine &NameStr,
1896 BasicBlock *InsertAtEnd) {
1897 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1900 /// Transparently provide more efficient getOperand methods.
1901 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1903 typedef const unsigned* idx_iterator;
1904 inline idx_iterator idx_begin() const { return Indices.begin(); }
1905 inline idx_iterator idx_end() const { return Indices.end(); }
1907 Value *getAggregateOperand() {
1908 return getOperand(0);
1910 const Value *getAggregateOperand() const {
1911 return getOperand(0);
1913 static unsigned getAggregateOperandIndex() {
1914 return 0U; // get index for modifying correct operand
1917 Value *getInsertedValueOperand() {
1918 return getOperand(1);
1920 const Value *getInsertedValueOperand() const {
1921 return getOperand(1);
1923 static unsigned getInsertedValueOperandIndex() {
1924 return 1U; // get index for modifying correct operand
1927 ArrayRef<unsigned> getIndices() const {
1931 unsigned getNumIndices() const {
1932 return (unsigned)Indices.size();
1935 bool hasIndices() const {
1939 // Methods for support type inquiry through isa, cast, and dyn_cast:
1940 static inline bool classof(const Instruction *I) {
1941 return I->getOpcode() == Instruction::InsertValue;
1943 static inline bool classof(const Value *V) {
1944 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1949 struct OperandTraits<InsertValueInst> :
1950 public FixedNumOperandTraits<InsertValueInst, 2> {
1953 InsertValueInst::InsertValueInst(Value *Agg,
1955 ArrayRef<unsigned> Idxs,
1956 const Twine &NameStr,
1957 Instruction *InsertBefore)
1958 : Instruction(Agg->getType(), InsertValue,
1959 OperandTraits<InsertValueInst>::op_begin(this),
1961 init(Agg, Val, Idxs, NameStr);
1963 InsertValueInst::InsertValueInst(Value *Agg,
1965 ArrayRef<unsigned> Idxs,
1966 const Twine &NameStr,
1967 BasicBlock *InsertAtEnd)
1968 : Instruction(Agg->getType(), InsertValue,
1969 OperandTraits<InsertValueInst>::op_begin(this),
1971 init(Agg, Val, Idxs, NameStr);
1974 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1976 //===----------------------------------------------------------------------===//
1978 //===----------------------------------------------------------------------===//
1980 // PHINode - The PHINode class is used to represent the magical mystical PHI
1981 // node, that can not exist in nature, but can be synthesized in a computer
1982 // scientist's overactive imagination.
1984 class PHINode : public Instruction {
1985 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1986 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1987 /// the number actually in use.
1988 unsigned ReservedSpace;
1989 PHINode(const PHINode &PN);
1990 // allocate space for exactly zero operands
1991 void *operator new(size_t s) {
1992 return User::operator new(s, 0);
1994 explicit PHINode(Type *Ty, unsigned NumReservedValues,
1995 const Twine &NameStr = "", Instruction *InsertBefore = 0)
1996 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1997 ReservedSpace(NumReservedValues) {
1999 OperandList = allocHungoffUses(ReservedSpace);
2002 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
2003 BasicBlock *InsertAtEnd)
2004 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
2005 ReservedSpace(NumReservedValues) {
2007 OperandList = allocHungoffUses(ReservedSpace);
2010 // allocHungoffUses - this is more complicated than the generic
2011 // User::allocHungoffUses, because we have to allocate Uses for the incoming
2012 // values and pointers to the incoming blocks, all in one allocation.
2013 Use *allocHungoffUses(unsigned) const;
2015 virtual PHINode *clone_impl() const;
2017 /// Constructors - NumReservedValues is a hint for the number of incoming
2018 /// edges that this phi node will have (use 0 if you really have no idea).
2019 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2020 const Twine &NameStr = "",
2021 Instruction *InsertBefore = 0) {
2022 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2024 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2025 const Twine &NameStr, BasicBlock *InsertAtEnd) {
2026 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2030 /// Provide fast operand accessors
2031 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2033 // Block iterator interface. This provides access to the list of incoming
2034 // basic blocks, which parallels the list of incoming values.
2036 typedef BasicBlock **block_iterator;
2037 typedef BasicBlock * const *const_block_iterator;
2039 block_iterator block_begin() {
2041 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2042 return reinterpret_cast<block_iterator>(ref + 1);
2045 const_block_iterator block_begin() const {
2046 const Use::UserRef *ref =
2047 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2048 return reinterpret_cast<const_block_iterator>(ref + 1);
2051 block_iterator block_end() {
2052 return block_begin() + getNumOperands();
2055 const_block_iterator block_end() const {
2056 return block_begin() + getNumOperands();
2059 /// getNumIncomingValues - Return the number of incoming edges
2061 unsigned getNumIncomingValues() const { return getNumOperands(); }
2063 /// getIncomingValue - Return incoming value number x
2065 Value *getIncomingValue(unsigned i) const {
2066 return getOperand(i);
2068 void setIncomingValue(unsigned i, Value *V) {
2071 static unsigned getOperandNumForIncomingValue(unsigned i) {
2074 static unsigned getIncomingValueNumForOperand(unsigned i) {
2078 /// getIncomingBlock - Return incoming basic block number @p i.
2080 BasicBlock *getIncomingBlock(unsigned i) const {
2081 return block_begin()[i];
2084 /// getIncomingBlock - Return incoming basic block corresponding
2085 /// to an operand of the PHI.
2087 BasicBlock *getIncomingBlock(const Use &U) const {
2088 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2089 return getIncomingBlock(unsigned(&U - op_begin()));
2092 /// getIncomingBlock - Return incoming basic block corresponding
2093 /// to value use iterator.
2095 template <typename U>
2096 BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
2097 return getIncomingBlock(I.getUse());
2100 void setIncomingBlock(unsigned i, BasicBlock *BB) {
2101 block_begin()[i] = BB;
2104 /// addIncoming - Add an incoming value to the end of the PHI list
2106 void addIncoming(Value *V, BasicBlock *BB) {
2107 assert(V && "PHI node got a null value!");
2108 assert(BB && "PHI node got a null basic block!");
2109 assert(getType() == V->getType() &&
2110 "All operands to PHI node must be the same type as the PHI node!");
2111 if (NumOperands == ReservedSpace)
2112 growOperands(); // Get more space!
2113 // Initialize some new operands.
2115 setIncomingValue(NumOperands - 1, V);
2116 setIncomingBlock(NumOperands - 1, BB);
2119 /// removeIncomingValue - Remove an incoming value. This is useful if a
2120 /// predecessor basic block is deleted. The value removed is returned.
2122 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2123 /// is true), the PHI node is destroyed and any uses of it are replaced with
2124 /// dummy values. The only time there should be zero incoming values to a PHI
2125 /// node is when the block is dead, so this strategy is sound.
2127 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2129 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2130 int Idx = getBasicBlockIndex(BB);
2131 assert(Idx >= 0 && "Invalid basic block argument to remove!");
2132 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2135 /// getBasicBlockIndex - Return the first index of the specified basic
2136 /// block in the value list for this PHI. Returns -1 if no instance.
2138 int getBasicBlockIndex(const BasicBlock *BB) const {
2139 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2140 if (block_begin()[i] == BB)
2145 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2146 int Idx = getBasicBlockIndex(BB);
2147 assert(Idx >= 0 && "Invalid basic block argument!");
2148 return getIncomingValue(Idx);
2151 /// hasConstantValue - If the specified PHI node always merges together the
2152 /// same value, return the value, otherwise return null.
2153 Value *hasConstantValue() const;
2155 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2156 static inline bool classof(const Instruction *I) {
2157 return I->getOpcode() == Instruction::PHI;
2159 static inline bool classof(const Value *V) {
2160 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2163 void growOperands();
2167 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2170 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
2172 //===----------------------------------------------------------------------===//
2173 // LandingPadInst Class
2174 //===----------------------------------------------------------------------===//
2176 //===---------------------------------------------------------------------------
2177 /// LandingPadInst - The landingpad instruction holds all of the information
2178 /// necessary to generate correct exception handling. The landingpad instruction
2179 /// cannot be moved from the top of a landing pad block, which itself is
2180 /// accessible only from the 'unwind' edge of an invoke. This uses the
2181 /// SubclassData field in Value to store whether or not the landingpad is a
2184 class LandingPadInst : public Instruction {
2185 /// ReservedSpace - The number of operands actually allocated. NumOperands is
2186 /// the number actually in use.
2187 unsigned ReservedSpace;
2188 LandingPadInst(const LandingPadInst &LP);
2190 enum ClauseType { Catch, Filter };
2192 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2193 // Allocate space for exactly zero operands.
2194 void *operator new(size_t s) {
2195 return User::operator new(s, 0);
2197 void growOperands(unsigned Size);
2198 void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
2200 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2201 unsigned NumReservedValues, const Twine &NameStr,
2202 Instruction *InsertBefore);
2203 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2204 unsigned NumReservedValues, const Twine &NameStr,
2205 BasicBlock *InsertAtEnd);
2207 virtual LandingPadInst *clone_impl() const;
2209 /// Constructors - NumReservedClauses is a hint for the number of incoming
2210 /// clauses that this landingpad will have (use 0 if you really have no idea).
2211 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2212 unsigned NumReservedClauses,
2213 const Twine &NameStr = "",
2214 Instruction *InsertBefore = 0);
2215 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2216 unsigned NumReservedClauses,
2217 const Twine &NameStr, BasicBlock *InsertAtEnd);
2220 /// Provide fast operand accessors
2221 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2223 /// getPersonalityFn - Get the personality function associated with this
2225 Value *getPersonalityFn() const { return getOperand(0); }
2227 /// isCleanup - Return 'true' if this landingpad instruction is a
2228 /// cleanup. I.e., it should be run when unwinding even if its landing pad
2229 /// doesn't catch the exception.
2230 bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2232 /// setCleanup - Indicate that this landingpad instruction is a cleanup.
2233 void setCleanup(bool V) {
2234 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2238 /// addClause - Add a catch or filter clause to the landing pad.
2239 void addClause(Value *ClauseVal);
2241 /// getClause - Get the value of the clause at index Idx. Use isCatch/isFilter
2242 /// to determine what type of clause this is.
2243 Value *getClause(unsigned Idx) const { return OperandList[Idx + 1]; }
2245 /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
2246 bool isCatch(unsigned Idx) const {
2247 return !isa<ArrayType>(OperandList[Idx + 1]->getType());
2250 /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
2251 bool isFilter(unsigned Idx) const {
2252 return isa<ArrayType>(OperandList[Idx + 1]->getType());
2255 /// getNumClauses - Get the number of clauses for this landing pad.
2256 unsigned getNumClauses() const { return getNumOperands() - 1; }
2258 /// reserveClauses - Grow the size of the operand list to accommodate the new
2259 /// number of clauses.
2260 void reserveClauses(unsigned Size) { growOperands(Size); }
2262 // Methods for support type inquiry through isa, cast, and dyn_cast:
2263 static inline bool classof(const Instruction *I) {
2264 return I->getOpcode() == Instruction::LandingPad;
2266 static inline bool classof(const Value *V) {
2267 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2272 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
2275 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
2277 //===----------------------------------------------------------------------===//
2279 //===----------------------------------------------------------------------===//
2281 //===---------------------------------------------------------------------------
2282 /// ReturnInst - Return a value (possibly void), from a function. Execution
2283 /// does not continue in this function any longer.
2285 class ReturnInst : public TerminatorInst {
2286 ReturnInst(const ReturnInst &RI);
2289 // ReturnInst constructors:
2290 // ReturnInst() - 'ret void' instruction
2291 // ReturnInst( null) - 'ret void' instruction
2292 // ReturnInst(Value* X) - 'ret X' instruction
2293 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
2294 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
2295 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2296 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
2298 // NOTE: If the Value* passed is of type void then the constructor behaves as
2299 // if it was passed NULL.
2300 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
2301 Instruction *InsertBefore = 0);
2302 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2303 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2305 virtual ReturnInst *clone_impl() const;
2307 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
2308 Instruction *InsertBefore = 0) {
2309 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2311 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2312 BasicBlock *InsertAtEnd) {
2313 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2315 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2316 return new(0) ReturnInst(C, InsertAtEnd);
2318 virtual ~ReturnInst();
2320 /// Provide fast operand accessors
2321 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2323 /// Convenience accessor. Returns null if there is no return value.
2324 Value *getReturnValue() const {
2325 return getNumOperands() != 0 ? getOperand(0) : 0;
2328 unsigned getNumSuccessors() const { return 0; }
2330 // Methods for support type inquiry through isa, cast, and dyn_cast:
2331 static inline bool classof(const Instruction *I) {
2332 return (I->getOpcode() == Instruction::Ret);
2334 static inline bool classof(const Value *V) {
2335 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2338 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2339 virtual unsigned getNumSuccessorsV() const;
2340 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2344 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2347 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2349 //===----------------------------------------------------------------------===//
2351 //===----------------------------------------------------------------------===//
2353 //===---------------------------------------------------------------------------
2354 /// BranchInst - Conditional or Unconditional Branch instruction.
2356 class BranchInst : public TerminatorInst {
2357 /// Ops list - Branches are strange. The operands are ordered:
2358 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2359 /// they don't have to check for cond/uncond branchness. These are mostly
2360 /// accessed relative from op_end().
2361 BranchInst(const BranchInst &BI);
2363 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2364 // BranchInst(BB *B) - 'br B'
2365 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2366 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2367 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2368 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2369 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2370 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2371 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2372 Instruction *InsertBefore = 0);
2373 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2374 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2375 BasicBlock *InsertAtEnd);
2377 virtual BranchInst *clone_impl() const;
2379 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2380 return new(1) BranchInst(IfTrue, InsertBefore);
2382 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2383 Value *Cond, Instruction *InsertBefore = 0) {
2384 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2386 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2387 return new(1) BranchInst(IfTrue, InsertAtEnd);
2389 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2390 Value *Cond, BasicBlock *InsertAtEnd) {
2391 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2394 /// Transparently provide more efficient getOperand methods.
2395 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2397 bool isUnconditional() const { return getNumOperands() == 1; }
2398 bool isConditional() const { return getNumOperands() == 3; }
2400 Value *getCondition() const {
2401 assert(isConditional() && "Cannot get condition of an uncond branch!");
2405 void setCondition(Value *V) {
2406 assert(isConditional() && "Cannot set condition of unconditional branch!");
2410 unsigned getNumSuccessors() const { return 1+isConditional(); }
2412 BasicBlock *getSuccessor(unsigned i) const {
2413 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2414 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2417 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2418 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2419 *(&Op<-1>() - idx) = (Value*)NewSucc;
2422 /// \brief Swap the successors of this branch instruction.
2424 /// Swaps the successors of the branch instruction. This also swaps any
2425 /// branch weight metadata associated with the instruction so that it
2426 /// continues to map correctly to each operand.
2427 void swapSuccessors();
2429 // Methods for support type inquiry through isa, cast, and dyn_cast:
2430 static inline bool classof(const Instruction *I) {
2431 return (I->getOpcode() == Instruction::Br);
2433 static inline bool classof(const Value *V) {
2434 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2437 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2438 virtual unsigned getNumSuccessorsV() const;
2439 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2443 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2446 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2448 //===----------------------------------------------------------------------===//
2450 //===----------------------------------------------------------------------===//
2452 //===---------------------------------------------------------------------------
2453 /// SwitchInst - Multiway switch
2455 class SwitchInst : public TerminatorInst {
2456 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2457 unsigned ReservedSpace;
2458 // Operand[0] = Value to switch on
2459 // Operand[1] = Default basic block destination
2460 // Operand[2n ] = Value to match
2461 // Operand[2n+1] = BasicBlock to go to on match
2462 SwitchInst(const SwitchInst &SI);
2463 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2464 void growOperands();
2465 // allocate space for exactly zero operands
2466 void *operator new(size_t s) {
2467 return User::operator new(s, 0);
2469 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2470 /// switch on and a default destination. The number of additional cases can
2471 /// be specified here to make memory allocation more efficient. This
2472 /// constructor can also autoinsert before another instruction.
2473 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2474 Instruction *InsertBefore);
2476 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2477 /// switch on and a default destination. The number of additional cases can
2478 /// be specified here to make memory allocation more efficient. This
2479 /// constructor also autoinserts at the end of the specified BasicBlock.
2480 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2481 BasicBlock *InsertAtEnd);
2483 virtual SwitchInst *clone_impl() const;
2487 static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
2489 template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy>
2490 class CaseIteratorT {
2498 typedef CaseIteratorT<SwitchInstTy, ConstantIntTy, BasicBlockTy> Self;
2500 /// Initializes case iterator for given SwitchInst and for given
2502 CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
2507 /// Initializes case iterator for given SwitchInst and for given
2508 /// TerminatorInst's successor index.
2509 static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
2510 assert(SuccessorIndex < SI->getNumSuccessors() &&
2511 "Successor index # out of range!");
2512 return SuccessorIndex != 0 ?
2513 Self(SI, SuccessorIndex - 1) :
2514 Self(SI, DefaultPseudoIndex);
2517 /// Resolves case value for current case.
2518 ConstantIntTy *getCaseValue() {
2519 assert(Index < SI->getNumCases() && "Index out the number of cases.");
2520 return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2));
2523 /// Resolves successor for current case.
2524 BasicBlockTy *getCaseSuccessor() {
2525 assert((Index < SI->getNumCases() ||
2526 Index == DefaultPseudoIndex) &&
2527 "Index out the number of cases.");
2528 return SI->getSuccessor(getSuccessorIndex());
2531 /// Returns number of current case.
2532 unsigned getCaseIndex() const { return Index; }
2534 /// Returns TerminatorInst's successor index for current case successor.
2535 unsigned getSuccessorIndex() const {
2536 assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
2537 "Index out the number of cases.");
2538 return Index != DefaultPseudoIndex ? Index + 1 : 0;
2542 // Check index correctness after increment.
2543 // Note: Index == getNumCases() means end().
2544 assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
2548 Self operator++(int) {
2554 // Check index correctness after decrement.
2555 // Note: Index == getNumCases() means end().
2556 // Also allow "-1" iterator here. That will became valid after ++.
2557 assert((Index == 0 || Index-1 <= SI->getNumCases()) &&
2558 "Index out the number of cases.");
2562 Self operator--(int) {
2567 bool operator==(const Self& RHS) const {
2568 assert(RHS.SI == SI && "Incompatible operators.");
2569 return RHS.Index == Index;
2571 bool operator!=(const Self& RHS) const {
2572 assert(RHS.SI == SI && "Incompatible operators.");
2573 return RHS.Index != Index;
2577 typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock>
2580 class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> {
2582 typedef CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> ParentTy;
2586 CaseIt(const ParentTy& Src) : ParentTy(Src) {}
2587 CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
2589 /// Sets the new value for current case.
2590 void setValue(ConstantInt *V) {
2591 assert(Index < SI->getNumCases() && "Index out the number of cases.");
2592 SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V));
2595 /// Sets the new successor for current case.
2596 void setSuccessor(BasicBlock *S) {
2597 SI->setSuccessor(getSuccessorIndex(), S);
2601 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2602 unsigned NumCases, Instruction *InsertBefore = 0) {
2603 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2605 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2606 unsigned NumCases, BasicBlock *InsertAtEnd) {
2607 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2612 /// Provide fast operand accessors
2613 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2615 // Accessor Methods for Switch stmt
2616 Value *getCondition() const { return getOperand(0); }
2617 void setCondition(Value *V) { setOperand(0, V); }
2619 BasicBlock *getDefaultDest() const {
2620 return cast<BasicBlock>(getOperand(1));
2623 void setDefaultDest(BasicBlock *DefaultCase) {
2624 setOperand(1, reinterpret_cast<Value*>(DefaultCase));
2627 /// getNumCases - return the number of 'cases' in this switch instruction,
2628 /// except the default case
2629 unsigned getNumCases() const {
2630 return getNumOperands()/2 - 1;
2633 /// Returns a read/write iterator that points to the first
2634 /// case in SwitchInst.
2635 CaseIt case_begin() {
2636 return CaseIt(this, 0);
2638 /// Returns a read-only iterator that points to the first
2639 /// case in the SwitchInst.
2640 ConstCaseIt case_begin() const {
2641 return ConstCaseIt(this, 0);
2644 /// Returns a read/write iterator that points one past the last
2645 /// in the SwitchInst.
2647 return CaseIt(this, getNumCases());
2649 /// Returns a read-only iterator that points one past the last
2650 /// in the SwitchInst.
2651 ConstCaseIt case_end() const {
2652 return ConstCaseIt(this, getNumCases());
2654 /// Returns an iterator that points to the default case.
2655 /// Note: this iterator allows to resolve successor only. Attempt
2656 /// to resolve case value causes an assertion.
2657 /// Also note, that increment and decrement also causes an assertion and
2658 /// makes iterator invalid.
2659 CaseIt case_default() {
2660 return CaseIt(this, DefaultPseudoIndex);
2662 ConstCaseIt case_default() const {
2663 return ConstCaseIt(this, DefaultPseudoIndex);
2666 /// findCaseValue - Search all of the case values for the specified constant.
2667 /// If it is explicitly handled, return the case iterator of it, otherwise
2668 /// return default case iterator to indicate
2669 /// that it is handled by the default handler.
2670 CaseIt findCaseValue(const ConstantInt *C) {
2671 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
2672 if (i.getCaseValue() == C)
2674 return case_default();
2676 ConstCaseIt findCaseValue(const ConstantInt *C) const {
2677 for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
2678 if (i.getCaseValue() == C)
2680 return case_default();
2683 /// findCaseDest - Finds the unique case value for a given successor. Returns
2684 /// null if the successor is not found, not unique, or is the default case.
2685 ConstantInt *findCaseDest(BasicBlock *BB) {
2686 if (BB == getDefaultDest()) return NULL;
2688 ConstantInt *CI = NULL;
2689 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
2690 if (i.getCaseSuccessor() == BB) {
2691 if (CI) return NULL; // Multiple cases lead to BB.
2692 else CI = i.getCaseValue();
2698 /// addCase - Add an entry to the switch instruction...
2700 /// This action invalidates case_end(). Old case_end() iterator will
2701 /// point to the added case.
2702 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2704 /// removeCase - This method removes the specified case and its successor
2705 /// from the switch instruction. Note that this operation may reorder the
2706 /// remaining cases at index idx and above.
2708 /// This action invalidates iterators for all cases following the one removed,
2709 /// including the case_end() iterator.
2710 void removeCase(CaseIt i);
2712 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2713 BasicBlock *getSuccessor(unsigned idx) const {
2714 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2715 return cast<BasicBlock>(getOperand(idx*2+1));
2717 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2718 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2719 setOperand(idx*2+1, (Value*)NewSucc);
2722 // Methods for support type inquiry through isa, cast, and dyn_cast:
2723 static inline bool classof(const Instruction *I) {
2724 return I->getOpcode() == Instruction::Switch;
2726 static inline bool classof(const Value *V) {
2727 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2730 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2731 virtual unsigned getNumSuccessorsV() const;
2732 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2736 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2739 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2742 //===----------------------------------------------------------------------===//
2743 // IndirectBrInst Class
2744 //===----------------------------------------------------------------------===//
2746 //===---------------------------------------------------------------------------
2747 /// IndirectBrInst - Indirect Branch Instruction.
2749 class IndirectBrInst : public TerminatorInst {
2750 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2751 unsigned ReservedSpace;
2752 // Operand[0] = Value to switch on
2753 // Operand[1] = Default basic block destination
2754 // Operand[2n ] = Value to match
2755 // Operand[2n+1] = BasicBlock to go to on match
2756 IndirectBrInst(const IndirectBrInst &IBI);
2757 void init(Value *Address, unsigned NumDests);
2758 void growOperands();
2759 // allocate space for exactly zero operands
2760 void *operator new(size_t s) {
2761 return User::operator new(s, 0);
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 can also
2766 /// autoinsert before another instruction.
2767 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2769 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2770 /// Address to jump to. The number of expected destinations can be specified
2771 /// here to make memory allocation more efficient. This constructor also
2772 /// autoinserts at the end of the specified BasicBlock.
2773 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2775 virtual IndirectBrInst *clone_impl() const;
2777 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2778 Instruction *InsertBefore = 0) {
2779 return new IndirectBrInst(Address, NumDests, InsertBefore);
2781 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2782 BasicBlock *InsertAtEnd) {
2783 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2787 /// Provide fast operand accessors.
2788 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2790 // Accessor Methods for IndirectBrInst instruction.
2791 Value *getAddress() { return getOperand(0); }
2792 const Value *getAddress() const { return getOperand(0); }
2793 void setAddress(Value *V) { setOperand(0, V); }
2796 /// getNumDestinations - return the number of possible destinations in this
2797 /// indirectbr instruction.
2798 unsigned getNumDestinations() const { return getNumOperands()-1; }
2800 /// getDestination - Return the specified destination.
2801 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2802 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2804 /// addDestination - Add a destination.
2806 void addDestination(BasicBlock *Dest);
2808 /// removeDestination - This method removes the specified successor from the
2809 /// indirectbr instruction.
2810 void removeDestination(unsigned i);
2812 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2813 BasicBlock *getSuccessor(unsigned i) const {
2814 return cast<BasicBlock>(getOperand(i+1));
2816 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2817 setOperand(i+1, (Value*)NewSucc);
2820 // Methods for support type inquiry through isa, cast, and dyn_cast:
2821 static inline bool classof(const Instruction *I) {
2822 return I->getOpcode() == Instruction::IndirectBr;
2824 static inline bool classof(const Value *V) {
2825 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2828 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2829 virtual unsigned getNumSuccessorsV() const;
2830 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2834 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2837 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2840 //===----------------------------------------------------------------------===//
2842 //===----------------------------------------------------------------------===//
2844 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2845 /// calling convention of the call.
2847 class InvokeInst : public TerminatorInst {
2848 AttributeSet AttributeList;
2849 InvokeInst(const InvokeInst &BI);
2850 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2851 ArrayRef<Value *> Args, const Twine &NameStr);
2853 /// Construct an InvokeInst given a range of arguments.
2855 /// \brief Construct an InvokeInst from a range of arguments
2856 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2857 ArrayRef<Value *> Args, unsigned Values,
2858 const Twine &NameStr, Instruction *InsertBefore);
2860 /// Construct an InvokeInst given a range of arguments.
2862 /// \brief Construct an InvokeInst from a range of arguments
2863 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2864 ArrayRef<Value *> Args, unsigned Values,
2865 const Twine &NameStr, BasicBlock *InsertAtEnd);
2867 virtual InvokeInst *clone_impl() const;
2869 static InvokeInst *Create(Value *Func,
2870 BasicBlock *IfNormal, BasicBlock *IfException,
2871 ArrayRef<Value *> Args, const Twine &NameStr = "",
2872 Instruction *InsertBefore = 0) {
2873 unsigned Values = unsigned(Args.size()) + 3;
2874 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2875 Values, NameStr, InsertBefore);
2877 static InvokeInst *Create(Value *Func,
2878 BasicBlock *IfNormal, BasicBlock *IfException,
2879 ArrayRef<Value *> Args, const Twine &NameStr,
2880 BasicBlock *InsertAtEnd) {
2881 unsigned Values = unsigned(Args.size()) + 3;
2882 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2883 Values, NameStr, InsertAtEnd);
2886 /// Provide fast operand accessors
2887 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2889 /// getNumArgOperands - Return the number of invoke arguments.
2891 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2893 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2895 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2896 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2898 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2900 CallingConv::ID getCallingConv() const {
2901 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2903 void setCallingConv(CallingConv::ID CC) {
2904 setInstructionSubclassData(static_cast<unsigned>(CC));
2907 /// getAttributes - Return the parameter attributes for this invoke.
2909 const AttributeSet &getAttributes() const { return AttributeList; }
2911 /// setAttributes - Set the parameter attributes for this invoke.
2913 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
2915 /// addAttribute - adds the attribute to the list of attributes.
2916 void addAttribute(unsigned i, Attribute::AttrKind attr);
2918 /// removeAttribute - removes the attribute from the list of attributes.
2919 void removeAttribute(unsigned i, Attribute attr);
2921 /// \brief Determine whether this call has the NoAlias attribute.
2922 bool hasFnAttr(Attribute::AttrKind A) const {
2923 assert(A != Attribute::NoBuiltin &&
2924 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
2925 return hasFnAttrImpl(A);
2928 /// \brief Determine whether the call or the callee has the given attributes.
2929 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
2931 /// \brief Extract the alignment for a call or parameter (0=unknown).
2932 unsigned getParamAlignment(unsigned i) const {
2933 return AttributeList.getParamAlignment(i);
2936 /// \brief Return true if the call should not be treated as a call to a
2938 bool isNoBuiltin() const {
2939 // We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have
2940 // to check it by hand.
2941 return hasFnAttrImpl(Attribute::NoBuiltin) &&
2942 !hasFnAttrImpl(Attribute::Builtin);
2945 /// \brief Return true if the call should not be inlined.
2946 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
2947 void setIsNoInline() {
2948 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
2951 /// \brief Determine if the call does not access memory.
2952 bool doesNotAccessMemory() const {
2953 return hasFnAttr(Attribute::ReadNone);
2955 void setDoesNotAccessMemory() {
2956 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
2959 /// \brief Determine if the call does not access or only reads memory.
2960 bool onlyReadsMemory() const {
2961 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
2963 void setOnlyReadsMemory() {
2964 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
2967 /// \brief Determine if the call cannot return.
2968 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
2969 void setDoesNotReturn() {
2970 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
2973 /// \brief Determine if the call cannot unwind.
2974 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
2975 void setDoesNotThrow() {
2976 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
2979 /// \brief Determine if the call returns a structure through first
2980 /// pointer argument.
2981 bool hasStructRetAttr() const {
2982 // Be friendly and also check the callee.
2983 return paramHasAttr(1, Attribute::StructRet);
2986 /// \brief Determine if any call argument is an aggregate passed by value.
2987 bool hasByValArgument() const {
2988 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2991 /// getCalledFunction - Return the function called, or null if this is an
2992 /// indirect function invocation.
2994 Function *getCalledFunction() const {
2995 return dyn_cast<Function>(Op<-3>());
2998 /// getCalledValue - Get a pointer to the function that is invoked by this
3000 const Value *getCalledValue() const { return Op<-3>(); }
3001 Value *getCalledValue() { return Op<-3>(); }
3003 /// setCalledFunction - Set the function called.
3004 void setCalledFunction(Value* Fn) {
3008 // get*Dest - Return the destination basic blocks...
3009 BasicBlock *getNormalDest() const {
3010 return cast<BasicBlock>(Op<-2>());
3012 BasicBlock *getUnwindDest() const {
3013 return cast<BasicBlock>(Op<-1>());
3015 void setNormalDest(BasicBlock *B) {
3016 Op<-2>() = reinterpret_cast<Value*>(B);
3018 void setUnwindDest(BasicBlock *B) {
3019 Op<-1>() = reinterpret_cast<Value*>(B);
3022 /// getLandingPadInst - Get the landingpad instruction from the landing pad
3023 /// block (the unwind destination).
3024 LandingPadInst *getLandingPadInst() const;
3026 BasicBlock *getSuccessor(unsigned i) const {
3027 assert(i < 2 && "Successor # out of range for invoke!");
3028 return i == 0 ? getNormalDest() : getUnwindDest();
3031 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3032 assert(idx < 2 && "Successor # out of range for invoke!");
3033 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
3036 unsigned getNumSuccessors() const { return 2; }
3038 // Methods for support type inquiry through isa, cast, and dyn_cast:
3039 static inline bool classof(const Instruction *I) {
3040 return (I->getOpcode() == Instruction::Invoke);
3042 static inline bool classof(const Value *V) {
3043 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3047 virtual BasicBlock *getSuccessorV(unsigned idx) const;
3048 virtual unsigned getNumSuccessorsV() const;
3049 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3051 bool hasFnAttrImpl(Attribute::AttrKind A) const;
3053 // Shadow Instruction::setInstructionSubclassData with a private forwarding
3054 // method so that subclasses cannot accidentally use it.
3055 void setInstructionSubclassData(unsigned short D) {
3056 Instruction::setInstructionSubclassData(D);
3061 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
3064 InvokeInst::InvokeInst(Value *Func,
3065 BasicBlock *IfNormal, BasicBlock *IfException,
3066 ArrayRef<Value *> Args, unsigned Values,
3067 const Twine &NameStr, Instruction *InsertBefore)
3068 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3069 ->getElementType())->getReturnType(),
3070 Instruction::Invoke,
3071 OperandTraits<InvokeInst>::op_end(this) - Values,
3072 Values, InsertBefore) {
3073 init(Func, IfNormal, IfException, Args, NameStr);
3075 InvokeInst::InvokeInst(Value *Func,
3076 BasicBlock *IfNormal, BasicBlock *IfException,
3077 ArrayRef<Value *> Args, unsigned Values,
3078 const Twine &NameStr, BasicBlock *InsertAtEnd)
3079 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3080 ->getElementType())->getReturnType(),
3081 Instruction::Invoke,
3082 OperandTraits<InvokeInst>::op_end(this) - Values,
3083 Values, InsertAtEnd) {
3084 init(Func, IfNormal, IfException, Args, NameStr);
3087 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
3089 //===----------------------------------------------------------------------===//
3091 //===----------------------------------------------------------------------===//
3093 //===---------------------------------------------------------------------------
3094 /// ResumeInst - Resume the propagation of an exception.
3096 class ResumeInst : public TerminatorInst {
3097 ResumeInst(const ResumeInst &RI);
3099 explicit ResumeInst(Value *Exn, Instruction *InsertBefore=0);
3100 ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
3102 virtual ResumeInst *clone_impl() const;
3104 static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = 0) {
3105 return new(1) ResumeInst(Exn, InsertBefore);
3107 static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
3108 return new(1) ResumeInst(Exn, InsertAtEnd);
3111 /// Provide fast operand accessors
3112 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3114 /// Convenience accessor.
3115 Value *getValue() const { return Op<0>(); }
3117 unsigned getNumSuccessors() const { return 0; }
3119 // Methods for support type inquiry through isa, cast, and dyn_cast:
3120 static inline bool classof(const Instruction *I) {
3121 return I->getOpcode() == Instruction::Resume;
3123 static inline bool classof(const Value *V) {
3124 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3127 virtual BasicBlock *getSuccessorV(unsigned idx) const;
3128 virtual unsigned getNumSuccessorsV() const;
3129 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3133 struct OperandTraits<ResumeInst> :
3134 public FixedNumOperandTraits<ResumeInst, 1> {
3137 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
3139 //===----------------------------------------------------------------------===//
3140 // UnreachableInst Class
3141 //===----------------------------------------------------------------------===//
3143 //===---------------------------------------------------------------------------
3144 /// UnreachableInst - This function has undefined behavior. In particular, the
3145 /// presence of this instruction indicates some higher level knowledge that the
3146 /// end of the block cannot be reached.
3148 class UnreachableInst : public TerminatorInst {
3149 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
3151 virtual UnreachableInst *clone_impl() const;
3154 // allocate space for exactly zero operands
3155 void *operator new(size_t s) {
3156 return User::operator new(s, 0);
3158 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
3159 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
3161 unsigned getNumSuccessors() const { return 0; }
3163 // Methods for support type inquiry through isa, cast, and dyn_cast:
3164 static inline bool classof(const Instruction *I) {
3165 return I->getOpcode() == Instruction::Unreachable;
3167 static inline bool classof(const Value *V) {
3168 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3171 virtual BasicBlock *getSuccessorV(unsigned idx) const;
3172 virtual unsigned getNumSuccessorsV() const;
3173 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3176 //===----------------------------------------------------------------------===//
3178 //===----------------------------------------------------------------------===//
3180 /// \brief This class represents a truncation of integer types.
3181 class TruncInst : public CastInst {
3183 /// \brief Clone an identical TruncInst
3184 virtual TruncInst *clone_impl() const;
3187 /// \brief Constructor with insert-before-instruction semantics
3189 Value *S, ///< The value to be truncated
3190 Type *Ty, ///< The (smaller) type to truncate to
3191 const Twine &NameStr = "", ///< A name for the new instruction
3192 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3195 /// \brief Constructor with insert-at-end-of-block semantics
3197 Value *S, ///< The value to be truncated
3198 Type *Ty, ///< The (smaller) type to truncate to
3199 const Twine &NameStr, ///< A name for the new instruction
3200 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3203 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3204 static inline bool classof(const Instruction *I) {
3205 return I->getOpcode() == Trunc;
3207 static inline bool classof(const Value *V) {
3208 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3212 //===----------------------------------------------------------------------===//
3214 //===----------------------------------------------------------------------===//
3216 /// \brief This class represents zero extension of integer types.
3217 class ZExtInst : public CastInst {
3219 /// \brief Clone an identical ZExtInst
3220 virtual ZExtInst *clone_impl() const;
3223 /// \brief Constructor with insert-before-instruction semantics
3225 Value *S, ///< The value to be zero extended
3226 Type *Ty, ///< The type to zero extend to
3227 const Twine &NameStr = "", ///< A name for the new instruction
3228 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3231 /// \brief Constructor with insert-at-end semantics.
3233 Value *S, ///< The value to be zero extended
3234 Type *Ty, ///< The type to zero extend to
3235 const Twine &NameStr, ///< A name for the new instruction
3236 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3239 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3240 static inline bool classof(const Instruction *I) {
3241 return I->getOpcode() == ZExt;
3243 static inline bool classof(const Value *V) {
3244 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3248 //===----------------------------------------------------------------------===//
3250 //===----------------------------------------------------------------------===//
3252 /// \brief This class represents a sign extension of integer types.
3253 class SExtInst : public CastInst {
3255 /// \brief Clone an identical SExtInst
3256 virtual SExtInst *clone_impl() const;
3259 /// \brief Constructor with insert-before-instruction semantics
3261 Value *S, ///< The value to be sign extended
3262 Type *Ty, ///< The type to sign extend to
3263 const Twine &NameStr = "", ///< A name for the new instruction
3264 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3267 /// \brief Constructor with insert-at-end-of-block semantics
3269 Value *S, ///< The value to be sign extended
3270 Type *Ty, ///< The type to sign extend to
3271 const Twine &NameStr, ///< A name for the new instruction
3272 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3275 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3276 static inline bool classof(const Instruction *I) {
3277 return I->getOpcode() == SExt;
3279 static inline bool classof(const Value *V) {
3280 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3284 //===----------------------------------------------------------------------===//
3285 // FPTruncInst Class
3286 //===----------------------------------------------------------------------===//
3288 /// \brief This class represents a truncation of floating point types.
3289 class FPTruncInst : public CastInst {
3291 /// \brief Clone an identical FPTruncInst
3292 virtual FPTruncInst *clone_impl() const;
3295 /// \brief Constructor with insert-before-instruction semantics
3297 Value *S, ///< The value to be truncated
3298 Type *Ty, ///< The type to truncate to
3299 const Twine &NameStr = "", ///< A name for the new instruction
3300 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3303 /// \brief Constructor with insert-before-instruction semantics
3305 Value *S, ///< The value to be truncated
3306 Type *Ty, ///< The type to truncate to
3307 const Twine &NameStr, ///< A name for the new instruction
3308 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3311 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3312 static inline bool classof(const Instruction *I) {
3313 return I->getOpcode() == FPTrunc;
3315 static inline bool classof(const Value *V) {
3316 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3320 //===----------------------------------------------------------------------===//
3322 //===----------------------------------------------------------------------===//
3324 /// \brief This class represents an extension of floating point types.
3325 class FPExtInst : public CastInst {
3327 /// \brief Clone an identical FPExtInst
3328 virtual FPExtInst *clone_impl() const;
3331 /// \brief Constructor with insert-before-instruction semantics
3333 Value *S, ///< The value to be extended
3334 Type *Ty, ///< The type to extend to
3335 const Twine &NameStr = "", ///< A name for the new instruction
3336 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3339 /// \brief Constructor with insert-at-end-of-block semantics
3341 Value *S, ///< The value to be extended
3342 Type *Ty, ///< The type to extend to
3343 const Twine &NameStr, ///< A name for the new instruction
3344 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3347 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3348 static inline bool classof(const Instruction *I) {
3349 return I->getOpcode() == FPExt;
3351 static inline bool classof(const Value *V) {
3352 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3356 //===----------------------------------------------------------------------===//
3358 //===----------------------------------------------------------------------===//
3360 /// \brief This class represents a cast unsigned integer to floating point.
3361 class UIToFPInst : public CastInst {
3363 /// \brief Clone an identical UIToFPInst
3364 virtual UIToFPInst *clone_impl() const;
3367 /// \brief Constructor with insert-before-instruction semantics
3369 Value *S, ///< The value to be converted
3370 Type *Ty, ///< The type to convert to
3371 const Twine &NameStr = "", ///< A name for the new instruction
3372 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3375 /// \brief Constructor with insert-at-end-of-block semantics
3377 Value *S, ///< The value to be converted
3378 Type *Ty, ///< The type to convert to
3379 const Twine &NameStr, ///< A name for the new instruction
3380 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3383 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3384 static inline bool classof(const Instruction *I) {
3385 return I->getOpcode() == UIToFP;
3387 static inline bool classof(const Value *V) {
3388 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3392 //===----------------------------------------------------------------------===//
3394 //===----------------------------------------------------------------------===//
3396 /// \brief This class represents a cast from signed integer to floating point.
3397 class SIToFPInst : public CastInst {
3399 /// \brief Clone an identical SIToFPInst
3400 virtual SIToFPInst *clone_impl() const;
3403 /// \brief Constructor with insert-before-instruction semantics
3405 Value *S, ///< The value to be converted
3406 Type *Ty, ///< The type to convert to
3407 const Twine &NameStr = "", ///< A name for the new instruction
3408 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3411 /// \brief Constructor with insert-at-end-of-block semantics
3413 Value *S, ///< The value to be converted
3414 Type *Ty, ///< The type to convert to
3415 const Twine &NameStr, ///< A name for the new instruction
3416 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3419 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3420 static inline bool classof(const Instruction *I) {
3421 return I->getOpcode() == SIToFP;
3423 static inline bool classof(const Value *V) {
3424 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3428 //===----------------------------------------------------------------------===//
3430 //===----------------------------------------------------------------------===//
3432 /// \brief This class represents a cast from floating point to unsigned integer
3433 class FPToUIInst : public CastInst {
3435 /// \brief Clone an identical FPToUIInst
3436 virtual FPToUIInst *clone_impl() const;
3439 /// \brief Constructor with insert-before-instruction semantics
3441 Value *S, ///< The value to be converted
3442 Type *Ty, ///< The type to convert to
3443 const Twine &NameStr = "", ///< A name for the new instruction
3444 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3447 /// \brief Constructor with insert-at-end-of-block semantics
3449 Value *S, ///< The value to be converted
3450 Type *Ty, ///< The type to convert to
3451 const Twine &NameStr, ///< A name for the new instruction
3452 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3455 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3456 static inline bool classof(const Instruction *I) {
3457 return I->getOpcode() == FPToUI;
3459 static inline bool classof(const Value *V) {
3460 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3464 //===----------------------------------------------------------------------===//
3466 //===----------------------------------------------------------------------===//
3468 /// \brief This class represents a cast from floating point to signed integer.
3469 class FPToSIInst : public CastInst {
3471 /// \brief Clone an identical FPToSIInst
3472 virtual FPToSIInst *clone_impl() const;
3475 /// \brief Constructor with insert-before-instruction semantics
3477 Value *S, ///< The value to be converted
3478 Type *Ty, ///< The type to convert to
3479 const Twine &NameStr = "", ///< A name for the new instruction
3480 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3483 /// \brief Constructor with insert-at-end-of-block semantics
3485 Value *S, ///< The value to be converted
3486 Type *Ty, ///< The type to convert to
3487 const Twine &NameStr, ///< A name for the new instruction
3488 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3491 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3492 static inline bool classof(const Instruction *I) {
3493 return I->getOpcode() == FPToSI;
3495 static inline bool classof(const Value *V) {
3496 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3500 //===----------------------------------------------------------------------===//
3501 // IntToPtrInst Class
3502 //===----------------------------------------------------------------------===//
3504 /// \brief This class represents a cast from an integer to a pointer.
3505 class IntToPtrInst : public CastInst {
3507 /// \brief Constructor with insert-before-instruction semantics
3509 Value *S, ///< The value to be converted
3510 Type *Ty, ///< The type to convert to
3511 const Twine &NameStr = "", ///< A name for the new instruction
3512 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3515 /// \brief Constructor with insert-at-end-of-block semantics
3517 Value *S, ///< The value to be converted
3518 Type *Ty, ///< The type to convert to
3519 const Twine &NameStr, ///< A name for the new instruction
3520 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3523 /// \brief Clone an identical IntToPtrInst
3524 virtual IntToPtrInst *clone_impl() const;
3526 /// \brief Returns the address space of this instruction's pointer type.
3527 unsigned getAddressSpace() const {
3528 return getType()->getPointerAddressSpace();
3531 // Methods for support type inquiry through isa, cast, and dyn_cast:
3532 static inline bool classof(const Instruction *I) {
3533 return I->getOpcode() == IntToPtr;
3535 static inline bool classof(const Value *V) {
3536 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3540 //===----------------------------------------------------------------------===//
3541 // PtrToIntInst Class
3542 //===----------------------------------------------------------------------===//
3544 /// \brief This class represents a cast from a pointer to an integer
3545 class PtrToIntInst : public CastInst {
3547 /// \brief Clone an identical PtrToIntInst
3548 virtual PtrToIntInst *clone_impl() const;
3551 /// \brief Constructor with insert-before-instruction semantics
3553 Value *S, ///< The value to be converted
3554 Type *Ty, ///< The type to convert to
3555 const Twine &NameStr = "", ///< A name for the new instruction
3556 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3559 /// \brief Constructor with insert-at-end-of-block semantics
3561 Value *S, ///< The value to be converted
3562 Type *Ty, ///< The type to convert to
3563 const Twine &NameStr, ///< A name for the new instruction
3564 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3567 /// \brief Gets the pointer operand.
3568 Value *getPointerOperand() { return getOperand(0); }
3569 /// \brief Gets the pointer operand.
3570 const Value *getPointerOperand() const { return getOperand(0); }
3571 /// \brief Gets the operand index of the pointer operand.
3572 static unsigned getPointerOperandIndex() { return 0U; }
3574 /// \brief Returns the address space of the pointer operand.
3575 unsigned getPointerAddressSpace() const {
3576 return getPointerOperand()->getType()->getPointerAddressSpace();
3579 // Methods for support type inquiry through isa, cast, and dyn_cast:
3580 static inline bool classof(const Instruction *I) {
3581 return I->getOpcode() == PtrToInt;
3583 static inline bool classof(const Value *V) {
3584 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3588 //===----------------------------------------------------------------------===//
3589 // BitCastInst Class
3590 //===----------------------------------------------------------------------===//
3592 /// \brief This class represents a no-op cast from one type to another.
3593 class BitCastInst : public CastInst {
3595 /// \brief Clone an identical BitCastInst
3596 virtual BitCastInst *clone_impl() const;
3599 /// \brief Constructor with insert-before-instruction semantics
3601 Value *S, ///< The value to be casted
3602 Type *Ty, ///< The type to casted to
3603 const Twine &NameStr = "", ///< A name for the new instruction
3604 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3607 /// \brief Constructor with insert-at-end-of-block semantics
3609 Value *S, ///< The value to be casted
3610 Type *Ty, ///< The type to casted to
3611 const Twine &NameStr, ///< A name for the new instruction
3612 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3615 // Methods for support type inquiry through isa, cast, and dyn_cast:
3616 static inline bool classof(const Instruction *I) {
3617 return I->getOpcode() == BitCast;
3619 static inline bool classof(const Value *V) {
3620 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3624 } // End llvm namespace