1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the class definitions of all of the subclasses of the
11 // Instruction class. This is meant to be an easy way to get access to all
12 // instruction subclasses.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_IR_INSTRUCTIONS_H
17 #define LLVM_IR_INSTRUCTIONS_H
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/iterator_range.h"
22 #include "llvm/IR/Attributes.h"
23 #include "llvm/IR/CallingConv.h"
24 #include "llvm/IR/DerivedTypes.h"
25 #include "llvm/IR/Function.h"
26 #include "llvm/IR/InstrTypes.h"
27 #include "llvm/Support/ErrorHandling.h"
42 // Consume = 3, // Not specified yet.
46 SequentiallyConsistent = 7
49 enum SynchronizationScope {
54 /// Returns true if the ordering is at least as strong as acquire
55 /// (i.e. acquire, acq_rel or seq_cst)
56 inline bool isAtLeastAcquire(AtomicOrdering Ord) {
57 return (Ord == Acquire ||
58 Ord == AcquireRelease ||
59 Ord == SequentiallyConsistent);
62 /// Returns true if the ordering is at least as strong as release
63 /// (i.e. release, acq_rel or seq_cst)
64 inline bool isAtLeastRelease(AtomicOrdering Ord) {
65 return (Ord == Release ||
66 Ord == AcquireRelease ||
67 Ord == SequentiallyConsistent);
70 //===----------------------------------------------------------------------===//
72 //===----------------------------------------------------------------------===//
74 /// AllocaInst - an instruction to allocate memory on the stack
76 class AllocaInst : public UnaryInstruction {
80 // Note: Instruction needs to be a friend here to call cloneImpl.
81 friend class Instruction;
82 AllocaInst *cloneImpl() const;
85 explicit AllocaInst(Type *Ty, Value *ArraySize = nullptr,
86 const Twine &Name = "",
87 Instruction *InsertBefore = nullptr);
88 AllocaInst(Type *Ty, Value *ArraySize,
89 const Twine &Name, BasicBlock *InsertAtEnd);
91 AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = nullptr);
92 AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
94 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
95 const Twine &Name = "", Instruction *InsertBefore = nullptr);
96 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
97 const Twine &Name, BasicBlock *InsertAtEnd);
99 // Out of line virtual method, so the vtable, etc. has a home.
100 ~AllocaInst() override;
102 /// isArrayAllocation - Return true if there is an allocation size parameter
103 /// to the allocation instruction that is not 1.
105 bool isArrayAllocation() const;
107 /// getArraySize - Get the number of elements allocated. For a simple
108 /// allocation of a single element, this will return a constant 1 value.
110 const Value *getArraySize() const { return getOperand(0); }
111 Value *getArraySize() { return getOperand(0); }
113 /// getType - Overload to return most specific pointer type
115 PointerType *getType() const {
116 return cast<PointerType>(Instruction::getType());
119 /// getAllocatedType - Return the type that is being allocated by the
122 Type *getAllocatedType() const { return AllocatedType; }
123 /// \brief for use only in special circumstances that need to generically
124 /// transform a whole instruction (eg: IR linking and vectorization).
125 void setAllocatedType(Type *Ty) { AllocatedType = Ty; }
127 /// getAlignment - Return the alignment of the memory that is being allocated
128 /// by the instruction.
130 unsigned getAlignment() const {
131 return (1u << (getSubclassDataFromInstruction() & 31)) >> 1;
133 void setAlignment(unsigned Align);
135 /// isStaticAlloca - Return true if this alloca is in the entry block of the
136 /// function and is a constant size. If so, the code generator will fold it
137 /// into the prolog/epilog code, so it is basically free.
138 bool isStaticAlloca() const;
140 /// \brief Return true if this alloca is used as an inalloca argument to a
141 /// call. Such allocas are never considered static even if they are in the
143 bool isUsedWithInAlloca() const {
144 return getSubclassDataFromInstruction() & 32;
147 /// \brief Specify whether this alloca is used to represent the arguments to
149 void setUsedWithInAlloca(bool V) {
150 setInstructionSubclassData((getSubclassDataFromInstruction() & ~32) |
154 // Methods for support type inquiry through isa, cast, and dyn_cast:
155 static inline bool classof(const Instruction *I) {
156 return (I->getOpcode() == Instruction::Alloca);
158 static inline bool classof(const Value *V) {
159 return isa<Instruction>(V) && classof(cast<Instruction>(V));
163 // Shadow Instruction::setInstructionSubclassData with a private forwarding
164 // method so that subclasses cannot accidentally use it.
165 void setInstructionSubclassData(unsigned short D) {
166 Instruction::setInstructionSubclassData(D);
170 //===----------------------------------------------------------------------===//
172 //===----------------------------------------------------------------------===//
174 /// LoadInst - an instruction for reading from memory. This uses the
175 /// SubclassData field in Value to store whether or not the load is volatile.
177 class LoadInst : public UnaryInstruction {
181 // Note: Instruction needs to be a friend here to call cloneImpl.
182 friend class Instruction;
183 LoadInst *cloneImpl() const;
186 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
187 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
188 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile = false,
189 Instruction *InsertBefore = nullptr);
190 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
191 Instruction *InsertBefore = nullptr)
192 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
193 NameStr, isVolatile, InsertBefore) {}
194 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
195 BasicBlock *InsertAtEnd);
196 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
197 Instruction *InsertBefore = nullptr)
198 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
199 NameStr, isVolatile, Align, InsertBefore) {}
200 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
201 unsigned Align, Instruction *InsertBefore = nullptr);
202 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
203 unsigned Align, BasicBlock *InsertAtEnd);
204 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
205 AtomicOrdering Order, SynchronizationScope SynchScope = CrossThread,
206 Instruction *InsertBefore = nullptr)
207 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
208 NameStr, isVolatile, Align, Order, SynchScope, InsertBefore) {}
209 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
210 unsigned Align, AtomicOrdering Order,
211 SynchronizationScope SynchScope = CrossThread,
212 Instruction *InsertBefore = nullptr);
213 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
214 unsigned Align, AtomicOrdering Order,
215 SynchronizationScope SynchScope,
216 BasicBlock *InsertAtEnd);
218 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
219 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
220 LoadInst(Type *Ty, Value *Ptr, const char *NameStr = nullptr,
221 bool isVolatile = false, Instruction *InsertBefore = nullptr);
222 explicit LoadInst(Value *Ptr, const char *NameStr = nullptr,
223 bool isVolatile = false,
224 Instruction *InsertBefore = nullptr)
225 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
226 NameStr, isVolatile, InsertBefore) {}
227 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
228 BasicBlock *InsertAtEnd);
230 /// isVolatile - Return true if this is a load from a volatile memory
233 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
235 /// setVolatile - Specify whether this is a volatile load or not.
237 void setVolatile(bool V) {
238 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
242 /// getAlignment - Return the alignment of the access that is being performed
244 unsigned getAlignment() const {
245 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
248 void setAlignment(unsigned Align);
250 /// Returns the ordering effect of this fence.
251 AtomicOrdering getOrdering() const {
252 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
255 /// Set the ordering constraint on this load. May not be Release or
257 void setOrdering(AtomicOrdering Ordering) {
258 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
262 SynchronizationScope getSynchScope() const {
263 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
266 /// Specify whether this load is ordered with respect to all
267 /// concurrently executing threads, or only with respect to signal handlers
268 /// executing in the same thread.
269 void setSynchScope(SynchronizationScope xthread) {
270 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
274 void setAtomic(AtomicOrdering Ordering,
275 SynchronizationScope SynchScope = CrossThread) {
276 setOrdering(Ordering);
277 setSynchScope(SynchScope);
280 bool isSimple() const { return !isAtomic() && !isVolatile(); }
281 bool isUnordered() const {
282 return getOrdering() <= Unordered && !isVolatile();
285 Value *getPointerOperand() { return getOperand(0); }
286 const Value *getPointerOperand() const { return getOperand(0); }
287 static unsigned getPointerOperandIndex() { return 0U; }
289 /// \brief Returns the address space of the pointer operand.
290 unsigned getPointerAddressSpace() const {
291 return getPointerOperand()->getType()->getPointerAddressSpace();
294 // Methods for support type inquiry through isa, cast, and dyn_cast:
295 static inline bool classof(const Instruction *I) {
296 return I->getOpcode() == Instruction::Load;
298 static inline bool classof(const Value *V) {
299 return isa<Instruction>(V) && classof(cast<Instruction>(V));
303 // Shadow Instruction::setInstructionSubclassData with a private forwarding
304 // method so that subclasses cannot accidentally use it.
305 void setInstructionSubclassData(unsigned short D) {
306 Instruction::setInstructionSubclassData(D);
310 //===----------------------------------------------------------------------===//
312 //===----------------------------------------------------------------------===//
314 /// StoreInst - an instruction for storing to memory
316 class StoreInst : public Instruction {
317 void *operator new(size_t, unsigned) = delete;
321 // Note: Instruction needs to be a friend here to call cloneImpl.
322 friend class Instruction;
323 StoreInst *cloneImpl() const;
326 // allocate space for exactly two operands
327 void *operator new(size_t s) {
328 return User::operator new(s, 2);
330 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
331 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
332 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
333 Instruction *InsertBefore = nullptr);
334 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
335 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
336 unsigned Align, Instruction *InsertBefore = nullptr);
337 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
338 unsigned Align, BasicBlock *InsertAtEnd);
339 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
340 unsigned Align, AtomicOrdering Order,
341 SynchronizationScope SynchScope = CrossThread,
342 Instruction *InsertBefore = nullptr);
343 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
344 unsigned Align, AtomicOrdering Order,
345 SynchronizationScope SynchScope,
346 BasicBlock *InsertAtEnd);
348 /// isVolatile - Return true if this is a store to a volatile memory
351 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
353 /// setVolatile - Specify whether this is a volatile store or not.
355 void setVolatile(bool V) {
356 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
360 /// Transparently provide more efficient getOperand methods.
361 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
363 /// getAlignment - Return the alignment of the access that is being performed
365 unsigned getAlignment() const {
366 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
369 void setAlignment(unsigned Align);
371 /// Returns the ordering effect of this store.
372 AtomicOrdering getOrdering() const {
373 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
376 /// Set the ordering constraint on this store. May not be Acquire or
378 void setOrdering(AtomicOrdering Ordering) {
379 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
383 SynchronizationScope getSynchScope() const {
384 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
387 /// Specify whether this store instruction is ordered with respect to all
388 /// concurrently executing threads, or only with respect to signal handlers
389 /// executing in the same thread.
390 void setSynchScope(SynchronizationScope xthread) {
391 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
395 void setAtomic(AtomicOrdering Ordering,
396 SynchronizationScope SynchScope = CrossThread) {
397 setOrdering(Ordering);
398 setSynchScope(SynchScope);
401 bool isSimple() const { return !isAtomic() && !isVolatile(); }
402 bool isUnordered() const {
403 return getOrdering() <= Unordered && !isVolatile();
406 Value *getValueOperand() { return getOperand(0); }
407 const Value *getValueOperand() const { return getOperand(0); }
409 Value *getPointerOperand() { return getOperand(1); }
410 const Value *getPointerOperand() const { return getOperand(1); }
411 static unsigned getPointerOperandIndex() { return 1U; }
413 /// \brief Returns the address space of the pointer operand.
414 unsigned getPointerAddressSpace() const {
415 return getPointerOperand()->getType()->getPointerAddressSpace();
418 // Methods for support type inquiry through isa, cast, and dyn_cast:
419 static inline bool classof(const Instruction *I) {
420 return I->getOpcode() == Instruction::Store;
422 static inline bool classof(const Value *V) {
423 return isa<Instruction>(V) && classof(cast<Instruction>(V));
427 // Shadow Instruction::setInstructionSubclassData with a private forwarding
428 // method so that subclasses cannot accidentally use it.
429 void setInstructionSubclassData(unsigned short D) {
430 Instruction::setInstructionSubclassData(D);
435 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
438 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
440 //===----------------------------------------------------------------------===//
442 //===----------------------------------------------------------------------===//
444 /// FenceInst - an instruction for ordering other memory operations
446 class FenceInst : public Instruction {
447 void *operator new(size_t, unsigned) = delete;
448 void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
451 // Note: Instruction needs to be a friend here to call cloneImpl.
452 friend class Instruction;
453 FenceInst *cloneImpl() const;
456 // allocate space for exactly zero operands
457 void *operator new(size_t s) {
458 return User::operator new(s, 0);
461 // Ordering may only be Acquire, Release, AcquireRelease, or
462 // SequentiallyConsistent.
463 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
464 SynchronizationScope SynchScope = CrossThread,
465 Instruction *InsertBefore = nullptr);
466 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
467 SynchronizationScope SynchScope,
468 BasicBlock *InsertAtEnd);
470 /// Returns the ordering effect of this fence.
471 AtomicOrdering getOrdering() const {
472 return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
475 /// Set the ordering constraint on this fence. May only be Acquire, Release,
476 /// AcquireRelease, or SequentiallyConsistent.
477 void setOrdering(AtomicOrdering Ordering) {
478 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
482 SynchronizationScope getSynchScope() const {
483 return SynchronizationScope(getSubclassDataFromInstruction() & 1);
486 /// Specify whether this fence orders other operations with respect to all
487 /// concurrently executing threads, or only with respect to signal handlers
488 /// executing in the same thread.
489 void setSynchScope(SynchronizationScope xthread) {
490 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
494 // Methods for support type inquiry through isa, cast, and dyn_cast:
495 static inline bool classof(const Instruction *I) {
496 return I->getOpcode() == Instruction::Fence;
498 static inline bool classof(const Value *V) {
499 return isa<Instruction>(V) && classof(cast<Instruction>(V));
503 // Shadow Instruction::setInstructionSubclassData with a private forwarding
504 // method so that subclasses cannot accidentally use it.
505 void setInstructionSubclassData(unsigned short D) {
506 Instruction::setInstructionSubclassData(D);
510 //===----------------------------------------------------------------------===//
511 // AtomicCmpXchgInst Class
512 //===----------------------------------------------------------------------===//
514 /// AtomicCmpXchgInst - an instruction that atomically checks whether a
515 /// specified value is in a memory location, and, if it is, stores a new value
516 /// there. Returns the value that was loaded.
518 class AtomicCmpXchgInst : public Instruction {
519 void *operator new(size_t, unsigned) = delete;
520 void Init(Value *Ptr, Value *Cmp, Value *NewVal,
521 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
522 SynchronizationScope SynchScope);
525 // Note: Instruction needs to be a friend here to call cloneImpl.
526 friend class Instruction;
527 AtomicCmpXchgInst *cloneImpl() const;
530 // allocate space for exactly three operands
531 void *operator new(size_t s) {
532 return User::operator new(s, 3);
534 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
535 AtomicOrdering SuccessOrdering,
536 AtomicOrdering FailureOrdering,
537 SynchronizationScope SynchScope,
538 Instruction *InsertBefore = nullptr);
539 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
540 AtomicOrdering SuccessOrdering,
541 AtomicOrdering FailureOrdering,
542 SynchronizationScope SynchScope,
543 BasicBlock *InsertAtEnd);
545 /// isVolatile - Return true if this is a cmpxchg from a volatile memory
548 bool isVolatile() const {
549 return getSubclassDataFromInstruction() & 1;
552 /// setVolatile - Specify whether this is a volatile cmpxchg.
554 void setVolatile(bool V) {
555 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
559 /// Return true if this cmpxchg may spuriously fail.
560 bool isWeak() const {
561 return getSubclassDataFromInstruction() & 0x100;
564 void setWeak(bool IsWeak) {
565 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x100) |
569 /// Transparently provide more efficient getOperand methods.
570 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
572 /// Set the ordering constraint on this cmpxchg.
573 void setSuccessOrdering(AtomicOrdering Ordering) {
574 assert(Ordering != NotAtomic &&
575 "CmpXchg instructions can only be atomic.");
576 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x1c) |
580 void setFailureOrdering(AtomicOrdering Ordering) {
581 assert(Ordering != NotAtomic &&
582 "CmpXchg instructions can only be atomic.");
583 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0xe0) |
587 /// Specify whether this cmpxchg is atomic and orders other operations with
588 /// respect to all concurrently executing threads, or only with respect to
589 /// signal handlers executing in the same thread.
590 void setSynchScope(SynchronizationScope SynchScope) {
591 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
595 /// Returns the ordering constraint on this cmpxchg.
596 AtomicOrdering getSuccessOrdering() const {
597 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
600 /// Returns the ordering constraint on this cmpxchg.
601 AtomicOrdering getFailureOrdering() const {
602 return AtomicOrdering((getSubclassDataFromInstruction() >> 5) & 7);
605 /// Returns whether this cmpxchg is atomic between threads or only within a
607 SynchronizationScope getSynchScope() const {
608 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
611 Value *getPointerOperand() { return getOperand(0); }
612 const Value *getPointerOperand() const { return getOperand(0); }
613 static unsigned getPointerOperandIndex() { return 0U; }
615 Value *getCompareOperand() { return getOperand(1); }
616 const Value *getCompareOperand() const { return getOperand(1); }
618 Value *getNewValOperand() { return getOperand(2); }
619 const Value *getNewValOperand() const { return getOperand(2); }
621 /// \brief Returns the address space of the pointer operand.
622 unsigned getPointerAddressSpace() const {
623 return getPointerOperand()->getType()->getPointerAddressSpace();
626 /// \brief Returns the strongest permitted ordering on failure, given the
627 /// desired ordering on success.
629 /// If the comparison in a cmpxchg operation fails, there is no atomic store
630 /// so release semantics cannot be provided. So this function drops explicit
631 /// Release requests from the AtomicOrdering. A SequentiallyConsistent
632 /// operation would remain SequentiallyConsistent.
633 static AtomicOrdering
634 getStrongestFailureOrdering(AtomicOrdering SuccessOrdering) {
635 switch (SuccessOrdering) {
636 default: llvm_unreachable("invalid cmpxchg success ordering");
643 case SequentiallyConsistent:
644 return SequentiallyConsistent;
648 // Methods for support type inquiry through isa, cast, and dyn_cast:
649 static inline bool classof(const Instruction *I) {
650 return I->getOpcode() == Instruction::AtomicCmpXchg;
652 static inline bool classof(const Value *V) {
653 return isa<Instruction>(V) && classof(cast<Instruction>(V));
657 // Shadow Instruction::setInstructionSubclassData with a private forwarding
658 // method so that subclasses cannot accidentally use it.
659 void setInstructionSubclassData(unsigned short D) {
660 Instruction::setInstructionSubclassData(D);
665 struct OperandTraits<AtomicCmpXchgInst> :
666 public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
669 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)
671 //===----------------------------------------------------------------------===//
672 // AtomicRMWInst Class
673 //===----------------------------------------------------------------------===//
675 /// AtomicRMWInst - an instruction that atomically reads a memory location,
676 /// combines it with another value, and then stores the result back. Returns
679 class AtomicRMWInst : public Instruction {
680 void *operator new(size_t, unsigned) = delete;
683 // Note: Instruction needs to be a friend here to call cloneImpl.
684 friend class Instruction;
685 AtomicRMWInst *cloneImpl() const;
688 /// This enumeration lists the possible modifications atomicrmw can make. In
689 /// the descriptions, 'p' is the pointer to the instruction's memory location,
690 /// 'old' is the initial value of *p, and 'v' is the other value passed to the
691 /// instruction. These instructions always return 'old'.
707 /// *p = old >signed v ? old : v
709 /// *p = old <signed v ? old : v
711 /// *p = old >unsigned v ? old : v
713 /// *p = old <unsigned v ? old : v
721 // allocate space for exactly two operands
722 void *operator new(size_t s) {
723 return User::operator new(s, 2);
725 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
726 AtomicOrdering Ordering, SynchronizationScope SynchScope,
727 Instruction *InsertBefore = nullptr);
728 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
729 AtomicOrdering Ordering, SynchronizationScope SynchScope,
730 BasicBlock *InsertAtEnd);
732 BinOp getOperation() const {
733 return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
736 void setOperation(BinOp Operation) {
737 unsigned short SubclassData = getSubclassDataFromInstruction();
738 setInstructionSubclassData((SubclassData & 31) |
742 /// isVolatile - Return true if this is a RMW on a volatile memory location.
744 bool isVolatile() const {
745 return getSubclassDataFromInstruction() & 1;
748 /// setVolatile - Specify whether this is a volatile RMW or not.
750 void setVolatile(bool V) {
751 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
755 /// Transparently provide more efficient getOperand methods.
756 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
758 /// Set the ordering constraint on this RMW.
759 void setOrdering(AtomicOrdering Ordering) {
760 assert(Ordering != NotAtomic &&
761 "atomicrmw instructions can only be atomic.");
762 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
766 /// Specify whether this RMW orders other operations with respect to all
767 /// concurrently executing threads, or only with respect to signal handlers
768 /// executing in the same thread.
769 void setSynchScope(SynchronizationScope SynchScope) {
770 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
774 /// Returns the ordering constraint on this RMW.
775 AtomicOrdering getOrdering() const {
776 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
779 /// Returns whether this RMW is atomic between threads or only within a
781 SynchronizationScope getSynchScope() const {
782 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
785 Value *getPointerOperand() { return getOperand(0); }
786 const Value *getPointerOperand() const { return getOperand(0); }
787 static unsigned getPointerOperandIndex() { return 0U; }
789 Value *getValOperand() { return getOperand(1); }
790 const Value *getValOperand() const { return getOperand(1); }
792 /// \brief Returns the address space of the pointer operand.
793 unsigned getPointerAddressSpace() const {
794 return getPointerOperand()->getType()->getPointerAddressSpace();
797 // Methods for support type inquiry through isa, cast, and dyn_cast:
798 static inline bool classof(const Instruction *I) {
799 return I->getOpcode() == Instruction::AtomicRMW;
801 static inline bool classof(const Value *V) {
802 return isa<Instruction>(V) && classof(cast<Instruction>(V));
806 void Init(BinOp Operation, Value *Ptr, Value *Val,
807 AtomicOrdering Ordering, SynchronizationScope SynchScope);
808 // Shadow Instruction::setInstructionSubclassData with a private forwarding
809 // method so that subclasses cannot accidentally use it.
810 void setInstructionSubclassData(unsigned short D) {
811 Instruction::setInstructionSubclassData(D);
816 struct OperandTraits<AtomicRMWInst>
817 : public FixedNumOperandTraits<AtomicRMWInst,2> {
820 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)
822 //===----------------------------------------------------------------------===//
823 // GetElementPtrInst Class
824 //===----------------------------------------------------------------------===//
826 // checkGEPType - Simple wrapper function to give a better assertion failure
827 // message on bad indexes for a gep instruction.
829 inline Type *checkGEPType(Type *Ty) {
830 assert(Ty && "Invalid GetElementPtrInst indices for type!");
834 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
835 /// access elements of arrays and structs
837 class GetElementPtrInst : public Instruction {
838 Type *SourceElementType;
839 Type *ResultElementType;
841 GetElementPtrInst(const GetElementPtrInst &GEPI);
842 void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
844 /// Constructors - Create a getelementptr instruction with a base pointer an
845 /// list of indices. The first ctor can optionally insert before an existing
846 /// instruction, the second appends the new instruction to the specified
848 inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
849 ArrayRef<Value *> IdxList, unsigned Values,
850 const Twine &NameStr, Instruction *InsertBefore);
851 inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
852 ArrayRef<Value *> IdxList, unsigned Values,
853 const Twine &NameStr, BasicBlock *InsertAtEnd);
856 // Note: Instruction needs to be a friend here to call cloneImpl.
857 friend class Instruction;
858 GetElementPtrInst *cloneImpl() const;
861 static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
862 ArrayRef<Value *> IdxList,
863 const Twine &NameStr = "",
864 Instruction *InsertBefore = nullptr) {
865 unsigned Values = 1 + unsigned(IdxList.size());
868 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
872 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
873 return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
874 NameStr, InsertBefore);
876 static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
877 ArrayRef<Value *> IdxList,
878 const Twine &NameStr,
879 BasicBlock *InsertAtEnd) {
880 unsigned Values = 1 + unsigned(IdxList.size());
883 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
887 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
888 return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
889 NameStr, InsertAtEnd);
892 /// Create an "inbounds" getelementptr. See the documentation for the
893 /// "inbounds" flag in LangRef.html for details.
894 static GetElementPtrInst *CreateInBounds(Value *Ptr,
895 ArrayRef<Value *> IdxList,
896 const Twine &NameStr = "",
897 Instruction *InsertBefore = nullptr){
898 return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertBefore);
900 static GetElementPtrInst *
901 CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef<Value *> IdxList,
902 const Twine &NameStr = "",
903 Instruction *InsertBefore = nullptr) {
904 GetElementPtrInst *GEP =
905 Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore);
906 GEP->setIsInBounds(true);
909 static GetElementPtrInst *CreateInBounds(Value *Ptr,
910 ArrayRef<Value *> IdxList,
911 const Twine &NameStr,
912 BasicBlock *InsertAtEnd) {
913 return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertAtEnd);
915 static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr,
916 ArrayRef<Value *> IdxList,
917 const Twine &NameStr,
918 BasicBlock *InsertAtEnd) {
919 GetElementPtrInst *GEP =
920 Create(PointeeType, Ptr, IdxList, NameStr, InsertAtEnd);
921 GEP->setIsInBounds(true);
925 /// Transparently provide more efficient getOperand methods.
926 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
928 // getType - Overload to return most specific sequential type.
929 SequentialType *getType() const {
930 return cast<SequentialType>(Instruction::getType());
933 Type *getSourceElementType() const { return SourceElementType; }
935 void setSourceElementType(Type *Ty) { SourceElementType = Ty; }
936 void setResultElementType(Type *Ty) { ResultElementType = Ty; }
938 Type *getResultElementType() const {
939 assert(ResultElementType ==
940 cast<PointerType>(getType()->getScalarType())->getElementType());
941 return ResultElementType;
944 /// \brief Returns the address space of this instruction's pointer type.
945 unsigned getAddressSpace() const {
946 // Note that this is always the same as the pointer operand's address space
947 // and that is cheaper to compute, so cheat here.
948 return getPointerAddressSpace();
951 /// getIndexedType - Returns the type of the element that would be loaded with
952 /// a load instruction with the specified parameters.
954 /// Null is returned if the indices are invalid for the specified
957 static Type *getIndexedType(Type *Ty, ArrayRef<Value *> IdxList);
958 static Type *getIndexedType(Type *Ty, ArrayRef<Constant *> IdxList);
959 static Type *getIndexedType(Type *Ty, ArrayRef<uint64_t> IdxList);
961 inline op_iterator idx_begin() { return op_begin()+1; }
962 inline const_op_iterator idx_begin() const { return op_begin()+1; }
963 inline op_iterator idx_end() { return op_end(); }
964 inline const_op_iterator idx_end() const { return op_end(); }
966 Value *getPointerOperand() {
967 return getOperand(0);
969 const Value *getPointerOperand() const {
970 return getOperand(0);
972 static unsigned getPointerOperandIndex() {
973 return 0U; // get index for modifying correct operand.
976 /// getPointerOperandType - Method to return the pointer operand as a
978 Type *getPointerOperandType() const {
979 return getPointerOperand()->getType();
982 /// \brief Returns the address space of the pointer operand.
983 unsigned getPointerAddressSpace() const {
984 return getPointerOperandType()->getPointerAddressSpace();
987 /// GetGEPReturnType - Returns the pointer type returned by the GEP
988 /// instruction, which may be a vector of pointers.
989 static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
990 return getGEPReturnType(
991 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType(),
994 static Type *getGEPReturnType(Type *ElTy, Value *Ptr,
995 ArrayRef<Value *> IdxList) {
996 Type *PtrTy = PointerType::get(checkGEPType(getIndexedType(ElTy, IdxList)),
997 Ptr->getType()->getPointerAddressSpace());
999 if (Ptr->getType()->isVectorTy()) {
1000 unsigned NumElem = Ptr->getType()->getVectorNumElements();
1001 return VectorType::get(PtrTy, NumElem);
1003 for (Value *Index : IdxList)
1004 if (Index->getType()->isVectorTy()) {
1005 unsigned NumElem = Index->getType()->getVectorNumElements();
1006 return VectorType::get(PtrTy, NumElem);
1012 unsigned getNumIndices() const { // Note: always non-negative
1013 return getNumOperands() - 1;
1016 bool hasIndices() const {
1017 return getNumOperands() > 1;
1020 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
1021 /// zeros. If so, the result pointer and the first operand have the same
1022 /// value, just potentially different types.
1023 bool hasAllZeroIndices() const;
1025 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
1026 /// constant integers. If so, the result pointer and the first operand have
1027 /// a constant offset between them.
1028 bool hasAllConstantIndices() const;
1030 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
1031 /// See LangRef.html for the meaning of inbounds on a getelementptr.
1032 void setIsInBounds(bool b = true);
1034 /// isInBounds - Determine whether the GEP has the inbounds flag.
1035 bool isInBounds() const;
1037 /// \brief Accumulate the constant address offset of this GEP if possible.
1039 /// This routine accepts an APInt into which it will accumulate the constant
1040 /// offset of this GEP if the GEP is in fact constant. If the GEP is not
1041 /// all-constant, it returns false and the value of the offset APInt is
1042 /// undefined (it is *not* preserved!). The APInt passed into this routine
1043 /// must be at least as wide as the IntPtr type for the address space of
1044 /// the base GEP pointer.
1045 bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
1047 // Methods for support type inquiry through isa, cast, and dyn_cast:
1048 static inline bool classof(const Instruction *I) {
1049 return (I->getOpcode() == Instruction::GetElementPtr);
1051 static inline bool classof(const Value *V) {
1052 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1057 struct OperandTraits<GetElementPtrInst> :
1058 public VariadicOperandTraits<GetElementPtrInst, 1> {
1061 GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
1062 ArrayRef<Value *> IdxList, unsigned Values,
1063 const Twine &NameStr,
1064 Instruction *InsertBefore)
1065 : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
1066 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
1067 Values, InsertBefore),
1068 SourceElementType(PointeeType),
1069 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1070 assert(ResultElementType ==
1071 cast<PointerType>(getType()->getScalarType())->getElementType());
1072 init(Ptr, IdxList, NameStr);
1074 GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
1075 ArrayRef<Value *> IdxList, unsigned Values,
1076 const Twine &NameStr,
1077 BasicBlock *InsertAtEnd)
1078 : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
1079 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
1080 Values, InsertAtEnd),
1081 SourceElementType(PointeeType),
1082 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1083 assert(ResultElementType ==
1084 cast<PointerType>(getType()->getScalarType())->getElementType());
1085 init(Ptr, IdxList, NameStr);
1088 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
1090 //===----------------------------------------------------------------------===//
1092 //===----------------------------------------------------------------------===//
1094 /// This instruction compares its operands according to the predicate given
1095 /// to the constructor. It only operates on integers or pointers. The operands
1096 /// must be identical types.
1097 /// \brief Represent an integer comparison operator.
1098 class ICmpInst: public CmpInst {
1100 assert(getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE &&
1101 getPredicate() <= CmpInst::LAST_ICMP_PREDICATE &&
1102 "Invalid ICmp predicate value");
1103 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1104 "Both operands to ICmp instruction are not of the same type!");
1105 // Check that the operands are the right type
1106 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
1107 getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
1108 "Invalid operand types for ICmp instruction");
1112 // Note: Instruction needs to be a friend here to call cloneImpl.
1113 friend class Instruction;
1114 /// \brief Clone an identical ICmpInst
1115 ICmpInst *cloneImpl() const;
1118 /// \brief Constructor with insert-before-instruction semantics.
1120 Instruction *InsertBefore, ///< Where to insert
1121 Predicate pred, ///< The predicate to use for the comparison
1122 Value *LHS, ///< The left-hand-side of the expression
1123 Value *RHS, ///< The right-hand-side of the expression
1124 const Twine &NameStr = "" ///< Name of the instruction
1125 ) : CmpInst(makeCmpResultType(LHS->getType()),
1126 Instruction::ICmp, pred, LHS, RHS, NameStr,
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::ICmp, pred, LHS, RHS, NameStr,
1148 /// \brief Constructor with no-insertion semantics
1150 Predicate pred, ///< The predicate to use for the comparison
1151 Value *LHS, ///< The left-hand-side of the expression
1152 Value *RHS, ///< The right-hand-side of the expression
1153 const Twine &NameStr = "" ///< Name of the instruction
1154 ) : CmpInst(makeCmpResultType(LHS->getType()),
1155 Instruction::ICmp, pred, LHS, RHS, NameStr) {
1161 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
1162 /// @returns the predicate that would be the result if the operand were
1163 /// regarded as signed.
1164 /// \brief Return the signed version of the predicate
1165 Predicate getSignedPredicate() const {
1166 return getSignedPredicate(getPredicate());
1169 /// This is a static version that you can use without an instruction.
1170 /// \brief Return the signed version of the predicate.
1171 static Predicate getSignedPredicate(Predicate pred);
1173 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
1174 /// @returns the predicate that would be the result if the operand were
1175 /// regarded as unsigned.
1176 /// \brief Return the unsigned version of the predicate
1177 Predicate getUnsignedPredicate() const {
1178 return getUnsignedPredicate(getPredicate());
1181 /// This is a static version that you can use without an instruction.
1182 /// \brief Return the unsigned version of the predicate.
1183 static Predicate getUnsignedPredicate(Predicate pred);
1185 /// isEquality - Return true if this predicate is either EQ or NE. This also
1186 /// tests for commutativity.
1187 static bool isEquality(Predicate P) {
1188 return P == ICMP_EQ || P == ICMP_NE;
1191 /// isEquality - Return true if this predicate is either EQ or NE. This also
1192 /// tests for commutativity.
1193 bool isEquality() const {
1194 return isEquality(getPredicate());
1197 /// @returns true if the predicate of this ICmpInst is commutative
1198 /// \brief Determine if this relation is commutative.
1199 bool isCommutative() const { return isEquality(); }
1201 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1203 bool isRelational() const {
1204 return !isEquality();
1207 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1209 static bool isRelational(Predicate P) {
1210 return !isEquality(P);
1213 /// Initialize a set of values that all satisfy the predicate with C.
1214 /// \brief Make a ConstantRange for a relation with a constant value.
1215 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
1217 /// Exchange the two operands to this instruction in such a way that it does
1218 /// not modify the semantics of the instruction. The predicate value may be
1219 /// changed to retain the same result if the predicate is order dependent
1221 /// \brief Swap operands and adjust predicate.
1222 void swapOperands() {
1223 setPredicate(getSwappedPredicate());
1224 Op<0>().swap(Op<1>());
1227 // Methods for support type inquiry through isa, cast, and dyn_cast:
1228 static inline bool classof(const Instruction *I) {
1229 return I->getOpcode() == Instruction::ICmp;
1231 static inline bool classof(const Value *V) {
1232 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1236 //===----------------------------------------------------------------------===//
1238 //===----------------------------------------------------------------------===//
1240 /// This instruction compares its operands according to the predicate given
1241 /// to the constructor. It only operates on floating point values or packed
1242 /// vectors of floating point values. The operands must be identical types.
1243 /// \brief Represents a floating point comparison operator.
1244 class FCmpInst: public CmpInst {
1246 // Note: Instruction needs to be a friend here to call cloneImpl.
1247 friend class Instruction;
1248 /// \brief Clone an identical FCmpInst
1249 FCmpInst *cloneImpl() const;
1252 /// \brief Constructor with insert-before-instruction semantics.
1254 Instruction *InsertBefore, ///< Where to insert
1255 Predicate pred, ///< The predicate to use for the comparison
1256 Value *LHS, ///< The left-hand-side of the expression
1257 Value *RHS, ///< The right-hand-side of the expression
1258 const Twine &NameStr = "" ///< Name of the instruction
1259 ) : CmpInst(makeCmpResultType(LHS->getType()),
1260 Instruction::FCmp, pred, LHS, RHS, NameStr,
1262 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1263 "Invalid FCmp predicate value");
1264 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1265 "Both operands to FCmp instruction are not of the same type!");
1266 // Check that the operands are the right type
1267 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1268 "Invalid operand types for FCmp instruction");
1271 /// \brief Constructor with insert-at-end semantics.
1273 BasicBlock &InsertAtEnd, ///< Block to insert into.
1274 Predicate pred, ///< The predicate to use for the comparison
1275 Value *LHS, ///< The left-hand-side of the expression
1276 Value *RHS, ///< The right-hand-side of the expression
1277 const Twine &NameStr = "" ///< Name of the instruction
1278 ) : CmpInst(makeCmpResultType(LHS->getType()),
1279 Instruction::FCmp, pred, LHS, RHS, NameStr,
1281 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1282 "Invalid FCmp predicate value");
1283 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1284 "Both operands to FCmp instruction are not of the same type!");
1285 // Check that the operands are the right type
1286 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1287 "Invalid operand types for FCmp instruction");
1290 /// \brief Constructor with no-insertion semantics
1292 Predicate pred, ///< The predicate to use for the comparison
1293 Value *LHS, ///< The left-hand-side of the expression
1294 Value *RHS, ///< The right-hand-side of the expression
1295 const Twine &NameStr = "" ///< Name of the instruction
1296 ) : CmpInst(makeCmpResultType(LHS->getType()),
1297 Instruction::FCmp, pred, LHS, RHS, NameStr) {
1298 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1299 "Invalid FCmp predicate value");
1300 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1301 "Both operands to FCmp instruction are not of the same type!");
1302 // Check that the operands are the right type
1303 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1304 "Invalid operand types for FCmp instruction");
1307 /// @returns true if the predicate of this instruction is EQ or NE.
1308 /// \brief Determine if this is an equality predicate.
1309 static bool isEquality(Predicate Pred) {
1310 return Pred == FCMP_OEQ || Pred == FCMP_ONE || Pred == FCMP_UEQ ||
1314 /// @returns true if the predicate of this instruction is EQ or NE.
1315 /// \brief Determine if this is an equality predicate.
1316 bool isEquality() const { return isEquality(getPredicate()); }
1318 /// @returns true if the predicate of this instruction is commutative.
1319 /// \brief Determine if this is a commutative predicate.
1320 bool isCommutative() const {
1321 return isEquality() ||
1322 getPredicate() == FCMP_FALSE ||
1323 getPredicate() == FCMP_TRUE ||
1324 getPredicate() == FCMP_ORD ||
1325 getPredicate() == FCMP_UNO;
1328 /// @returns true if the predicate is relational (not EQ or NE).
1329 /// \brief Determine if this a relational predicate.
1330 bool isRelational() const { return !isEquality(); }
1332 /// Exchange the two operands to this instruction in such a way that it does
1333 /// not modify the semantics of the instruction. The predicate value may be
1334 /// changed to retain the same result if the predicate is order dependent
1336 /// \brief Swap operands and adjust predicate.
1337 void swapOperands() {
1338 setPredicate(getSwappedPredicate());
1339 Op<0>().swap(Op<1>());
1342 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
1343 static inline bool classof(const Instruction *I) {
1344 return I->getOpcode() == Instruction::FCmp;
1346 static inline bool classof(const Value *V) {
1347 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1351 //===----------------------------------------------------------------------===//
1352 /// CallInst - This class represents a function call, abstracting a target
1353 /// machine's calling convention. This class uses low bit of the SubClassData
1354 /// field to indicate whether or not this is a tail call. The rest of the bits
1355 /// hold the calling convention of the call.
1357 class CallInst : public Instruction,
1358 public OperandBundleUser<CallInst, User::op_iterator> {
1359 AttributeSet AttributeList; ///< parameter attributes for call
1361 CallInst(const CallInst &CI);
1362 void init(Value *Func, ArrayRef<Value *> Args,
1363 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr) {
1364 init(cast<FunctionType>(
1365 cast<PointerType>(Func->getType())->getElementType()),
1366 Func, Args, Bundles, NameStr);
1368 void init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
1369 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
1370 void init(Value *Func, const Twine &NameStr);
1372 /// Construct a CallInst given a range of arguments.
1373 /// \brief Construct a CallInst from a range of arguments
1374 inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1375 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1376 Instruction *InsertBefore);
1377 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1378 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1379 Instruction *InsertBefore)
1380 : CallInst(cast<FunctionType>(
1381 cast<PointerType>(Func->getType())->getElementType()),
1382 Func, Args, Bundles, NameStr, InsertBefore) {}
1384 inline CallInst(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr,
1385 Instruction *InsertBefore)
1386 : CallInst(Func, Args, None, NameStr, InsertBefore) {}
1388 /// Construct a CallInst given a range of arguments.
1389 /// \brief Construct a CallInst from a range of arguments
1390 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1391 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1392 BasicBlock *InsertAtEnd);
1394 explicit CallInst(Value *F, const Twine &NameStr,
1395 Instruction *InsertBefore);
1396 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1398 friend class OperandBundleUser<CallInst, User::op_iterator>;
1399 bool hasDescriptor() const { return HasDescriptor; }
1402 // Note: Instruction needs to be a friend here to call cloneImpl.
1403 friend class Instruction;
1404 CallInst *cloneImpl() const;
1407 static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
1408 ArrayRef<OperandBundleDef> Bundles = None,
1409 const Twine &NameStr = "",
1410 Instruction *InsertBefore = nullptr) {
1411 return Create(cast<FunctionType>(
1412 cast<PointerType>(Func->getType())->getElementType()),
1413 Func, Args, Bundles, NameStr, InsertBefore);
1415 static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
1416 const Twine &NameStr,
1417 Instruction *InsertBefore = nullptr) {
1418 return Create(cast<FunctionType>(
1419 cast<PointerType>(Func->getType())->getElementType()),
1420 Func, Args, None, NameStr, InsertBefore);
1422 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1423 const Twine &NameStr,
1424 Instruction *InsertBefore = nullptr) {
1425 return new (unsigned(Args.size() + 1))
1426 CallInst(Ty, Func, Args, None, NameStr, InsertBefore);
1428 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1429 ArrayRef<OperandBundleDef> Bundles = None,
1430 const Twine &NameStr = "",
1431 Instruction *InsertBefore = nullptr) {
1432 const unsigned TotalOps =
1433 unsigned(Args.size()) + CountBundleInputs(Bundles) + 1;
1434 const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
1436 return new (TotalOps, DescriptorBytes)
1437 CallInst(Ty, Func, Args, Bundles, NameStr, InsertBefore);
1439 static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
1440 ArrayRef<OperandBundleDef> Bundles,
1441 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1442 const unsigned TotalOps =
1443 unsigned(Args.size()) + CountBundleInputs(Bundles) + 1;
1444 const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
1446 return new (TotalOps, DescriptorBytes)
1447 CallInst(Func, Args, Bundles, NameStr, InsertAtEnd);
1449 static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
1450 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1451 return new (unsigned(Args.size() + 1))
1452 CallInst(Func, Args, None, NameStr, InsertAtEnd);
1454 static CallInst *Create(Value *F, const Twine &NameStr = "",
1455 Instruction *InsertBefore = nullptr) {
1456 return new(1) CallInst(F, NameStr, InsertBefore);
1458 static CallInst *Create(Value *F, const Twine &NameStr,
1459 BasicBlock *InsertAtEnd) {
1460 return new(1) CallInst(F, NameStr, InsertAtEnd);
1462 /// CreateMalloc - Generate the IR for a call to malloc:
1463 /// 1. Compute the malloc call's argument as the specified type's size,
1464 /// possibly multiplied by the array size if the array size is not
1466 /// 2. Call malloc with that argument.
1467 /// 3. Bitcast the result of the malloc call to the specified type.
1468 static Instruction *CreateMalloc(Instruction *InsertBefore,
1469 Type *IntPtrTy, Type *AllocTy,
1470 Value *AllocSize, Value *ArraySize = nullptr,
1471 Function* MallocF = nullptr,
1472 const Twine &Name = "");
1473 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1474 Type *IntPtrTy, Type *AllocTy,
1475 Value *AllocSize, Value *ArraySize = nullptr,
1476 Function* MallocF = nullptr,
1477 const Twine &Name = "");
1478 /// CreateFree - Generate the IR for a call to the builtin free function.
1479 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
1480 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
1482 ~CallInst() override;
1484 FunctionType *getFunctionType() const { return FTy; }
1486 void mutateFunctionType(FunctionType *FTy) {
1487 mutateType(FTy->getReturnType());
1491 // Note that 'musttail' implies 'tail'.
1492 enum TailCallKind { TCK_None = 0, TCK_Tail = 1, TCK_MustTail = 2,
1494 TailCallKind getTailCallKind() const {
1495 return TailCallKind(getSubclassDataFromInstruction() & 3);
1497 bool isTailCall() const {
1498 unsigned Kind = getSubclassDataFromInstruction() & 3;
1499 return Kind == TCK_Tail || Kind == TCK_MustTail;
1501 bool isMustTailCall() const {
1502 return (getSubclassDataFromInstruction() & 3) == TCK_MustTail;
1504 bool isNoTailCall() const {
1505 return (getSubclassDataFromInstruction() & 3) == TCK_NoTail;
1507 void setTailCall(bool isTC = true) {
1508 setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
1509 unsigned(isTC ? TCK_Tail : TCK_None));
1511 void setTailCallKind(TailCallKind TCK) {
1512 setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
1516 /// Provide fast operand accessors
1517 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1519 /// getNumArgOperands - Return the number of call arguments.
1521 unsigned getNumArgOperands() const {
1522 return getNumOperands() - getNumTotalBundleOperands() - 1;
1525 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1527 Value *getArgOperand(unsigned i) const {
1528 assert(i < getNumArgOperands() && "Out of bounds!");
1529 return getOperand(i);
1531 void setArgOperand(unsigned i, Value *v) {
1532 assert(i < getNumArgOperands() && "Out of bounds!");
1536 /// arg_operands - iteration adapter for range-for loops.
1537 iterator_range<op_iterator> arg_operands() {
1538 // The last operand in the op list is the callee - it's not one of the args
1539 // so we don't want to iterate over it.
1540 return iterator_range<op_iterator>(
1541 op_begin(), op_end() - getNumTotalBundleOperands() - 1);
1544 /// arg_operands - iteration adapter for range-for loops.
1545 iterator_range<const_op_iterator> arg_operands() const {
1546 return iterator_range<const_op_iterator>(
1547 op_begin(), op_end() - getNumTotalBundleOperands() - 1);
1550 /// \brief Wrappers for getting the \c Use of a call argument.
1551 const Use &getArgOperandUse(unsigned i) const {
1552 assert(i < getNumArgOperands() && "Out of bounds!");
1553 return getOperandUse(i);
1555 Use &getArgOperandUse(unsigned i) {
1556 assert(i < getNumArgOperands() && "Out of bounds!");
1557 return getOperandUse(i);
1560 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1562 CallingConv::ID getCallingConv() const {
1563 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2);
1565 void setCallingConv(CallingConv::ID CC) {
1566 auto ID = static_cast<unsigned>(CC);
1567 assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention");
1568 setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
1572 /// getAttributes - Return the parameter attributes for this call.
1574 const AttributeSet &getAttributes() const { return AttributeList; }
1576 /// setAttributes - Set the parameter attributes for this call.
1578 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
1580 /// addAttribute - adds the attribute to the list of attributes.
1581 void addAttribute(unsigned i, Attribute::AttrKind attr);
1583 /// addAttribute - adds the attribute to the list of attributes.
1584 void addAttribute(unsigned i, StringRef Kind, StringRef Value);
1586 /// removeAttribute - removes the attribute from the list of attributes.
1587 void removeAttribute(unsigned i, Attribute attr);
1589 /// \brief adds the dereferenceable attribute to the list of attributes.
1590 void addDereferenceableAttr(unsigned i, uint64_t Bytes);
1592 /// \brief adds the dereferenceable_or_null attribute to the list of
1594 void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
1596 /// \brief Determine whether this call has the given attribute.
1597 bool hasFnAttr(Attribute::AttrKind A) const {
1598 assert(A != Attribute::NoBuiltin &&
1599 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
1600 return hasFnAttrImpl(A);
1603 /// \brief Determine whether this call has the given attribute.
1604 bool hasFnAttr(StringRef A) const {
1605 return hasFnAttrImpl(A);
1608 /// \brief Determine whether the call or the callee has the given attributes.
1609 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
1611 /// \brief Return true if the data operand at index \p i has the attribute \p
1614 /// Data operands include call arguments and values used in operand bundles,
1615 /// but does not include the callee operand. This routine dispatches to the
1616 /// underlying AttributeList or the OperandBundleUser as appropriate.
1618 /// The index \p i is interpreted as
1620 /// \p i == Attribute::ReturnIndex -> the return value
1621 /// \p i in [1, arg_size + 1) -> argument number (\p i - 1)
1622 /// \p i in [arg_size + 1, data_operand_size + 1) -> bundle operand at index
1623 /// (\p i - 1) in the operand list.
1624 bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind A) const;
1626 /// \brief Extract the alignment for a call or parameter (0=unknown).
1627 unsigned getParamAlignment(unsigned i) const {
1628 return AttributeList.getParamAlignment(i);
1631 /// \brief Extract the number of dereferenceable bytes for a call or
1632 /// parameter (0=unknown).
1633 uint64_t getDereferenceableBytes(unsigned i) const {
1634 return AttributeList.getDereferenceableBytes(i);
1637 /// \brief Extract the number of dereferenceable_or_null bytes for a call or
1638 /// parameter (0=unknown).
1639 uint64_t getDereferenceableOrNullBytes(unsigned i) const {
1640 return AttributeList.getDereferenceableOrNullBytes(i);
1643 /// @brief Determine if the parameter or return value is marked with NoAlias
1645 /// @param n The parameter to check. 1 is the first parameter, 0 is the return
1646 bool doesNotAlias(unsigned n) const {
1647 return AttributeList.hasAttribute(n, Attribute::NoAlias);
1650 /// \brief Return true if the call should not be treated as a call to a
1652 bool isNoBuiltin() const {
1653 return hasFnAttrImpl(Attribute::NoBuiltin) &&
1654 !hasFnAttrImpl(Attribute::Builtin);
1657 /// \brief Return true if the call should not be inlined.
1658 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
1659 void setIsNoInline() {
1660 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
1663 /// \brief Return true if the call can return twice
1664 bool canReturnTwice() const {
1665 return hasFnAttr(Attribute::ReturnsTwice);
1667 void setCanReturnTwice() {
1668 addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice);
1671 /// \brief Determine if the call does not access memory.
1672 bool doesNotAccessMemory() const {
1673 return hasFnAttr(Attribute::ReadNone);
1675 void setDoesNotAccessMemory() {
1676 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
1679 /// \brief Determine if the call does not access or only reads memory.
1680 bool onlyReadsMemory() const {
1681 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
1683 void setOnlyReadsMemory() {
1684 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
1687 /// @brief Determine if the call can access memmory only using pointers based
1688 /// on its arguments.
1689 bool onlyAccessesArgMemory() const {
1690 return hasFnAttr(Attribute::ArgMemOnly);
1692 void setOnlyAccessesArgMemory() {
1693 addAttribute(AttributeSet::FunctionIndex, Attribute::ArgMemOnly);
1696 /// \brief Determine if the call cannot return.
1697 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
1698 void setDoesNotReturn() {
1699 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
1702 /// \brief Determine if the call cannot unwind.
1703 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
1704 void setDoesNotThrow() {
1705 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
1708 /// \brief Determine if the call cannot be duplicated.
1709 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
1710 void setCannotDuplicate() {
1711 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
1714 /// \brief Determine if the call is convergent
1715 bool isConvergent() const { return hasFnAttr(Attribute::Convergent); }
1716 void setConvergent() {
1717 addAttribute(AttributeSet::FunctionIndex, Attribute::Convergent);
1720 /// \brief Determine if the call returns a structure through first
1721 /// pointer argument.
1722 bool hasStructRetAttr() const {
1723 // Be friendly and also check the callee.
1724 return paramHasAttr(1, Attribute::StructRet);
1727 /// \brief Determine if any call argument is an aggregate passed by value.
1728 bool hasByValArgument() const {
1729 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1732 /// getCalledFunction - Return the function called, or null if this is an
1733 /// indirect function invocation.
1735 Function *getCalledFunction() const {
1736 return dyn_cast<Function>(Op<-1>());
1739 /// getCalledValue - Get a pointer to the function that is invoked by this
1741 const Value *getCalledValue() const { return Op<-1>(); }
1742 Value *getCalledValue() { return Op<-1>(); }
1744 /// setCalledFunction - Set the function called.
1745 void setCalledFunction(Value* Fn) {
1747 cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()),
1750 void setCalledFunction(FunctionType *FTy, Value *Fn) {
1752 assert(FTy == cast<FunctionType>(
1753 cast<PointerType>(Fn->getType())->getElementType()));
1757 /// isInlineAsm - Check if this call is an inline asm statement.
1758 bool isInlineAsm() const {
1759 return isa<InlineAsm>(Op<-1>());
1762 // Methods for support type inquiry through isa, cast, and dyn_cast:
1763 static inline bool classof(const Instruction *I) {
1764 return I->getOpcode() == Instruction::Call;
1766 static inline bool classof(const Value *V) {
1767 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1771 template <typename AttrKind> bool hasFnAttrImpl(AttrKind A) const {
1772 if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, A))
1775 // Operand bundles override attributes on the called function, but don't
1776 // override attributes directly present on the call instruction.
1777 if (isFnAttrDisallowedByOpBundle(A))
1780 if (const Function *F = getCalledFunction())
1781 return F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, A);
1785 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1786 // method so that subclasses cannot accidentally use it.
1787 void setInstructionSubclassData(unsigned short D) {
1788 Instruction::setInstructionSubclassData(D);
1793 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1796 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1797 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1798 BasicBlock *InsertAtEnd)
1800 cast<FunctionType>(cast<PointerType>(Func->getType())
1801 ->getElementType())->getReturnType(),
1802 Instruction::Call, OperandTraits<CallInst>::op_end(this) -
1803 (Args.size() + CountBundleInputs(Bundles) + 1),
1804 unsigned(Args.size() + CountBundleInputs(Bundles) + 1), InsertAtEnd) {
1805 init(Func, Args, Bundles, NameStr);
1808 CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1809 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1810 Instruction *InsertBefore)
1811 : Instruction(Ty->getReturnType(), Instruction::Call,
1812 OperandTraits<CallInst>::op_end(this) -
1813 (Args.size() + CountBundleInputs(Bundles) + 1),
1814 unsigned(Args.size() + CountBundleInputs(Bundles) + 1),
1816 init(Ty, Func, Args, Bundles, NameStr);
1819 // Note: if you get compile errors about private methods then
1820 // please update your code to use the high-level operand
1821 // interfaces. See line 943 above.
1822 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1824 //===----------------------------------------------------------------------===//
1826 //===----------------------------------------------------------------------===//
1828 /// SelectInst - This class represents the LLVM 'select' instruction.
1830 class SelectInst : public Instruction {
1831 void init(Value *C, Value *S1, Value *S2) {
1832 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1838 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1839 Instruction *InsertBefore)
1840 : Instruction(S1->getType(), Instruction::Select,
1841 &Op<0>(), 3, InsertBefore) {
1845 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1846 BasicBlock *InsertAtEnd)
1847 : Instruction(S1->getType(), Instruction::Select,
1848 &Op<0>(), 3, InsertAtEnd) {
1854 // Note: Instruction needs to be a friend here to call cloneImpl.
1855 friend class Instruction;
1856 SelectInst *cloneImpl() const;
1859 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1860 const Twine &NameStr = "",
1861 Instruction *InsertBefore = nullptr) {
1862 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1864 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1865 const Twine &NameStr,
1866 BasicBlock *InsertAtEnd) {
1867 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1870 const Value *getCondition() const { return Op<0>(); }
1871 const Value *getTrueValue() const { return Op<1>(); }
1872 const Value *getFalseValue() const { return Op<2>(); }
1873 Value *getCondition() { return Op<0>(); }
1874 Value *getTrueValue() { return Op<1>(); }
1875 Value *getFalseValue() { return Op<2>(); }
1877 /// areInvalidOperands - Return a string if the specified operands are invalid
1878 /// for a select operation, otherwise return null.
1879 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1881 /// Transparently provide more efficient getOperand methods.
1882 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1884 OtherOps getOpcode() const {
1885 return static_cast<OtherOps>(Instruction::getOpcode());
1888 // Methods for support type inquiry through isa, cast, and dyn_cast:
1889 static inline bool classof(const Instruction *I) {
1890 return I->getOpcode() == Instruction::Select;
1892 static inline bool classof(const Value *V) {
1893 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1898 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1901 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1903 //===----------------------------------------------------------------------===//
1905 //===----------------------------------------------------------------------===//
1907 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1908 /// an argument of the specified type given a va_list and increments that list
1910 class VAArgInst : public UnaryInstruction {
1912 // Note: Instruction needs to be a friend here to call cloneImpl.
1913 friend class Instruction;
1914 VAArgInst *cloneImpl() const;
1917 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1918 Instruction *InsertBefore = nullptr)
1919 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1922 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1923 BasicBlock *InsertAtEnd)
1924 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1928 Value *getPointerOperand() { return getOperand(0); }
1929 const Value *getPointerOperand() const { return getOperand(0); }
1930 static unsigned getPointerOperandIndex() { return 0U; }
1932 // Methods for support type inquiry through isa, cast, and dyn_cast:
1933 static inline bool classof(const Instruction *I) {
1934 return I->getOpcode() == VAArg;
1936 static inline bool classof(const Value *V) {
1937 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1941 //===----------------------------------------------------------------------===//
1942 // ExtractElementInst Class
1943 //===----------------------------------------------------------------------===//
1945 /// ExtractElementInst - This instruction extracts a single (scalar)
1946 /// element from a VectorType value
1948 class ExtractElementInst : public Instruction {
1949 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1950 Instruction *InsertBefore = nullptr);
1951 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1952 BasicBlock *InsertAtEnd);
1955 // Note: Instruction needs to be a friend here to call cloneImpl.
1956 friend class Instruction;
1957 ExtractElementInst *cloneImpl() const;
1960 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1961 const Twine &NameStr = "",
1962 Instruction *InsertBefore = nullptr) {
1963 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1965 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1966 const Twine &NameStr,
1967 BasicBlock *InsertAtEnd) {
1968 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1971 /// isValidOperands - Return true if an extractelement instruction can be
1972 /// formed with the specified operands.
1973 static bool isValidOperands(const Value *Vec, const Value *Idx);
1975 Value *getVectorOperand() { return Op<0>(); }
1976 Value *getIndexOperand() { return Op<1>(); }
1977 const Value *getVectorOperand() const { return Op<0>(); }
1978 const Value *getIndexOperand() const { return Op<1>(); }
1980 VectorType *getVectorOperandType() const {
1981 return cast<VectorType>(getVectorOperand()->getType());
1984 /// Transparently provide more efficient getOperand methods.
1985 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1987 // Methods for support type inquiry through isa, cast, and dyn_cast:
1988 static inline bool classof(const Instruction *I) {
1989 return I->getOpcode() == Instruction::ExtractElement;
1991 static inline bool classof(const Value *V) {
1992 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1997 struct OperandTraits<ExtractElementInst> :
1998 public FixedNumOperandTraits<ExtractElementInst, 2> {
2001 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
2003 //===----------------------------------------------------------------------===//
2004 // InsertElementInst Class
2005 //===----------------------------------------------------------------------===//
2007 /// InsertElementInst - This instruction inserts a single (scalar)
2008 /// element into a VectorType value
2010 class InsertElementInst : public Instruction {
2011 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
2012 const Twine &NameStr = "",
2013 Instruction *InsertBefore = nullptr);
2014 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr,
2015 BasicBlock *InsertAtEnd);
2018 // Note: Instruction needs to be a friend here to call cloneImpl.
2019 friend class Instruction;
2020 InsertElementInst *cloneImpl() const;
2023 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
2024 const Twine &NameStr = "",
2025 Instruction *InsertBefore = nullptr) {
2026 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
2028 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
2029 const Twine &NameStr,
2030 BasicBlock *InsertAtEnd) {
2031 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
2034 /// isValidOperands - Return true if an insertelement instruction can be
2035 /// formed with the specified operands.
2036 static bool isValidOperands(const Value *Vec, const Value *NewElt,
2039 /// getType - Overload to return most specific vector type.
2041 VectorType *getType() const {
2042 return cast<VectorType>(Instruction::getType());
2045 /// Transparently provide more efficient getOperand methods.
2046 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2048 // Methods for support type inquiry through isa, cast, and dyn_cast:
2049 static inline bool classof(const Instruction *I) {
2050 return I->getOpcode() == Instruction::InsertElement;
2052 static inline bool classof(const Value *V) {
2053 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2058 struct OperandTraits<InsertElementInst> :
2059 public FixedNumOperandTraits<InsertElementInst, 3> {
2062 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
2064 //===----------------------------------------------------------------------===//
2065 // ShuffleVectorInst Class
2066 //===----------------------------------------------------------------------===//
2068 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
2071 class ShuffleVectorInst : public Instruction {
2073 // Note: Instruction needs to be a friend here to call cloneImpl.
2074 friend class Instruction;
2075 ShuffleVectorInst *cloneImpl() const;
2078 // allocate space for exactly three operands
2079 void *operator new(size_t s) {
2080 return User::operator new(s, 3);
2082 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
2083 const Twine &NameStr = "",
2084 Instruction *InsertBefor = nullptr);
2085 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
2086 const Twine &NameStr, BasicBlock *InsertAtEnd);
2088 /// isValidOperands - Return true if a shufflevector instruction can be
2089 /// formed with the specified operands.
2090 static bool isValidOperands(const Value *V1, const Value *V2,
2093 /// getType - Overload to return most specific vector type.
2095 VectorType *getType() const {
2096 return cast<VectorType>(Instruction::getType());
2099 /// Transparently provide more efficient getOperand methods.
2100 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2102 Constant *getMask() const {
2103 return cast<Constant>(getOperand(2));
2106 /// getMaskValue - Return the index from the shuffle mask for the specified
2107 /// output result. This is either -1 if the element is undef or a number less
2108 /// than 2*numelements.
2109 static int getMaskValue(Constant *Mask, unsigned i);
2111 int getMaskValue(unsigned i) const {
2112 return getMaskValue(getMask(), i);
2115 /// getShuffleMask - Return the full mask for this instruction, where each
2116 /// element is the element number and undef's are returned as -1.
2117 static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
2119 void getShuffleMask(SmallVectorImpl<int> &Result) const {
2120 return getShuffleMask(getMask(), Result);
2123 SmallVector<int, 16> getShuffleMask() const {
2124 SmallVector<int, 16> Mask;
2125 getShuffleMask(Mask);
2129 // Methods for support type inquiry through isa, cast, and dyn_cast:
2130 static inline bool classof(const Instruction *I) {
2131 return I->getOpcode() == Instruction::ShuffleVector;
2133 static inline bool classof(const Value *V) {
2134 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2139 struct OperandTraits<ShuffleVectorInst> :
2140 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
2143 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
2145 //===----------------------------------------------------------------------===//
2146 // ExtractValueInst Class
2147 //===----------------------------------------------------------------------===//
2149 /// ExtractValueInst - This instruction extracts a struct member or array
2150 /// element value from an aggregate value.
2152 class ExtractValueInst : public UnaryInstruction {
2153 SmallVector<unsigned, 4> Indices;
2155 ExtractValueInst(const ExtractValueInst &EVI);
2156 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
2158 /// Constructors - Create a extractvalue instruction with a base aggregate
2159 /// value and a list of indices. The first ctor can optionally insert before
2160 /// an existing instruction, the second appends the new instruction to the
2161 /// specified BasicBlock.
2162 inline ExtractValueInst(Value *Agg,
2163 ArrayRef<unsigned> Idxs,
2164 const Twine &NameStr,
2165 Instruction *InsertBefore);
2166 inline ExtractValueInst(Value *Agg,
2167 ArrayRef<unsigned> Idxs,
2168 const Twine &NameStr, BasicBlock *InsertAtEnd);
2170 // allocate space for exactly one operand
2171 void *operator new(size_t s) { return User::operator new(s, 1); }
2174 // Note: Instruction needs to be a friend here to call cloneImpl.
2175 friend class Instruction;
2176 ExtractValueInst *cloneImpl() const;
2179 static ExtractValueInst *Create(Value *Agg,
2180 ArrayRef<unsigned> Idxs,
2181 const Twine &NameStr = "",
2182 Instruction *InsertBefore = nullptr) {
2184 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
2186 static ExtractValueInst *Create(Value *Agg,
2187 ArrayRef<unsigned> Idxs,
2188 const Twine &NameStr,
2189 BasicBlock *InsertAtEnd) {
2190 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
2193 /// getIndexedType - Returns the type of the element that would be extracted
2194 /// with an extractvalue instruction with the specified parameters.
2196 /// Null is returned if the indices are invalid for the specified type.
2197 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
2199 typedef const unsigned* idx_iterator;
2200 inline idx_iterator idx_begin() const { return Indices.begin(); }
2201 inline idx_iterator idx_end() const { return Indices.end(); }
2202 inline iterator_range<idx_iterator> indices() const {
2203 return iterator_range<idx_iterator>(idx_begin(), idx_end());
2206 Value *getAggregateOperand() {
2207 return getOperand(0);
2209 const Value *getAggregateOperand() const {
2210 return getOperand(0);
2212 static unsigned getAggregateOperandIndex() {
2213 return 0U; // get index for modifying correct operand
2216 ArrayRef<unsigned> getIndices() const {
2220 unsigned getNumIndices() const {
2221 return (unsigned)Indices.size();
2224 bool hasIndices() const {
2228 // Methods for support type inquiry through isa, cast, and dyn_cast:
2229 static inline bool classof(const Instruction *I) {
2230 return I->getOpcode() == Instruction::ExtractValue;
2232 static inline bool classof(const Value *V) {
2233 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2237 ExtractValueInst::ExtractValueInst(Value *Agg,
2238 ArrayRef<unsigned> Idxs,
2239 const Twine &NameStr,
2240 Instruction *InsertBefore)
2241 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
2242 ExtractValue, Agg, InsertBefore) {
2243 init(Idxs, NameStr);
2245 ExtractValueInst::ExtractValueInst(Value *Agg,
2246 ArrayRef<unsigned> Idxs,
2247 const Twine &NameStr,
2248 BasicBlock *InsertAtEnd)
2249 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
2250 ExtractValue, Agg, InsertAtEnd) {
2251 init(Idxs, NameStr);
2254 //===----------------------------------------------------------------------===//
2255 // InsertValueInst Class
2256 //===----------------------------------------------------------------------===//
2258 /// InsertValueInst - This instruction inserts a struct field of array element
2259 /// value into an aggregate value.
2261 class InsertValueInst : public Instruction {
2262 SmallVector<unsigned, 4> Indices;
2264 void *operator new(size_t, unsigned) = delete;
2265 InsertValueInst(const InsertValueInst &IVI);
2266 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
2267 const Twine &NameStr);
2269 /// Constructors - Create a insertvalue instruction with a base aggregate
2270 /// value, a value to insert, and a list of indices. The first ctor can
2271 /// optionally insert before an existing instruction, the second appends
2272 /// the new instruction to the specified BasicBlock.
2273 inline InsertValueInst(Value *Agg, Value *Val,
2274 ArrayRef<unsigned> Idxs,
2275 const Twine &NameStr,
2276 Instruction *InsertBefore);
2277 inline InsertValueInst(Value *Agg, Value *Val,
2278 ArrayRef<unsigned> Idxs,
2279 const Twine &NameStr, BasicBlock *InsertAtEnd);
2281 /// Constructors - These two constructors are convenience methods because one
2282 /// and two index insertvalue instructions are so common.
2283 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
2284 const Twine &NameStr = "",
2285 Instruction *InsertBefore = nullptr);
2286 InsertValueInst(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr,
2287 BasicBlock *InsertAtEnd);
2290 // Note: Instruction needs to be a friend here to call cloneImpl.
2291 friend class Instruction;
2292 InsertValueInst *cloneImpl() const;
2295 // allocate space for exactly two operands
2296 void *operator new(size_t s) {
2297 return User::operator new(s, 2);
2300 static InsertValueInst *Create(Value *Agg, Value *Val,
2301 ArrayRef<unsigned> Idxs,
2302 const Twine &NameStr = "",
2303 Instruction *InsertBefore = nullptr) {
2304 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
2306 static InsertValueInst *Create(Value *Agg, Value *Val,
2307 ArrayRef<unsigned> Idxs,
2308 const Twine &NameStr,
2309 BasicBlock *InsertAtEnd) {
2310 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
2313 /// Transparently provide more efficient getOperand methods.
2314 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2316 typedef const unsigned* idx_iterator;
2317 inline idx_iterator idx_begin() const { return Indices.begin(); }
2318 inline idx_iterator idx_end() const { return Indices.end(); }
2319 inline iterator_range<idx_iterator> indices() const {
2320 return iterator_range<idx_iterator>(idx_begin(), idx_end());
2323 Value *getAggregateOperand() {
2324 return getOperand(0);
2326 const Value *getAggregateOperand() const {
2327 return getOperand(0);
2329 static unsigned getAggregateOperandIndex() {
2330 return 0U; // get index for modifying correct operand
2333 Value *getInsertedValueOperand() {
2334 return getOperand(1);
2336 const Value *getInsertedValueOperand() const {
2337 return getOperand(1);
2339 static unsigned getInsertedValueOperandIndex() {
2340 return 1U; // get index for modifying correct operand
2343 ArrayRef<unsigned> getIndices() const {
2347 unsigned getNumIndices() const {
2348 return (unsigned)Indices.size();
2351 bool hasIndices() const {
2355 // Methods for support type inquiry through isa, cast, and dyn_cast:
2356 static inline bool classof(const Instruction *I) {
2357 return I->getOpcode() == Instruction::InsertValue;
2359 static inline bool classof(const Value *V) {
2360 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2365 struct OperandTraits<InsertValueInst> :
2366 public FixedNumOperandTraits<InsertValueInst, 2> {
2369 InsertValueInst::InsertValueInst(Value *Agg,
2371 ArrayRef<unsigned> Idxs,
2372 const Twine &NameStr,
2373 Instruction *InsertBefore)
2374 : Instruction(Agg->getType(), InsertValue,
2375 OperandTraits<InsertValueInst>::op_begin(this),
2377 init(Agg, Val, Idxs, NameStr);
2379 InsertValueInst::InsertValueInst(Value *Agg,
2381 ArrayRef<unsigned> Idxs,
2382 const Twine &NameStr,
2383 BasicBlock *InsertAtEnd)
2384 : Instruction(Agg->getType(), InsertValue,
2385 OperandTraits<InsertValueInst>::op_begin(this),
2387 init(Agg, Val, Idxs, NameStr);
2390 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
2392 //===----------------------------------------------------------------------===//
2394 //===----------------------------------------------------------------------===//
2396 // PHINode - The PHINode class is used to represent the magical mystical PHI
2397 // node, that can not exist in nature, but can be synthesized in a computer
2398 // scientist's overactive imagination.
2400 class PHINode : public Instruction {
2401 void *operator new(size_t, unsigned) = delete;
2402 /// ReservedSpace - The number of operands actually allocated. NumOperands is
2403 /// the number actually in use.
2404 unsigned ReservedSpace;
2405 PHINode(const PHINode &PN);
2406 // allocate space for exactly zero operands
2407 void *operator new(size_t s) {
2408 return User::operator new(s);
2410 explicit PHINode(Type *Ty, unsigned NumReservedValues,
2411 const Twine &NameStr = "",
2412 Instruction *InsertBefore = nullptr)
2413 : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore),
2414 ReservedSpace(NumReservedValues) {
2416 allocHungoffUses(ReservedSpace);
2419 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
2420 BasicBlock *InsertAtEnd)
2421 : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd),
2422 ReservedSpace(NumReservedValues) {
2424 allocHungoffUses(ReservedSpace);
2428 // allocHungoffUses - this is more complicated than the generic
2429 // User::allocHungoffUses, because we have to allocate Uses for the incoming
2430 // values and pointers to the incoming blocks, all in one allocation.
2431 void allocHungoffUses(unsigned N) {
2432 User::allocHungoffUses(N, /* IsPhi */ true);
2435 // Note: Instruction needs to be a friend here to call cloneImpl.
2436 friend class Instruction;
2437 PHINode *cloneImpl() const;
2440 /// Constructors - NumReservedValues is a hint for the number of incoming
2441 /// edges that this phi node will have (use 0 if you really have no idea).
2442 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2443 const Twine &NameStr = "",
2444 Instruction *InsertBefore = nullptr) {
2445 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2447 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2448 const Twine &NameStr, BasicBlock *InsertAtEnd) {
2449 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2452 /// Provide fast operand accessors
2453 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2455 // Block iterator interface. This provides access to the list of incoming
2456 // basic blocks, which parallels the list of incoming values.
2458 typedef BasicBlock **block_iterator;
2459 typedef BasicBlock * const *const_block_iterator;
2461 block_iterator block_begin() {
2463 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2464 return reinterpret_cast<block_iterator>(ref + 1);
2467 const_block_iterator block_begin() const {
2468 const Use::UserRef *ref =
2469 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2470 return reinterpret_cast<const_block_iterator>(ref + 1);
2473 block_iterator block_end() {
2474 return block_begin() + getNumOperands();
2477 const_block_iterator block_end() const {
2478 return block_begin() + getNumOperands();
2481 op_range incoming_values() { return operands(); }
2483 const_op_range incoming_values() const { return operands(); }
2485 /// getNumIncomingValues - Return the number of incoming edges
2487 unsigned getNumIncomingValues() const { return getNumOperands(); }
2489 /// getIncomingValue - Return incoming value number x
2491 Value *getIncomingValue(unsigned i) const {
2492 return getOperand(i);
2494 void setIncomingValue(unsigned i, Value *V) {
2495 assert(V && "PHI node got a null value!");
2496 assert(getType() == V->getType() &&
2497 "All operands to PHI node must be the same type as the PHI node!");
2500 static unsigned getOperandNumForIncomingValue(unsigned i) {
2503 static unsigned getIncomingValueNumForOperand(unsigned i) {
2507 /// getIncomingBlock - Return incoming basic block number @p i.
2509 BasicBlock *getIncomingBlock(unsigned i) const {
2510 return block_begin()[i];
2513 /// getIncomingBlock - Return incoming basic block corresponding
2514 /// to an operand of the PHI.
2516 BasicBlock *getIncomingBlock(const Use &U) const {
2517 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2518 return getIncomingBlock(unsigned(&U - op_begin()));
2521 /// getIncomingBlock - Return incoming basic block corresponding
2522 /// to value use iterator.
2524 BasicBlock *getIncomingBlock(Value::const_user_iterator I) const {
2525 return getIncomingBlock(I.getUse());
2528 void setIncomingBlock(unsigned i, BasicBlock *BB) {
2529 assert(BB && "PHI node got a null basic block!");
2530 block_begin()[i] = BB;
2533 /// addIncoming - Add an incoming value to the end of the PHI list
2535 void addIncoming(Value *V, BasicBlock *BB) {
2536 if (getNumOperands() == ReservedSpace)
2537 growOperands(); // Get more space!
2538 // Initialize some new operands.
2539 setNumHungOffUseOperands(getNumOperands() + 1);
2540 setIncomingValue(getNumOperands() - 1, V);
2541 setIncomingBlock(getNumOperands() - 1, BB);
2544 /// removeIncomingValue - Remove an incoming value. This is useful if a
2545 /// predecessor basic block is deleted. The value removed is returned.
2547 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2548 /// is true), the PHI node is destroyed and any uses of it are replaced with
2549 /// dummy values. The only time there should be zero incoming values to a PHI
2550 /// node is when the block is dead, so this strategy is sound.
2552 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2554 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2555 int Idx = getBasicBlockIndex(BB);
2556 assert(Idx >= 0 && "Invalid basic block argument to remove!");
2557 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2560 /// getBasicBlockIndex - Return the first index of the specified basic
2561 /// block in the value list for this PHI. Returns -1 if no instance.
2563 int getBasicBlockIndex(const BasicBlock *BB) const {
2564 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2565 if (block_begin()[i] == BB)
2570 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2571 int Idx = getBasicBlockIndex(BB);
2572 assert(Idx >= 0 && "Invalid basic block argument!");
2573 return getIncomingValue(Idx);
2576 /// hasConstantValue - If the specified PHI node always merges together the
2577 /// same value, return the value, otherwise return null.
2578 Value *hasConstantValue() const;
2580 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2581 static inline bool classof(const Instruction *I) {
2582 return I->getOpcode() == Instruction::PHI;
2584 static inline bool classof(const Value *V) {
2585 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2589 void growOperands();
2593 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2596 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
2598 //===----------------------------------------------------------------------===//
2599 // LandingPadInst Class
2600 //===----------------------------------------------------------------------===//
2602 //===---------------------------------------------------------------------------
2603 /// LandingPadInst - The landingpad instruction holds all of the information
2604 /// necessary to generate correct exception handling. The landingpad instruction
2605 /// cannot be moved from the top of a landing pad block, which itself is
2606 /// accessible only from the 'unwind' edge of an invoke. This uses the
2607 /// SubclassData field in Value to store whether or not the landingpad is a
2610 class LandingPadInst : public Instruction {
2611 /// ReservedSpace - The number of operands actually allocated. NumOperands is
2612 /// the number actually in use.
2613 unsigned ReservedSpace;
2614 LandingPadInst(const LandingPadInst &LP);
2617 enum ClauseType { Catch, Filter };
2620 void *operator new(size_t, unsigned) = delete;
2621 // Allocate space for exactly zero operands.
2622 void *operator new(size_t s) {
2623 return User::operator new(s);
2625 void growOperands(unsigned Size);
2626 void init(unsigned NumReservedValues, const Twine &NameStr);
2628 explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
2629 const Twine &NameStr, Instruction *InsertBefore);
2630 explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
2631 const Twine &NameStr, BasicBlock *InsertAtEnd);
2634 // Note: Instruction needs to be a friend here to call cloneImpl.
2635 friend class Instruction;
2636 LandingPadInst *cloneImpl() const;
2639 /// Constructors - NumReservedClauses is a hint for the number of incoming
2640 /// clauses that this landingpad will have (use 0 if you really have no idea).
2641 static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
2642 const Twine &NameStr = "",
2643 Instruction *InsertBefore = nullptr);
2644 static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
2645 const Twine &NameStr, BasicBlock *InsertAtEnd);
2647 /// Provide fast operand accessors
2648 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2650 /// isCleanup - Return 'true' if this landingpad instruction is a
2651 /// cleanup. I.e., it should be run when unwinding even if its landing pad
2652 /// doesn't catch the exception.
2653 bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2655 /// setCleanup - Indicate that this landingpad instruction is a cleanup.
2656 void setCleanup(bool V) {
2657 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2661 /// Add a catch or filter clause to the landing pad.
2662 void addClause(Constant *ClauseVal);
2664 /// Get the value of the clause at index Idx. Use isCatch/isFilter to
2665 /// determine what type of clause this is.
2666 Constant *getClause(unsigned Idx) const {
2667 return cast<Constant>(getOperandList()[Idx]);
2670 /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
2671 bool isCatch(unsigned Idx) const {
2672 return !isa<ArrayType>(getOperandList()[Idx]->getType());
2675 /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
2676 bool isFilter(unsigned Idx) const {
2677 return isa<ArrayType>(getOperandList()[Idx]->getType());
2680 /// getNumClauses - Get the number of clauses for this landing pad.
2681 unsigned getNumClauses() const { return getNumOperands(); }
2683 /// reserveClauses - Grow the size of the operand list to accommodate the new
2684 /// number of clauses.
2685 void reserveClauses(unsigned Size) { growOperands(Size); }
2687 // Methods for support type inquiry through isa, cast, and dyn_cast:
2688 static inline bool classof(const Instruction *I) {
2689 return I->getOpcode() == Instruction::LandingPad;
2691 static inline bool classof(const Value *V) {
2692 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2697 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<1> {
2700 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
2702 //===----------------------------------------------------------------------===//
2704 //===----------------------------------------------------------------------===//
2706 //===---------------------------------------------------------------------------
2707 /// ReturnInst - Return a value (possibly void), from a function. Execution
2708 /// does not continue in this function any longer.
2710 class ReturnInst : public TerminatorInst {
2711 ReturnInst(const ReturnInst &RI);
2714 // ReturnInst constructors:
2715 // ReturnInst() - 'ret void' instruction
2716 // ReturnInst( null) - 'ret void' instruction
2717 // ReturnInst(Value* X) - 'ret X' instruction
2718 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
2719 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
2720 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2721 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
2723 // NOTE: If the Value* passed is of type void then the constructor behaves as
2724 // if it was passed NULL.
2725 explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr,
2726 Instruction *InsertBefore = nullptr);
2727 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2728 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2731 // Note: Instruction needs to be a friend here to call cloneImpl.
2732 friend class Instruction;
2733 ReturnInst *cloneImpl() const;
2736 static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr,
2737 Instruction *InsertBefore = nullptr) {
2738 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2740 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2741 BasicBlock *InsertAtEnd) {
2742 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2744 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2745 return new(0) ReturnInst(C, InsertAtEnd);
2747 ~ReturnInst() override;
2749 /// Provide fast operand accessors
2750 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2752 /// Convenience accessor. Returns null if there is no return value.
2753 Value *getReturnValue() const {
2754 return getNumOperands() != 0 ? getOperand(0) : nullptr;
2757 unsigned getNumSuccessors() const { return 0; }
2759 // Methods for support type inquiry through isa, cast, and dyn_cast:
2760 static inline bool classof(const Instruction *I) {
2761 return (I->getOpcode() == Instruction::Ret);
2763 static inline bool classof(const Value *V) {
2764 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2768 BasicBlock *getSuccessorV(unsigned idx) const override;
2769 unsigned getNumSuccessorsV() const override;
2770 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2774 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2777 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2779 //===----------------------------------------------------------------------===//
2781 //===----------------------------------------------------------------------===//
2783 //===---------------------------------------------------------------------------
2784 /// BranchInst - Conditional or Unconditional Branch instruction.
2786 class BranchInst : public TerminatorInst {
2787 /// Ops list - Branches are strange. The operands are ordered:
2788 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2789 /// they don't have to check for cond/uncond branchness. These are mostly
2790 /// accessed relative from op_end().
2791 BranchInst(const BranchInst &BI);
2793 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2794 // BranchInst(BB *B) - 'br B'
2795 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2796 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2797 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2798 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2799 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2800 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr);
2801 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2802 Instruction *InsertBefore = nullptr);
2803 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2804 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2805 BasicBlock *InsertAtEnd);
2808 // Note: Instruction needs to be a friend here to call cloneImpl.
2809 friend class Instruction;
2810 BranchInst *cloneImpl() const;
2813 static BranchInst *Create(BasicBlock *IfTrue,
2814 Instruction *InsertBefore = nullptr) {
2815 return new(1) BranchInst(IfTrue, InsertBefore);
2817 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2818 Value *Cond, Instruction *InsertBefore = nullptr) {
2819 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2821 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2822 return new(1) BranchInst(IfTrue, InsertAtEnd);
2824 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2825 Value *Cond, BasicBlock *InsertAtEnd) {
2826 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2829 /// Transparently provide more efficient getOperand methods.
2830 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2832 bool isUnconditional() const { return getNumOperands() == 1; }
2833 bool isConditional() const { return getNumOperands() == 3; }
2835 Value *getCondition() const {
2836 assert(isConditional() && "Cannot get condition of an uncond branch!");
2840 void setCondition(Value *V) {
2841 assert(isConditional() && "Cannot set condition of unconditional branch!");
2845 unsigned getNumSuccessors() const { return 1+isConditional(); }
2847 BasicBlock *getSuccessor(unsigned i) const {
2848 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2849 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2852 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2853 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2854 *(&Op<-1>() - idx) = NewSucc;
2857 /// \brief Swap the successors of this branch instruction.
2859 /// Swaps the successors of the branch instruction. This also swaps any
2860 /// branch weight metadata associated with the instruction so that it
2861 /// continues to map correctly to each operand.
2862 void swapSuccessors();
2864 // Methods for support type inquiry through isa, cast, and dyn_cast:
2865 static inline bool classof(const Instruction *I) {
2866 return (I->getOpcode() == Instruction::Br);
2868 static inline bool classof(const Value *V) {
2869 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2873 BasicBlock *getSuccessorV(unsigned idx) const override;
2874 unsigned getNumSuccessorsV() const override;
2875 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2879 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2882 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2884 //===----------------------------------------------------------------------===//
2886 //===----------------------------------------------------------------------===//
2888 //===---------------------------------------------------------------------------
2889 /// SwitchInst - Multiway switch
2891 class SwitchInst : public TerminatorInst {
2892 void *operator new(size_t, unsigned) = delete;
2893 unsigned ReservedSpace;
2894 // Operand[0] = Value to switch on
2895 // Operand[1] = Default basic block destination
2896 // Operand[2n ] = Value to match
2897 // Operand[2n+1] = BasicBlock to go to on match
2898 SwitchInst(const SwitchInst &SI);
2899 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2900 void growOperands();
2901 // allocate space for exactly zero operands
2902 void *operator new(size_t s) {
2903 return User::operator new(s);
2905 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2906 /// switch on and a default destination. The number of additional cases can
2907 /// be specified here to make memory allocation more efficient. This
2908 /// constructor can also autoinsert before another instruction.
2909 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2910 Instruction *InsertBefore);
2912 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2913 /// switch on and a default destination. The number of additional cases can
2914 /// be specified here to make memory allocation more efficient. This
2915 /// constructor also autoinserts at the end of the specified BasicBlock.
2916 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2917 BasicBlock *InsertAtEnd);
2920 // Note: Instruction needs to be a friend here to call cloneImpl.
2921 friend class Instruction;
2922 SwitchInst *cloneImpl() const;
2926 static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
2928 template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy>
2929 class CaseIteratorT {
2935 typedef CaseIteratorT<SwitchInstTy, ConstantIntTy, BasicBlockTy> Self;
2937 /// Initializes case iterator for given SwitchInst and for given
2939 CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
2944 /// Initializes case iterator for given SwitchInst and for given
2945 /// TerminatorInst's successor index.
2946 static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
2947 assert(SuccessorIndex < SI->getNumSuccessors() &&
2948 "Successor index # out of range!");
2949 return SuccessorIndex != 0 ?
2950 Self(SI, SuccessorIndex - 1) :
2951 Self(SI, DefaultPseudoIndex);
2954 /// Resolves case value for current case.
2955 ConstantIntTy *getCaseValue() {
2956 assert(Index < SI->getNumCases() && "Index out the number of cases.");
2957 return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2));
2960 /// Resolves successor for current case.
2961 BasicBlockTy *getCaseSuccessor() {
2962 assert((Index < SI->getNumCases() ||
2963 Index == DefaultPseudoIndex) &&
2964 "Index out the number of cases.");
2965 return SI->getSuccessor(getSuccessorIndex());
2968 /// Returns number of current case.
2969 unsigned getCaseIndex() const { return Index; }
2971 /// Returns TerminatorInst's successor index for current case successor.
2972 unsigned getSuccessorIndex() const {
2973 assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
2974 "Index out the number of cases.");
2975 return Index != DefaultPseudoIndex ? Index + 1 : 0;
2979 // Check index correctness after increment.
2980 // Note: Index == getNumCases() means end().
2981 assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
2985 Self operator++(int) {
2991 // Check index correctness after decrement.
2992 // Note: Index == getNumCases() means end().
2993 // Also allow "-1" iterator here. That will became valid after ++.
2994 assert((Index == 0 || Index-1 <= SI->getNumCases()) &&
2995 "Index out the number of cases.");
2999 Self operator--(int) {
3004 bool operator==(const Self& RHS) const {
3005 assert(RHS.SI == SI && "Incompatible operators.");
3006 return RHS.Index == Index;
3008 bool operator!=(const Self& RHS) const {
3009 assert(RHS.SI == SI && "Incompatible operators.");
3010 return RHS.Index != Index;
3017 typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock>
3020 class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> {
3022 typedef CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> ParentTy;
3025 CaseIt(const ParentTy &Src) : ParentTy(Src) {}
3026 CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
3028 /// Sets the new value for current case.
3029 void setValue(ConstantInt *V) {
3030 assert(Index < SI->getNumCases() && "Index out the number of cases.");
3031 SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V));
3034 /// Sets the new successor for current case.
3035 void setSuccessor(BasicBlock *S) {
3036 SI->setSuccessor(getSuccessorIndex(), S);
3040 static SwitchInst *Create(Value *Value, BasicBlock *Default,
3042 Instruction *InsertBefore = nullptr) {
3043 return new SwitchInst(Value, Default, NumCases, InsertBefore);
3045 static SwitchInst *Create(Value *Value, BasicBlock *Default,
3046 unsigned NumCases, BasicBlock *InsertAtEnd) {
3047 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
3050 /// Provide fast operand accessors
3051 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3053 // Accessor Methods for Switch stmt
3054 Value *getCondition() const { return getOperand(0); }
3055 void setCondition(Value *V) { setOperand(0, V); }
3057 BasicBlock *getDefaultDest() const {
3058 return cast<BasicBlock>(getOperand(1));
3061 void setDefaultDest(BasicBlock *DefaultCase) {
3062 setOperand(1, reinterpret_cast<Value*>(DefaultCase));
3065 /// getNumCases - return the number of 'cases' in this switch instruction,
3066 /// except the default case
3067 unsigned getNumCases() const {
3068 return getNumOperands()/2 - 1;
3071 /// Returns a read/write iterator that points to the first
3072 /// case in SwitchInst.
3073 CaseIt case_begin() {
3074 return CaseIt(this, 0);
3076 /// Returns a read-only iterator that points to the first
3077 /// case in the SwitchInst.
3078 ConstCaseIt case_begin() const {
3079 return ConstCaseIt(this, 0);
3082 /// Returns a read/write iterator that points one past the last
3083 /// in the SwitchInst.
3085 return CaseIt(this, getNumCases());
3087 /// Returns a read-only iterator that points one past the last
3088 /// in the SwitchInst.
3089 ConstCaseIt case_end() const {
3090 return ConstCaseIt(this, getNumCases());
3093 /// cases - iteration adapter for range-for loops.
3094 iterator_range<CaseIt> cases() {
3095 return iterator_range<CaseIt>(case_begin(), case_end());
3098 /// cases - iteration adapter for range-for loops.
3099 iterator_range<ConstCaseIt> cases() const {
3100 return iterator_range<ConstCaseIt>(case_begin(), case_end());
3103 /// Returns an iterator that points to the default case.
3104 /// Note: this iterator allows to resolve successor only. Attempt
3105 /// to resolve case value causes an assertion.
3106 /// Also note, that increment and decrement also causes an assertion and
3107 /// makes iterator invalid.
3108 CaseIt case_default() {
3109 return CaseIt(this, DefaultPseudoIndex);
3111 ConstCaseIt case_default() const {
3112 return ConstCaseIt(this, DefaultPseudoIndex);
3115 /// findCaseValue - Search all of the case values for the specified constant.
3116 /// If it is explicitly handled, return the case iterator of it, otherwise
3117 /// return default case iterator to indicate
3118 /// that it is handled by the default handler.
3119 CaseIt findCaseValue(const ConstantInt *C) {
3120 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
3121 if (i.getCaseValue() == C)
3123 return case_default();
3125 ConstCaseIt findCaseValue(const ConstantInt *C) const {
3126 for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
3127 if (i.getCaseValue() == C)
3129 return case_default();
3132 /// findCaseDest - Finds the unique case value for a given successor. Returns
3133 /// null if the successor is not found, not unique, or is the default case.
3134 ConstantInt *findCaseDest(BasicBlock *BB) {
3135 if (BB == getDefaultDest()) return nullptr;
3137 ConstantInt *CI = nullptr;
3138 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
3139 if (i.getCaseSuccessor() == BB) {
3140 if (CI) return nullptr; // Multiple cases lead to BB.
3141 else CI = i.getCaseValue();
3147 /// addCase - Add an entry to the switch instruction...
3149 /// This action invalidates case_end(). Old case_end() iterator will
3150 /// point to the added case.
3151 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
3153 /// removeCase - This method removes the specified case and its successor
3154 /// from the switch instruction. Note that this operation may reorder the
3155 /// remaining cases at index idx and above.
3157 /// This action invalidates iterators for all cases following the one removed,
3158 /// including the case_end() iterator.
3159 void removeCase(CaseIt i);
3161 unsigned getNumSuccessors() const { return getNumOperands()/2; }
3162 BasicBlock *getSuccessor(unsigned idx) const {
3163 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
3164 return cast<BasicBlock>(getOperand(idx*2+1));
3166 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3167 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
3168 setOperand(idx * 2 + 1, NewSucc);
3171 // Methods for support type inquiry through isa, cast, and dyn_cast:
3172 static inline bool classof(const Instruction *I) {
3173 return I->getOpcode() == Instruction::Switch;
3175 static inline bool classof(const Value *V) {
3176 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3180 BasicBlock *getSuccessorV(unsigned idx) const override;
3181 unsigned getNumSuccessorsV() const override;
3182 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3186 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
3189 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
3191 //===----------------------------------------------------------------------===//
3192 // IndirectBrInst Class
3193 //===----------------------------------------------------------------------===//
3195 //===---------------------------------------------------------------------------
3196 /// IndirectBrInst - Indirect Branch Instruction.
3198 class IndirectBrInst : public TerminatorInst {
3199 void *operator new(size_t, unsigned) = delete;
3200 unsigned ReservedSpace;
3201 // Operand[0] = Value to switch on
3202 // Operand[1] = Default basic block destination
3203 // Operand[2n ] = Value to match
3204 // Operand[2n+1] = BasicBlock to go to on match
3205 IndirectBrInst(const IndirectBrInst &IBI);
3206 void init(Value *Address, unsigned NumDests);
3207 void growOperands();
3208 // allocate space for exactly zero operands
3209 void *operator new(size_t s) {
3210 return User::operator new(s);
3212 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
3213 /// Address to jump to. The number of expected destinations can be specified
3214 /// here to make memory allocation more efficient. This constructor can also
3215 /// autoinsert before another instruction.
3216 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
3218 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
3219 /// Address to jump to. The number of expected destinations can be specified
3220 /// here to make memory allocation more efficient. This constructor also
3221 /// autoinserts at the end of the specified BasicBlock.
3222 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
3225 // Note: Instruction needs to be a friend here to call cloneImpl.
3226 friend class Instruction;
3227 IndirectBrInst *cloneImpl() const;
3230 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
3231 Instruction *InsertBefore = nullptr) {
3232 return new IndirectBrInst(Address, NumDests, InsertBefore);
3234 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
3235 BasicBlock *InsertAtEnd) {
3236 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
3239 /// Provide fast operand accessors.
3240 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3242 // Accessor Methods for IndirectBrInst instruction.
3243 Value *getAddress() { return getOperand(0); }
3244 const Value *getAddress() const { return getOperand(0); }
3245 void setAddress(Value *V) { setOperand(0, V); }
3247 /// getNumDestinations - return the number of possible destinations in this
3248 /// indirectbr instruction.
3249 unsigned getNumDestinations() const { return getNumOperands()-1; }
3251 /// getDestination - Return the specified destination.
3252 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
3253 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
3255 /// addDestination - Add a destination.
3257 void addDestination(BasicBlock *Dest);
3259 /// removeDestination - This method removes the specified successor from the
3260 /// indirectbr instruction.
3261 void removeDestination(unsigned i);
3263 unsigned getNumSuccessors() const { return getNumOperands()-1; }
3264 BasicBlock *getSuccessor(unsigned i) const {
3265 return cast<BasicBlock>(getOperand(i+1));
3267 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
3268 setOperand(i + 1, NewSucc);
3271 // Methods for support type inquiry through isa, cast, and dyn_cast:
3272 static inline bool classof(const Instruction *I) {
3273 return I->getOpcode() == Instruction::IndirectBr;
3275 static inline bool classof(const Value *V) {
3276 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3280 BasicBlock *getSuccessorV(unsigned idx) const override;
3281 unsigned getNumSuccessorsV() const override;
3282 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3286 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
3289 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
3291 //===----------------------------------------------------------------------===//
3293 //===----------------------------------------------------------------------===//
3295 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
3296 /// calling convention of the call.
3298 class InvokeInst : public TerminatorInst,
3299 public OperandBundleUser<InvokeInst, User::op_iterator> {
3300 AttributeSet AttributeList;
3302 InvokeInst(const InvokeInst &BI);
3303 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3304 ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
3305 const Twine &NameStr) {
3306 init(cast<FunctionType>(
3307 cast<PointerType>(Func->getType())->getElementType()),
3308 Func, IfNormal, IfException, Args, Bundles, NameStr);
3310 void init(FunctionType *FTy, Value *Func, BasicBlock *IfNormal,
3311 BasicBlock *IfException, ArrayRef<Value *> Args,
3312 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
3314 /// Construct an InvokeInst given a range of arguments.
3316 /// \brief Construct an InvokeInst from a range of arguments
3317 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3318 ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
3319 unsigned Values, const Twine &NameStr,
3320 Instruction *InsertBefore)
3321 : InvokeInst(cast<FunctionType>(
3322 cast<PointerType>(Func->getType())->getElementType()),
3323 Func, IfNormal, IfException, Args, Bundles, Values, NameStr,
3326 inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3327 BasicBlock *IfException, ArrayRef<Value *> Args,
3328 ArrayRef<OperandBundleDef> Bundles, unsigned Values,
3329 const Twine &NameStr, Instruction *InsertBefore);
3330 /// Construct an InvokeInst given a range of arguments.
3332 /// \brief Construct an InvokeInst from a range of arguments
3333 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3334 ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
3335 unsigned Values, const Twine &NameStr,
3336 BasicBlock *InsertAtEnd);
3338 friend class OperandBundleUser<InvokeInst, User::op_iterator>;
3339 bool hasDescriptor() const { return HasDescriptor; }
3342 // Note: Instruction needs to be a friend here to call cloneImpl.
3343 friend class Instruction;
3344 InvokeInst *cloneImpl() const;
3347 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3348 BasicBlock *IfException, ArrayRef<Value *> Args,
3349 const Twine &NameStr,
3350 Instruction *InsertBefore = nullptr) {
3351 return Create(cast<FunctionType>(
3352 cast<PointerType>(Func->getType())->getElementType()),
3353 Func, IfNormal, IfException, Args, None, NameStr,
3356 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3357 BasicBlock *IfException, ArrayRef<Value *> Args,
3358 ArrayRef<OperandBundleDef> Bundles = None,
3359 const Twine &NameStr = "",
3360 Instruction *InsertBefore = nullptr) {
3361 return Create(cast<FunctionType>(
3362 cast<PointerType>(Func->getType())->getElementType()),
3363 Func, IfNormal, IfException, Args, Bundles, NameStr,
3366 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3367 BasicBlock *IfException, ArrayRef<Value *> Args,
3368 const Twine &NameStr,
3369 Instruction *InsertBefore = nullptr) {
3370 unsigned Values = unsigned(Args.size()) + 3;
3371 return new (Values) InvokeInst(Ty, Func, IfNormal, IfException, Args, None,
3372 Values, NameStr, InsertBefore);
3374 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3375 BasicBlock *IfException, ArrayRef<Value *> Args,
3376 ArrayRef<OperandBundleDef> Bundles = None,
3377 const Twine &NameStr = "",
3378 Instruction *InsertBefore = nullptr) {
3379 unsigned Values = unsigned(Args.size()) + CountBundleInputs(Bundles) + 3;
3380 unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
3382 return new (Values, DescriptorBytes)
3383 InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, Values,
3384 NameStr, InsertBefore);
3386 static InvokeInst *Create(Value *Func,
3387 BasicBlock *IfNormal, BasicBlock *IfException,
3388 ArrayRef<Value *> Args, const Twine &NameStr,
3389 BasicBlock *InsertAtEnd) {
3390 unsigned Values = unsigned(Args.size()) + 3;
3391 return new (Values) InvokeInst(Func, IfNormal, IfException, Args, None,
3392 Values, NameStr, InsertAtEnd);
3394 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3395 BasicBlock *IfException, ArrayRef<Value *> Args,
3396 ArrayRef<OperandBundleDef> Bundles,
3397 const Twine &NameStr, BasicBlock *InsertAtEnd) {
3398 unsigned Values = unsigned(Args.size()) + CountBundleInputs(Bundles) + 3;
3399 unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
3401 return new (Values, DescriptorBytes)
3402 InvokeInst(Func, IfNormal, IfException, Args, Bundles, Values, NameStr,
3406 /// Provide fast operand accessors
3407 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3409 FunctionType *getFunctionType() const { return FTy; }
3411 void mutateFunctionType(FunctionType *FTy) {
3412 mutateType(FTy->getReturnType());
3416 /// getNumArgOperands - Return the number of invoke arguments.
3418 unsigned getNumArgOperands() const {
3419 return getNumOperands() - getNumTotalBundleOperands() - 3;
3422 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
3424 Value *getArgOperand(unsigned i) const {
3425 assert(i < getNumArgOperands() && "Out of bounds!");
3426 return getOperand(i);
3428 void setArgOperand(unsigned i, Value *v) {
3429 assert(i < getNumArgOperands() && "Out of bounds!");
3433 /// arg_operands - iteration adapter for range-for loops.
3434 iterator_range<op_iterator> arg_operands() {
3435 return iterator_range<op_iterator>(
3436 op_begin(), op_end() - getNumTotalBundleOperands() - 3);
3439 /// arg_operands - iteration adapter for range-for loops.
3440 iterator_range<const_op_iterator> arg_operands() const {
3441 return iterator_range<const_op_iterator>(
3442 op_begin(), op_end() - getNumTotalBundleOperands() - 3);
3445 /// \brief Wrappers for getting the \c Use of a invoke argument.
3446 const Use &getArgOperandUse(unsigned i) const {
3447 assert(i < getNumArgOperands() && "Out of bounds!");
3448 return getOperandUse(i);
3450 Use &getArgOperandUse(unsigned i) {
3451 assert(i < getNumArgOperands() && "Out of bounds!");
3452 return getOperandUse(i);
3455 /// getCallingConv/setCallingConv - Get or set the calling convention of this
3457 CallingConv::ID getCallingConv() const {
3458 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
3460 void setCallingConv(CallingConv::ID CC) {
3461 auto ID = static_cast<unsigned>(CC);
3462 assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention");
3463 setInstructionSubclassData(ID);
3466 /// getAttributes - Return the parameter attributes for this invoke.
3468 const AttributeSet &getAttributes() const { return AttributeList; }
3470 /// setAttributes - Set the parameter attributes for this invoke.
3472 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
3474 /// addAttribute - adds the attribute to the list of attributes.
3475 void addAttribute(unsigned i, Attribute::AttrKind attr);
3477 /// removeAttribute - removes the attribute from the list of attributes.
3478 void removeAttribute(unsigned i, Attribute attr);
3480 /// \brief adds the dereferenceable attribute to the list of attributes.
3481 void addDereferenceableAttr(unsigned i, uint64_t Bytes);
3483 /// \brief adds the dereferenceable_or_null attribute to the list of
3485 void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
3487 /// \brief Determine whether this call has the given attribute.
3488 bool hasFnAttr(Attribute::AttrKind A) const {
3489 assert(A != Attribute::NoBuiltin &&
3490 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
3491 return hasFnAttrImpl(A);
3494 /// \brief Determine whether the call or the callee has the given attributes.
3495 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
3497 /// \brief Return true if the data operand at index \p i has the attribute \p
3500 /// Data operands include invoke arguments and values used in operand bundles,
3501 /// but does not include the invokee operand, or the two successor blocks.
3502 /// This routine dispatches to the underlying AttributeList or the
3503 /// OperandBundleUser as appropriate.
3505 /// The index \p i is interpreted as
3507 /// \p i == Attribute::ReturnIndex -> the return value
3508 /// \p i in [1, arg_size + 1) -> argument number (\p i - 1)
3509 /// \p i in [arg_size + 1, data_operand_size + 1) -> bundle operand at index
3510 /// (\p i - 1) in the operand list.
3511 bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind A) const;
3513 /// \brief Extract the alignment for a call or parameter (0=unknown).
3514 unsigned getParamAlignment(unsigned i) const {
3515 return AttributeList.getParamAlignment(i);
3518 /// \brief Extract the number of dereferenceable bytes for a call or
3519 /// parameter (0=unknown).
3520 uint64_t getDereferenceableBytes(unsigned i) const {
3521 return AttributeList.getDereferenceableBytes(i);
3524 /// \brief Extract the number of dereferenceable_or_null bytes for a call or
3525 /// parameter (0=unknown).
3526 uint64_t getDereferenceableOrNullBytes(unsigned i) const {
3527 return AttributeList.getDereferenceableOrNullBytes(i);
3530 /// @brief Determine if the parameter or return value is marked with NoAlias
3532 /// @param n The parameter to check. 1 is the first parameter, 0 is the return
3533 bool doesNotAlias(unsigned n) const {
3534 return AttributeList.hasAttribute(n, Attribute::NoAlias);
3537 /// \brief Return true if the call should not be treated as a call to a
3539 bool isNoBuiltin() const {
3540 // We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have
3541 // to check it by hand.
3542 return hasFnAttrImpl(Attribute::NoBuiltin) &&
3543 !hasFnAttrImpl(Attribute::Builtin);
3546 /// \brief Return true if the call should not be inlined.
3547 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
3548 void setIsNoInline() {
3549 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
3552 /// \brief Determine if the call does not access memory.
3553 bool doesNotAccessMemory() const {
3554 return hasFnAttr(Attribute::ReadNone);
3556 void setDoesNotAccessMemory() {
3557 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
3560 /// \brief Determine if the call does not access or only reads memory.
3561 bool onlyReadsMemory() const {
3562 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
3564 void setOnlyReadsMemory() {
3565 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
3568 /// @brief Determine if the call access memmory only using it's pointer
3570 bool onlyAccessesArgMemory() const {
3571 return hasFnAttr(Attribute::ArgMemOnly);
3573 void setOnlyAccessesArgMemory() {
3574 addAttribute(AttributeSet::FunctionIndex, Attribute::ArgMemOnly);
3577 /// \brief Determine if the call cannot return.
3578 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
3579 void setDoesNotReturn() {
3580 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
3583 /// \brief Determine if the call cannot unwind.
3584 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
3585 void setDoesNotThrow() {
3586 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
3589 /// \brief Determine if the invoke cannot be duplicated.
3590 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
3591 void setCannotDuplicate() {
3592 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
3595 /// \brief Determine if the call returns a structure through first
3596 /// pointer argument.
3597 bool hasStructRetAttr() const {
3598 // Be friendly and also check the callee.
3599 return paramHasAttr(1, Attribute::StructRet);
3602 /// \brief Determine if any call argument is an aggregate passed by value.
3603 bool hasByValArgument() const {
3604 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
3607 /// getCalledFunction - Return the function called, or null if this is an
3608 /// indirect function invocation.
3610 Function *getCalledFunction() const {
3611 return dyn_cast<Function>(Op<-3>());
3614 /// getCalledValue - Get a pointer to the function that is invoked by this
3616 const Value *getCalledValue() const { return Op<-3>(); }
3617 Value *getCalledValue() { return Op<-3>(); }
3619 /// setCalledFunction - Set the function called.
3620 void setCalledFunction(Value* Fn) {
3622 cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()),
3625 void setCalledFunction(FunctionType *FTy, Value *Fn) {
3627 assert(FTy == cast<FunctionType>(
3628 cast<PointerType>(Fn->getType())->getElementType()));
3632 // get*Dest - Return the destination basic blocks...
3633 BasicBlock *getNormalDest() const {
3634 return cast<BasicBlock>(Op<-2>());
3636 BasicBlock *getUnwindDest() const {
3637 return cast<BasicBlock>(Op<-1>());
3639 void setNormalDest(BasicBlock *B) {
3640 Op<-2>() = reinterpret_cast<Value*>(B);
3642 void setUnwindDest(BasicBlock *B) {
3643 Op<-1>() = reinterpret_cast<Value*>(B);
3646 /// getLandingPadInst - Get the landingpad instruction from the landing pad
3647 /// block (the unwind destination).
3648 LandingPadInst *getLandingPadInst() const;
3650 BasicBlock *getSuccessor(unsigned i) const {
3651 assert(i < 2 && "Successor # out of range for invoke!");
3652 return i == 0 ? getNormalDest() : getUnwindDest();
3655 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3656 assert(idx < 2 && "Successor # out of range for invoke!");
3657 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
3660 unsigned getNumSuccessors() const { return 2; }
3662 // Methods for support type inquiry through isa, cast, and dyn_cast:
3663 static inline bool classof(const Instruction *I) {
3664 return (I->getOpcode() == Instruction::Invoke);
3666 static inline bool classof(const Value *V) {
3667 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3671 BasicBlock *getSuccessorV(unsigned idx) const override;
3672 unsigned getNumSuccessorsV() const override;
3673 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3675 bool hasFnAttrImpl(Attribute::AttrKind A) const;
3677 // Shadow Instruction::setInstructionSubclassData with a private forwarding
3678 // method so that subclasses cannot accidentally use it.
3679 void setInstructionSubclassData(unsigned short D) {
3680 Instruction::setInstructionSubclassData(D);
3685 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
3688 InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3689 BasicBlock *IfException, ArrayRef<Value *> Args,
3690 ArrayRef<OperandBundleDef> Bundles, unsigned Values,
3691 const Twine &NameStr, Instruction *InsertBefore)
3692 : TerminatorInst(Ty->getReturnType(), Instruction::Invoke,
3693 OperandTraits<InvokeInst>::op_end(this) - Values, Values,
3695 init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
3697 InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
3698 BasicBlock *IfException, ArrayRef<Value *> Args,
3699 ArrayRef<OperandBundleDef> Bundles, unsigned Values,
3700 const Twine &NameStr, BasicBlock *InsertAtEnd)
3702 cast<FunctionType>(cast<PointerType>(Func->getType())
3703 ->getElementType())->getReturnType(),
3704 Instruction::Invoke, OperandTraits<InvokeInst>::op_end(this) - Values,
3705 Values, InsertAtEnd) {
3706 init(Func, IfNormal, IfException, Args, Bundles, NameStr);
3709 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
3711 //===----------------------------------------------------------------------===//
3713 //===----------------------------------------------------------------------===//
3715 //===---------------------------------------------------------------------------
3716 /// ResumeInst - Resume the propagation of an exception.
3718 class ResumeInst : public TerminatorInst {
3719 ResumeInst(const ResumeInst &RI);
3721 explicit ResumeInst(Value *Exn, Instruction *InsertBefore=nullptr);
3722 ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
3725 // Note: Instruction needs to be a friend here to call cloneImpl.
3726 friend class Instruction;
3727 ResumeInst *cloneImpl() const;
3730 static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = nullptr) {
3731 return new(1) ResumeInst(Exn, InsertBefore);
3733 static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
3734 return new(1) ResumeInst(Exn, InsertAtEnd);
3737 /// Provide fast operand accessors
3738 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3740 /// Convenience accessor.
3741 Value *getValue() const { return Op<0>(); }
3743 unsigned getNumSuccessors() const { return 0; }
3745 // Methods for support type inquiry through isa, cast, and dyn_cast:
3746 static inline bool classof(const Instruction *I) {
3747 return I->getOpcode() == Instruction::Resume;
3749 static inline bool classof(const Value *V) {
3750 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3754 BasicBlock *getSuccessorV(unsigned idx) const override;
3755 unsigned getNumSuccessorsV() const override;
3756 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3760 struct OperandTraits<ResumeInst> :
3761 public FixedNumOperandTraits<ResumeInst, 1> {
3764 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
3766 //===----------------------------------------------------------------------===//
3767 // CatchEndPadInst Class
3768 //===----------------------------------------------------------------------===//
3770 class CatchEndPadInst : public TerminatorInst {
3772 CatchEndPadInst(const CatchEndPadInst &RI);
3774 void init(BasicBlock *UnwindBB);
3775 CatchEndPadInst(LLVMContext &C, BasicBlock *UnwindBB, unsigned Values,
3776 Instruction *InsertBefore = nullptr);
3777 CatchEndPadInst(LLVMContext &C, BasicBlock *UnwindBB, unsigned Values,
3778 BasicBlock *InsertAtEnd);
3781 // Note: Instruction needs to be a friend here to call cloneImpl.
3782 friend class Instruction;
3783 CatchEndPadInst *cloneImpl() const;
3786 static CatchEndPadInst *Create(LLVMContext &C, BasicBlock *UnwindBB = nullptr,
3787 Instruction *InsertBefore = nullptr) {
3788 unsigned Values = UnwindBB ? 1 : 0;
3789 return new (Values) CatchEndPadInst(C, UnwindBB, Values, InsertBefore);
3791 static CatchEndPadInst *Create(LLVMContext &C, BasicBlock *UnwindBB,
3792 BasicBlock *InsertAtEnd) {
3793 unsigned Values = UnwindBB ? 1 : 0;
3794 return new (Values) CatchEndPadInst(C, UnwindBB, Values, InsertAtEnd);
3797 /// Provide fast operand accessors
3798 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3800 bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
3801 bool unwindsToCaller() const { return !hasUnwindDest(); }
3803 /// Convenience accessor. Returns null if there is no return value.
3804 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
3806 BasicBlock *getUnwindDest() const {
3807 return hasUnwindDest() ? cast<BasicBlock>(Op<-1>()) : nullptr;
3809 void setUnwindDest(BasicBlock *NewDest) {
3814 // Methods for support type inquiry through isa, cast, and dyn_cast:
3815 static inline bool classof(const Instruction *I) {
3816 return (I->getOpcode() == Instruction::CatchEndPad);
3818 static inline bool classof(const Value *V) {
3819 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3823 BasicBlock *getSuccessorV(unsigned Idx) const override;
3824 unsigned getNumSuccessorsV() const override;
3825 void setSuccessorV(unsigned Idx, BasicBlock *B) override;
3827 // Shadow Instruction::setInstructionSubclassData with a private forwarding
3828 // method so that subclasses cannot accidentally use it.
3829 void setInstructionSubclassData(unsigned short D) {
3830 Instruction::setInstructionSubclassData(D);
3835 struct OperandTraits<CatchEndPadInst>
3836 : public VariadicOperandTraits<CatchEndPadInst> {};
3838 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchEndPadInst, Value)
3840 //===----------------------------------------------------------------------===//
3841 // CatchPadInst Class
3842 //===----------------------------------------------------------------------===//
3844 class CatchPadInst : public TerminatorInst {
3846 void init(BasicBlock *IfNormal, BasicBlock *IfException,
3847 ArrayRef<Value *> Args, const Twine &NameStr);
3849 CatchPadInst(const CatchPadInst &CPI);
3851 explicit CatchPadInst(BasicBlock *IfNormal, BasicBlock *IfException,
3852 ArrayRef<Value *> Args, unsigned Values,
3853 const Twine &NameStr, Instruction *InsertBefore);
3854 explicit CatchPadInst(BasicBlock *IfNormal, BasicBlock *IfException,
3855 ArrayRef<Value *> Args, unsigned Values,
3856 const Twine &NameStr, BasicBlock *InsertAtEnd);
3859 // Note: Instruction needs to be a friend here to call cloneImpl.
3860 friend class Instruction;
3861 CatchPadInst *cloneImpl() const;
3864 static CatchPadInst *Create(BasicBlock *IfNormal, BasicBlock *IfException,
3865 ArrayRef<Value *> Args, const Twine &NameStr = "",
3866 Instruction *InsertBefore = nullptr) {
3867 unsigned Values = unsigned(Args.size()) + 2;
3868 return new (Values) CatchPadInst(IfNormal, IfException, Args, Values,
3869 NameStr, InsertBefore);
3871 static CatchPadInst *Create(BasicBlock *IfNormal, BasicBlock *IfException,
3872 ArrayRef<Value *> Args, const Twine &NameStr,
3873 BasicBlock *InsertAtEnd) {
3874 unsigned Values = unsigned(Args.size()) + 2;
3876 CatchPadInst(IfNormal, IfException, Args, Values, NameStr, InsertAtEnd);
3879 /// Provide fast operand accessors
3880 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3882 /// getNumArgOperands - Return the number of catchpad arguments.
3884 unsigned getNumArgOperands() const { return getNumOperands() - 2; }
3886 /// getArgOperand/setArgOperand - Return/set the i-th catchpad argument.
3888 Value *getArgOperand(unsigned i) const { return getOperand(i); }
3889 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
3891 /// arg_operands - iteration adapter for range-for loops.
3892 iterator_range<op_iterator> arg_operands() {
3893 return iterator_range<op_iterator>(op_begin(), op_end() - 2);
3896 /// arg_operands - iteration adapter for range-for loops.
3897 iterator_range<const_op_iterator> arg_operands() const {
3898 return iterator_range<const_op_iterator>(op_begin(), op_end() - 2);
3901 /// \brief Wrappers for getting the \c Use of a catchpad argument.
3902 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
3903 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
3905 // get*Dest - Return the destination basic blocks...
3906 BasicBlock *getNormalDest() const { return cast<BasicBlock>(Op<-2>()); }
3907 BasicBlock *getUnwindDest() const { return cast<BasicBlock>(Op<-1>()); }
3908 void setNormalDest(BasicBlock *B) { Op<-2>() = B; }
3909 void setUnwindDest(BasicBlock *B) { Op<-1>() = B; }
3911 BasicBlock *getSuccessor(unsigned i) const {
3912 assert(i < 2 && "Successor # out of range for catchpad!");
3913 return i == 0 ? getNormalDest() : getUnwindDest();
3916 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3917 assert(idx < 2 && "Successor # out of range for catchpad!");
3918 *(&Op<-2>() + idx) = NewSucc;
3921 unsigned getNumSuccessors() const { return 2; }
3923 // Methods for support type inquiry through isa, cast, and dyn_cast:
3924 static inline bool classof(const Instruction *I) {
3925 return I->getOpcode() == Instruction::CatchPad;
3927 static inline bool classof(const Value *V) {
3928 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3932 BasicBlock *getSuccessorV(unsigned idx) const override;
3933 unsigned getNumSuccessorsV() const override;
3934 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3938 struct OperandTraits<CatchPadInst>
3939 : public VariadicOperandTraits<CatchPadInst, /*MINARITY=*/2> {};
3941 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchPadInst, Value)
3943 //===----------------------------------------------------------------------===//
3944 // TerminatePadInst Class
3945 //===----------------------------------------------------------------------===//
3947 class TerminatePadInst : public TerminatorInst {
3949 void init(BasicBlock *BB, ArrayRef<Value *> Args);
3951 TerminatePadInst(const TerminatePadInst &TPI);
3953 explicit TerminatePadInst(LLVMContext &C, BasicBlock *BB,
3954 ArrayRef<Value *> Args, unsigned Values,
3955 Instruction *InsertBefore);
3956 explicit TerminatePadInst(LLVMContext &C, BasicBlock *BB,
3957 ArrayRef<Value *> Args, unsigned Values,
3958 BasicBlock *InsertAtEnd);
3961 // Note: Instruction needs to be a friend here to call cloneImpl.
3962 friend class Instruction;
3963 TerminatePadInst *cloneImpl() const;
3966 static TerminatePadInst *Create(LLVMContext &C, BasicBlock *BB = nullptr,
3967 ArrayRef<Value *> Args = None,
3968 Instruction *InsertBefore = nullptr) {
3969 unsigned Values = unsigned(Args.size());
3972 return new (Values) TerminatePadInst(C, BB, Args, Values, InsertBefore);
3974 static TerminatePadInst *Create(LLVMContext &C, BasicBlock *BB,
3975 ArrayRef<Value *> Args,
3976 BasicBlock *InsertAtEnd) {
3977 unsigned Values = unsigned(Args.size());
3980 return new (Values) TerminatePadInst(C, BB, Args, Values, InsertAtEnd);
3983 /// Provide fast operand accessors
3984 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3986 bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
3987 bool unwindsToCaller() const { return !hasUnwindDest(); }
3989 /// getNumArgOperands - Return the number of terminatepad arguments.
3991 unsigned getNumArgOperands() const {
3992 unsigned NumOperands = getNumOperands();
3993 if (hasUnwindDest())
3994 return NumOperands - 1;
3998 /// getArgOperand/setArgOperand - Return/set the i-th terminatepad argument.
4000 Value *getArgOperand(unsigned i) const { return getOperand(i); }
4001 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
4003 const_op_iterator arg_end() const {
4004 if (hasUnwindDest())
4005 return op_end() - 1;
4009 op_iterator arg_end() {
4010 if (hasUnwindDest())
4011 return op_end() - 1;
4015 /// arg_operands - iteration adapter for range-for loops.
4016 iterator_range<op_iterator> arg_operands() {
4017 return iterator_range<op_iterator>(op_begin(), arg_end());
4020 /// arg_operands - iteration adapter for range-for loops.
4021 iterator_range<const_op_iterator> arg_operands() const {
4022 return iterator_range<const_op_iterator>(op_begin(), arg_end());
4025 /// \brief Wrappers for getting the \c Use of a terminatepad argument.
4026 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
4027 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
4029 // get*Dest - Return the destination basic blocks...
4030 BasicBlock *getUnwindDest() const {
4031 if (!hasUnwindDest())
4033 return cast<BasicBlock>(Op<-1>());
4035 void setUnwindDest(BasicBlock *B) {
4036 assert(B && hasUnwindDest());
4040 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
4042 // Methods for support type inquiry through isa, cast, and dyn_cast:
4043 static inline bool classof(const Instruction *I) {
4044 return I->getOpcode() == Instruction::TerminatePad;
4046 static inline bool classof(const Value *V) {
4047 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4051 BasicBlock *getSuccessorV(unsigned idx) const override;
4052 unsigned getNumSuccessorsV() const override;
4053 void setSuccessorV(unsigned idx, BasicBlock *B) override;
4055 // Shadow Instruction::setInstructionSubclassData with a private forwarding
4056 // method so that subclasses cannot accidentally use it.
4057 void setInstructionSubclassData(unsigned short D) {
4058 Instruction::setInstructionSubclassData(D);
4063 struct OperandTraits<TerminatePadInst>
4064 : public VariadicOperandTraits<TerminatePadInst, /*MINARITY=*/1> {};
4066 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(TerminatePadInst, Value)
4068 //===----------------------------------------------------------------------===//
4069 // CleanupPadInst Class
4070 //===----------------------------------------------------------------------===//
4072 class CleanupPadInst : public Instruction {
4074 void init(ArrayRef<Value *> Args, const Twine &NameStr);
4076 CleanupPadInst(const CleanupPadInst &CPI);
4078 explicit CleanupPadInst(LLVMContext &C, ArrayRef<Value *> Args,
4079 const Twine &NameStr, Instruction *InsertBefore);
4080 explicit CleanupPadInst(LLVMContext &C, ArrayRef<Value *> Args,
4081 const Twine &NameStr, BasicBlock *InsertAtEnd);
4084 // Note: Instruction needs to be a friend here to call cloneImpl.
4085 friend class Instruction;
4086 CleanupPadInst *cloneImpl() const;
4089 static CleanupPadInst *Create(LLVMContext &C, ArrayRef<Value *> Args,
4090 const Twine &NameStr = "",
4091 Instruction *InsertBefore = nullptr) {
4092 return new (Args.size()) CleanupPadInst(C, Args, NameStr, InsertBefore);
4094 static CleanupPadInst *Create(LLVMContext &C, ArrayRef<Value *> Args,
4095 const Twine &NameStr, BasicBlock *InsertAtEnd) {
4096 return new (Args.size()) CleanupPadInst(C, Args, NameStr, InsertAtEnd);
4099 /// Provide fast operand accessors
4100 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
4102 // Methods for support type inquiry through isa, cast, and dyn_cast:
4103 static inline bool classof(const Instruction *I) {
4104 return I->getOpcode() == Instruction::CleanupPad;
4106 static inline bool classof(const Value *V) {
4107 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4112 struct OperandTraits<CleanupPadInst>
4113 : public VariadicOperandTraits<CleanupPadInst, /*MINARITY=*/0> {};
4115 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CleanupPadInst, Value)
4117 //===----------------------------------------------------------------------===//
4118 // CatchReturnInst Class
4119 //===----------------------------------------------------------------------===//
4121 class CatchReturnInst : public TerminatorInst {
4122 CatchReturnInst(const CatchReturnInst &RI);
4124 void init(CatchPadInst *CatchPad, BasicBlock *BB);
4125 CatchReturnInst(CatchPadInst *CatchPad, BasicBlock *BB,
4126 Instruction *InsertBefore);
4127 CatchReturnInst(CatchPadInst *CatchPad, BasicBlock *BB,
4128 BasicBlock *InsertAtEnd);
4131 // Note: Instruction needs to be a friend here to call cloneImpl.
4132 friend class Instruction;
4133 CatchReturnInst *cloneImpl() const;
4136 static CatchReturnInst *Create(CatchPadInst *CatchPad, BasicBlock *BB,
4137 Instruction *InsertBefore = nullptr) {
4140 return new (2) CatchReturnInst(CatchPad, BB, InsertBefore);
4142 static CatchReturnInst *Create(CatchPadInst *CatchPad, BasicBlock *BB,
4143 BasicBlock *InsertAtEnd) {
4146 return new (2) CatchReturnInst(CatchPad, BB, InsertAtEnd);
4149 /// Provide fast operand accessors
4150 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
4152 /// Convenience accessors.
4153 CatchPadInst *getCatchPad() const { return cast<CatchPadInst>(Op<0>()); }
4154 void setCatchPad(CatchPadInst *CatchPad) {
4159 BasicBlock *getSuccessor() const { return cast<BasicBlock>(Op<1>()); }
4160 void setSuccessor(BasicBlock *NewSucc) {
4164 unsigned getNumSuccessors() const { return 1; }
4166 // Methods for support type inquiry through isa, cast, and dyn_cast:
4167 static inline bool classof(const Instruction *I) {
4168 return (I->getOpcode() == Instruction::CatchRet);
4170 static inline bool classof(const Value *V) {
4171 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4175 BasicBlock *getSuccessorV(unsigned Idx) const override;
4176 unsigned getNumSuccessorsV() const override;
4177 void setSuccessorV(unsigned Idx, BasicBlock *B) override;
4181 struct OperandTraits<CatchReturnInst>
4182 : public FixedNumOperandTraits<CatchReturnInst, 2> {};
4184 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchReturnInst, Value)
4186 //===----------------------------------------------------------------------===//
4187 // CleanupEndPadInst Class
4188 //===----------------------------------------------------------------------===//
4190 class CleanupEndPadInst : public TerminatorInst {
4192 CleanupEndPadInst(const CleanupEndPadInst &CEPI);
4194 void init(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB);
4195 CleanupEndPadInst(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB,
4196 unsigned Values, Instruction *InsertBefore = nullptr);
4197 CleanupEndPadInst(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB,
4198 unsigned Values, BasicBlock *InsertAtEnd);
4201 // Note: Instruction needs to be a friend here to call cloneImpl.
4202 friend class Instruction;
4203 CleanupEndPadInst *cloneImpl() const;
4206 static CleanupEndPadInst *Create(CleanupPadInst *CleanupPad,
4207 BasicBlock *UnwindBB = nullptr,
4208 Instruction *InsertBefore = nullptr) {
4209 unsigned Values = UnwindBB ? 2 : 1;
4211 CleanupEndPadInst(CleanupPad, UnwindBB, Values, InsertBefore);
4213 static CleanupEndPadInst *Create(CleanupPadInst *CleanupPad,
4214 BasicBlock *UnwindBB,
4215 BasicBlock *InsertAtEnd) {
4216 unsigned Values = UnwindBB ? 2 : 1;
4218 CleanupEndPadInst(CleanupPad, UnwindBB, Values, InsertAtEnd);
4221 /// Provide fast operand accessors
4222 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
4224 bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
4225 bool unwindsToCaller() const { return !hasUnwindDest(); }
4227 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
4229 /// Convenience accessors
4230 CleanupPadInst *getCleanupPad() const {
4231 return cast<CleanupPadInst>(Op<-1>());
4233 void setCleanupPad(CleanupPadInst *CleanupPad) {
4235 Op<-1>() = CleanupPad;
4238 BasicBlock *getUnwindDest() const {
4239 return hasUnwindDest() ? cast<BasicBlock>(Op<-2>()) : nullptr;
4241 void setUnwindDest(BasicBlock *NewDest) {
4242 assert(hasUnwindDest());
4247 // Methods for support type inquiry through isa, cast, and dyn_cast:
4248 static inline bool classof(const Instruction *I) {
4249 return (I->getOpcode() == Instruction::CleanupEndPad);
4251 static inline bool classof(const Value *V) {
4252 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4256 BasicBlock *getSuccessorV(unsigned Idx) const override;
4257 unsigned getNumSuccessorsV() const override;
4258 void setSuccessorV(unsigned Idx, BasicBlock *B) override;
4260 // Shadow Instruction::setInstructionSubclassData with a private forwarding
4261 // method so that subclasses cannot accidentally use it.
4262 void setInstructionSubclassData(unsigned short D) {
4263 Instruction::setInstructionSubclassData(D);
4268 struct OperandTraits<CleanupEndPadInst>
4269 : public VariadicOperandTraits<CleanupEndPadInst, /*MINARITY=*/1> {};
4271 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CleanupEndPadInst, Value)
4273 //===----------------------------------------------------------------------===//
4274 // CleanupReturnInst Class
4275 //===----------------------------------------------------------------------===//
4277 class CleanupReturnInst : public TerminatorInst {
4279 CleanupReturnInst(const CleanupReturnInst &RI);
4281 void init(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB);
4282 CleanupReturnInst(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB,
4283 unsigned Values, Instruction *InsertBefore = nullptr);
4284 CleanupReturnInst(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB,
4285 unsigned Values, BasicBlock *InsertAtEnd);
4288 // Note: Instruction needs to be a friend here to call cloneImpl.
4289 friend class Instruction;
4290 CleanupReturnInst *cloneImpl() const;
4293 static CleanupReturnInst *Create(CleanupPadInst *CleanupPad,
4294 BasicBlock *UnwindBB = nullptr,
4295 Instruction *InsertBefore = nullptr) {
4297 unsigned Values = 1;
4301 CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertBefore);
4303 static CleanupReturnInst *Create(CleanupPadInst *CleanupPad,
4304 BasicBlock *UnwindBB,
4305 BasicBlock *InsertAtEnd) {
4307 unsigned Values = 1;
4311 CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertAtEnd);
4314 /// Provide fast operand accessors
4315 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
4317 bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
4318 bool unwindsToCaller() const { return !hasUnwindDest(); }
4320 /// Convenience accessor.
4321 CleanupPadInst *getCleanupPad() const {
4322 return cast<CleanupPadInst>(Op<-1>());
4324 void setCleanupPad(CleanupPadInst *CleanupPad) {
4326 Op<-1>() = CleanupPad;
4329 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
4331 BasicBlock *getUnwindDest() const {
4332 return hasUnwindDest() ? cast<BasicBlock>(Op<-2>()) : nullptr;
4334 void setUnwindDest(BasicBlock *NewDest) {
4336 assert(hasUnwindDest());
4340 // Methods for support type inquiry through isa, cast, and dyn_cast:
4341 static inline bool classof(const Instruction *I) {
4342 return (I->getOpcode() == Instruction::CleanupRet);
4344 static inline bool classof(const Value *V) {
4345 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4349 BasicBlock *getSuccessorV(unsigned Idx) const override;
4350 unsigned getNumSuccessorsV() const override;
4351 void setSuccessorV(unsigned Idx, BasicBlock *B) override;
4353 // Shadow Instruction::setInstructionSubclassData with a private forwarding
4354 // method so that subclasses cannot accidentally use it.
4355 void setInstructionSubclassData(unsigned short D) {
4356 Instruction::setInstructionSubclassData(D);
4361 struct OperandTraits<CleanupReturnInst>
4362 : public VariadicOperandTraits<CleanupReturnInst, /*MINARITY=*/1> {};
4364 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CleanupReturnInst, Value)
4366 //===----------------------------------------------------------------------===//
4367 // UnreachableInst Class
4368 //===----------------------------------------------------------------------===//
4370 //===---------------------------------------------------------------------------
4371 /// UnreachableInst - This function has undefined behavior. In particular, the
4372 /// presence of this instruction indicates some higher level knowledge that the
4373 /// end of the block cannot be reached.
4375 class UnreachableInst : public TerminatorInst {
4376 void *operator new(size_t, unsigned) = delete;
4379 // Note: Instruction needs to be a friend here to call cloneImpl.
4380 friend class Instruction;
4381 UnreachableInst *cloneImpl() const;
4384 // allocate space for exactly zero operands
4385 void *operator new(size_t s) {
4386 return User::operator new(s, 0);
4388 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = nullptr);
4389 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
4391 unsigned getNumSuccessors() const { return 0; }
4393 // Methods for support type inquiry through isa, cast, and dyn_cast:
4394 static inline bool classof(const Instruction *I) {
4395 return I->getOpcode() == Instruction::Unreachable;
4397 static inline bool classof(const Value *V) {
4398 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4402 BasicBlock *getSuccessorV(unsigned idx) const override;
4403 unsigned getNumSuccessorsV() const override;
4404 void setSuccessorV(unsigned idx, BasicBlock *B) override;
4407 //===----------------------------------------------------------------------===//
4409 //===----------------------------------------------------------------------===//
4411 /// \brief This class represents a truncation of integer types.
4412 class TruncInst : public CastInst {
4414 // Note: Instruction needs to be a friend here to call cloneImpl.
4415 friend class Instruction;
4416 /// \brief Clone an identical TruncInst
4417 TruncInst *cloneImpl() const;
4420 /// \brief Constructor with insert-before-instruction semantics
4422 Value *S, ///< The value to be truncated
4423 Type *Ty, ///< The (smaller) type to truncate to
4424 const Twine &NameStr = "", ///< A name for the new instruction
4425 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4428 /// \brief Constructor with insert-at-end-of-block semantics
4430 Value *S, ///< The value to be truncated
4431 Type *Ty, ///< The (smaller) type to truncate to
4432 const Twine &NameStr, ///< A name for the new instruction
4433 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4436 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
4437 static inline bool classof(const Instruction *I) {
4438 return I->getOpcode() == Trunc;
4440 static inline bool classof(const Value *V) {
4441 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4445 //===----------------------------------------------------------------------===//
4447 //===----------------------------------------------------------------------===//
4449 /// \brief This class represents zero extension of integer types.
4450 class ZExtInst : public CastInst {
4452 // Note: Instruction needs to be a friend here to call cloneImpl.
4453 friend class Instruction;
4454 /// \brief Clone an identical ZExtInst
4455 ZExtInst *cloneImpl() const;
4458 /// \brief Constructor with insert-before-instruction semantics
4460 Value *S, ///< The value to be zero extended
4461 Type *Ty, ///< The type to zero extend to
4462 const Twine &NameStr = "", ///< A name for the new instruction
4463 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4466 /// \brief Constructor with insert-at-end semantics.
4468 Value *S, ///< The value to be zero extended
4469 Type *Ty, ///< The type to zero extend to
4470 const Twine &NameStr, ///< A name for the new instruction
4471 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4474 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
4475 static inline bool classof(const Instruction *I) {
4476 return I->getOpcode() == ZExt;
4478 static inline bool classof(const Value *V) {
4479 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4483 //===----------------------------------------------------------------------===//
4485 //===----------------------------------------------------------------------===//
4487 /// \brief This class represents a sign extension of integer types.
4488 class SExtInst : public CastInst {
4490 // Note: Instruction needs to be a friend here to call cloneImpl.
4491 friend class Instruction;
4492 /// \brief Clone an identical SExtInst
4493 SExtInst *cloneImpl() const;
4496 /// \brief Constructor with insert-before-instruction semantics
4498 Value *S, ///< The value to be sign extended
4499 Type *Ty, ///< The type to sign extend to
4500 const Twine &NameStr = "", ///< A name for the new instruction
4501 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4504 /// \brief Constructor with insert-at-end-of-block semantics
4506 Value *S, ///< The value to be sign extended
4507 Type *Ty, ///< The type to sign extend to
4508 const Twine &NameStr, ///< A name for the new instruction
4509 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4512 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
4513 static inline bool classof(const Instruction *I) {
4514 return I->getOpcode() == SExt;
4516 static inline bool classof(const Value *V) {
4517 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4521 //===----------------------------------------------------------------------===//
4522 // FPTruncInst Class
4523 //===----------------------------------------------------------------------===//
4525 /// \brief This class represents a truncation of floating point types.
4526 class FPTruncInst : public CastInst {
4528 // Note: Instruction needs to be a friend here to call cloneImpl.
4529 friend class Instruction;
4530 /// \brief Clone an identical FPTruncInst
4531 FPTruncInst *cloneImpl() const;
4534 /// \brief Constructor with insert-before-instruction semantics
4536 Value *S, ///< The value to be truncated
4537 Type *Ty, ///< The type to truncate to
4538 const Twine &NameStr = "", ///< A name for the new instruction
4539 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4542 /// \brief Constructor with insert-before-instruction semantics
4544 Value *S, ///< The value to be truncated
4545 Type *Ty, ///< The type to truncate to
4546 const Twine &NameStr, ///< A name for the new instruction
4547 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4550 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
4551 static inline bool classof(const Instruction *I) {
4552 return I->getOpcode() == FPTrunc;
4554 static inline bool classof(const Value *V) {
4555 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4559 //===----------------------------------------------------------------------===//
4561 //===----------------------------------------------------------------------===//
4563 /// \brief This class represents an extension of floating point types.
4564 class FPExtInst : public CastInst {
4566 // Note: Instruction needs to be a friend here to call cloneImpl.
4567 friend class Instruction;
4568 /// \brief Clone an identical FPExtInst
4569 FPExtInst *cloneImpl() const;
4572 /// \brief Constructor with insert-before-instruction semantics
4574 Value *S, ///< The value to be extended
4575 Type *Ty, ///< The type to extend to
4576 const Twine &NameStr = "", ///< A name for the new instruction
4577 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4580 /// \brief Constructor with insert-at-end-of-block semantics
4582 Value *S, ///< The value to be extended
4583 Type *Ty, ///< The type to extend to
4584 const Twine &NameStr, ///< A name for the new instruction
4585 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4588 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
4589 static inline bool classof(const Instruction *I) {
4590 return I->getOpcode() == FPExt;
4592 static inline bool classof(const Value *V) {
4593 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4597 //===----------------------------------------------------------------------===//
4599 //===----------------------------------------------------------------------===//
4601 /// \brief This class represents a cast unsigned integer to floating point.
4602 class UIToFPInst : public CastInst {
4604 // Note: Instruction needs to be a friend here to call cloneImpl.
4605 friend class Instruction;
4606 /// \brief Clone an identical UIToFPInst
4607 UIToFPInst *cloneImpl() const;
4610 /// \brief Constructor with insert-before-instruction semantics
4612 Value *S, ///< The value to be converted
4613 Type *Ty, ///< The type to convert to
4614 const Twine &NameStr = "", ///< A name for the new instruction
4615 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4618 /// \brief Constructor with insert-at-end-of-block semantics
4620 Value *S, ///< The value to be converted
4621 Type *Ty, ///< The type to convert to
4622 const Twine &NameStr, ///< A name for the new instruction
4623 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4626 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
4627 static inline bool classof(const Instruction *I) {
4628 return I->getOpcode() == UIToFP;
4630 static inline bool classof(const Value *V) {
4631 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4635 //===----------------------------------------------------------------------===//
4637 //===----------------------------------------------------------------------===//
4639 /// \brief This class represents a cast from signed integer to floating point.
4640 class SIToFPInst : public CastInst {
4642 // Note: Instruction needs to be a friend here to call cloneImpl.
4643 friend class Instruction;
4644 /// \brief Clone an identical SIToFPInst
4645 SIToFPInst *cloneImpl() const;
4648 /// \brief Constructor with insert-before-instruction semantics
4650 Value *S, ///< The value to be converted
4651 Type *Ty, ///< The type to convert to
4652 const Twine &NameStr = "", ///< A name for the new instruction
4653 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4656 /// \brief Constructor with insert-at-end-of-block semantics
4658 Value *S, ///< The value to be converted
4659 Type *Ty, ///< The type to convert to
4660 const Twine &NameStr, ///< A name for the new instruction
4661 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4664 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
4665 static inline bool classof(const Instruction *I) {
4666 return I->getOpcode() == SIToFP;
4668 static inline bool classof(const Value *V) {
4669 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4673 //===----------------------------------------------------------------------===//
4675 //===----------------------------------------------------------------------===//
4677 /// \brief This class represents a cast from floating point to unsigned integer
4678 class FPToUIInst : public CastInst {
4680 // Note: Instruction needs to be a friend here to call cloneImpl.
4681 friend class Instruction;
4682 /// \brief Clone an identical FPToUIInst
4683 FPToUIInst *cloneImpl() const;
4686 /// \brief Constructor with insert-before-instruction semantics
4688 Value *S, ///< The value to be converted
4689 Type *Ty, ///< The type to convert to
4690 const Twine &NameStr = "", ///< A name for the new instruction
4691 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4694 /// \brief Constructor with insert-at-end-of-block semantics
4696 Value *S, ///< The value to be converted
4697 Type *Ty, ///< The type to convert to
4698 const Twine &NameStr, ///< A name for the new instruction
4699 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
4702 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
4703 static inline bool classof(const Instruction *I) {
4704 return I->getOpcode() == FPToUI;
4706 static inline bool classof(const Value *V) {
4707 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4711 //===----------------------------------------------------------------------===//
4713 //===----------------------------------------------------------------------===//
4715 /// \brief This class represents a cast from floating point to signed integer.
4716 class FPToSIInst : public CastInst {
4718 // Note: Instruction needs to be a friend here to call cloneImpl.
4719 friend class Instruction;
4720 /// \brief Clone an identical FPToSIInst
4721 FPToSIInst *cloneImpl() const;
4724 /// \brief Constructor with insert-before-instruction semantics
4726 Value *S, ///< The value to be converted
4727 Type *Ty, ///< The type to convert to
4728 const Twine &NameStr = "", ///< A name for the new instruction
4729 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4732 /// \brief Constructor with insert-at-end-of-block semantics
4734 Value *S, ///< The value to be converted
4735 Type *Ty, ///< The type to convert to
4736 const Twine &NameStr, ///< A name for the new instruction
4737 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4740 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
4741 static inline bool classof(const Instruction *I) {
4742 return I->getOpcode() == FPToSI;
4744 static inline bool classof(const Value *V) {
4745 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4749 //===----------------------------------------------------------------------===//
4750 // IntToPtrInst Class
4751 //===----------------------------------------------------------------------===//
4753 /// \brief This class represents a cast from an integer to a pointer.
4754 class IntToPtrInst : public CastInst {
4756 /// \brief Constructor with insert-before-instruction semantics
4758 Value *S, ///< The value to be converted
4759 Type *Ty, ///< The type to convert to
4760 const Twine &NameStr = "", ///< A name for the new instruction
4761 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4764 /// \brief Constructor with insert-at-end-of-block semantics
4766 Value *S, ///< The value to be converted
4767 Type *Ty, ///< The type to convert to
4768 const Twine &NameStr, ///< A name for the new instruction
4769 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4772 // Note: Instruction needs to be a friend here to call cloneImpl.
4773 friend class Instruction;
4774 /// \brief Clone an identical IntToPtrInst
4775 IntToPtrInst *cloneImpl() const;
4777 /// \brief Returns the address space of this instruction's pointer type.
4778 unsigned getAddressSpace() const {
4779 return getType()->getPointerAddressSpace();
4782 // Methods for support type inquiry through isa, cast, and dyn_cast:
4783 static inline bool classof(const Instruction *I) {
4784 return I->getOpcode() == IntToPtr;
4786 static inline bool classof(const Value *V) {
4787 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4791 //===----------------------------------------------------------------------===//
4792 // PtrToIntInst Class
4793 //===----------------------------------------------------------------------===//
4795 /// \brief This class represents a cast from a pointer to an integer
4796 class PtrToIntInst : public CastInst {
4798 // Note: Instruction needs to be a friend here to call cloneImpl.
4799 friend class Instruction;
4800 /// \brief Clone an identical PtrToIntInst
4801 PtrToIntInst *cloneImpl() const;
4804 /// \brief Constructor with insert-before-instruction semantics
4806 Value *S, ///< The value to be converted
4807 Type *Ty, ///< The type to convert to
4808 const Twine &NameStr = "", ///< A name for the new instruction
4809 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4812 /// \brief Constructor with insert-at-end-of-block semantics
4814 Value *S, ///< The value to be converted
4815 Type *Ty, ///< The type to convert to
4816 const Twine &NameStr, ///< A name for the new instruction
4817 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4820 /// \brief Gets the pointer operand.
4821 Value *getPointerOperand() { return getOperand(0); }
4822 /// \brief Gets the pointer operand.
4823 const Value *getPointerOperand() const { return getOperand(0); }
4824 /// \brief Gets the operand index of the pointer operand.
4825 static unsigned getPointerOperandIndex() { return 0U; }
4827 /// \brief Returns the address space of the pointer operand.
4828 unsigned getPointerAddressSpace() const {
4829 return getPointerOperand()->getType()->getPointerAddressSpace();
4832 // Methods for support type inquiry through isa, cast, and dyn_cast:
4833 static inline bool classof(const Instruction *I) {
4834 return I->getOpcode() == PtrToInt;
4836 static inline bool classof(const Value *V) {
4837 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4841 //===----------------------------------------------------------------------===//
4842 // BitCastInst Class
4843 //===----------------------------------------------------------------------===//
4845 /// \brief This class represents a no-op cast from one type to another.
4846 class BitCastInst : public CastInst {
4848 // Note: Instruction needs to be a friend here to call cloneImpl.
4849 friend class Instruction;
4850 /// \brief Clone an identical BitCastInst
4851 BitCastInst *cloneImpl() const;
4854 /// \brief Constructor with insert-before-instruction semantics
4856 Value *S, ///< The value to be casted
4857 Type *Ty, ///< The type to casted to
4858 const Twine &NameStr = "", ///< A name for the new instruction
4859 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4862 /// \brief Constructor with insert-at-end-of-block semantics
4864 Value *S, ///< The value to be casted
4865 Type *Ty, ///< The type to casted to
4866 const Twine &NameStr, ///< A name for the new instruction
4867 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4870 // Methods for support type inquiry through isa, cast, and dyn_cast:
4871 static inline bool classof(const Instruction *I) {
4872 return I->getOpcode() == BitCast;
4874 static inline bool classof(const Value *V) {
4875 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4879 //===----------------------------------------------------------------------===//
4880 // AddrSpaceCastInst Class
4881 //===----------------------------------------------------------------------===//
4883 /// \brief This class represents a conversion between pointers from
4884 /// one address space to another.
4885 class AddrSpaceCastInst : public CastInst {
4887 // Note: Instruction needs to be a friend here to call cloneImpl.
4888 friend class Instruction;
4889 /// \brief Clone an identical AddrSpaceCastInst
4890 AddrSpaceCastInst *cloneImpl() const;
4893 /// \brief Constructor with insert-before-instruction semantics
4895 Value *S, ///< The value to be casted
4896 Type *Ty, ///< The type to casted to
4897 const Twine &NameStr = "", ///< A name for the new instruction
4898 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4901 /// \brief Constructor with insert-at-end-of-block semantics
4903 Value *S, ///< The value to be casted
4904 Type *Ty, ///< The type to casted to
4905 const Twine &NameStr, ///< A name for the new instruction
4906 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4909 // Methods for support type inquiry through isa, cast, and dyn_cast:
4910 static inline bool classof(const Instruction *I) {
4911 return I->getOpcode() == AddrSpaceCast;
4913 static inline bool classof(const Value *V) {
4914 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4918 } // End llvm namespace