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/iterator_range.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/IR/Attributes.h"
23 #include "llvm/IR/CallingConv.h"
24 #include "llvm/IR/DerivedTypes.h"
25 #include "llvm/IR/InstrTypes.h"
26 #include "llvm/Support/ErrorHandling.h"
41 // Consume = 3, // Not specified yet.
45 SequentiallyConsistent = 7
48 enum SynchronizationScope {
53 //===----------------------------------------------------------------------===//
55 //===----------------------------------------------------------------------===//
57 /// AllocaInst - an instruction to allocate memory on the stack
59 class AllocaInst : public UnaryInstruction {
61 AllocaInst *clone_impl() const override;
63 explicit AllocaInst(Type *Ty, Value *ArraySize = 0,
64 const Twine &Name = "", Instruction *InsertBefore = 0);
65 AllocaInst(Type *Ty, Value *ArraySize,
66 const Twine &Name, BasicBlock *InsertAtEnd);
68 AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
69 AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
71 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
72 const Twine &Name = "", Instruction *InsertBefore = 0);
73 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
74 const Twine &Name, BasicBlock *InsertAtEnd);
76 // Out of line virtual method, so the vtable, etc. has a home.
77 virtual ~AllocaInst();
79 /// isArrayAllocation - Return true if there is an allocation size parameter
80 /// to the allocation instruction that is not 1.
82 bool isArrayAllocation() const;
84 /// getArraySize - Get the number of elements allocated. For a simple
85 /// allocation of a single element, this will return a constant 1 value.
87 const Value *getArraySize() const { return getOperand(0); }
88 Value *getArraySize() { return getOperand(0); }
90 /// getType - Overload to return most specific pointer type
92 PointerType *getType() const {
93 return cast<PointerType>(Instruction::getType());
96 /// getAllocatedType - Return the type that is being allocated by the
99 Type *getAllocatedType() const;
101 /// getAlignment - Return the alignment of the memory that is being allocated
102 /// by the instruction.
104 unsigned getAlignment() const {
105 return (1u << (getSubclassDataFromInstruction() & 31)) >> 1;
107 void setAlignment(unsigned Align);
109 /// isStaticAlloca - Return true if this alloca is in the entry block of the
110 /// function and is a constant size. If so, the code generator will fold it
111 /// into the prolog/epilog code, so it is basically free.
112 bool isStaticAlloca() const;
114 /// \brief Return true if this alloca is used as an inalloca argument to a
115 /// call. Such allocas are never considered static even if they are in the
117 bool isUsedWithInAlloca() const {
118 return getSubclassDataFromInstruction() & 32;
121 /// \brief Specify whether this alloca is used to represent a the arguments to
123 void setUsedWithInAlloca(bool V) {
124 setInstructionSubclassData((getSubclassDataFromInstruction() & ~32) |
128 // Methods for support type inquiry through isa, cast, and dyn_cast:
129 static inline bool classof(const Instruction *I) {
130 return (I->getOpcode() == Instruction::Alloca);
132 static inline bool classof(const Value *V) {
133 return isa<Instruction>(V) && classof(cast<Instruction>(V));
136 // Shadow Instruction::setInstructionSubclassData with a private forwarding
137 // method so that subclasses cannot accidentally use it.
138 void setInstructionSubclassData(unsigned short D) {
139 Instruction::setInstructionSubclassData(D);
144 //===----------------------------------------------------------------------===//
146 //===----------------------------------------------------------------------===//
148 /// LoadInst - an instruction for reading from memory. This uses the
149 /// SubclassData field in Value to store whether or not the load is volatile.
151 class LoadInst : public UnaryInstruction {
154 LoadInst *clone_impl() const override;
156 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
157 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
158 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
159 Instruction *InsertBefore = 0);
160 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
161 BasicBlock *InsertAtEnd);
162 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
163 unsigned Align, Instruction *InsertBefore = 0);
164 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
165 unsigned Align, BasicBlock *InsertAtEnd);
166 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
167 unsigned Align, AtomicOrdering Order,
168 SynchronizationScope SynchScope = CrossThread,
169 Instruction *InsertBefore = 0);
170 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
171 unsigned Align, AtomicOrdering Order,
172 SynchronizationScope SynchScope,
173 BasicBlock *InsertAtEnd);
175 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
176 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
177 explicit LoadInst(Value *Ptr, const char *NameStr = 0,
178 bool isVolatile = false, Instruction *InsertBefore = 0);
179 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
180 BasicBlock *InsertAtEnd);
182 /// isVolatile - Return true if this is a load from a volatile memory
185 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
187 /// setVolatile - Specify whether this is a volatile load or not.
189 void setVolatile(bool V) {
190 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
194 /// getAlignment - Return the alignment of the access that is being performed
196 unsigned getAlignment() const {
197 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
200 void setAlignment(unsigned Align);
202 /// Returns the ordering effect of this fence.
203 AtomicOrdering getOrdering() const {
204 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
207 /// Set the ordering constraint on this load. May not be Release or
209 void setOrdering(AtomicOrdering Ordering) {
210 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
214 SynchronizationScope getSynchScope() const {
215 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
218 /// Specify whether this load is ordered with respect to all
219 /// concurrently executing threads, or only with respect to signal handlers
220 /// executing in the same thread.
221 void setSynchScope(SynchronizationScope xthread) {
222 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
226 bool isAtomic() const { return getOrdering() != NotAtomic; }
227 void setAtomic(AtomicOrdering Ordering,
228 SynchronizationScope SynchScope = CrossThread) {
229 setOrdering(Ordering);
230 setSynchScope(SynchScope);
233 bool isSimple() const { return !isAtomic() && !isVolatile(); }
234 bool isUnordered() const {
235 return getOrdering() <= Unordered && !isVolatile();
238 Value *getPointerOperand() { return getOperand(0); }
239 const Value *getPointerOperand() const { return getOperand(0); }
240 static unsigned getPointerOperandIndex() { return 0U; }
242 /// \brief Returns the address space of the pointer operand.
243 unsigned getPointerAddressSpace() const {
244 return getPointerOperand()->getType()->getPointerAddressSpace();
248 // Methods for support type inquiry through isa, cast, and dyn_cast:
249 static inline bool classof(const Instruction *I) {
250 return I->getOpcode() == Instruction::Load;
252 static inline bool classof(const Value *V) {
253 return isa<Instruction>(V) && classof(cast<Instruction>(V));
256 // Shadow Instruction::setInstructionSubclassData with a private forwarding
257 // method so that subclasses cannot accidentally use it.
258 void setInstructionSubclassData(unsigned short D) {
259 Instruction::setInstructionSubclassData(D);
264 //===----------------------------------------------------------------------===//
266 //===----------------------------------------------------------------------===//
268 /// StoreInst - an instruction for storing to memory
270 class StoreInst : public Instruction {
271 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
274 StoreInst *clone_impl() const override;
276 // allocate space for exactly two operands
277 void *operator new(size_t s) {
278 return User::operator new(s, 2);
280 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
281 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
282 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
283 Instruction *InsertBefore = 0);
284 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
285 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
286 unsigned Align, Instruction *InsertBefore = 0);
287 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
288 unsigned Align, BasicBlock *InsertAtEnd);
289 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
290 unsigned Align, AtomicOrdering Order,
291 SynchronizationScope SynchScope = CrossThread,
292 Instruction *InsertBefore = 0);
293 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
294 unsigned Align, AtomicOrdering Order,
295 SynchronizationScope SynchScope,
296 BasicBlock *InsertAtEnd);
299 /// isVolatile - Return true if this is a store to a volatile memory
302 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
304 /// setVolatile - Specify whether this is a volatile store or not.
306 void setVolatile(bool V) {
307 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
311 /// Transparently provide more efficient getOperand methods.
312 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
314 /// getAlignment - Return the alignment of the access that is being performed
316 unsigned getAlignment() const {
317 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
320 void setAlignment(unsigned Align);
322 /// Returns the ordering effect of this store.
323 AtomicOrdering getOrdering() const {
324 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
327 /// Set the ordering constraint on this store. May not be Acquire or
329 void setOrdering(AtomicOrdering Ordering) {
330 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
334 SynchronizationScope getSynchScope() const {
335 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
338 /// Specify whether this store instruction is ordered with respect to all
339 /// concurrently executing threads, or only with respect to signal handlers
340 /// executing in the same thread.
341 void setSynchScope(SynchronizationScope xthread) {
342 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
346 bool isAtomic() const { return getOrdering() != NotAtomic; }
347 void setAtomic(AtomicOrdering Ordering,
348 SynchronizationScope SynchScope = CrossThread) {
349 setOrdering(Ordering);
350 setSynchScope(SynchScope);
353 bool isSimple() const { return !isAtomic() && !isVolatile(); }
354 bool isUnordered() const {
355 return getOrdering() <= Unordered && !isVolatile();
358 Value *getValueOperand() { return getOperand(0); }
359 const Value *getValueOperand() const { return getOperand(0); }
361 Value *getPointerOperand() { return getOperand(1); }
362 const Value *getPointerOperand() const { return getOperand(1); }
363 static unsigned getPointerOperandIndex() { return 1U; }
365 /// \brief Returns the address space of the pointer operand.
366 unsigned getPointerAddressSpace() const {
367 return getPointerOperand()->getType()->getPointerAddressSpace();
370 // Methods for support type inquiry through isa, cast, and dyn_cast:
371 static inline bool classof(const Instruction *I) {
372 return I->getOpcode() == Instruction::Store;
374 static inline bool classof(const Value *V) {
375 return isa<Instruction>(V) && classof(cast<Instruction>(V));
378 // Shadow Instruction::setInstructionSubclassData with a private forwarding
379 // method so that subclasses cannot accidentally use it.
380 void setInstructionSubclassData(unsigned short D) {
381 Instruction::setInstructionSubclassData(D);
386 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
389 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
391 //===----------------------------------------------------------------------===//
393 //===----------------------------------------------------------------------===//
395 /// FenceInst - an instruction for ordering other memory operations
397 class FenceInst : public Instruction {
398 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
399 void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
401 FenceInst *clone_impl() const override;
403 // allocate space for exactly zero operands
404 void *operator new(size_t s) {
405 return User::operator new(s, 0);
408 // Ordering may only be Acquire, Release, AcquireRelease, or
409 // SequentiallyConsistent.
410 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
411 SynchronizationScope SynchScope = CrossThread,
412 Instruction *InsertBefore = 0);
413 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
414 SynchronizationScope SynchScope,
415 BasicBlock *InsertAtEnd);
417 /// Returns the ordering effect of this fence.
418 AtomicOrdering getOrdering() const {
419 return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
422 /// Set the ordering constraint on this fence. May only be Acquire, Release,
423 /// AcquireRelease, or SequentiallyConsistent.
424 void setOrdering(AtomicOrdering Ordering) {
425 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
429 SynchronizationScope getSynchScope() const {
430 return SynchronizationScope(getSubclassDataFromInstruction() & 1);
433 /// Specify whether this fence orders other operations with respect to all
434 /// concurrently executing threads, or only with respect to signal handlers
435 /// executing in the same thread.
436 void setSynchScope(SynchronizationScope xthread) {
437 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
441 // Methods for support type inquiry through isa, cast, and dyn_cast:
442 static inline bool classof(const Instruction *I) {
443 return I->getOpcode() == Instruction::Fence;
445 static inline bool classof(const Value *V) {
446 return isa<Instruction>(V) && classof(cast<Instruction>(V));
449 // Shadow Instruction::setInstructionSubclassData with a private forwarding
450 // method so that subclasses cannot accidentally use it.
451 void setInstructionSubclassData(unsigned short D) {
452 Instruction::setInstructionSubclassData(D);
456 //===----------------------------------------------------------------------===//
457 // AtomicCmpXchgInst Class
458 //===----------------------------------------------------------------------===//
460 /// AtomicCmpXchgInst - an instruction that atomically checks whether a
461 /// specified value is in a memory location, and, if it is, stores a new value
462 /// there. Returns the value that was loaded.
464 class AtomicCmpXchgInst : public Instruction {
465 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
466 void Init(Value *Ptr, Value *Cmp, Value *NewVal,
467 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
468 SynchronizationScope SynchScope);
470 AtomicCmpXchgInst *clone_impl() const override;
472 // allocate space for exactly three operands
473 void *operator new(size_t s) {
474 return User::operator new(s, 3);
476 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
477 AtomicOrdering SuccessOrdering,
478 AtomicOrdering FailureOrdering,
479 SynchronizationScope SynchScope,
480 Instruction *InsertBefore = 0);
481 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
482 AtomicOrdering SuccessOrdering,
483 AtomicOrdering FailureOrdering,
484 SynchronizationScope SynchScope,
485 BasicBlock *InsertAtEnd);
487 /// isVolatile - Return true if this is a cmpxchg from a volatile memory
490 bool isVolatile() const {
491 return getSubclassDataFromInstruction() & 1;
494 /// setVolatile - Specify whether this is a volatile cmpxchg.
496 void setVolatile(bool V) {
497 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
501 /// Transparently provide more efficient getOperand methods.
502 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
504 /// Set the ordering constraint on this cmpxchg.
505 void setSuccessOrdering(AtomicOrdering Ordering) {
506 assert(Ordering != NotAtomic &&
507 "CmpXchg instructions can only be atomic.");
508 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x1c) |
512 void setFailureOrdering(AtomicOrdering Ordering) {
513 assert(Ordering != NotAtomic &&
514 "CmpXchg instructions can only be atomic.");
515 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0xe0) |
519 /// Specify whether this cmpxchg is atomic and orders other operations with
520 /// respect to all concurrently executing threads, or only with respect to
521 /// signal handlers executing in the same thread.
522 void setSynchScope(SynchronizationScope SynchScope) {
523 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
527 /// Returns the ordering constraint on this cmpxchg.
528 AtomicOrdering getSuccessOrdering() const {
529 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
532 /// Returns the ordering constraint on this cmpxchg.
533 AtomicOrdering getFailureOrdering() const {
534 return AtomicOrdering((getSubclassDataFromInstruction() >> 5) & 7);
537 /// Returns whether this cmpxchg is atomic between threads or only within a
539 SynchronizationScope getSynchScope() const {
540 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
543 Value *getPointerOperand() { return getOperand(0); }
544 const Value *getPointerOperand() const { return getOperand(0); }
545 static unsigned getPointerOperandIndex() { return 0U; }
547 Value *getCompareOperand() { return getOperand(1); }
548 const Value *getCompareOperand() const { return getOperand(1); }
550 Value *getNewValOperand() { return getOperand(2); }
551 const Value *getNewValOperand() const { return getOperand(2); }
553 /// \brief Returns the address space of the pointer operand.
554 unsigned getPointerAddressSpace() const {
555 return getPointerOperand()->getType()->getPointerAddressSpace();
558 /// \brief Returns the strongest permitted ordering on failure, given the
559 /// desired ordering on success.
561 /// If the comparison in a cmpxchg operation fails, there is no atomic store
562 /// so release semantics cannot be provided. So this function drops explicit
563 /// Release requests from the AtomicOrdering. A SequentiallyConsistent
564 /// operation would remain SequentiallyConsistent.
565 static AtomicOrdering
566 getStrongestFailureOrdering(AtomicOrdering SuccessOrdering) {
567 switch (SuccessOrdering) {
568 default: llvm_unreachable("invalid cmpxchg success ordering");
575 case SequentiallyConsistent:
576 return SequentiallyConsistent;
580 // Methods for support type inquiry through isa, cast, and dyn_cast:
581 static inline bool classof(const Instruction *I) {
582 return I->getOpcode() == Instruction::AtomicCmpXchg;
584 static inline bool classof(const Value *V) {
585 return isa<Instruction>(V) && classof(cast<Instruction>(V));
588 // Shadow Instruction::setInstructionSubclassData with a private forwarding
589 // method so that subclasses cannot accidentally use it.
590 void setInstructionSubclassData(unsigned short D) {
591 Instruction::setInstructionSubclassData(D);
596 struct OperandTraits<AtomicCmpXchgInst> :
597 public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
600 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)
602 //===----------------------------------------------------------------------===//
603 // AtomicRMWInst Class
604 //===----------------------------------------------------------------------===//
606 /// AtomicRMWInst - an instruction that atomically reads a memory location,
607 /// combines it with another value, and then stores the result back. Returns
610 class AtomicRMWInst : public Instruction {
611 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
613 AtomicRMWInst *clone_impl() const override;
615 /// This enumeration lists the possible modifications atomicrmw can make. In
616 /// the descriptions, 'p' is the pointer to the instruction's memory location,
617 /// 'old' is the initial value of *p, and 'v' is the other value passed to the
618 /// instruction. These instructions always return 'old'.
634 /// *p = old >signed v ? old : v
636 /// *p = old <signed v ? old : v
638 /// *p = old >unsigned v ? old : v
640 /// *p = old <unsigned v ? old : v
648 // allocate space for exactly two operands
649 void *operator new(size_t s) {
650 return User::operator new(s, 2);
652 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
653 AtomicOrdering Ordering, SynchronizationScope SynchScope,
654 Instruction *InsertBefore = 0);
655 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
656 AtomicOrdering Ordering, SynchronizationScope SynchScope,
657 BasicBlock *InsertAtEnd);
659 BinOp getOperation() const {
660 return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
663 void setOperation(BinOp Operation) {
664 unsigned short SubclassData = getSubclassDataFromInstruction();
665 setInstructionSubclassData((SubclassData & 31) |
669 /// isVolatile - Return true if this is a RMW on a volatile memory location.
671 bool isVolatile() const {
672 return getSubclassDataFromInstruction() & 1;
675 /// setVolatile - Specify whether this is a volatile RMW or not.
677 void setVolatile(bool V) {
678 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
682 /// Transparently provide more efficient getOperand methods.
683 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
685 /// Set the ordering constraint on this RMW.
686 void setOrdering(AtomicOrdering Ordering) {
687 assert(Ordering != NotAtomic &&
688 "atomicrmw instructions can only be atomic.");
689 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
693 /// Specify whether this RMW orders other operations with respect to all
694 /// concurrently executing threads, or only with respect to signal handlers
695 /// executing in the same thread.
696 void setSynchScope(SynchronizationScope SynchScope) {
697 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
701 /// Returns the ordering constraint on this RMW.
702 AtomicOrdering getOrdering() const {
703 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
706 /// Returns whether this RMW is atomic between threads or only within a
708 SynchronizationScope getSynchScope() const {
709 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
712 Value *getPointerOperand() { return getOperand(0); }
713 const Value *getPointerOperand() const { return getOperand(0); }
714 static unsigned getPointerOperandIndex() { return 0U; }
716 Value *getValOperand() { return getOperand(1); }
717 const Value *getValOperand() const { return getOperand(1); }
719 /// \brief Returns the address space of the pointer operand.
720 unsigned getPointerAddressSpace() const {
721 return getPointerOperand()->getType()->getPointerAddressSpace();
724 // Methods for support type inquiry through isa, cast, and dyn_cast:
725 static inline bool classof(const Instruction *I) {
726 return I->getOpcode() == Instruction::AtomicRMW;
728 static inline bool classof(const Value *V) {
729 return isa<Instruction>(V) && classof(cast<Instruction>(V));
732 void Init(BinOp Operation, Value *Ptr, Value *Val,
733 AtomicOrdering Ordering, SynchronizationScope SynchScope);
734 // Shadow Instruction::setInstructionSubclassData with a private forwarding
735 // method so that subclasses cannot accidentally use it.
736 void setInstructionSubclassData(unsigned short D) {
737 Instruction::setInstructionSubclassData(D);
742 struct OperandTraits<AtomicRMWInst>
743 : public FixedNumOperandTraits<AtomicRMWInst,2> {
746 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)
748 //===----------------------------------------------------------------------===//
749 // GetElementPtrInst Class
750 //===----------------------------------------------------------------------===//
752 // checkGEPType - Simple wrapper function to give a better assertion failure
753 // message on bad indexes for a gep instruction.
755 inline Type *checkGEPType(Type *Ty) {
756 assert(Ty && "Invalid GetElementPtrInst indices for type!");
760 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
761 /// access elements of arrays and structs
763 class GetElementPtrInst : public Instruction {
764 GetElementPtrInst(const GetElementPtrInst &GEPI);
765 void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
767 /// Constructors - Create a getelementptr instruction with a base pointer an
768 /// list of indices. The first ctor can optionally insert before an existing
769 /// instruction, the second appends the new instruction to the specified
771 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
772 unsigned Values, const Twine &NameStr,
773 Instruction *InsertBefore);
774 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
775 unsigned Values, const Twine &NameStr,
776 BasicBlock *InsertAtEnd);
778 GetElementPtrInst *clone_impl() const override;
780 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
781 const Twine &NameStr = "",
782 Instruction *InsertBefore = 0) {
783 unsigned Values = 1 + unsigned(IdxList.size());
785 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
787 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
788 const Twine &NameStr,
789 BasicBlock *InsertAtEnd) {
790 unsigned Values = 1 + unsigned(IdxList.size());
792 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
795 /// Create an "inbounds" getelementptr. See the documentation for the
796 /// "inbounds" flag in LangRef.html for details.
797 static GetElementPtrInst *CreateInBounds(Value *Ptr,
798 ArrayRef<Value *> IdxList,
799 const Twine &NameStr = "",
800 Instruction *InsertBefore = 0) {
801 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
802 GEP->setIsInBounds(true);
805 static GetElementPtrInst *CreateInBounds(Value *Ptr,
806 ArrayRef<Value *> IdxList,
807 const Twine &NameStr,
808 BasicBlock *InsertAtEnd) {
809 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
810 GEP->setIsInBounds(true);
814 /// Transparently provide more efficient getOperand methods.
815 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
817 // getType - Overload to return most specific sequential type.
818 SequentialType *getType() const {
819 return cast<SequentialType>(Instruction::getType());
822 /// \brief Returns the address space of this instruction's pointer type.
823 unsigned getAddressSpace() const {
824 // Note that this is always the same as the pointer operand's address space
825 // and that is cheaper to compute, so cheat here.
826 return getPointerAddressSpace();
829 /// getIndexedType - Returns the type of the element that would be loaded with
830 /// a load instruction with the specified parameters.
832 /// Null is returned if the indices are invalid for the specified
835 static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList);
836 static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList);
837 static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList);
839 inline op_iterator idx_begin() { return op_begin()+1; }
840 inline const_op_iterator idx_begin() const { return op_begin()+1; }
841 inline op_iterator idx_end() { return op_end(); }
842 inline const_op_iterator idx_end() const { return op_end(); }
844 Value *getPointerOperand() {
845 return getOperand(0);
847 const Value *getPointerOperand() const {
848 return getOperand(0);
850 static unsigned getPointerOperandIndex() {
851 return 0U; // get index for modifying correct operand.
854 /// getPointerOperandType - Method to return the pointer operand as a
856 Type *getPointerOperandType() const {
857 return getPointerOperand()->getType();
860 /// \brief Returns the address space of the pointer operand.
861 unsigned getPointerAddressSpace() const {
862 return getPointerOperandType()->getPointerAddressSpace();
865 /// GetGEPReturnType - Returns the pointer type returned by the GEP
866 /// instruction, which may be a vector of pointers.
867 static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
868 Type *PtrTy = PointerType::get(checkGEPType(
869 getIndexedType(Ptr->getType(), IdxList)),
870 Ptr->getType()->getPointerAddressSpace());
872 if (Ptr->getType()->isVectorTy()) {
873 unsigned NumElem = cast<VectorType>(Ptr->getType())->getNumElements();
874 return VectorType::get(PtrTy, NumElem);
881 unsigned getNumIndices() const { // Note: always non-negative
882 return getNumOperands() - 1;
885 bool hasIndices() const {
886 return getNumOperands() > 1;
889 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
890 /// zeros. If so, the result pointer and the first operand have the same
891 /// value, just potentially different types.
892 bool hasAllZeroIndices() const;
894 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
895 /// constant integers. If so, the result pointer and the first operand have
896 /// a constant offset between them.
897 bool hasAllConstantIndices() const;
899 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
900 /// See LangRef.html for the meaning of inbounds on a getelementptr.
901 void setIsInBounds(bool b = true);
903 /// isInBounds - Determine whether the GEP has the inbounds flag.
904 bool isInBounds() const;
906 /// \brief Accumulate the constant address offset of this GEP if possible.
908 /// This routine accepts an APInt into which it will accumulate the constant
909 /// offset of this GEP if the GEP is in fact constant. If the GEP is not
910 /// all-constant, it returns false and the value of the offset APInt is
911 /// undefined (it is *not* preserved!). The APInt passed into this routine
912 /// must be at least as wide as the IntPtr type for the address space of
913 /// the base GEP pointer.
914 bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
916 // Methods for support type inquiry through isa, cast, and dyn_cast:
917 static inline bool classof(const Instruction *I) {
918 return (I->getOpcode() == Instruction::GetElementPtr);
920 static inline bool classof(const Value *V) {
921 return isa<Instruction>(V) && classof(cast<Instruction>(V));
926 struct OperandTraits<GetElementPtrInst> :
927 public VariadicOperandTraits<GetElementPtrInst, 1> {
930 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
931 ArrayRef<Value *> IdxList,
933 const Twine &NameStr,
934 Instruction *InsertBefore)
935 : Instruction(getGEPReturnType(Ptr, IdxList),
937 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
938 Values, InsertBefore) {
939 init(Ptr, IdxList, NameStr);
941 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
942 ArrayRef<Value *> IdxList,
944 const Twine &NameStr,
945 BasicBlock *InsertAtEnd)
946 : Instruction(getGEPReturnType(Ptr, IdxList),
948 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
949 Values, InsertAtEnd) {
950 init(Ptr, IdxList, NameStr);
954 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
957 //===----------------------------------------------------------------------===//
959 //===----------------------------------------------------------------------===//
961 /// This instruction compares its operands according to the predicate given
962 /// to the constructor. It only operates on integers or pointers. The operands
963 /// must be identical types.
964 /// \brief Represent an integer comparison operator.
965 class ICmpInst: public CmpInst {
967 assert(getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE &&
968 getPredicate() <= CmpInst::LAST_ICMP_PREDICATE &&
969 "Invalid ICmp predicate value");
970 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
971 "Both operands to ICmp instruction are not of the same type!");
972 // Check that the operands are the right type
973 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
974 getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
975 "Invalid operand types for ICmp instruction");
979 /// \brief Clone an identical ICmpInst
980 ICmpInst *clone_impl() const override;
982 /// \brief Constructor with insert-before-instruction semantics.
984 Instruction *InsertBefore, ///< Where to insert
985 Predicate pred, ///< The predicate to use for the comparison
986 Value *LHS, ///< The left-hand-side of the expression
987 Value *RHS, ///< The right-hand-side of the expression
988 const Twine &NameStr = "" ///< Name of the instruction
989 ) : CmpInst(makeCmpResultType(LHS->getType()),
990 Instruction::ICmp, pred, LHS, RHS, NameStr,
997 /// \brief Constructor with insert-at-end semantics.
999 BasicBlock &InsertAtEnd, ///< Block to insert into.
1000 Predicate pred, ///< The predicate to use for the comparison
1001 Value *LHS, ///< The left-hand-side of the expression
1002 Value *RHS, ///< The right-hand-side of the expression
1003 const Twine &NameStr = "" ///< Name of the instruction
1004 ) : CmpInst(makeCmpResultType(LHS->getType()),
1005 Instruction::ICmp, pred, LHS, RHS, NameStr,
1012 /// \brief Constructor with no-insertion semantics
1014 Predicate pred, ///< The predicate to use for the comparison
1015 Value *LHS, ///< The left-hand-side of the expression
1016 Value *RHS, ///< The right-hand-side of the expression
1017 const Twine &NameStr = "" ///< Name of the instruction
1018 ) : CmpInst(makeCmpResultType(LHS->getType()),
1019 Instruction::ICmp, pred, LHS, RHS, NameStr) {
1025 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
1026 /// @returns the predicate that would be the result if the operand were
1027 /// regarded as signed.
1028 /// \brief Return the signed version of the predicate
1029 Predicate getSignedPredicate() const {
1030 return getSignedPredicate(getPredicate());
1033 /// This is a static version that you can use without an instruction.
1034 /// \brief Return the signed version of the predicate.
1035 static Predicate getSignedPredicate(Predicate pred);
1037 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
1038 /// @returns the predicate that would be the result if the operand were
1039 /// regarded as unsigned.
1040 /// \brief Return the unsigned version of the predicate
1041 Predicate getUnsignedPredicate() const {
1042 return getUnsignedPredicate(getPredicate());
1045 /// This is a static version that you can use without an instruction.
1046 /// \brief Return the unsigned version of the predicate.
1047 static Predicate getUnsignedPredicate(Predicate pred);
1049 /// isEquality - Return true if this predicate is either EQ or NE. This also
1050 /// tests for commutativity.
1051 static bool isEquality(Predicate P) {
1052 return P == ICMP_EQ || P == ICMP_NE;
1055 /// isEquality - Return true if this predicate is either EQ or NE. This also
1056 /// tests for commutativity.
1057 bool isEquality() const {
1058 return isEquality(getPredicate());
1061 /// @returns true if the predicate of this ICmpInst is commutative
1062 /// \brief Determine if this relation is commutative.
1063 bool isCommutative() const { return isEquality(); }
1065 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1067 bool isRelational() const {
1068 return !isEquality();
1071 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1073 static bool isRelational(Predicate P) {
1074 return !isEquality(P);
1077 /// Initialize a set of values that all satisfy the predicate with C.
1078 /// \brief Make a ConstantRange for a relation with a constant value.
1079 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
1081 /// Exchange the two operands to this instruction in such a way that it does
1082 /// not modify the semantics of the instruction. The predicate value may be
1083 /// changed to retain the same result if the predicate is order dependent
1085 /// \brief Swap operands and adjust predicate.
1086 void swapOperands() {
1087 setPredicate(getSwappedPredicate());
1088 Op<0>().swap(Op<1>());
1091 // Methods for support type inquiry through isa, cast, and dyn_cast:
1092 static inline bool classof(const Instruction *I) {
1093 return I->getOpcode() == Instruction::ICmp;
1095 static inline bool classof(const Value *V) {
1096 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1101 //===----------------------------------------------------------------------===//
1103 //===----------------------------------------------------------------------===//
1105 /// This instruction compares its operands according to the predicate given
1106 /// to the constructor. It only operates on floating point values or packed
1107 /// vectors of floating point values. The operands must be identical types.
1108 /// \brief Represents a floating point comparison operator.
1109 class FCmpInst: public CmpInst {
1111 /// \brief Clone an identical FCmpInst
1112 FCmpInst *clone_impl() const override;
1114 /// \brief Constructor with insert-before-instruction semantics.
1116 Instruction *InsertBefore, ///< Where to insert
1117 Predicate pred, ///< The predicate to use for the comparison
1118 Value *LHS, ///< The left-hand-side of the expression
1119 Value *RHS, ///< The right-hand-side of the expression
1120 const Twine &NameStr = "" ///< Name of the instruction
1121 ) : CmpInst(makeCmpResultType(LHS->getType()),
1122 Instruction::FCmp, pred, LHS, RHS, NameStr,
1124 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1125 "Invalid FCmp predicate value");
1126 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1127 "Both operands to FCmp instruction are not of the same type!");
1128 // Check that the operands are the right type
1129 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1130 "Invalid operand types for FCmp instruction");
1133 /// \brief Constructor with insert-at-end semantics.
1135 BasicBlock &InsertAtEnd, ///< Block to insert into.
1136 Predicate pred, ///< The predicate to use for the comparison
1137 Value *LHS, ///< The left-hand-side of the expression
1138 Value *RHS, ///< The right-hand-side of the expression
1139 const Twine &NameStr = "" ///< Name of the instruction
1140 ) : CmpInst(makeCmpResultType(LHS->getType()),
1141 Instruction::FCmp, pred, LHS, RHS, NameStr,
1143 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1144 "Invalid FCmp predicate value");
1145 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1146 "Both operands to FCmp instruction are not of the same type!");
1147 // Check that the operands are the right type
1148 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1149 "Invalid operand types for FCmp instruction");
1152 /// \brief Constructor with no-insertion semantics
1154 Predicate pred, ///< The predicate to use for the comparison
1155 Value *LHS, ///< The left-hand-side of the expression
1156 Value *RHS, ///< The right-hand-side of the expression
1157 const Twine &NameStr = "" ///< Name of the instruction
1158 ) : CmpInst(makeCmpResultType(LHS->getType()),
1159 Instruction::FCmp, pred, LHS, RHS, NameStr) {
1160 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1161 "Invalid FCmp predicate value");
1162 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1163 "Both operands to FCmp instruction are not of the same type!");
1164 // Check that the operands are the right type
1165 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1166 "Invalid operand types for FCmp instruction");
1169 /// @returns true if the predicate of this instruction is EQ or NE.
1170 /// \brief Determine if this is an equality predicate.
1171 bool isEquality() const {
1172 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
1173 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
1176 /// @returns true if the predicate of this instruction is commutative.
1177 /// \brief Determine if this is a commutative predicate.
1178 bool isCommutative() const {
1179 return isEquality() ||
1180 getPredicate() == FCMP_FALSE ||
1181 getPredicate() == FCMP_TRUE ||
1182 getPredicate() == FCMP_ORD ||
1183 getPredicate() == FCMP_UNO;
1186 /// @returns true if the predicate is relational (not EQ or NE).
1187 /// \brief Determine if this a relational predicate.
1188 bool isRelational() const { return !isEquality(); }
1190 /// Exchange the two operands to this instruction in such a way that it does
1191 /// not modify the semantics of the instruction. The predicate value may be
1192 /// changed to retain the same result if the predicate is order dependent
1194 /// \brief Swap operands and adjust predicate.
1195 void swapOperands() {
1196 setPredicate(getSwappedPredicate());
1197 Op<0>().swap(Op<1>());
1200 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
1201 static inline bool classof(const Instruction *I) {
1202 return I->getOpcode() == Instruction::FCmp;
1204 static inline bool classof(const Value *V) {
1205 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1209 //===----------------------------------------------------------------------===//
1210 /// CallInst - This class represents a function call, abstracting a target
1211 /// machine's calling convention. This class uses low bit of the SubClassData
1212 /// field to indicate whether or not this is a tail call. The rest of the bits
1213 /// hold the calling convention of the call.
1215 class CallInst : public Instruction {
1216 AttributeSet AttributeList; ///< parameter attributes for call
1217 CallInst(const CallInst &CI);
1218 void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
1219 void init(Value *Func, const Twine &NameStr);
1221 /// Construct a CallInst given a range of arguments.
1222 /// \brief Construct a CallInst from a range of arguments
1223 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1224 const Twine &NameStr, Instruction *InsertBefore);
1226 /// Construct a CallInst given a range of arguments.
1227 /// \brief Construct a CallInst from a range of arguments
1228 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1229 const Twine &NameStr, BasicBlock *InsertAtEnd);
1231 explicit CallInst(Value *F, const Twine &NameStr,
1232 Instruction *InsertBefore);
1233 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1235 CallInst *clone_impl() const override;
1237 static CallInst *Create(Value *Func,
1238 ArrayRef<Value *> Args,
1239 const Twine &NameStr = "",
1240 Instruction *InsertBefore = 0) {
1241 return new(unsigned(Args.size() + 1))
1242 CallInst(Func, Args, NameStr, InsertBefore);
1244 static CallInst *Create(Value *Func,
1245 ArrayRef<Value *> Args,
1246 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1247 return new(unsigned(Args.size() + 1))
1248 CallInst(Func, Args, NameStr, InsertAtEnd);
1250 static CallInst *Create(Value *F, const Twine &NameStr = "",
1251 Instruction *InsertBefore = 0) {
1252 return new(1) CallInst(F, NameStr, InsertBefore);
1254 static CallInst *Create(Value *F, const Twine &NameStr,
1255 BasicBlock *InsertAtEnd) {
1256 return new(1) CallInst(F, NameStr, InsertAtEnd);
1258 /// CreateMalloc - Generate the IR for a call to malloc:
1259 /// 1. Compute the malloc call's argument as the specified type's size,
1260 /// possibly multiplied by the array size if the array size is not
1262 /// 2. Call malloc with that argument.
1263 /// 3. Bitcast the result of the malloc call to the specified type.
1264 static Instruction *CreateMalloc(Instruction *InsertBefore,
1265 Type *IntPtrTy, Type *AllocTy,
1266 Value *AllocSize, Value *ArraySize = 0,
1267 Function* MallocF = 0,
1268 const Twine &Name = "");
1269 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1270 Type *IntPtrTy, Type *AllocTy,
1271 Value *AllocSize, Value *ArraySize = 0,
1272 Function* MallocF = 0,
1273 const Twine &Name = "");
1274 /// CreateFree - Generate the IR for a call to the builtin free function.
1275 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
1276 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
1280 bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
1281 void setTailCall(bool isTC = true) {
1282 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
1286 /// Provide fast operand accessors
1287 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1289 /// getNumArgOperands - Return the number of call arguments.
1291 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
1293 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1295 Value *getArgOperand(unsigned i) const { return getOperand(i); }
1296 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
1298 /// arg_operands - iteration adapter for range-for loops.
1299 iterator_range<op_iterator> arg_operands() {
1300 // The last operand in the op list is the callee - it's not one of the args
1301 // so we don't want to iterate over it.
1302 return iterator_range<op_iterator>(op_begin(), op_end() - 1);
1305 /// arg_operands - iteration adapter for range-for loops.
1306 iterator_range<const_op_iterator> arg_operands() const {
1307 return iterator_range<const_op_iterator>(op_begin(), op_end() - 1);
1310 /// \brief Wrappers for getting the \c Use of a call argument.
1311 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
1312 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
1314 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1316 CallingConv::ID getCallingConv() const {
1317 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
1319 void setCallingConv(CallingConv::ID CC) {
1320 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
1321 (static_cast<unsigned>(CC) << 1));
1324 /// getAttributes - Return the parameter attributes for this call.
1326 const AttributeSet &getAttributes() const { return AttributeList; }
1328 /// setAttributes - Set the parameter attributes for this call.
1330 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
1332 /// addAttribute - adds the attribute to the list of attributes.
1333 void addAttribute(unsigned i, Attribute::AttrKind attr);
1335 /// removeAttribute - removes the attribute from the list of attributes.
1336 void removeAttribute(unsigned i, Attribute attr);
1338 /// \brief Determine whether this call has the given attribute.
1339 bool hasFnAttr(Attribute::AttrKind A) const {
1340 assert(A != Attribute::NoBuiltin &&
1341 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
1342 return hasFnAttrImpl(A);
1345 /// \brief Determine whether the call or the callee has the given attributes.
1346 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
1348 /// \brief Extract the alignment for a call or parameter (0=unknown).
1349 unsigned getParamAlignment(unsigned i) const {
1350 return AttributeList.getParamAlignment(i);
1353 /// \brief Return true if the call should not be treated as a call to a
1355 bool isNoBuiltin() const {
1356 return hasFnAttrImpl(Attribute::NoBuiltin) &&
1357 !hasFnAttrImpl(Attribute::Builtin);
1360 /// \brief Return true if the call should not be inlined.
1361 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
1362 void setIsNoInline() {
1363 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
1366 /// \brief Return true if the call can return twice
1367 bool canReturnTwice() const {
1368 return hasFnAttr(Attribute::ReturnsTwice);
1370 void setCanReturnTwice() {
1371 addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice);
1374 /// \brief Determine if the call does not access memory.
1375 bool doesNotAccessMemory() const {
1376 return hasFnAttr(Attribute::ReadNone);
1378 void setDoesNotAccessMemory() {
1379 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
1382 /// \brief Determine if the call does not access or only reads memory.
1383 bool onlyReadsMemory() const {
1384 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
1386 void setOnlyReadsMemory() {
1387 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
1390 /// \brief Determine if the call cannot return.
1391 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
1392 void setDoesNotReturn() {
1393 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
1396 /// \brief Determine if the call cannot unwind.
1397 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
1398 void setDoesNotThrow() {
1399 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
1402 /// \brief Determine if the call cannot be duplicated.
1403 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
1404 void setCannotDuplicate() {
1405 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
1408 /// \brief Determine if the call returns a structure through first
1409 /// pointer argument.
1410 bool hasStructRetAttr() const {
1411 // Be friendly and also check the callee.
1412 return paramHasAttr(1, Attribute::StructRet);
1415 /// \brief Determine if any call argument is an aggregate passed by value.
1416 bool hasByValArgument() const {
1417 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1420 /// getCalledFunction - Return the function called, or null if this is an
1421 /// indirect function invocation.
1423 Function *getCalledFunction() const {
1424 return dyn_cast<Function>(Op<-1>());
1427 /// getCalledValue - Get a pointer to the function that is invoked by this
1429 const Value *getCalledValue() const { return Op<-1>(); }
1430 Value *getCalledValue() { return Op<-1>(); }
1432 /// setCalledFunction - Set the function called.
1433 void setCalledFunction(Value* Fn) {
1437 /// isInlineAsm - Check if this call is an inline asm statement.
1438 bool isInlineAsm() const {
1439 return isa<InlineAsm>(Op<-1>());
1442 // Methods for support type inquiry through isa, cast, and dyn_cast:
1443 static inline bool classof(const Instruction *I) {
1444 return I->getOpcode() == Instruction::Call;
1446 static inline bool classof(const Value *V) {
1447 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1451 bool hasFnAttrImpl(Attribute::AttrKind A) const;
1453 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1454 // method so that subclasses cannot accidentally use it.
1455 void setInstructionSubclassData(unsigned short D) {
1456 Instruction::setInstructionSubclassData(D);
1461 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1464 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1465 const Twine &NameStr, BasicBlock *InsertAtEnd)
1466 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1467 ->getElementType())->getReturnType(),
1469 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1470 unsigned(Args.size() + 1), InsertAtEnd) {
1471 init(Func, Args, NameStr);
1474 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1475 const Twine &NameStr, Instruction *InsertBefore)
1476 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1477 ->getElementType())->getReturnType(),
1479 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1480 unsigned(Args.size() + 1), InsertBefore) {
1481 init(Func, Args, NameStr);
1485 // Note: if you get compile errors about private methods then
1486 // please update your code to use the high-level operand
1487 // interfaces. See line 943 above.
1488 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1490 //===----------------------------------------------------------------------===//
1492 //===----------------------------------------------------------------------===//
1494 /// SelectInst - This class represents the LLVM 'select' instruction.
1496 class SelectInst : public Instruction {
1497 void init(Value *C, Value *S1, Value *S2) {
1498 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1504 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1505 Instruction *InsertBefore)
1506 : Instruction(S1->getType(), Instruction::Select,
1507 &Op<0>(), 3, InsertBefore) {
1511 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1512 BasicBlock *InsertAtEnd)
1513 : Instruction(S1->getType(), Instruction::Select,
1514 &Op<0>(), 3, InsertAtEnd) {
1519 SelectInst *clone_impl() const override;
1521 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1522 const Twine &NameStr = "",
1523 Instruction *InsertBefore = 0) {
1524 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1526 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1527 const Twine &NameStr,
1528 BasicBlock *InsertAtEnd) {
1529 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1532 const Value *getCondition() const { return Op<0>(); }
1533 const Value *getTrueValue() const { return Op<1>(); }
1534 const Value *getFalseValue() const { return Op<2>(); }
1535 Value *getCondition() { return Op<0>(); }
1536 Value *getTrueValue() { return Op<1>(); }
1537 Value *getFalseValue() { return Op<2>(); }
1539 /// areInvalidOperands - Return a string if the specified operands are invalid
1540 /// for a select operation, otherwise return null.
1541 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1543 /// Transparently provide more efficient getOperand methods.
1544 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1546 OtherOps getOpcode() const {
1547 return static_cast<OtherOps>(Instruction::getOpcode());
1550 // Methods for support type inquiry through isa, cast, and dyn_cast:
1551 static inline bool classof(const Instruction *I) {
1552 return I->getOpcode() == Instruction::Select;
1554 static inline bool classof(const Value *V) {
1555 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1560 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1563 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1565 //===----------------------------------------------------------------------===//
1567 //===----------------------------------------------------------------------===//
1569 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1570 /// an argument of the specified type given a va_list and increments that list
1572 class VAArgInst : public UnaryInstruction {
1574 VAArgInst *clone_impl() const override;
1577 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1578 Instruction *InsertBefore = 0)
1579 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1582 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1583 BasicBlock *InsertAtEnd)
1584 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1588 Value *getPointerOperand() { return getOperand(0); }
1589 const Value *getPointerOperand() const { return getOperand(0); }
1590 static unsigned getPointerOperandIndex() { return 0U; }
1592 // Methods for support type inquiry through isa, cast, and dyn_cast:
1593 static inline bool classof(const Instruction *I) {
1594 return I->getOpcode() == VAArg;
1596 static inline bool classof(const Value *V) {
1597 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1601 //===----------------------------------------------------------------------===//
1602 // ExtractElementInst Class
1603 //===----------------------------------------------------------------------===//
1605 /// ExtractElementInst - This instruction extracts a single (scalar)
1606 /// element from a VectorType value
1608 class ExtractElementInst : public Instruction {
1609 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1610 Instruction *InsertBefore = 0);
1611 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1612 BasicBlock *InsertAtEnd);
1614 ExtractElementInst *clone_impl() const override;
1617 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1618 const Twine &NameStr = "",
1619 Instruction *InsertBefore = 0) {
1620 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1622 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1623 const Twine &NameStr,
1624 BasicBlock *InsertAtEnd) {
1625 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1628 /// isValidOperands - Return true if an extractelement instruction can be
1629 /// formed with the specified operands.
1630 static bool isValidOperands(const Value *Vec, const Value *Idx);
1632 Value *getVectorOperand() { return Op<0>(); }
1633 Value *getIndexOperand() { return Op<1>(); }
1634 const Value *getVectorOperand() const { return Op<0>(); }
1635 const Value *getIndexOperand() const { return Op<1>(); }
1637 VectorType *getVectorOperandType() const {
1638 return cast<VectorType>(getVectorOperand()->getType());
1642 /// Transparently provide more efficient getOperand methods.
1643 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1645 // Methods for support type inquiry through isa, cast, and dyn_cast:
1646 static inline bool classof(const Instruction *I) {
1647 return I->getOpcode() == Instruction::ExtractElement;
1649 static inline bool classof(const Value *V) {
1650 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1655 struct OperandTraits<ExtractElementInst> :
1656 public FixedNumOperandTraits<ExtractElementInst, 2> {
1659 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1661 //===----------------------------------------------------------------------===//
1662 // InsertElementInst Class
1663 //===----------------------------------------------------------------------===//
1665 /// InsertElementInst - This instruction inserts a single (scalar)
1666 /// element into a VectorType value
1668 class InsertElementInst : public Instruction {
1669 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1670 const Twine &NameStr = "",
1671 Instruction *InsertBefore = 0);
1672 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1673 const Twine &NameStr, BasicBlock *InsertAtEnd);
1675 InsertElementInst *clone_impl() const override;
1678 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1679 const Twine &NameStr = "",
1680 Instruction *InsertBefore = 0) {
1681 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1683 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1684 const Twine &NameStr,
1685 BasicBlock *InsertAtEnd) {
1686 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1689 /// isValidOperands - Return true if an insertelement instruction can be
1690 /// formed with the specified operands.
1691 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1694 /// getType - Overload to return most specific vector type.
1696 VectorType *getType() const {
1697 return cast<VectorType>(Instruction::getType());
1700 /// Transparently provide more efficient getOperand methods.
1701 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1703 // Methods for support type inquiry through isa, cast, and dyn_cast:
1704 static inline bool classof(const Instruction *I) {
1705 return I->getOpcode() == Instruction::InsertElement;
1707 static inline bool classof(const Value *V) {
1708 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1713 struct OperandTraits<InsertElementInst> :
1714 public FixedNumOperandTraits<InsertElementInst, 3> {
1717 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1719 //===----------------------------------------------------------------------===//
1720 // ShuffleVectorInst Class
1721 //===----------------------------------------------------------------------===//
1723 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1726 class ShuffleVectorInst : public Instruction {
1728 ShuffleVectorInst *clone_impl() const override;
1731 // allocate space for exactly three operands
1732 void *operator new(size_t s) {
1733 return User::operator new(s, 3);
1735 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1736 const Twine &NameStr = "",
1737 Instruction *InsertBefor = 0);
1738 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1739 const Twine &NameStr, BasicBlock *InsertAtEnd);
1741 /// isValidOperands - Return true if a shufflevector instruction can be
1742 /// formed with the specified operands.
1743 static bool isValidOperands(const Value *V1, const Value *V2,
1746 /// getType - Overload to return most specific vector type.
1748 VectorType *getType() const {
1749 return cast<VectorType>(Instruction::getType());
1752 /// Transparently provide more efficient getOperand methods.
1753 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1755 Constant *getMask() const {
1756 return cast<Constant>(getOperand(2));
1759 /// getMaskValue - Return the index from the shuffle mask for the specified
1760 /// output result. This is either -1 if the element is undef or a number less
1761 /// than 2*numelements.
1762 static int getMaskValue(Constant *Mask, unsigned i);
1764 int getMaskValue(unsigned i) const {
1765 return getMaskValue(getMask(), i);
1768 /// getShuffleMask - Return the full mask for this instruction, where each
1769 /// element is the element number and undef's are returned as -1.
1770 static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
1772 void getShuffleMask(SmallVectorImpl<int> &Result) const {
1773 return getShuffleMask(getMask(), Result);
1776 SmallVector<int, 16> getShuffleMask() const {
1777 SmallVector<int, 16> Mask;
1778 getShuffleMask(Mask);
1783 // Methods for support type inquiry through isa, cast, and dyn_cast:
1784 static inline bool classof(const Instruction *I) {
1785 return I->getOpcode() == Instruction::ShuffleVector;
1787 static inline bool classof(const Value *V) {
1788 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1793 struct OperandTraits<ShuffleVectorInst> :
1794 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1797 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1799 //===----------------------------------------------------------------------===//
1800 // ExtractValueInst Class
1801 //===----------------------------------------------------------------------===//
1803 /// ExtractValueInst - This instruction extracts a struct member or array
1804 /// element value from an aggregate value.
1806 class ExtractValueInst : public UnaryInstruction {
1807 SmallVector<unsigned, 4> Indices;
1809 ExtractValueInst(const ExtractValueInst &EVI);
1810 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1812 /// Constructors - Create a extractvalue instruction with a base aggregate
1813 /// value and a list of indices. The first ctor can optionally insert before
1814 /// an existing instruction, the second appends the new instruction to the
1815 /// specified BasicBlock.
1816 inline ExtractValueInst(Value *Agg,
1817 ArrayRef<unsigned> Idxs,
1818 const Twine &NameStr,
1819 Instruction *InsertBefore);
1820 inline ExtractValueInst(Value *Agg,
1821 ArrayRef<unsigned> Idxs,
1822 const Twine &NameStr, BasicBlock *InsertAtEnd);
1824 // allocate space for exactly one operand
1825 void *operator new(size_t s) {
1826 return User::operator new(s, 1);
1829 ExtractValueInst *clone_impl() const override;
1832 static ExtractValueInst *Create(Value *Agg,
1833 ArrayRef<unsigned> Idxs,
1834 const Twine &NameStr = "",
1835 Instruction *InsertBefore = 0) {
1837 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1839 static ExtractValueInst *Create(Value *Agg,
1840 ArrayRef<unsigned> Idxs,
1841 const Twine &NameStr,
1842 BasicBlock *InsertAtEnd) {
1843 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1846 /// getIndexedType - Returns the type of the element that would be extracted
1847 /// with an extractvalue instruction with the specified parameters.
1849 /// Null is returned if the indices are invalid for the specified type.
1850 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
1852 typedef const unsigned* idx_iterator;
1853 inline idx_iterator idx_begin() const { return Indices.begin(); }
1854 inline idx_iterator idx_end() const { return Indices.end(); }
1856 Value *getAggregateOperand() {
1857 return getOperand(0);
1859 const Value *getAggregateOperand() const {
1860 return getOperand(0);
1862 static unsigned getAggregateOperandIndex() {
1863 return 0U; // get index for modifying correct operand
1866 ArrayRef<unsigned> getIndices() const {
1870 unsigned getNumIndices() const {
1871 return (unsigned)Indices.size();
1874 bool hasIndices() const {
1878 // Methods for support type inquiry through isa, cast, and dyn_cast:
1879 static inline bool classof(const Instruction *I) {
1880 return I->getOpcode() == Instruction::ExtractValue;
1882 static inline bool classof(const Value *V) {
1883 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1887 ExtractValueInst::ExtractValueInst(Value *Agg,
1888 ArrayRef<unsigned> Idxs,
1889 const Twine &NameStr,
1890 Instruction *InsertBefore)
1891 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1892 ExtractValue, Agg, InsertBefore) {
1893 init(Idxs, NameStr);
1895 ExtractValueInst::ExtractValueInst(Value *Agg,
1896 ArrayRef<unsigned> Idxs,
1897 const Twine &NameStr,
1898 BasicBlock *InsertAtEnd)
1899 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1900 ExtractValue, Agg, InsertAtEnd) {
1901 init(Idxs, NameStr);
1905 //===----------------------------------------------------------------------===//
1906 // InsertValueInst Class
1907 //===----------------------------------------------------------------------===//
1909 /// InsertValueInst - This instruction inserts a struct field of array element
1910 /// value into an aggregate value.
1912 class InsertValueInst : public Instruction {
1913 SmallVector<unsigned, 4> Indices;
1915 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1916 InsertValueInst(const InsertValueInst &IVI);
1917 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1918 const Twine &NameStr);
1920 /// Constructors - Create a insertvalue instruction with a base aggregate
1921 /// value, a value to insert, and a list of indices. The first ctor can
1922 /// optionally insert before an existing instruction, the second appends
1923 /// the new instruction to the specified BasicBlock.
1924 inline InsertValueInst(Value *Agg, Value *Val,
1925 ArrayRef<unsigned> Idxs,
1926 const Twine &NameStr,
1927 Instruction *InsertBefore);
1928 inline InsertValueInst(Value *Agg, Value *Val,
1929 ArrayRef<unsigned> Idxs,
1930 const Twine &NameStr, BasicBlock *InsertAtEnd);
1932 /// Constructors - These two constructors are convenience methods because one
1933 /// and two index insertvalue instructions are so common.
1934 InsertValueInst(Value *Agg, Value *Val,
1935 unsigned Idx, const Twine &NameStr = "",
1936 Instruction *InsertBefore = 0);
1937 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1938 const Twine &NameStr, BasicBlock *InsertAtEnd);
1940 InsertValueInst *clone_impl() const override;
1942 // allocate space for exactly two operands
1943 void *operator new(size_t s) {
1944 return User::operator new(s, 2);
1947 static InsertValueInst *Create(Value *Agg, Value *Val,
1948 ArrayRef<unsigned> Idxs,
1949 const Twine &NameStr = "",
1950 Instruction *InsertBefore = 0) {
1951 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1953 static InsertValueInst *Create(Value *Agg, Value *Val,
1954 ArrayRef<unsigned> Idxs,
1955 const Twine &NameStr,
1956 BasicBlock *InsertAtEnd) {
1957 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1960 /// Transparently provide more efficient getOperand methods.
1961 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1963 typedef const unsigned* idx_iterator;
1964 inline idx_iterator idx_begin() const { return Indices.begin(); }
1965 inline idx_iterator idx_end() const { return Indices.end(); }
1967 Value *getAggregateOperand() {
1968 return getOperand(0);
1970 const Value *getAggregateOperand() const {
1971 return getOperand(0);
1973 static unsigned getAggregateOperandIndex() {
1974 return 0U; // get index for modifying correct operand
1977 Value *getInsertedValueOperand() {
1978 return getOperand(1);
1980 const Value *getInsertedValueOperand() const {
1981 return getOperand(1);
1983 static unsigned getInsertedValueOperandIndex() {
1984 return 1U; // get index for modifying correct operand
1987 ArrayRef<unsigned> getIndices() const {
1991 unsigned getNumIndices() const {
1992 return (unsigned)Indices.size();
1995 bool hasIndices() const {
1999 // Methods for support type inquiry through isa, cast, and dyn_cast:
2000 static inline bool classof(const Instruction *I) {
2001 return I->getOpcode() == Instruction::InsertValue;
2003 static inline bool classof(const Value *V) {
2004 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2009 struct OperandTraits<InsertValueInst> :
2010 public FixedNumOperandTraits<InsertValueInst, 2> {
2013 InsertValueInst::InsertValueInst(Value *Agg,
2015 ArrayRef<unsigned> Idxs,
2016 const Twine &NameStr,
2017 Instruction *InsertBefore)
2018 : Instruction(Agg->getType(), InsertValue,
2019 OperandTraits<InsertValueInst>::op_begin(this),
2021 init(Agg, Val, Idxs, NameStr);
2023 InsertValueInst::InsertValueInst(Value *Agg,
2025 ArrayRef<unsigned> Idxs,
2026 const Twine &NameStr,
2027 BasicBlock *InsertAtEnd)
2028 : Instruction(Agg->getType(), InsertValue,
2029 OperandTraits<InsertValueInst>::op_begin(this),
2031 init(Agg, Val, Idxs, NameStr);
2034 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
2036 //===----------------------------------------------------------------------===//
2038 //===----------------------------------------------------------------------===//
2040 // PHINode - The PHINode class is used to represent the magical mystical PHI
2041 // node, that can not exist in nature, but can be synthesized in a computer
2042 // scientist's overactive imagination.
2044 class PHINode : public Instruction {
2045 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2046 /// ReservedSpace - The number of operands actually allocated. NumOperands is
2047 /// the number actually in use.
2048 unsigned ReservedSpace;
2049 PHINode(const PHINode &PN);
2050 // allocate space for exactly zero operands
2051 void *operator new(size_t s) {
2052 return User::operator new(s, 0);
2054 explicit PHINode(Type *Ty, unsigned NumReservedValues,
2055 const Twine &NameStr = "", Instruction *InsertBefore = 0)
2056 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
2057 ReservedSpace(NumReservedValues) {
2059 OperandList = allocHungoffUses(ReservedSpace);
2062 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
2063 BasicBlock *InsertAtEnd)
2064 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
2065 ReservedSpace(NumReservedValues) {
2067 OperandList = allocHungoffUses(ReservedSpace);
2070 // allocHungoffUses - this is more complicated than the generic
2071 // User::allocHungoffUses, because we have to allocate Uses for the incoming
2072 // values and pointers to the incoming blocks, all in one allocation.
2073 Use *allocHungoffUses(unsigned) const;
2075 PHINode *clone_impl() const override;
2077 /// Constructors - NumReservedValues is a hint for the number of incoming
2078 /// edges that this phi node will have (use 0 if you really have no idea).
2079 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2080 const Twine &NameStr = "",
2081 Instruction *InsertBefore = 0) {
2082 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2084 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2085 const Twine &NameStr, BasicBlock *InsertAtEnd) {
2086 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2090 /// Provide fast operand accessors
2091 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2093 // Block iterator interface. This provides access to the list of incoming
2094 // basic blocks, which parallels the list of incoming values.
2096 typedef BasicBlock **block_iterator;
2097 typedef BasicBlock * const *const_block_iterator;
2099 block_iterator block_begin() {
2101 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2102 return reinterpret_cast<block_iterator>(ref + 1);
2105 const_block_iterator block_begin() const {
2106 const Use::UserRef *ref =
2107 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2108 return reinterpret_cast<const_block_iterator>(ref + 1);
2111 block_iterator block_end() {
2112 return block_begin() + getNumOperands();
2115 const_block_iterator block_end() const {
2116 return block_begin() + getNumOperands();
2119 /// getNumIncomingValues - Return the number of incoming edges
2121 unsigned getNumIncomingValues() const { return getNumOperands(); }
2123 /// getIncomingValue - Return incoming value number x
2125 Value *getIncomingValue(unsigned i) const {
2126 return getOperand(i);
2128 void setIncomingValue(unsigned i, Value *V) {
2131 static unsigned getOperandNumForIncomingValue(unsigned i) {
2134 static unsigned getIncomingValueNumForOperand(unsigned i) {
2138 /// getIncomingBlock - Return incoming basic block number @p i.
2140 BasicBlock *getIncomingBlock(unsigned i) const {
2141 return block_begin()[i];
2144 /// getIncomingBlock - Return incoming basic block corresponding
2145 /// to an operand of the PHI.
2147 BasicBlock *getIncomingBlock(const Use &U) const {
2148 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2149 return getIncomingBlock(unsigned(&U - op_begin()));
2152 /// getIncomingBlock - Return incoming basic block corresponding
2153 /// to value use iterator.
2155 BasicBlock *getIncomingBlock(Value::const_user_iterator I) const {
2156 return getIncomingBlock(I.getUse());
2159 void setIncomingBlock(unsigned i, BasicBlock *BB) {
2160 block_begin()[i] = BB;
2163 /// addIncoming - Add an incoming value to the end of the PHI list
2165 void addIncoming(Value *V, BasicBlock *BB) {
2166 assert(V && "PHI node got a null value!");
2167 assert(BB && "PHI node got a null basic block!");
2168 assert(getType() == V->getType() &&
2169 "All operands to PHI node must be the same type as the PHI node!");
2170 if (NumOperands == ReservedSpace)
2171 growOperands(); // Get more space!
2172 // Initialize some new operands.
2174 setIncomingValue(NumOperands - 1, V);
2175 setIncomingBlock(NumOperands - 1, BB);
2178 /// removeIncomingValue - Remove an incoming value. This is useful if a
2179 /// predecessor basic block is deleted. The value removed is returned.
2181 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2182 /// is true), the PHI node is destroyed and any uses of it are replaced with
2183 /// dummy values. The only time there should be zero incoming values to a PHI
2184 /// node is when the block is dead, so this strategy is sound.
2186 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2188 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2189 int Idx = getBasicBlockIndex(BB);
2190 assert(Idx >= 0 && "Invalid basic block argument to remove!");
2191 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2194 /// getBasicBlockIndex - Return the first index of the specified basic
2195 /// block in the value list for this PHI. Returns -1 if no instance.
2197 int getBasicBlockIndex(const BasicBlock *BB) const {
2198 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2199 if (block_begin()[i] == BB)
2204 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2205 int Idx = getBasicBlockIndex(BB);
2206 assert(Idx >= 0 && "Invalid basic block argument!");
2207 return getIncomingValue(Idx);
2210 /// hasConstantValue - If the specified PHI node always merges together the
2211 /// same value, return the value, otherwise return null.
2212 Value *hasConstantValue() const;
2214 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2215 static inline bool classof(const Instruction *I) {
2216 return I->getOpcode() == Instruction::PHI;
2218 static inline bool classof(const Value *V) {
2219 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2222 void growOperands();
2226 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2229 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
2231 //===----------------------------------------------------------------------===//
2232 // LandingPadInst Class
2233 //===----------------------------------------------------------------------===//
2235 //===---------------------------------------------------------------------------
2236 /// LandingPadInst - The landingpad instruction holds all of the information
2237 /// necessary to generate correct exception handling. The landingpad instruction
2238 /// cannot be moved from the top of a landing pad block, which itself is
2239 /// accessible only from the 'unwind' edge of an invoke. This uses the
2240 /// SubclassData field in Value to store whether or not the landingpad is a
2243 class LandingPadInst : public Instruction {
2244 /// ReservedSpace - The number of operands actually allocated. NumOperands is
2245 /// the number actually in use.
2246 unsigned ReservedSpace;
2247 LandingPadInst(const LandingPadInst &LP);
2249 enum ClauseType { Catch, Filter };
2251 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2252 // Allocate space for exactly zero operands.
2253 void *operator new(size_t s) {
2254 return User::operator new(s, 0);
2256 void growOperands(unsigned Size);
2257 void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
2259 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2260 unsigned NumReservedValues, const Twine &NameStr,
2261 Instruction *InsertBefore);
2262 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2263 unsigned NumReservedValues, const Twine &NameStr,
2264 BasicBlock *InsertAtEnd);
2266 LandingPadInst *clone_impl() const override;
2268 /// Constructors - NumReservedClauses is a hint for the number of incoming
2269 /// clauses that this landingpad will have (use 0 if you really have no idea).
2270 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2271 unsigned NumReservedClauses,
2272 const Twine &NameStr = "",
2273 Instruction *InsertBefore = 0);
2274 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2275 unsigned NumReservedClauses,
2276 const Twine &NameStr, BasicBlock *InsertAtEnd);
2279 /// Provide fast operand accessors
2280 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2282 /// getPersonalityFn - Get the personality function associated with this
2284 Value *getPersonalityFn() const { return getOperand(0); }
2286 /// isCleanup - Return 'true' if this landingpad instruction is a
2287 /// cleanup. I.e., it should be run when unwinding even if its landing pad
2288 /// doesn't catch the exception.
2289 bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2291 /// setCleanup - Indicate that this landingpad instruction is a cleanup.
2292 void setCleanup(bool V) {
2293 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2297 /// addClause - Add a catch or filter clause to the landing pad.
2298 void addClause(Value *ClauseVal);
2300 /// getClause - Get the value of the clause at index Idx. Use isCatch/isFilter
2301 /// to determine what type of clause this is.
2302 Value *getClause(unsigned Idx) const { return OperandList[Idx + 1]; }
2304 /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
2305 bool isCatch(unsigned Idx) const {
2306 return !isa<ArrayType>(OperandList[Idx + 1]->getType());
2309 /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
2310 bool isFilter(unsigned Idx) const {
2311 return isa<ArrayType>(OperandList[Idx + 1]->getType());
2314 /// getNumClauses - Get the number of clauses for this landing pad.
2315 unsigned getNumClauses() const { return getNumOperands() - 1; }
2317 /// reserveClauses - Grow the size of the operand list to accommodate the new
2318 /// number of clauses.
2319 void reserveClauses(unsigned Size) { growOperands(Size); }
2321 // Methods for support type inquiry through isa, cast, and dyn_cast:
2322 static inline bool classof(const Instruction *I) {
2323 return I->getOpcode() == Instruction::LandingPad;
2325 static inline bool classof(const Value *V) {
2326 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2331 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
2334 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
2336 //===----------------------------------------------------------------------===//
2338 //===----------------------------------------------------------------------===//
2340 //===---------------------------------------------------------------------------
2341 /// ReturnInst - Return a value (possibly void), from a function. Execution
2342 /// does not continue in this function any longer.
2344 class ReturnInst : public TerminatorInst {
2345 ReturnInst(const ReturnInst &RI);
2348 // ReturnInst constructors:
2349 // ReturnInst() - 'ret void' instruction
2350 // ReturnInst( null) - 'ret void' instruction
2351 // ReturnInst(Value* X) - 'ret X' instruction
2352 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
2353 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
2354 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2355 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
2357 // NOTE: If the Value* passed is of type void then the constructor behaves as
2358 // if it was passed NULL.
2359 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
2360 Instruction *InsertBefore = 0);
2361 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2362 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2364 ReturnInst *clone_impl() const override;
2366 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
2367 Instruction *InsertBefore = 0) {
2368 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2370 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2371 BasicBlock *InsertAtEnd) {
2372 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2374 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2375 return new(0) ReturnInst(C, InsertAtEnd);
2377 virtual ~ReturnInst();
2379 /// Provide fast operand accessors
2380 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2382 /// Convenience accessor. Returns null if there is no return value.
2383 Value *getReturnValue() const {
2384 return getNumOperands() != 0 ? getOperand(0) : 0;
2387 unsigned getNumSuccessors() const { return 0; }
2389 // Methods for support type inquiry through isa, cast, and dyn_cast:
2390 static inline bool classof(const Instruction *I) {
2391 return (I->getOpcode() == Instruction::Ret);
2393 static inline bool classof(const Value *V) {
2394 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2397 BasicBlock *getSuccessorV(unsigned idx) const override;
2398 unsigned getNumSuccessorsV() const override;
2399 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2403 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2406 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2408 //===----------------------------------------------------------------------===//
2410 //===----------------------------------------------------------------------===//
2412 //===---------------------------------------------------------------------------
2413 /// BranchInst - Conditional or Unconditional Branch instruction.
2415 class BranchInst : public TerminatorInst {
2416 /// Ops list - Branches are strange. The operands are ordered:
2417 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2418 /// they don't have to check for cond/uncond branchness. These are mostly
2419 /// accessed relative from op_end().
2420 BranchInst(const BranchInst &BI);
2422 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2423 // BranchInst(BB *B) - 'br B'
2424 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2425 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2426 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2427 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2428 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2429 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2430 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2431 Instruction *InsertBefore = 0);
2432 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2433 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2434 BasicBlock *InsertAtEnd);
2436 BranchInst *clone_impl() const override;
2438 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2439 return new(1) BranchInst(IfTrue, InsertBefore);
2441 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2442 Value *Cond, Instruction *InsertBefore = 0) {
2443 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2445 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2446 return new(1) BranchInst(IfTrue, InsertAtEnd);
2448 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2449 Value *Cond, BasicBlock *InsertAtEnd) {
2450 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2453 /// Transparently provide more efficient getOperand methods.
2454 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2456 bool isUnconditional() const { return getNumOperands() == 1; }
2457 bool isConditional() const { return getNumOperands() == 3; }
2459 Value *getCondition() const {
2460 assert(isConditional() && "Cannot get condition of an uncond branch!");
2464 void setCondition(Value *V) {
2465 assert(isConditional() && "Cannot set condition of unconditional branch!");
2469 unsigned getNumSuccessors() const { return 1+isConditional(); }
2471 BasicBlock *getSuccessor(unsigned i) const {
2472 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2473 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2476 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2477 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2478 *(&Op<-1>() - idx) = (Value*)NewSucc;
2481 /// \brief Swap the successors of this branch instruction.
2483 /// Swaps the successors of the branch instruction. This also swaps any
2484 /// branch weight metadata associated with the instruction so that it
2485 /// continues to map correctly to each operand.
2486 void swapSuccessors();
2488 // Methods for support type inquiry through isa, cast, and dyn_cast:
2489 static inline bool classof(const Instruction *I) {
2490 return (I->getOpcode() == Instruction::Br);
2492 static inline bool classof(const Value *V) {
2493 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2496 BasicBlock *getSuccessorV(unsigned idx) const override;
2497 unsigned getNumSuccessorsV() const override;
2498 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2502 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2505 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2507 //===----------------------------------------------------------------------===//
2509 //===----------------------------------------------------------------------===//
2511 //===---------------------------------------------------------------------------
2512 /// SwitchInst - Multiway switch
2514 class SwitchInst : public TerminatorInst {
2515 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2516 unsigned ReservedSpace;
2517 // Operand[0] = Value to switch on
2518 // Operand[1] = Default basic block destination
2519 // Operand[2n ] = Value to match
2520 // Operand[2n+1] = BasicBlock to go to on match
2521 SwitchInst(const SwitchInst &SI);
2522 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2523 void growOperands();
2524 // allocate space for exactly zero operands
2525 void *operator new(size_t s) {
2526 return User::operator new(s, 0);
2528 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2529 /// switch on and a default destination. The number of additional cases can
2530 /// be specified here to make memory allocation more efficient. This
2531 /// constructor can also autoinsert before another instruction.
2532 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2533 Instruction *InsertBefore);
2535 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2536 /// switch on and a default destination. The number of additional cases can
2537 /// be specified here to make memory allocation more efficient. This
2538 /// constructor also autoinserts at the end of the specified BasicBlock.
2539 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2540 BasicBlock *InsertAtEnd);
2542 SwitchInst *clone_impl() const override;
2546 static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
2548 template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy>
2549 class CaseIteratorT {
2557 typedef CaseIteratorT<SwitchInstTy, ConstantIntTy, BasicBlockTy> Self;
2559 /// Initializes case iterator for given SwitchInst and for given
2561 CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
2566 /// Initializes case iterator for given SwitchInst and for given
2567 /// TerminatorInst's successor index.
2568 static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
2569 assert(SuccessorIndex < SI->getNumSuccessors() &&
2570 "Successor index # out of range!");
2571 return SuccessorIndex != 0 ?
2572 Self(SI, SuccessorIndex - 1) :
2573 Self(SI, DefaultPseudoIndex);
2576 /// Resolves case value for current case.
2577 ConstantIntTy *getCaseValue() {
2578 assert(Index < SI->getNumCases() && "Index out the number of cases.");
2579 return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2));
2582 /// Resolves successor for current case.
2583 BasicBlockTy *getCaseSuccessor() {
2584 assert((Index < SI->getNumCases() ||
2585 Index == DefaultPseudoIndex) &&
2586 "Index out the number of cases.");
2587 return SI->getSuccessor(getSuccessorIndex());
2590 /// Returns number of current case.
2591 unsigned getCaseIndex() const { return Index; }
2593 /// Returns TerminatorInst's successor index for current case successor.
2594 unsigned getSuccessorIndex() const {
2595 assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
2596 "Index out the number of cases.");
2597 return Index != DefaultPseudoIndex ? Index + 1 : 0;
2601 // Check index correctness after increment.
2602 // Note: Index == getNumCases() means end().
2603 assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
2607 Self operator++(int) {
2613 // Check index correctness after decrement.
2614 // Note: Index == getNumCases() means end().
2615 // Also allow "-1" iterator here. That will became valid after ++.
2616 assert((Index == 0 || Index-1 <= SI->getNumCases()) &&
2617 "Index out the number of cases.");
2621 Self operator--(int) {
2626 bool operator==(const Self& RHS) const {
2627 assert(RHS.SI == SI && "Incompatible operators.");
2628 return RHS.Index == Index;
2630 bool operator!=(const Self& RHS) const {
2631 assert(RHS.SI == SI && "Incompatible operators.");
2632 return RHS.Index != Index;
2636 typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock>
2639 class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> {
2641 typedef CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> ParentTy;
2645 CaseIt(const ParentTy& Src) : ParentTy(Src) {}
2646 CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
2648 /// Sets the new value for current case.
2649 void setValue(ConstantInt *V) {
2650 assert(Index < SI->getNumCases() && "Index out the number of cases.");
2651 SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V));
2654 /// Sets the new successor for current case.
2655 void setSuccessor(BasicBlock *S) {
2656 SI->setSuccessor(getSuccessorIndex(), S);
2660 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2661 unsigned NumCases, Instruction *InsertBefore = 0) {
2662 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2664 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2665 unsigned NumCases, BasicBlock *InsertAtEnd) {
2666 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2671 /// Provide fast operand accessors
2672 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2674 // Accessor Methods for Switch stmt
2675 Value *getCondition() const { return getOperand(0); }
2676 void setCondition(Value *V) { setOperand(0, V); }
2678 BasicBlock *getDefaultDest() const {
2679 return cast<BasicBlock>(getOperand(1));
2682 void setDefaultDest(BasicBlock *DefaultCase) {
2683 setOperand(1, reinterpret_cast<Value*>(DefaultCase));
2686 /// getNumCases - return the number of 'cases' in this switch instruction,
2687 /// except the default case
2688 unsigned getNumCases() const {
2689 return getNumOperands()/2 - 1;
2692 /// Returns a read/write iterator that points to the first
2693 /// case in SwitchInst.
2694 CaseIt case_begin() {
2695 return CaseIt(this, 0);
2697 /// Returns a read-only iterator that points to the first
2698 /// case in the SwitchInst.
2699 ConstCaseIt case_begin() const {
2700 return ConstCaseIt(this, 0);
2703 /// Returns a read/write iterator that points one past the last
2704 /// in the SwitchInst.
2706 return CaseIt(this, getNumCases());
2708 /// Returns a read-only iterator that points one past the last
2709 /// in the SwitchInst.
2710 ConstCaseIt case_end() const {
2711 return ConstCaseIt(this, getNumCases());
2713 /// Returns an iterator that points to the default case.
2714 /// Note: this iterator allows to resolve successor only. Attempt
2715 /// to resolve case value causes an assertion.
2716 /// Also note, that increment and decrement also causes an assertion and
2717 /// makes iterator invalid.
2718 CaseIt case_default() {
2719 return CaseIt(this, DefaultPseudoIndex);
2721 ConstCaseIt case_default() const {
2722 return ConstCaseIt(this, DefaultPseudoIndex);
2725 /// findCaseValue - Search all of the case values for the specified constant.
2726 /// If it is explicitly handled, return the case iterator of it, otherwise
2727 /// return default case iterator to indicate
2728 /// that it is handled by the default handler.
2729 CaseIt findCaseValue(const ConstantInt *C) {
2730 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
2731 if (i.getCaseValue() == C)
2733 return case_default();
2735 ConstCaseIt findCaseValue(const ConstantInt *C) const {
2736 for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
2737 if (i.getCaseValue() == C)
2739 return case_default();
2742 /// findCaseDest - Finds the unique case value for a given successor. Returns
2743 /// null if the successor is not found, not unique, or is the default case.
2744 ConstantInt *findCaseDest(BasicBlock *BB) {
2745 if (BB == getDefaultDest()) return NULL;
2747 ConstantInt *CI = NULL;
2748 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
2749 if (i.getCaseSuccessor() == BB) {
2750 if (CI) return NULL; // Multiple cases lead to BB.
2751 else CI = i.getCaseValue();
2757 /// addCase - Add an entry to the switch instruction...
2759 /// This action invalidates case_end(). Old case_end() iterator will
2760 /// point to the added case.
2761 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2763 /// removeCase - This method removes the specified case and its successor
2764 /// from the switch instruction. Note that this operation may reorder the
2765 /// remaining cases at index idx and above.
2767 /// This action invalidates iterators for all cases following the one removed,
2768 /// including the case_end() iterator.
2769 void removeCase(CaseIt i);
2771 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2772 BasicBlock *getSuccessor(unsigned idx) const {
2773 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2774 return cast<BasicBlock>(getOperand(idx*2+1));
2776 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2777 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2778 setOperand(idx*2+1, (Value*)NewSucc);
2781 // Methods for support type inquiry through isa, cast, and dyn_cast:
2782 static inline bool classof(const Instruction *I) {
2783 return I->getOpcode() == Instruction::Switch;
2785 static inline bool classof(const Value *V) {
2786 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2789 BasicBlock *getSuccessorV(unsigned idx) const override;
2790 unsigned getNumSuccessorsV() const override;
2791 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2795 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2798 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2801 //===----------------------------------------------------------------------===//
2802 // IndirectBrInst Class
2803 //===----------------------------------------------------------------------===//
2805 //===---------------------------------------------------------------------------
2806 /// IndirectBrInst - Indirect Branch Instruction.
2808 class IndirectBrInst : public TerminatorInst {
2809 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2810 unsigned ReservedSpace;
2811 // Operand[0] = Value to switch on
2812 // Operand[1] = Default basic block destination
2813 // Operand[2n ] = Value to match
2814 // Operand[2n+1] = BasicBlock to go to on match
2815 IndirectBrInst(const IndirectBrInst &IBI);
2816 void init(Value *Address, unsigned NumDests);
2817 void growOperands();
2818 // allocate space for exactly zero operands
2819 void *operator new(size_t s) {
2820 return User::operator new(s, 0);
2822 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2823 /// Address to jump to. The number of expected destinations can be specified
2824 /// here to make memory allocation more efficient. This constructor can also
2825 /// autoinsert before another instruction.
2826 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2828 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2829 /// Address to jump to. The number of expected destinations can be specified
2830 /// here to make memory allocation more efficient. This constructor also
2831 /// autoinserts at the end of the specified BasicBlock.
2832 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2834 IndirectBrInst *clone_impl() const override;
2836 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2837 Instruction *InsertBefore = 0) {
2838 return new IndirectBrInst(Address, NumDests, InsertBefore);
2840 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2841 BasicBlock *InsertAtEnd) {
2842 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2846 /// Provide fast operand accessors.
2847 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2849 // Accessor Methods for IndirectBrInst instruction.
2850 Value *getAddress() { return getOperand(0); }
2851 const Value *getAddress() const { return getOperand(0); }
2852 void setAddress(Value *V) { setOperand(0, V); }
2855 /// getNumDestinations - return the number of possible destinations in this
2856 /// indirectbr instruction.
2857 unsigned getNumDestinations() const { return getNumOperands()-1; }
2859 /// getDestination - Return the specified destination.
2860 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2861 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2863 /// addDestination - Add a destination.
2865 void addDestination(BasicBlock *Dest);
2867 /// removeDestination - This method removes the specified successor from the
2868 /// indirectbr instruction.
2869 void removeDestination(unsigned i);
2871 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2872 BasicBlock *getSuccessor(unsigned i) const {
2873 return cast<BasicBlock>(getOperand(i+1));
2875 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2876 setOperand(i+1, (Value*)NewSucc);
2879 // Methods for support type inquiry through isa, cast, and dyn_cast:
2880 static inline bool classof(const Instruction *I) {
2881 return I->getOpcode() == Instruction::IndirectBr;
2883 static inline bool classof(const Value *V) {
2884 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2887 BasicBlock *getSuccessorV(unsigned idx) const override;
2888 unsigned getNumSuccessorsV() const override;
2889 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2893 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2896 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2899 //===----------------------------------------------------------------------===//
2901 //===----------------------------------------------------------------------===//
2903 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2904 /// calling convention of the call.
2906 class InvokeInst : public TerminatorInst {
2907 AttributeSet AttributeList;
2908 InvokeInst(const InvokeInst &BI);
2909 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2910 ArrayRef<Value *> Args, const Twine &NameStr);
2912 /// Construct an InvokeInst given a range of arguments.
2914 /// \brief Construct an InvokeInst from a range of arguments
2915 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2916 ArrayRef<Value *> Args, unsigned Values,
2917 const Twine &NameStr, Instruction *InsertBefore);
2919 /// Construct an InvokeInst given a range of arguments.
2921 /// \brief Construct an InvokeInst from a range of arguments
2922 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2923 ArrayRef<Value *> Args, unsigned Values,
2924 const Twine &NameStr, BasicBlock *InsertAtEnd);
2926 InvokeInst *clone_impl() const override;
2928 static InvokeInst *Create(Value *Func,
2929 BasicBlock *IfNormal, BasicBlock *IfException,
2930 ArrayRef<Value *> Args, const Twine &NameStr = "",
2931 Instruction *InsertBefore = 0) {
2932 unsigned Values = unsigned(Args.size()) + 3;
2933 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2934 Values, NameStr, InsertBefore);
2936 static InvokeInst *Create(Value *Func,
2937 BasicBlock *IfNormal, BasicBlock *IfException,
2938 ArrayRef<Value *> Args, const Twine &NameStr,
2939 BasicBlock *InsertAtEnd) {
2940 unsigned Values = unsigned(Args.size()) + 3;
2941 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2942 Values, NameStr, InsertAtEnd);
2945 /// Provide fast operand accessors
2946 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2948 /// getNumArgOperands - Return the number of invoke arguments.
2950 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2952 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2954 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2955 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2957 /// arg_operands - iteration adapter for range-for loops.
2958 iterator_range<op_iterator> arg_operands() {
2959 return iterator_range<op_iterator>(op_begin(), op_end() - 3);
2962 /// arg_operands - iteration adapter for range-for loops.
2963 iterator_range<const_op_iterator> arg_operands() const {
2964 return iterator_range<const_op_iterator>(op_begin(), op_end() - 3);
2967 /// \brief Wrappers for getting the \c Use of a invoke argument.
2968 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
2969 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
2971 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2973 CallingConv::ID getCallingConv() const {
2974 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2976 void setCallingConv(CallingConv::ID CC) {
2977 setInstructionSubclassData(static_cast<unsigned>(CC));
2980 /// getAttributes - Return the parameter attributes for this invoke.
2982 const AttributeSet &getAttributes() const { return AttributeList; }
2984 /// setAttributes - Set the parameter attributes for this invoke.
2986 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
2988 /// addAttribute - adds the attribute to the list of attributes.
2989 void addAttribute(unsigned i, Attribute::AttrKind attr);
2991 /// removeAttribute - removes the attribute from the list of attributes.
2992 void removeAttribute(unsigned i, Attribute attr);
2994 /// \brief Determine whether this call has the given attribute.
2995 bool hasFnAttr(Attribute::AttrKind A) const {
2996 assert(A != Attribute::NoBuiltin &&
2997 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
2998 return hasFnAttrImpl(A);
3001 /// \brief Determine whether the call or the callee has the given attributes.
3002 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
3004 /// \brief Extract the alignment for a call or parameter (0=unknown).
3005 unsigned getParamAlignment(unsigned i) const {
3006 return AttributeList.getParamAlignment(i);
3009 /// \brief Return true if the call should not be treated as a call to a
3011 bool isNoBuiltin() const {
3012 // We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have
3013 // to check it by hand.
3014 return hasFnAttrImpl(Attribute::NoBuiltin) &&
3015 !hasFnAttrImpl(Attribute::Builtin);
3018 /// \brief Return true if the call should not be inlined.
3019 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
3020 void setIsNoInline() {
3021 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
3024 /// \brief Determine if the call does not access memory.
3025 bool doesNotAccessMemory() const {
3026 return hasFnAttr(Attribute::ReadNone);
3028 void setDoesNotAccessMemory() {
3029 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
3032 /// \brief Determine if the call does not access or only reads memory.
3033 bool onlyReadsMemory() const {
3034 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
3036 void setOnlyReadsMemory() {
3037 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
3040 /// \brief Determine if the call cannot return.
3041 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
3042 void setDoesNotReturn() {
3043 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
3046 /// \brief Determine if the call cannot unwind.
3047 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
3048 void setDoesNotThrow() {
3049 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
3052 /// \brief Determine if the invoke cannot be duplicated.
3053 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
3054 void setCannotDuplicate() {
3055 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
3058 /// \brief Determine if the call returns a structure through first
3059 /// pointer argument.
3060 bool hasStructRetAttr() const {
3061 // Be friendly and also check the callee.
3062 return paramHasAttr(1, Attribute::StructRet);
3065 /// \brief Determine if any call argument is an aggregate passed by value.
3066 bool hasByValArgument() const {
3067 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
3070 /// getCalledFunction - Return the function called, or null if this is an
3071 /// indirect function invocation.
3073 Function *getCalledFunction() const {
3074 return dyn_cast<Function>(Op<-3>());
3077 /// getCalledValue - Get a pointer to the function that is invoked by this
3079 const Value *getCalledValue() const { return Op<-3>(); }
3080 Value *getCalledValue() { return Op<-3>(); }
3082 /// setCalledFunction - Set the function called.
3083 void setCalledFunction(Value* Fn) {
3087 // get*Dest - Return the destination basic blocks...
3088 BasicBlock *getNormalDest() const {
3089 return cast<BasicBlock>(Op<-2>());
3091 BasicBlock *getUnwindDest() const {
3092 return cast<BasicBlock>(Op<-1>());
3094 void setNormalDest(BasicBlock *B) {
3095 Op<-2>() = reinterpret_cast<Value*>(B);
3097 void setUnwindDest(BasicBlock *B) {
3098 Op<-1>() = reinterpret_cast<Value*>(B);
3101 /// getLandingPadInst - Get the landingpad instruction from the landing pad
3102 /// block (the unwind destination).
3103 LandingPadInst *getLandingPadInst() const;
3105 BasicBlock *getSuccessor(unsigned i) const {
3106 assert(i < 2 && "Successor # out of range for invoke!");
3107 return i == 0 ? getNormalDest() : getUnwindDest();
3110 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3111 assert(idx < 2 && "Successor # out of range for invoke!");
3112 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
3115 unsigned getNumSuccessors() const { return 2; }
3117 // Methods for support type inquiry through isa, cast, and dyn_cast:
3118 static inline bool classof(const Instruction *I) {
3119 return (I->getOpcode() == Instruction::Invoke);
3121 static inline bool classof(const Value *V) {
3122 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3126 BasicBlock *getSuccessorV(unsigned idx) const override;
3127 unsigned getNumSuccessorsV() const override;
3128 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3130 bool hasFnAttrImpl(Attribute::AttrKind A) const;
3132 // Shadow Instruction::setInstructionSubclassData with a private forwarding
3133 // method so that subclasses cannot accidentally use it.
3134 void setInstructionSubclassData(unsigned short D) {
3135 Instruction::setInstructionSubclassData(D);
3140 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
3143 InvokeInst::InvokeInst(Value *Func,
3144 BasicBlock *IfNormal, BasicBlock *IfException,
3145 ArrayRef<Value *> Args, unsigned Values,
3146 const Twine &NameStr, Instruction *InsertBefore)
3147 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3148 ->getElementType())->getReturnType(),
3149 Instruction::Invoke,
3150 OperandTraits<InvokeInst>::op_end(this) - Values,
3151 Values, InsertBefore) {
3152 init(Func, IfNormal, IfException, Args, NameStr);
3154 InvokeInst::InvokeInst(Value *Func,
3155 BasicBlock *IfNormal, BasicBlock *IfException,
3156 ArrayRef<Value *> Args, unsigned Values,
3157 const Twine &NameStr, BasicBlock *InsertAtEnd)
3158 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3159 ->getElementType())->getReturnType(),
3160 Instruction::Invoke,
3161 OperandTraits<InvokeInst>::op_end(this) - Values,
3162 Values, InsertAtEnd) {
3163 init(Func, IfNormal, IfException, Args, NameStr);
3166 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
3168 //===----------------------------------------------------------------------===//
3170 //===----------------------------------------------------------------------===//
3172 //===---------------------------------------------------------------------------
3173 /// ResumeInst - Resume the propagation of an exception.
3175 class ResumeInst : public TerminatorInst {
3176 ResumeInst(const ResumeInst &RI);
3178 explicit ResumeInst(Value *Exn, Instruction *InsertBefore=0);
3179 ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
3181 ResumeInst *clone_impl() const override;
3183 static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = 0) {
3184 return new(1) ResumeInst(Exn, InsertBefore);
3186 static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
3187 return new(1) ResumeInst(Exn, InsertAtEnd);
3190 /// Provide fast operand accessors
3191 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3193 /// Convenience accessor.
3194 Value *getValue() const { return Op<0>(); }
3196 unsigned getNumSuccessors() const { return 0; }
3198 // Methods for support type inquiry through isa, cast, and dyn_cast:
3199 static inline bool classof(const Instruction *I) {
3200 return I->getOpcode() == Instruction::Resume;
3202 static inline bool classof(const Value *V) {
3203 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3206 BasicBlock *getSuccessorV(unsigned idx) const override;
3207 unsigned getNumSuccessorsV() const override;
3208 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3212 struct OperandTraits<ResumeInst> :
3213 public FixedNumOperandTraits<ResumeInst, 1> {
3216 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
3218 //===----------------------------------------------------------------------===//
3219 // UnreachableInst Class
3220 //===----------------------------------------------------------------------===//
3222 //===---------------------------------------------------------------------------
3223 /// UnreachableInst - This function has undefined behavior. In particular, the
3224 /// presence of this instruction indicates some higher level knowledge that the
3225 /// end of the block cannot be reached.
3227 class UnreachableInst : public TerminatorInst {
3228 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
3230 UnreachableInst *clone_impl() const override;
3233 // allocate space for exactly zero operands
3234 void *operator new(size_t s) {
3235 return User::operator new(s, 0);
3237 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
3238 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
3240 unsigned getNumSuccessors() const { return 0; }
3242 // Methods for support type inquiry through isa, cast, and dyn_cast:
3243 static inline bool classof(const Instruction *I) {
3244 return I->getOpcode() == Instruction::Unreachable;
3246 static inline bool classof(const Value *V) {
3247 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3250 BasicBlock *getSuccessorV(unsigned idx) const override;
3251 unsigned getNumSuccessorsV() const override;
3252 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3255 //===----------------------------------------------------------------------===//
3257 //===----------------------------------------------------------------------===//
3259 /// \brief This class represents a truncation of integer types.
3260 class TruncInst : public CastInst {
3262 /// \brief Clone an identical TruncInst
3263 TruncInst *clone_impl() const override;
3266 /// \brief Constructor with insert-before-instruction semantics
3268 Value *S, ///< The value to be truncated
3269 Type *Ty, ///< The (smaller) type to truncate to
3270 const Twine &NameStr = "", ///< A name for the new instruction
3271 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3274 /// \brief Constructor with insert-at-end-of-block semantics
3276 Value *S, ///< The value to be truncated
3277 Type *Ty, ///< The (smaller) type to truncate to
3278 const Twine &NameStr, ///< A name for the new instruction
3279 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3282 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3283 static inline bool classof(const Instruction *I) {
3284 return I->getOpcode() == Trunc;
3286 static inline bool classof(const Value *V) {
3287 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3291 //===----------------------------------------------------------------------===//
3293 //===----------------------------------------------------------------------===//
3295 /// \brief This class represents zero extension of integer types.
3296 class ZExtInst : public CastInst {
3298 /// \brief Clone an identical ZExtInst
3299 ZExtInst *clone_impl() const override;
3302 /// \brief Constructor with insert-before-instruction semantics
3304 Value *S, ///< The value to be zero extended
3305 Type *Ty, ///< The type to zero extend to
3306 const Twine &NameStr = "", ///< A name for the new instruction
3307 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3310 /// \brief Constructor with insert-at-end semantics.
3312 Value *S, ///< The value to be zero extended
3313 Type *Ty, ///< The type to zero extend to
3314 const Twine &NameStr, ///< A name for the new instruction
3315 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3318 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3319 static inline bool classof(const Instruction *I) {
3320 return I->getOpcode() == ZExt;
3322 static inline bool classof(const Value *V) {
3323 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3327 //===----------------------------------------------------------------------===//
3329 //===----------------------------------------------------------------------===//
3331 /// \brief This class represents a sign extension of integer types.
3332 class SExtInst : public CastInst {
3334 /// \brief Clone an identical SExtInst
3335 SExtInst *clone_impl() const override;
3338 /// \brief Constructor with insert-before-instruction semantics
3340 Value *S, ///< The value to be sign extended
3341 Type *Ty, ///< The type to sign extend to
3342 const Twine &NameStr = "", ///< A name for the new instruction
3343 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3346 /// \brief Constructor with insert-at-end-of-block semantics
3348 Value *S, ///< The value to be sign extended
3349 Type *Ty, ///< The type to sign extend to
3350 const Twine &NameStr, ///< A name for the new instruction
3351 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3354 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3355 static inline bool classof(const Instruction *I) {
3356 return I->getOpcode() == SExt;
3358 static inline bool classof(const Value *V) {
3359 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3363 //===----------------------------------------------------------------------===//
3364 // FPTruncInst Class
3365 //===----------------------------------------------------------------------===//
3367 /// \brief This class represents a truncation of floating point types.
3368 class FPTruncInst : public CastInst {
3370 /// \brief Clone an identical FPTruncInst
3371 FPTruncInst *clone_impl() const override;
3374 /// \brief Constructor with insert-before-instruction semantics
3376 Value *S, ///< The value to be truncated
3377 Type *Ty, ///< The type to truncate to
3378 const Twine &NameStr = "", ///< A name for the new instruction
3379 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3382 /// \brief Constructor with insert-before-instruction semantics
3384 Value *S, ///< The value to be truncated
3385 Type *Ty, ///< The type to truncate to
3386 const Twine &NameStr, ///< A name for the new instruction
3387 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3390 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3391 static inline bool classof(const Instruction *I) {
3392 return I->getOpcode() == FPTrunc;
3394 static inline bool classof(const Value *V) {
3395 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3399 //===----------------------------------------------------------------------===//
3401 //===----------------------------------------------------------------------===//
3403 /// \brief This class represents an extension of floating point types.
3404 class FPExtInst : public CastInst {
3406 /// \brief Clone an identical FPExtInst
3407 FPExtInst *clone_impl() const override;
3410 /// \brief Constructor with insert-before-instruction semantics
3412 Value *S, ///< The value to be extended
3413 Type *Ty, ///< The type to extend to
3414 const Twine &NameStr = "", ///< A name for the new instruction
3415 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3418 /// \brief Constructor with insert-at-end-of-block semantics
3420 Value *S, ///< The value to be extended
3421 Type *Ty, ///< The type to extend to
3422 const Twine &NameStr, ///< A name for the new instruction
3423 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3426 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3427 static inline bool classof(const Instruction *I) {
3428 return I->getOpcode() == FPExt;
3430 static inline bool classof(const Value *V) {
3431 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3435 //===----------------------------------------------------------------------===//
3437 //===----------------------------------------------------------------------===//
3439 /// \brief This class represents a cast unsigned integer to floating point.
3440 class UIToFPInst : public CastInst {
3442 /// \brief Clone an identical UIToFPInst
3443 UIToFPInst *clone_impl() const override;
3446 /// \brief Constructor with insert-before-instruction semantics
3448 Value *S, ///< The value to be converted
3449 Type *Ty, ///< The type to convert to
3450 const Twine &NameStr = "", ///< A name for the new instruction
3451 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3454 /// \brief Constructor with insert-at-end-of-block semantics
3456 Value *S, ///< The value to be converted
3457 Type *Ty, ///< The type to convert to
3458 const Twine &NameStr, ///< A name for the new instruction
3459 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3462 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3463 static inline bool classof(const Instruction *I) {
3464 return I->getOpcode() == UIToFP;
3466 static inline bool classof(const Value *V) {
3467 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3471 //===----------------------------------------------------------------------===//
3473 //===----------------------------------------------------------------------===//
3475 /// \brief This class represents a cast from signed integer to floating point.
3476 class SIToFPInst : public CastInst {
3478 /// \brief Clone an identical SIToFPInst
3479 SIToFPInst *clone_impl() const override;
3482 /// \brief Constructor with insert-before-instruction semantics
3484 Value *S, ///< The value to be converted
3485 Type *Ty, ///< The type to convert to
3486 const Twine &NameStr = "", ///< A name for the new instruction
3487 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3490 /// \brief Constructor with insert-at-end-of-block semantics
3492 Value *S, ///< The value to be converted
3493 Type *Ty, ///< The type to convert to
3494 const Twine &NameStr, ///< A name for the new instruction
3495 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3498 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3499 static inline bool classof(const Instruction *I) {
3500 return I->getOpcode() == SIToFP;
3502 static inline bool classof(const Value *V) {
3503 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3507 //===----------------------------------------------------------------------===//
3509 //===----------------------------------------------------------------------===//
3511 /// \brief This class represents a cast from floating point to unsigned integer
3512 class FPToUIInst : public CastInst {
3514 /// \brief Clone an identical FPToUIInst
3515 FPToUIInst *clone_impl() const override;
3518 /// \brief Constructor with insert-before-instruction semantics
3520 Value *S, ///< The value to be converted
3521 Type *Ty, ///< The type to convert to
3522 const Twine &NameStr = "", ///< A name for the new instruction
3523 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3526 /// \brief Constructor with insert-at-end-of-block semantics
3528 Value *S, ///< The value to be converted
3529 Type *Ty, ///< The type to convert to
3530 const Twine &NameStr, ///< A name for the new instruction
3531 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3534 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3535 static inline bool classof(const Instruction *I) {
3536 return I->getOpcode() == FPToUI;
3538 static inline bool classof(const Value *V) {
3539 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3543 //===----------------------------------------------------------------------===//
3545 //===----------------------------------------------------------------------===//
3547 /// \brief This class represents a cast from floating point to signed integer.
3548 class FPToSIInst : public CastInst {
3550 /// \brief Clone an identical FPToSIInst
3551 FPToSIInst *clone_impl() const override;
3554 /// \brief Constructor with insert-before-instruction semantics
3556 Value *S, ///< The value to be converted
3557 Type *Ty, ///< The type to convert to
3558 const Twine &NameStr = "", ///< A name for the new instruction
3559 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3562 /// \brief Constructor with insert-at-end-of-block semantics
3564 Value *S, ///< The value to be converted
3565 Type *Ty, ///< The type to convert to
3566 const Twine &NameStr, ///< A name for the new instruction
3567 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3570 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3571 static inline bool classof(const Instruction *I) {
3572 return I->getOpcode() == FPToSI;
3574 static inline bool classof(const Value *V) {
3575 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3579 //===----------------------------------------------------------------------===//
3580 // IntToPtrInst Class
3581 //===----------------------------------------------------------------------===//
3583 /// \brief This class represents a cast from an integer to a pointer.
3584 class IntToPtrInst : public CastInst {
3586 /// \brief Constructor with insert-before-instruction semantics
3588 Value *S, ///< The value to be converted
3589 Type *Ty, ///< The type to convert to
3590 const Twine &NameStr = "", ///< A name for the new instruction
3591 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3594 /// \brief Constructor with insert-at-end-of-block semantics
3596 Value *S, ///< The value to be converted
3597 Type *Ty, ///< The type to convert to
3598 const Twine &NameStr, ///< A name for the new instruction
3599 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3602 /// \brief Clone an identical IntToPtrInst
3603 IntToPtrInst *clone_impl() const override;
3605 /// \brief Returns the address space of this instruction's pointer type.
3606 unsigned getAddressSpace() const {
3607 return getType()->getPointerAddressSpace();
3610 // Methods for support type inquiry through isa, cast, and dyn_cast:
3611 static inline bool classof(const Instruction *I) {
3612 return I->getOpcode() == IntToPtr;
3614 static inline bool classof(const Value *V) {
3615 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3619 //===----------------------------------------------------------------------===//
3620 // PtrToIntInst Class
3621 //===----------------------------------------------------------------------===//
3623 /// \brief This class represents a cast from a pointer to an integer
3624 class PtrToIntInst : public CastInst {
3626 /// \brief Clone an identical PtrToIntInst
3627 PtrToIntInst *clone_impl() const override;
3630 /// \brief Constructor with insert-before-instruction semantics
3632 Value *S, ///< The value to be converted
3633 Type *Ty, ///< The type to convert to
3634 const Twine &NameStr = "", ///< A name for the new instruction
3635 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3638 /// \brief Constructor with insert-at-end-of-block semantics
3640 Value *S, ///< The value to be converted
3641 Type *Ty, ///< The type to convert to
3642 const Twine &NameStr, ///< A name for the new instruction
3643 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3646 /// \brief Gets the pointer operand.
3647 Value *getPointerOperand() { return getOperand(0); }
3648 /// \brief Gets the pointer operand.
3649 const Value *getPointerOperand() const { return getOperand(0); }
3650 /// \brief Gets the operand index of the pointer operand.
3651 static unsigned getPointerOperandIndex() { return 0U; }
3653 /// \brief Returns the address space of the pointer operand.
3654 unsigned getPointerAddressSpace() const {
3655 return getPointerOperand()->getType()->getPointerAddressSpace();
3658 // Methods for support type inquiry through isa, cast, and dyn_cast:
3659 static inline bool classof(const Instruction *I) {
3660 return I->getOpcode() == PtrToInt;
3662 static inline bool classof(const Value *V) {
3663 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3667 //===----------------------------------------------------------------------===//
3668 // BitCastInst Class
3669 //===----------------------------------------------------------------------===//
3671 /// \brief This class represents a no-op cast from one type to another.
3672 class BitCastInst : public CastInst {
3674 /// \brief Clone an identical BitCastInst
3675 BitCastInst *clone_impl() const override;
3678 /// \brief Constructor with insert-before-instruction semantics
3680 Value *S, ///< The value to be casted
3681 Type *Ty, ///< The type to casted to
3682 const Twine &NameStr = "", ///< A name for the new instruction
3683 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3686 /// \brief Constructor with insert-at-end-of-block semantics
3688 Value *S, ///< The value to be casted
3689 Type *Ty, ///< The type to casted to
3690 const Twine &NameStr, ///< A name for the new instruction
3691 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3694 // Methods for support type inquiry through isa, cast, and dyn_cast:
3695 static inline bool classof(const Instruction *I) {
3696 return I->getOpcode() == BitCast;
3698 static inline bool classof(const Value *V) {
3699 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3703 //===----------------------------------------------------------------------===//
3704 // AddrSpaceCastInst Class
3705 //===----------------------------------------------------------------------===//
3707 /// \brief This class represents a conversion between pointers from
3708 /// one address space to another.
3709 class AddrSpaceCastInst : public CastInst {
3711 /// \brief Clone an identical AddrSpaceCastInst
3712 AddrSpaceCastInst *clone_impl() const override;
3715 /// \brief Constructor with insert-before-instruction semantics
3717 Value *S, ///< The value to be casted
3718 Type *Ty, ///< The type to casted to
3719 const Twine &NameStr = "", ///< A name for the new instruction
3720 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3723 /// \brief Constructor with insert-at-end-of-block semantics
3725 Value *S, ///< The value to be casted
3726 Type *Ty, ///< The type to casted to
3727 const Twine &NameStr, ///< A name for the new instruction
3728 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3731 // Methods for support type inquiry through isa, cast, and dyn_cast:
3732 static inline bool classof(const Instruction *I) {
3733 return I->getOpcode() == AddrSpaceCast;
3735 static inline bool classof(const Value *V) {
3736 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3740 } // End llvm namespace