1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the class definitions of all of the subclasses of the
11 // Instruction class. This is meant to be an easy way to get access to all
12 // instruction subclasses.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_IR_INSTRUCTIONS_H
17 #define LLVM_IR_INSTRUCTIONS_H
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/iterator_range.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/IR/Attributes.h"
23 #include "llvm/IR/CallingConv.h"
24 #include "llvm/IR/DerivedTypes.h"
25 #include "llvm/IR/InstrTypes.h"
26 #include "llvm/Support/ErrorHandling.h"
41 // Consume = 3, // Not specified yet.
45 SequentiallyConsistent = 7
48 enum SynchronizationScope {
53 //===----------------------------------------------------------------------===//
55 //===----------------------------------------------------------------------===//
57 /// AllocaInst - an instruction to allocate memory on the stack
59 class AllocaInst : public UnaryInstruction {
61 AllocaInst *clone_impl() const override;
63 explicit AllocaInst(Type *Ty, Value *ArraySize = nullptr,
64 const Twine &Name = "",
65 Instruction *InsertBefore = nullptr);
66 AllocaInst(Type *Ty, Value *ArraySize,
67 const Twine &Name, BasicBlock *InsertAtEnd);
69 AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = nullptr);
70 AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
72 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
73 const Twine &Name = "", Instruction *InsertBefore = nullptr);
74 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
75 const Twine &Name, BasicBlock *InsertAtEnd);
77 // Out of line virtual method, so the vtable, etc. has a home.
78 virtual ~AllocaInst();
80 /// isArrayAllocation - Return true if there is an allocation size parameter
81 /// to the allocation instruction that is not 1.
83 bool isArrayAllocation() const;
85 /// getArraySize - Get the number of elements allocated. For a simple
86 /// allocation of a single element, this will return a constant 1 value.
88 const Value *getArraySize() const { return getOperand(0); }
89 Value *getArraySize() { return getOperand(0); }
91 /// getType - Overload to return most specific pointer type
93 PointerType *getType() const {
94 return cast<PointerType>(Instruction::getType());
97 /// getAllocatedType - Return the type that is being allocated by the
100 Type *getAllocatedType() const;
102 /// getAlignment - Return the alignment of the memory that is being allocated
103 /// by the instruction.
105 unsigned getAlignment() const {
106 return (1u << (getSubclassDataFromInstruction() & 31)) >> 1;
108 void setAlignment(unsigned Align);
110 /// isStaticAlloca - Return true if this alloca is in the entry block of the
111 /// function and is a constant size. If so, the code generator will fold it
112 /// into the prolog/epilog code, so it is basically free.
113 bool isStaticAlloca() const;
115 /// \brief Return true if this alloca is used as an inalloca argument to a
116 /// call. Such allocas are never considered static even if they are in the
118 bool isUsedWithInAlloca() const {
119 return getSubclassDataFromInstruction() & 32;
122 /// \brief Specify whether this alloca is used to represent a the arguments to
124 void setUsedWithInAlloca(bool V) {
125 setInstructionSubclassData((getSubclassDataFromInstruction() & ~32) |
129 // Methods for support type inquiry through isa, cast, and dyn_cast:
130 static inline bool classof(const Instruction *I) {
131 return (I->getOpcode() == Instruction::Alloca);
133 static inline bool classof(const Value *V) {
134 return isa<Instruction>(V) && classof(cast<Instruction>(V));
137 // Shadow Instruction::setInstructionSubclassData with a private forwarding
138 // method so that subclasses cannot accidentally use it.
139 void setInstructionSubclassData(unsigned short D) {
140 Instruction::setInstructionSubclassData(D);
145 //===----------------------------------------------------------------------===//
147 //===----------------------------------------------------------------------===//
149 /// LoadInst - an instruction for reading from memory. This uses the
150 /// SubclassData field in Value to store whether or not the load is volatile.
152 class LoadInst : public UnaryInstruction {
155 LoadInst *clone_impl() const override;
157 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
158 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
159 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
160 Instruction *InsertBefore = nullptr);
161 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
162 BasicBlock *InsertAtEnd);
163 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
164 unsigned Align, Instruction *InsertBefore = nullptr);
165 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
166 unsigned Align, BasicBlock *InsertAtEnd);
167 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
168 unsigned Align, AtomicOrdering Order,
169 SynchronizationScope SynchScope = CrossThread,
170 Instruction *InsertBefore = nullptr);
171 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
172 unsigned Align, AtomicOrdering Order,
173 SynchronizationScope SynchScope,
174 BasicBlock *InsertAtEnd);
176 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
177 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
178 explicit LoadInst(Value *Ptr, const char *NameStr = nullptr,
179 bool isVolatile = false,
180 Instruction *InsertBefore = nullptr);
181 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
182 BasicBlock *InsertAtEnd);
184 /// isVolatile - Return true if this is a load from a volatile memory
187 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
189 /// setVolatile - Specify whether this is a volatile load or not.
191 void setVolatile(bool V) {
192 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
196 /// getAlignment - Return the alignment of the access that is being performed
198 unsigned getAlignment() const {
199 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
202 void setAlignment(unsigned Align);
204 /// Returns the ordering effect of this fence.
205 AtomicOrdering getOrdering() const {
206 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
209 /// Set the ordering constraint on this load. May not be Release or
211 void setOrdering(AtomicOrdering Ordering) {
212 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
216 SynchronizationScope getSynchScope() const {
217 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
220 /// Specify whether this load is ordered with respect to all
221 /// concurrently executing threads, or only with respect to signal handlers
222 /// executing in the same thread.
223 void setSynchScope(SynchronizationScope xthread) {
224 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
228 bool isAtomic() const { return getOrdering() != NotAtomic; }
229 void setAtomic(AtomicOrdering Ordering,
230 SynchronizationScope SynchScope = CrossThread) {
231 setOrdering(Ordering);
232 setSynchScope(SynchScope);
235 bool isSimple() const { return !isAtomic() && !isVolatile(); }
236 bool isUnordered() const {
237 return getOrdering() <= Unordered && !isVolatile();
240 Value *getPointerOperand() { return getOperand(0); }
241 const Value *getPointerOperand() const { return getOperand(0); }
242 static unsigned getPointerOperandIndex() { return 0U; }
244 /// \brief Returns the address space of the pointer operand.
245 unsigned getPointerAddressSpace() const {
246 return getPointerOperand()->getType()->getPointerAddressSpace();
250 // Methods for support type inquiry through isa, cast, and dyn_cast:
251 static inline bool classof(const Instruction *I) {
252 return I->getOpcode() == Instruction::Load;
254 static inline bool classof(const Value *V) {
255 return isa<Instruction>(V) && classof(cast<Instruction>(V));
258 // Shadow Instruction::setInstructionSubclassData with a private forwarding
259 // method so that subclasses cannot accidentally use it.
260 void setInstructionSubclassData(unsigned short D) {
261 Instruction::setInstructionSubclassData(D);
266 //===----------------------------------------------------------------------===//
268 //===----------------------------------------------------------------------===//
270 /// StoreInst - an instruction for storing to memory
272 class StoreInst : public Instruction {
273 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
276 StoreInst *clone_impl() const override;
278 // allocate space for exactly two operands
279 void *operator new(size_t s) {
280 return User::operator new(s, 2);
282 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
283 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
284 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
285 Instruction *InsertBefore = nullptr);
286 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
287 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
288 unsigned Align, Instruction *InsertBefore = nullptr);
289 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
290 unsigned Align, BasicBlock *InsertAtEnd);
291 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
292 unsigned Align, AtomicOrdering Order,
293 SynchronizationScope SynchScope = CrossThread,
294 Instruction *InsertBefore = nullptr);
295 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
296 unsigned Align, AtomicOrdering Order,
297 SynchronizationScope SynchScope,
298 BasicBlock *InsertAtEnd);
301 /// isVolatile - Return true if this is a store to a volatile memory
304 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
306 /// setVolatile - Specify whether this is a volatile store or not.
308 void setVolatile(bool V) {
309 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
313 /// Transparently provide more efficient getOperand methods.
314 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
316 /// getAlignment - Return the alignment of the access that is being performed
318 unsigned getAlignment() const {
319 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
322 void setAlignment(unsigned Align);
324 /// Returns the ordering effect of this store.
325 AtomicOrdering getOrdering() const {
326 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
329 /// Set the ordering constraint on this store. May not be Acquire or
331 void setOrdering(AtomicOrdering Ordering) {
332 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
336 SynchronizationScope getSynchScope() const {
337 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
340 /// Specify whether this store instruction is ordered with respect to all
341 /// concurrently executing threads, or only with respect to signal handlers
342 /// executing in the same thread.
343 void setSynchScope(SynchronizationScope xthread) {
344 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
348 bool isAtomic() const { return getOrdering() != NotAtomic; }
349 void setAtomic(AtomicOrdering Ordering,
350 SynchronizationScope SynchScope = CrossThread) {
351 setOrdering(Ordering);
352 setSynchScope(SynchScope);
355 bool isSimple() const { return !isAtomic() && !isVolatile(); }
356 bool isUnordered() const {
357 return getOrdering() <= Unordered && !isVolatile();
360 Value *getValueOperand() { return getOperand(0); }
361 const Value *getValueOperand() const { return getOperand(0); }
363 Value *getPointerOperand() { return getOperand(1); }
364 const Value *getPointerOperand() const { return getOperand(1); }
365 static unsigned getPointerOperandIndex() { return 1U; }
367 /// \brief Returns the address space of the pointer operand.
368 unsigned getPointerAddressSpace() const {
369 return getPointerOperand()->getType()->getPointerAddressSpace();
372 // Methods for support type inquiry through isa, cast, and dyn_cast:
373 static inline bool classof(const Instruction *I) {
374 return I->getOpcode() == Instruction::Store;
376 static inline bool classof(const Value *V) {
377 return isa<Instruction>(V) && classof(cast<Instruction>(V));
380 // Shadow Instruction::setInstructionSubclassData with a private forwarding
381 // method so that subclasses cannot accidentally use it.
382 void setInstructionSubclassData(unsigned short D) {
383 Instruction::setInstructionSubclassData(D);
388 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
391 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
393 //===----------------------------------------------------------------------===//
395 //===----------------------------------------------------------------------===//
397 /// FenceInst - an instruction for ordering other memory operations
399 class FenceInst : public Instruction {
400 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
401 void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
403 FenceInst *clone_impl() const override;
405 // allocate space for exactly zero operands
406 void *operator new(size_t s) {
407 return User::operator new(s, 0);
410 // Ordering may only be Acquire, Release, AcquireRelease, or
411 // SequentiallyConsistent.
412 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
413 SynchronizationScope SynchScope = CrossThread,
414 Instruction *InsertBefore = nullptr);
415 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
416 SynchronizationScope SynchScope,
417 BasicBlock *InsertAtEnd);
419 /// Returns the ordering effect of this fence.
420 AtomicOrdering getOrdering() const {
421 return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
424 /// Set the ordering constraint on this fence. May only be Acquire, Release,
425 /// AcquireRelease, or SequentiallyConsistent.
426 void setOrdering(AtomicOrdering Ordering) {
427 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
431 SynchronizationScope getSynchScope() const {
432 return SynchronizationScope(getSubclassDataFromInstruction() & 1);
435 /// Specify whether this fence orders other operations with respect to all
436 /// concurrently executing threads, or only with respect to signal handlers
437 /// executing in the same thread.
438 void setSynchScope(SynchronizationScope xthread) {
439 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
443 // Methods for support type inquiry through isa, cast, and dyn_cast:
444 static inline bool classof(const Instruction *I) {
445 return I->getOpcode() == Instruction::Fence;
447 static inline bool classof(const Value *V) {
448 return isa<Instruction>(V) && classof(cast<Instruction>(V));
451 // Shadow Instruction::setInstructionSubclassData with a private forwarding
452 // method so that subclasses cannot accidentally use it.
453 void setInstructionSubclassData(unsigned short D) {
454 Instruction::setInstructionSubclassData(D);
458 //===----------------------------------------------------------------------===//
459 // AtomicCmpXchgInst Class
460 //===----------------------------------------------------------------------===//
462 /// AtomicCmpXchgInst - an instruction that atomically checks whether a
463 /// specified value is in a memory location, and, if it is, stores a new value
464 /// there. Returns the value that was loaded.
466 class AtomicCmpXchgInst : public Instruction {
467 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
468 void Init(Value *Ptr, Value *Cmp, Value *NewVal,
469 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
470 SynchronizationScope SynchScope);
472 AtomicCmpXchgInst *clone_impl() const override;
474 // allocate space for exactly three operands
475 void *operator new(size_t s) {
476 return User::operator new(s, 3);
478 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
479 AtomicOrdering SuccessOrdering,
480 AtomicOrdering FailureOrdering,
481 SynchronizationScope SynchScope,
482 Instruction *InsertBefore = nullptr);
483 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
484 AtomicOrdering SuccessOrdering,
485 AtomicOrdering FailureOrdering,
486 SynchronizationScope SynchScope,
487 BasicBlock *InsertAtEnd);
489 /// isVolatile - Return true if this is a cmpxchg from a volatile memory
492 bool isVolatile() const {
493 return getSubclassDataFromInstruction() & 1;
496 /// setVolatile - Specify whether this is a volatile cmpxchg.
498 void setVolatile(bool V) {
499 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
503 /// Return true if this cmpxchg may spuriously fail.
504 bool isWeak() const {
505 return getSubclassDataFromInstruction() & 0x100;
508 void setWeak(bool IsWeak) {
509 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x100) |
513 /// Transparently provide more efficient getOperand methods.
514 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
516 /// Set the ordering constraint on this cmpxchg.
517 void setSuccessOrdering(AtomicOrdering Ordering) {
518 assert(Ordering != NotAtomic &&
519 "CmpXchg instructions can only be atomic.");
520 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x1c) |
524 void setFailureOrdering(AtomicOrdering Ordering) {
525 assert(Ordering != NotAtomic &&
526 "CmpXchg instructions can only be atomic.");
527 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0xe0) |
531 /// Specify whether this cmpxchg is atomic and orders other operations with
532 /// respect to all concurrently executing threads, or only with respect to
533 /// signal handlers executing in the same thread.
534 void setSynchScope(SynchronizationScope SynchScope) {
535 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
539 /// Returns the ordering constraint on this cmpxchg.
540 AtomicOrdering getSuccessOrdering() const {
541 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
544 /// Returns the ordering constraint on this cmpxchg.
545 AtomicOrdering getFailureOrdering() const {
546 return AtomicOrdering((getSubclassDataFromInstruction() >> 5) & 7);
549 /// Returns whether this cmpxchg is atomic between threads or only within a
551 SynchronizationScope getSynchScope() const {
552 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
555 Value *getPointerOperand() { return getOperand(0); }
556 const Value *getPointerOperand() const { return getOperand(0); }
557 static unsigned getPointerOperandIndex() { return 0U; }
559 Value *getCompareOperand() { return getOperand(1); }
560 const Value *getCompareOperand() const { return getOperand(1); }
562 Value *getNewValOperand() { return getOperand(2); }
563 const Value *getNewValOperand() const { return getOperand(2); }
565 /// \brief Returns the address space of the pointer operand.
566 unsigned getPointerAddressSpace() const {
567 return getPointerOperand()->getType()->getPointerAddressSpace();
570 /// \brief Returns the strongest permitted ordering on failure, given the
571 /// desired ordering on success.
573 /// If the comparison in a cmpxchg operation fails, there is no atomic store
574 /// so release semantics cannot be provided. So this function drops explicit
575 /// Release requests from the AtomicOrdering. A SequentiallyConsistent
576 /// operation would remain SequentiallyConsistent.
577 static AtomicOrdering
578 getStrongestFailureOrdering(AtomicOrdering SuccessOrdering) {
579 switch (SuccessOrdering) {
580 default: llvm_unreachable("invalid cmpxchg success ordering");
587 case SequentiallyConsistent:
588 return SequentiallyConsistent;
592 // Methods for support type inquiry through isa, cast, and dyn_cast:
593 static inline bool classof(const Instruction *I) {
594 return I->getOpcode() == Instruction::AtomicCmpXchg;
596 static inline bool classof(const Value *V) {
597 return isa<Instruction>(V) && classof(cast<Instruction>(V));
600 // Shadow Instruction::setInstructionSubclassData with a private forwarding
601 // method so that subclasses cannot accidentally use it.
602 void setInstructionSubclassData(unsigned short D) {
603 Instruction::setInstructionSubclassData(D);
608 struct OperandTraits<AtomicCmpXchgInst> :
609 public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
612 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)
614 //===----------------------------------------------------------------------===//
615 // AtomicRMWInst Class
616 //===----------------------------------------------------------------------===//
618 /// AtomicRMWInst - an instruction that atomically reads a memory location,
619 /// combines it with another value, and then stores the result back. Returns
622 class AtomicRMWInst : public Instruction {
623 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
625 AtomicRMWInst *clone_impl() const override;
627 /// This enumeration lists the possible modifications atomicrmw can make. In
628 /// the descriptions, 'p' is the pointer to the instruction's memory location,
629 /// 'old' is the initial value of *p, and 'v' is the other value passed to the
630 /// instruction. These instructions always return 'old'.
646 /// *p = old >signed v ? old : v
648 /// *p = old <signed v ? old : v
650 /// *p = old >unsigned v ? old : v
652 /// *p = old <unsigned v ? old : v
660 // allocate space for exactly two operands
661 void *operator new(size_t s) {
662 return User::operator new(s, 2);
664 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
665 AtomicOrdering Ordering, SynchronizationScope SynchScope,
666 Instruction *InsertBefore = nullptr);
667 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
668 AtomicOrdering Ordering, SynchronizationScope SynchScope,
669 BasicBlock *InsertAtEnd);
671 BinOp getOperation() const {
672 return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
675 void setOperation(BinOp Operation) {
676 unsigned short SubclassData = getSubclassDataFromInstruction();
677 setInstructionSubclassData((SubclassData & 31) |
681 /// isVolatile - Return true if this is a RMW on a volatile memory location.
683 bool isVolatile() const {
684 return getSubclassDataFromInstruction() & 1;
687 /// setVolatile - Specify whether this is a volatile RMW or not.
689 void setVolatile(bool V) {
690 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
694 /// Transparently provide more efficient getOperand methods.
695 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
697 /// Set the ordering constraint on this RMW.
698 void setOrdering(AtomicOrdering Ordering) {
699 assert(Ordering != NotAtomic &&
700 "atomicrmw instructions can only be atomic.");
701 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
705 /// Specify whether this RMW orders other operations with respect to all
706 /// concurrently executing threads, or only with respect to signal handlers
707 /// executing in the same thread.
708 void setSynchScope(SynchronizationScope SynchScope) {
709 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
713 /// Returns the ordering constraint on this RMW.
714 AtomicOrdering getOrdering() const {
715 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
718 /// Returns whether this RMW is atomic between threads or only within a
720 SynchronizationScope getSynchScope() const {
721 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
724 Value *getPointerOperand() { return getOperand(0); }
725 const Value *getPointerOperand() const { return getOperand(0); }
726 static unsigned getPointerOperandIndex() { return 0U; }
728 Value *getValOperand() { return getOperand(1); }
729 const Value *getValOperand() const { return getOperand(1); }
731 /// \brief Returns the address space of the pointer operand.
732 unsigned getPointerAddressSpace() const {
733 return getPointerOperand()->getType()->getPointerAddressSpace();
736 // Methods for support type inquiry through isa, cast, and dyn_cast:
737 static inline bool classof(const Instruction *I) {
738 return I->getOpcode() == Instruction::AtomicRMW;
740 static inline bool classof(const Value *V) {
741 return isa<Instruction>(V) && classof(cast<Instruction>(V));
744 void Init(BinOp Operation, Value *Ptr, Value *Val,
745 AtomicOrdering Ordering, SynchronizationScope SynchScope);
746 // Shadow Instruction::setInstructionSubclassData with a private forwarding
747 // method so that subclasses cannot accidentally use it.
748 void setInstructionSubclassData(unsigned short D) {
749 Instruction::setInstructionSubclassData(D);
754 struct OperandTraits<AtomicRMWInst>
755 : public FixedNumOperandTraits<AtomicRMWInst,2> {
758 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)
760 //===----------------------------------------------------------------------===//
761 // GetElementPtrInst Class
762 //===----------------------------------------------------------------------===//
764 // checkGEPType - Simple wrapper function to give a better assertion failure
765 // message on bad indexes for a gep instruction.
767 inline Type *checkGEPType(Type *Ty) {
768 assert(Ty && "Invalid GetElementPtrInst indices for type!");
772 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
773 /// access elements of arrays and structs
775 class GetElementPtrInst : public Instruction {
776 GetElementPtrInst(const GetElementPtrInst &GEPI);
777 void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
779 /// Constructors - Create a getelementptr instruction with a base pointer an
780 /// list of indices. The first ctor can optionally insert before an existing
781 /// instruction, the second appends the new instruction to the specified
783 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
784 unsigned Values, const Twine &NameStr,
785 Instruction *InsertBefore);
786 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
787 unsigned Values, const Twine &NameStr,
788 BasicBlock *InsertAtEnd);
790 GetElementPtrInst *clone_impl() const override;
792 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
793 const Twine &NameStr = "",
794 Instruction *InsertBefore = nullptr) {
795 unsigned Values = 1 + unsigned(IdxList.size());
797 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
799 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
800 const Twine &NameStr,
801 BasicBlock *InsertAtEnd) {
802 unsigned Values = 1 + unsigned(IdxList.size());
804 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
807 /// Create an "inbounds" getelementptr. See the documentation for the
808 /// "inbounds" flag in LangRef.html for details.
809 static GetElementPtrInst *CreateInBounds(Value *Ptr,
810 ArrayRef<Value *> IdxList,
811 const Twine &NameStr = "",
812 Instruction *InsertBefore = nullptr){
813 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
814 GEP->setIsInBounds(true);
817 static GetElementPtrInst *CreateInBounds(Value *Ptr,
818 ArrayRef<Value *> IdxList,
819 const Twine &NameStr,
820 BasicBlock *InsertAtEnd) {
821 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
822 GEP->setIsInBounds(true);
826 /// Transparently provide more efficient getOperand methods.
827 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
829 // getType - Overload to return most specific sequential type.
830 SequentialType *getType() const {
831 return cast<SequentialType>(Instruction::getType());
834 /// \brief Returns the address space of this instruction's pointer type.
835 unsigned getAddressSpace() const {
836 // Note that this is always the same as the pointer operand's address space
837 // and that is cheaper to compute, so cheat here.
838 return getPointerAddressSpace();
841 /// getIndexedType - Returns the type of the element that would be loaded with
842 /// a load instruction with the specified parameters.
844 /// Null is returned if the indices are invalid for the specified
847 static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList);
848 static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList);
849 static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList);
851 inline op_iterator idx_begin() { return op_begin()+1; }
852 inline const_op_iterator idx_begin() const { return op_begin()+1; }
853 inline op_iterator idx_end() { return op_end(); }
854 inline const_op_iterator idx_end() const { return op_end(); }
856 Value *getPointerOperand() {
857 return getOperand(0);
859 const Value *getPointerOperand() const {
860 return getOperand(0);
862 static unsigned getPointerOperandIndex() {
863 return 0U; // get index for modifying correct operand.
866 /// getPointerOperandType - Method to return the pointer operand as a
868 Type *getPointerOperandType() const {
869 return getPointerOperand()->getType();
872 /// \brief Returns the address space of the pointer operand.
873 unsigned getPointerAddressSpace() const {
874 return getPointerOperandType()->getPointerAddressSpace();
877 /// GetGEPReturnType - Returns the pointer type returned by the GEP
878 /// instruction, which may be a vector of pointers.
879 static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
880 Type *PtrTy = PointerType::get(checkGEPType(
881 getIndexedType(Ptr->getType(), IdxList)),
882 Ptr->getType()->getPointerAddressSpace());
884 if (Ptr->getType()->isVectorTy()) {
885 unsigned NumElem = cast<VectorType>(Ptr->getType())->getNumElements();
886 return VectorType::get(PtrTy, NumElem);
893 unsigned getNumIndices() const { // Note: always non-negative
894 return getNumOperands() - 1;
897 bool hasIndices() const {
898 return getNumOperands() > 1;
901 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
902 /// zeros. If so, the result pointer and the first operand have the same
903 /// value, just potentially different types.
904 bool hasAllZeroIndices() const;
906 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
907 /// constant integers. If so, the result pointer and the first operand have
908 /// a constant offset between them.
909 bool hasAllConstantIndices() const;
911 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
912 /// See LangRef.html for the meaning of inbounds on a getelementptr.
913 void setIsInBounds(bool b = true);
915 /// isInBounds - Determine whether the GEP has the inbounds flag.
916 bool isInBounds() const;
918 /// \brief Accumulate the constant address offset of this GEP if possible.
920 /// This routine accepts an APInt into which it will accumulate the constant
921 /// offset of this GEP if the GEP is in fact constant. If the GEP is not
922 /// all-constant, it returns false and the value of the offset APInt is
923 /// undefined (it is *not* preserved!). The APInt passed into this routine
924 /// must be at least as wide as the IntPtr type for the address space of
925 /// the base GEP pointer.
926 bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
928 // Methods for support type inquiry through isa, cast, and dyn_cast:
929 static inline bool classof(const Instruction *I) {
930 return (I->getOpcode() == Instruction::GetElementPtr);
932 static inline bool classof(const Value *V) {
933 return isa<Instruction>(V) && classof(cast<Instruction>(V));
938 struct OperandTraits<GetElementPtrInst> :
939 public VariadicOperandTraits<GetElementPtrInst, 1> {
942 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
943 ArrayRef<Value *> IdxList,
945 const Twine &NameStr,
946 Instruction *InsertBefore)
947 : Instruction(getGEPReturnType(Ptr, IdxList),
949 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
950 Values, InsertBefore) {
951 init(Ptr, IdxList, NameStr);
953 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
954 ArrayRef<Value *> IdxList,
956 const Twine &NameStr,
957 BasicBlock *InsertAtEnd)
958 : Instruction(getGEPReturnType(Ptr, IdxList),
960 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
961 Values, InsertAtEnd) {
962 init(Ptr, IdxList, NameStr);
966 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
969 //===----------------------------------------------------------------------===//
971 //===----------------------------------------------------------------------===//
973 /// This instruction compares its operands according to the predicate given
974 /// to the constructor. It only operates on integers or pointers. The operands
975 /// must be identical types.
976 /// \brief Represent an integer comparison operator.
977 class ICmpInst: public CmpInst {
979 assert(getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE &&
980 getPredicate() <= CmpInst::LAST_ICMP_PREDICATE &&
981 "Invalid ICmp predicate value");
982 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
983 "Both operands to ICmp instruction are not of the same type!");
984 // Check that the operands are the right type
985 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
986 getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
987 "Invalid operand types for ICmp instruction");
991 /// \brief Clone an identical ICmpInst
992 ICmpInst *clone_impl() const override;
994 /// \brief Constructor with insert-before-instruction semantics.
996 Instruction *InsertBefore, ///< Where to insert
997 Predicate pred, ///< The predicate to use for the comparison
998 Value *LHS, ///< The left-hand-side of the expression
999 Value *RHS, ///< The right-hand-side of the expression
1000 const Twine &NameStr = "" ///< Name of the instruction
1001 ) : CmpInst(makeCmpResultType(LHS->getType()),
1002 Instruction::ICmp, pred, LHS, RHS, NameStr,
1009 /// \brief Constructor with insert-at-end semantics.
1011 BasicBlock &InsertAtEnd, ///< Block to insert into.
1012 Predicate pred, ///< The predicate to use for the comparison
1013 Value *LHS, ///< The left-hand-side of the expression
1014 Value *RHS, ///< The right-hand-side of the expression
1015 const Twine &NameStr = "" ///< Name of the instruction
1016 ) : CmpInst(makeCmpResultType(LHS->getType()),
1017 Instruction::ICmp, pred, LHS, RHS, NameStr,
1024 /// \brief Constructor with no-insertion semantics
1026 Predicate pred, ///< The predicate to use for the comparison
1027 Value *LHS, ///< The left-hand-side of the expression
1028 Value *RHS, ///< The right-hand-side of the expression
1029 const Twine &NameStr = "" ///< Name of the instruction
1030 ) : CmpInst(makeCmpResultType(LHS->getType()),
1031 Instruction::ICmp, pred, LHS, RHS, NameStr) {
1037 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
1038 /// @returns the predicate that would be the result if the operand were
1039 /// regarded as signed.
1040 /// \brief Return the signed version of the predicate
1041 Predicate getSignedPredicate() const {
1042 return getSignedPredicate(getPredicate());
1045 /// This is a static version that you can use without an instruction.
1046 /// \brief Return the signed version of the predicate.
1047 static Predicate getSignedPredicate(Predicate pred);
1049 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
1050 /// @returns the predicate that would be the result if the operand were
1051 /// regarded as unsigned.
1052 /// \brief Return the unsigned version of the predicate
1053 Predicate getUnsignedPredicate() const {
1054 return getUnsignedPredicate(getPredicate());
1057 /// This is a static version that you can use without an instruction.
1058 /// \brief Return the unsigned version of the predicate.
1059 static Predicate getUnsignedPredicate(Predicate pred);
1061 /// isEquality - Return true if this predicate is either EQ or NE. This also
1062 /// tests for commutativity.
1063 static bool isEquality(Predicate P) {
1064 return P == ICMP_EQ || P == ICMP_NE;
1067 /// isEquality - Return true if this predicate is either EQ or NE. This also
1068 /// tests for commutativity.
1069 bool isEquality() const {
1070 return isEquality(getPredicate());
1073 /// @returns true if the predicate of this ICmpInst is commutative
1074 /// \brief Determine if this relation is commutative.
1075 bool isCommutative() const { return isEquality(); }
1077 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1079 bool isRelational() const {
1080 return !isEquality();
1083 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1085 static bool isRelational(Predicate P) {
1086 return !isEquality(P);
1089 /// Initialize a set of values that all satisfy the predicate with C.
1090 /// \brief Make a ConstantRange for a relation with a constant value.
1091 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
1093 /// Exchange the two operands to this instruction in such a way that it does
1094 /// not modify the semantics of the instruction. The predicate value may be
1095 /// changed to retain the same result if the predicate is order dependent
1097 /// \brief Swap operands and adjust predicate.
1098 void swapOperands() {
1099 setPredicate(getSwappedPredicate());
1100 Op<0>().swap(Op<1>());
1103 // Methods for support type inquiry through isa, cast, and dyn_cast:
1104 static inline bool classof(const Instruction *I) {
1105 return I->getOpcode() == Instruction::ICmp;
1107 static inline bool classof(const Value *V) {
1108 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1113 //===----------------------------------------------------------------------===//
1115 //===----------------------------------------------------------------------===//
1117 /// This instruction compares its operands according to the predicate given
1118 /// to the constructor. It only operates on floating point values or packed
1119 /// vectors of floating point values. The operands must be identical types.
1120 /// \brief Represents a floating point comparison operator.
1121 class FCmpInst: public CmpInst {
1123 /// \brief Clone an identical FCmpInst
1124 FCmpInst *clone_impl() const override;
1126 /// \brief Constructor with insert-before-instruction semantics.
1128 Instruction *InsertBefore, ///< Where to insert
1129 Predicate pred, ///< The predicate to use for the comparison
1130 Value *LHS, ///< The left-hand-side of the expression
1131 Value *RHS, ///< The right-hand-side of the expression
1132 const Twine &NameStr = "" ///< Name of the instruction
1133 ) : CmpInst(makeCmpResultType(LHS->getType()),
1134 Instruction::FCmp, pred, LHS, RHS, NameStr,
1136 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1137 "Invalid FCmp predicate value");
1138 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1139 "Both operands to FCmp instruction are not of the same type!");
1140 // Check that the operands are the right type
1141 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1142 "Invalid operand types for FCmp instruction");
1145 /// \brief Constructor with insert-at-end semantics.
1147 BasicBlock &InsertAtEnd, ///< Block to insert into.
1148 Predicate pred, ///< The predicate to use for the comparison
1149 Value *LHS, ///< The left-hand-side of the expression
1150 Value *RHS, ///< The right-hand-side of the expression
1151 const Twine &NameStr = "" ///< Name of the instruction
1152 ) : CmpInst(makeCmpResultType(LHS->getType()),
1153 Instruction::FCmp, pred, LHS, RHS, NameStr,
1155 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1156 "Invalid FCmp predicate value");
1157 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1158 "Both operands to FCmp instruction are not of the same type!");
1159 // Check that the operands are the right type
1160 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1161 "Invalid operand types for FCmp instruction");
1164 /// \brief Constructor with no-insertion semantics
1166 Predicate pred, ///< The predicate to use for the comparison
1167 Value *LHS, ///< The left-hand-side of the expression
1168 Value *RHS, ///< The right-hand-side of the expression
1169 const Twine &NameStr = "" ///< Name of the instruction
1170 ) : CmpInst(makeCmpResultType(LHS->getType()),
1171 Instruction::FCmp, pred, LHS, RHS, NameStr) {
1172 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1173 "Invalid FCmp predicate value");
1174 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1175 "Both operands to FCmp instruction are not of the same type!");
1176 // Check that the operands are the right type
1177 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1178 "Invalid operand types for FCmp instruction");
1181 /// @returns true if the predicate of this instruction is EQ or NE.
1182 /// \brief Determine if this is an equality predicate.
1183 bool isEquality() const {
1184 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
1185 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
1188 /// @returns true if the predicate of this instruction is commutative.
1189 /// \brief Determine if this is a commutative predicate.
1190 bool isCommutative() const {
1191 return isEquality() ||
1192 getPredicate() == FCMP_FALSE ||
1193 getPredicate() == FCMP_TRUE ||
1194 getPredicate() == FCMP_ORD ||
1195 getPredicate() == FCMP_UNO;
1198 /// @returns true if the predicate is relational (not EQ or NE).
1199 /// \brief Determine if this a relational predicate.
1200 bool isRelational() const { return !isEquality(); }
1202 /// Exchange the two operands to this instruction in such a way that it does
1203 /// not modify the semantics of the instruction. The predicate value may be
1204 /// changed to retain the same result if the predicate is order dependent
1206 /// \brief Swap operands and adjust predicate.
1207 void swapOperands() {
1208 setPredicate(getSwappedPredicate());
1209 Op<0>().swap(Op<1>());
1212 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
1213 static inline bool classof(const Instruction *I) {
1214 return I->getOpcode() == Instruction::FCmp;
1216 static inline bool classof(const Value *V) {
1217 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1221 //===----------------------------------------------------------------------===//
1222 /// CallInst - This class represents a function call, abstracting a target
1223 /// machine's calling convention. This class uses low bit of the SubClassData
1224 /// field to indicate whether or not this is a tail call. The rest of the bits
1225 /// hold the calling convention of the call.
1227 class CallInst : public Instruction {
1228 AttributeSet AttributeList; ///< parameter attributes for call
1229 CallInst(const CallInst &CI);
1230 void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
1231 void init(Value *Func, const Twine &NameStr);
1233 /// Construct a CallInst given a range of arguments.
1234 /// \brief Construct a CallInst from a range of arguments
1235 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1236 const Twine &NameStr, Instruction *InsertBefore);
1238 /// Construct a CallInst given a range of arguments.
1239 /// \brief Construct a CallInst from a range of arguments
1240 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1241 const Twine &NameStr, BasicBlock *InsertAtEnd);
1243 explicit CallInst(Value *F, const Twine &NameStr,
1244 Instruction *InsertBefore);
1245 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1247 CallInst *clone_impl() const override;
1249 static CallInst *Create(Value *Func,
1250 ArrayRef<Value *> Args,
1251 const Twine &NameStr = "",
1252 Instruction *InsertBefore = nullptr) {
1253 return new(unsigned(Args.size() + 1))
1254 CallInst(Func, Args, NameStr, InsertBefore);
1256 static CallInst *Create(Value *Func,
1257 ArrayRef<Value *> Args,
1258 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1259 return new(unsigned(Args.size() + 1))
1260 CallInst(Func, Args, NameStr, InsertAtEnd);
1262 static CallInst *Create(Value *F, const Twine &NameStr = "",
1263 Instruction *InsertBefore = nullptr) {
1264 return new(1) CallInst(F, NameStr, InsertBefore);
1266 static CallInst *Create(Value *F, const Twine &NameStr,
1267 BasicBlock *InsertAtEnd) {
1268 return new(1) CallInst(F, NameStr, InsertAtEnd);
1270 /// CreateMalloc - Generate the IR for a call to malloc:
1271 /// 1. Compute the malloc call's argument as the specified type's size,
1272 /// possibly multiplied by the array size if the array size is not
1274 /// 2. Call malloc with that argument.
1275 /// 3. Bitcast the result of the malloc call to the specified type.
1276 static Instruction *CreateMalloc(Instruction *InsertBefore,
1277 Type *IntPtrTy, Type *AllocTy,
1278 Value *AllocSize, Value *ArraySize = nullptr,
1279 Function* MallocF = nullptr,
1280 const Twine &Name = "");
1281 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1282 Type *IntPtrTy, Type *AllocTy,
1283 Value *AllocSize, Value *ArraySize = nullptr,
1284 Function* MallocF = nullptr,
1285 const Twine &Name = "");
1286 /// CreateFree - Generate the IR for a call to the builtin free function.
1287 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
1288 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
1292 // Note that 'musttail' implies 'tail'.
1293 enum TailCallKind { TCK_None = 0, TCK_Tail = 1, TCK_MustTail = 2 };
1294 TailCallKind getTailCallKind() const {
1295 return TailCallKind(getSubclassDataFromInstruction() & 3);
1297 bool isTailCall() const {
1298 return (getSubclassDataFromInstruction() & 3) != TCK_None;
1300 bool isMustTailCall() const {
1301 return (getSubclassDataFromInstruction() & 3) == TCK_MustTail;
1303 void setTailCall(bool isTC = true) {
1304 setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
1305 unsigned(isTC ? TCK_Tail : TCK_None));
1307 void setTailCallKind(TailCallKind TCK) {
1308 setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
1312 /// Provide fast operand accessors
1313 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1315 /// getNumArgOperands - Return the number of call arguments.
1317 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
1319 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1321 Value *getArgOperand(unsigned i) const { return getOperand(i); }
1322 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
1324 /// arg_operands - iteration adapter for range-for loops.
1325 iterator_range<op_iterator> arg_operands() {
1326 // The last operand in the op list is the callee - it's not one of the args
1327 // so we don't want to iterate over it.
1328 return iterator_range<op_iterator>(op_begin(), op_end() - 1);
1331 /// arg_operands - iteration adapter for range-for loops.
1332 iterator_range<const_op_iterator> arg_operands() const {
1333 return iterator_range<const_op_iterator>(op_begin(), op_end() - 1);
1336 /// \brief Wrappers for getting the \c Use of a call argument.
1337 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
1338 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
1340 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1342 CallingConv::ID getCallingConv() const {
1343 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2);
1345 void setCallingConv(CallingConv::ID CC) {
1346 setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
1347 (static_cast<unsigned>(CC) << 2));
1350 /// getAttributes - Return the parameter attributes for this call.
1352 const AttributeSet &getAttributes() const { return AttributeList; }
1354 /// setAttributes - Set the parameter attributes for this call.
1356 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
1358 /// addAttribute - adds the attribute to the list of attributes.
1359 void addAttribute(unsigned i, Attribute::AttrKind attr);
1361 /// removeAttribute - removes the attribute from the list of attributes.
1362 void removeAttribute(unsigned i, Attribute attr);
1364 /// \brief Determine whether this call has the given attribute.
1365 bool hasFnAttr(Attribute::AttrKind A) const {
1366 assert(A != Attribute::NoBuiltin &&
1367 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
1368 return hasFnAttrImpl(A);
1371 /// \brief Determine whether the call or the callee has the given attributes.
1372 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
1374 /// \brief Extract the alignment for a call or parameter (0=unknown).
1375 unsigned getParamAlignment(unsigned i) const {
1376 return AttributeList.getParamAlignment(i);
1379 /// \brief Return true if the call should not be treated as a call to a
1381 bool isNoBuiltin() const {
1382 return hasFnAttrImpl(Attribute::NoBuiltin) &&
1383 !hasFnAttrImpl(Attribute::Builtin);
1386 /// \brief Return true if the call should not be inlined.
1387 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
1388 void setIsNoInline() {
1389 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
1392 /// \brief Return true if the call can return twice
1393 bool canReturnTwice() const {
1394 return hasFnAttr(Attribute::ReturnsTwice);
1396 void setCanReturnTwice() {
1397 addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice);
1400 /// \brief Determine if the call does not access memory.
1401 bool doesNotAccessMemory() const {
1402 return hasFnAttr(Attribute::ReadNone);
1404 void setDoesNotAccessMemory() {
1405 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
1408 /// \brief Determine if the call does not access or only reads memory.
1409 bool onlyReadsMemory() const {
1410 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
1412 void setOnlyReadsMemory() {
1413 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
1416 /// \brief Determine if the call cannot return.
1417 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
1418 void setDoesNotReturn() {
1419 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
1422 /// \brief Determine if the call cannot unwind.
1423 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
1424 void setDoesNotThrow() {
1425 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
1428 /// \brief Determine if the call cannot be duplicated.
1429 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
1430 void setCannotDuplicate() {
1431 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
1434 /// \brief Determine if the call returns a structure through first
1435 /// pointer argument.
1436 bool hasStructRetAttr() const {
1437 // Be friendly and also check the callee.
1438 return paramHasAttr(1, Attribute::StructRet);
1441 /// \brief Determine if any call argument is an aggregate passed by value.
1442 bool hasByValArgument() const {
1443 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1446 /// getCalledFunction - Return the function called, or null if this is an
1447 /// indirect function invocation.
1449 Function *getCalledFunction() const {
1450 return dyn_cast<Function>(Op<-1>());
1453 /// getCalledValue - Get a pointer to the function that is invoked by this
1455 const Value *getCalledValue() const { return Op<-1>(); }
1456 Value *getCalledValue() { return Op<-1>(); }
1458 /// setCalledFunction - Set the function called.
1459 void setCalledFunction(Value* Fn) {
1463 /// isInlineAsm - Check if this call is an inline asm statement.
1464 bool isInlineAsm() const {
1465 return isa<InlineAsm>(Op<-1>());
1468 // Methods for support type inquiry through isa, cast, and dyn_cast:
1469 static inline bool classof(const Instruction *I) {
1470 return I->getOpcode() == Instruction::Call;
1472 static inline bool classof(const Value *V) {
1473 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1477 bool hasFnAttrImpl(Attribute::AttrKind A) const;
1479 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1480 // method so that subclasses cannot accidentally use it.
1481 void setInstructionSubclassData(unsigned short D) {
1482 Instruction::setInstructionSubclassData(D);
1487 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1490 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1491 const Twine &NameStr, BasicBlock *InsertAtEnd)
1492 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1493 ->getElementType())->getReturnType(),
1495 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1496 unsigned(Args.size() + 1), InsertAtEnd) {
1497 init(Func, Args, NameStr);
1500 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1501 const Twine &NameStr, Instruction *InsertBefore)
1502 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1503 ->getElementType())->getReturnType(),
1505 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1506 unsigned(Args.size() + 1), InsertBefore) {
1507 init(Func, Args, NameStr);
1511 // Note: if you get compile errors about private methods then
1512 // please update your code to use the high-level operand
1513 // interfaces. See line 943 above.
1514 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1516 //===----------------------------------------------------------------------===//
1518 //===----------------------------------------------------------------------===//
1520 /// SelectInst - This class represents the LLVM 'select' instruction.
1522 class SelectInst : public Instruction {
1523 void init(Value *C, Value *S1, Value *S2) {
1524 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1530 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1531 Instruction *InsertBefore)
1532 : Instruction(S1->getType(), Instruction::Select,
1533 &Op<0>(), 3, InsertBefore) {
1537 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1538 BasicBlock *InsertAtEnd)
1539 : Instruction(S1->getType(), Instruction::Select,
1540 &Op<0>(), 3, InsertAtEnd) {
1545 SelectInst *clone_impl() const override;
1547 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1548 const Twine &NameStr = "",
1549 Instruction *InsertBefore = nullptr) {
1550 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1552 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1553 const Twine &NameStr,
1554 BasicBlock *InsertAtEnd) {
1555 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1558 const Value *getCondition() const { return Op<0>(); }
1559 const Value *getTrueValue() const { return Op<1>(); }
1560 const Value *getFalseValue() const { return Op<2>(); }
1561 Value *getCondition() { return Op<0>(); }
1562 Value *getTrueValue() { return Op<1>(); }
1563 Value *getFalseValue() { return Op<2>(); }
1565 /// areInvalidOperands - Return a string if the specified operands are invalid
1566 /// for a select operation, otherwise return null.
1567 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1569 /// Transparently provide more efficient getOperand methods.
1570 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1572 OtherOps getOpcode() const {
1573 return static_cast<OtherOps>(Instruction::getOpcode());
1576 // Methods for support type inquiry through isa, cast, and dyn_cast:
1577 static inline bool classof(const Instruction *I) {
1578 return I->getOpcode() == Instruction::Select;
1580 static inline bool classof(const Value *V) {
1581 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1586 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1589 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1591 //===----------------------------------------------------------------------===//
1593 //===----------------------------------------------------------------------===//
1595 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1596 /// an argument of the specified type given a va_list and increments that list
1598 class VAArgInst : public UnaryInstruction {
1600 VAArgInst *clone_impl() const override;
1603 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1604 Instruction *InsertBefore = nullptr)
1605 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1608 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1609 BasicBlock *InsertAtEnd)
1610 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1614 Value *getPointerOperand() { return getOperand(0); }
1615 const Value *getPointerOperand() const { return getOperand(0); }
1616 static unsigned getPointerOperandIndex() { return 0U; }
1618 // Methods for support type inquiry through isa, cast, and dyn_cast:
1619 static inline bool classof(const Instruction *I) {
1620 return I->getOpcode() == VAArg;
1622 static inline bool classof(const Value *V) {
1623 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1627 //===----------------------------------------------------------------------===//
1628 // ExtractElementInst Class
1629 //===----------------------------------------------------------------------===//
1631 /// ExtractElementInst - This instruction extracts a single (scalar)
1632 /// element from a VectorType value
1634 class ExtractElementInst : public Instruction {
1635 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1636 Instruction *InsertBefore = nullptr);
1637 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1638 BasicBlock *InsertAtEnd);
1640 ExtractElementInst *clone_impl() const override;
1643 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1644 const Twine &NameStr = "",
1645 Instruction *InsertBefore = nullptr) {
1646 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1648 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1649 const Twine &NameStr,
1650 BasicBlock *InsertAtEnd) {
1651 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1654 /// isValidOperands - Return true if an extractelement instruction can be
1655 /// formed with the specified operands.
1656 static bool isValidOperands(const Value *Vec, const Value *Idx);
1658 Value *getVectorOperand() { return Op<0>(); }
1659 Value *getIndexOperand() { return Op<1>(); }
1660 const Value *getVectorOperand() const { return Op<0>(); }
1661 const Value *getIndexOperand() const { return Op<1>(); }
1663 VectorType *getVectorOperandType() const {
1664 return cast<VectorType>(getVectorOperand()->getType());
1668 /// Transparently provide more efficient getOperand methods.
1669 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1671 // Methods for support type inquiry through isa, cast, and dyn_cast:
1672 static inline bool classof(const Instruction *I) {
1673 return I->getOpcode() == Instruction::ExtractElement;
1675 static inline bool classof(const Value *V) {
1676 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1681 struct OperandTraits<ExtractElementInst> :
1682 public FixedNumOperandTraits<ExtractElementInst, 2> {
1685 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1687 //===----------------------------------------------------------------------===//
1688 // InsertElementInst Class
1689 //===----------------------------------------------------------------------===//
1691 /// InsertElementInst - This instruction inserts a single (scalar)
1692 /// element into a VectorType value
1694 class InsertElementInst : public Instruction {
1695 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1696 const Twine &NameStr = "",
1697 Instruction *InsertBefore = nullptr);
1698 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1699 const Twine &NameStr, BasicBlock *InsertAtEnd);
1701 InsertElementInst *clone_impl() const override;
1704 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1705 const Twine &NameStr = "",
1706 Instruction *InsertBefore = nullptr) {
1707 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1709 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1710 const Twine &NameStr,
1711 BasicBlock *InsertAtEnd) {
1712 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1715 /// isValidOperands - Return true if an insertelement instruction can be
1716 /// formed with the specified operands.
1717 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1720 /// getType - Overload to return most specific vector type.
1722 VectorType *getType() const {
1723 return cast<VectorType>(Instruction::getType());
1726 /// Transparently provide more efficient getOperand methods.
1727 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1729 // Methods for support type inquiry through isa, cast, and dyn_cast:
1730 static inline bool classof(const Instruction *I) {
1731 return I->getOpcode() == Instruction::InsertElement;
1733 static inline bool classof(const Value *V) {
1734 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1739 struct OperandTraits<InsertElementInst> :
1740 public FixedNumOperandTraits<InsertElementInst, 3> {
1743 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1745 //===----------------------------------------------------------------------===//
1746 // ShuffleVectorInst Class
1747 //===----------------------------------------------------------------------===//
1749 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1752 class ShuffleVectorInst : public Instruction {
1754 ShuffleVectorInst *clone_impl() const override;
1757 // allocate space for exactly three operands
1758 void *operator new(size_t s) {
1759 return User::operator new(s, 3);
1761 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1762 const Twine &NameStr = "",
1763 Instruction *InsertBefor = nullptr);
1764 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1765 const Twine &NameStr, BasicBlock *InsertAtEnd);
1767 /// isValidOperands - Return true if a shufflevector instruction can be
1768 /// formed with the specified operands.
1769 static bool isValidOperands(const Value *V1, const Value *V2,
1772 /// getType - Overload to return most specific vector type.
1774 VectorType *getType() const {
1775 return cast<VectorType>(Instruction::getType());
1778 /// Transparently provide more efficient getOperand methods.
1779 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1781 Constant *getMask() const {
1782 return cast<Constant>(getOperand(2));
1785 /// getMaskValue - Return the index from the shuffle mask for the specified
1786 /// output result. This is either -1 if the element is undef or a number less
1787 /// than 2*numelements.
1788 static int getMaskValue(Constant *Mask, unsigned i);
1790 int getMaskValue(unsigned i) const {
1791 return getMaskValue(getMask(), i);
1794 /// getShuffleMask - Return the full mask for this instruction, where each
1795 /// element is the element number and undef's are returned as -1.
1796 static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
1798 void getShuffleMask(SmallVectorImpl<int> &Result) const {
1799 return getShuffleMask(getMask(), Result);
1802 SmallVector<int, 16> getShuffleMask() const {
1803 SmallVector<int, 16> Mask;
1804 getShuffleMask(Mask);
1809 // Methods for support type inquiry through isa, cast, and dyn_cast:
1810 static inline bool classof(const Instruction *I) {
1811 return I->getOpcode() == Instruction::ShuffleVector;
1813 static inline bool classof(const Value *V) {
1814 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1819 struct OperandTraits<ShuffleVectorInst> :
1820 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1823 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1825 //===----------------------------------------------------------------------===//
1826 // ExtractValueInst Class
1827 //===----------------------------------------------------------------------===//
1829 /// ExtractValueInst - This instruction extracts a struct member or array
1830 /// element value from an aggregate value.
1832 class ExtractValueInst : public UnaryInstruction {
1833 SmallVector<unsigned, 4> Indices;
1835 ExtractValueInst(const ExtractValueInst &EVI);
1836 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1838 /// Constructors - Create a extractvalue instruction with a base aggregate
1839 /// value and a list of indices. The first ctor can optionally insert before
1840 /// an existing instruction, the second appends the new instruction to the
1841 /// specified BasicBlock.
1842 inline ExtractValueInst(Value *Agg,
1843 ArrayRef<unsigned> Idxs,
1844 const Twine &NameStr,
1845 Instruction *InsertBefore);
1846 inline ExtractValueInst(Value *Agg,
1847 ArrayRef<unsigned> Idxs,
1848 const Twine &NameStr, BasicBlock *InsertAtEnd);
1850 // allocate space for exactly one operand
1851 void *operator new(size_t s) {
1852 return User::operator new(s, 1);
1855 ExtractValueInst *clone_impl() const override;
1858 static ExtractValueInst *Create(Value *Agg,
1859 ArrayRef<unsigned> Idxs,
1860 const Twine &NameStr = "",
1861 Instruction *InsertBefore = nullptr) {
1863 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1865 static ExtractValueInst *Create(Value *Agg,
1866 ArrayRef<unsigned> Idxs,
1867 const Twine &NameStr,
1868 BasicBlock *InsertAtEnd) {
1869 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1872 /// getIndexedType - Returns the type of the element that would be extracted
1873 /// with an extractvalue instruction with the specified parameters.
1875 /// Null is returned if the indices are invalid for the specified type.
1876 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
1878 typedef const unsigned* idx_iterator;
1879 inline idx_iterator idx_begin() const { return Indices.begin(); }
1880 inline idx_iterator idx_end() const { return Indices.end(); }
1882 Value *getAggregateOperand() {
1883 return getOperand(0);
1885 const Value *getAggregateOperand() const {
1886 return getOperand(0);
1888 static unsigned getAggregateOperandIndex() {
1889 return 0U; // get index for modifying correct operand
1892 ArrayRef<unsigned> getIndices() const {
1896 unsigned getNumIndices() const {
1897 return (unsigned)Indices.size();
1900 bool hasIndices() const {
1904 // Methods for support type inquiry through isa, cast, and dyn_cast:
1905 static inline bool classof(const Instruction *I) {
1906 return I->getOpcode() == Instruction::ExtractValue;
1908 static inline bool classof(const Value *V) {
1909 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1913 ExtractValueInst::ExtractValueInst(Value *Agg,
1914 ArrayRef<unsigned> Idxs,
1915 const Twine &NameStr,
1916 Instruction *InsertBefore)
1917 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1918 ExtractValue, Agg, InsertBefore) {
1919 init(Idxs, NameStr);
1921 ExtractValueInst::ExtractValueInst(Value *Agg,
1922 ArrayRef<unsigned> Idxs,
1923 const Twine &NameStr,
1924 BasicBlock *InsertAtEnd)
1925 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1926 ExtractValue, Agg, InsertAtEnd) {
1927 init(Idxs, NameStr);
1931 //===----------------------------------------------------------------------===//
1932 // InsertValueInst Class
1933 //===----------------------------------------------------------------------===//
1935 /// InsertValueInst - This instruction inserts a struct field of array element
1936 /// value into an aggregate value.
1938 class InsertValueInst : public Instruction {
1939 SmallVector<unsigned, 4> Indices;
1941 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1942 InsertValueInst(const InsertValueInst &IVI);
1943 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1944 const Twine &NameStr);
1946 /// Constructors - Create a insertvalue instruction with a base aggregate
1947 /// value, a value to insert, and a list of indices. The first ctor can
1948 /// optionally insert before an existing instruction, the second appends
1949 /// the new instruction to the specified BasicBlock.
1950 inline InsertValueInst(Value *Agg, Value *Val,
1951 ArrayRef<unsigned> Idxs,
1952 const Twine &NameStr,
1953 Instruction *InsertBefore);
1954 inline InsertValueInst(Value *Agg, Value *Val,
1955 ArrayRef<unsigned> Idxs,
1956 const Twine &NameStr, BasicBlock *InsertAtEnd);
1958 /// Constructors - These two constructors are convenience methods because one
1959 /// and two index insertvalue instructions are so common.
1960 InsertValueInst(Value *Agg, Value *Val,
1961 unsigned Idx, const Twine &NameStr = "",
1962 Instruction *InsertBefore = nullptr);
1963 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1964 const Twine &NameStr, BasicBlock *InsertAtEnd);
1966 InsertValueInst *clone_impl() const override;
1968 // allocate space for exactly two operands
1969 void *operator new(size_t s) {
1970 return User::operator new(s, 2);
1973 static InsertValueInst *Create(Value *Agg, Value *Val,
1974 ArrayRef<unsigned> Idxs,
1975 const Twine &NameStr = "",
1976 Instruction *InsertBefore = nullptr) {
1977 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1979 static InsertValueInst *Create(Value *Agg, Value *Val,
1980 ArrayRef<unsigned> Idxs,
1981 const Twine &NameStr,
1982 BasicBlock *InsertAtEnd) {
1983 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1986 /// Transparently provide more efficient getOperand methods.
1987 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1989 typedef const unsigned* idx_iterator;
1990 inline idx_iterator idx_begin() const { return Indices.begin(); }
1991 inline idx_iterator idx_end() const { return Indices.end(); }
1993 Value *getAggregateOperand() {
1994 return getOperand(0);
1996 const Value *getAggregateOperand() const {
1997 return getOperand(0);
1999 static unsigned getAggregateOperandIndex() {
2000 return 0U; // get index for modifying correct operand
2003 Value *getInsertedValueOperand() {
2004 return getOperand(1);
2006 const Value *getInsertedValueOperand() const {
2007 return getOperand(1);
2009 static unsigned getInsertedValueOperandIndex() {
2010 return 1U; // get index for modifying correct operand
2013 ArrayRef<unsigned> getIndices() const {
2017 unsigned getNumIndices() const {
2018 return (unsigned)Indices.size();
2021 bool hasIndices() const {
2025 // Methods for support type inquiry through isa, cast, and dyn_cast:
2026 static inline bool classof(const Instruction *I) {
2027 return I->getOpcode() == Instruction::InsertValue;
2029 static inline bool classof(const Value *V) {
2030 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2035 struct OperandTraits<InsertValueInst> :
2036 public FixedNumOperandTraits<InsertValueInst, 2> {
2039 InsertValueInst::InsertValueInst(Value *Agg,
2041 ArrayRef<unsigned> Idxs,
2042 const Twine &NameStr,
2043 Instruction *InsertBefore)
2044 : Instruction(Agg->getType(), InsertValue,
2045 OperandTraits<InsertValueInst>::op_begin(this),
2047 init(Agg, Val, Idxs, NameStr);
2049 InsertValueInst::InsertValueInst(Value *Agg,
2051 ArrayRef<unsigned> Idxs,
2052 const Twine &NameStr,
2053 BasicBlock *InsertAtEnd)
2054 : Instruction(Agg->getType(), InsertValue,
2055 OperandTraits<InsertValueInst>::op_begin(this),
2057 init(Agg, Val, Idxs, NameStr);
2060 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
2062 //===----------------------------------------------------------------------===//
2064 //===----------------------------------------------------------------------===//
2066 // PHINode - The PHINode class is used to represent the magical mystical PHI
2067 // node, that can not exist in nature, but can be synthesized in a computer
2068 // scientist's overactive imagination.
2070 class PHINode : public Instruction {
2071 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2072 /// ReservedSpace - The number of operands actually allocated. NumOperands is
2073 /// the number actually in use.
2074 unsigned ReservedSpace;
2075 PHINode(const PHINode &PN);
2076 // allocate space for exactly zero operands
2077 void *operator new(size_t s) {
2078 return User::operator new(s, 0);
2080 explicit PHINode(Type *Ty, unsigned NumReservedValues,
2081 const Twine &NameStr = "",
2082 Instruction *InsertBefore = nullptr)
2083 : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore),
2084 ReservedSpace(NumReservedValues) {
2086 OperandList = allocHungoffUses(ReservedSpace);
2089 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
2090 BasicBlock *InsertAtEnd)
2091 : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd),
2092 ReservedSpace(NumReservedValues) {
2094 OperandList = allocHungoffUses(ReservedSpace);
2097 // allocHungoffUses - this is more complicated than the generic
2098 // User::allocHungoffUses, because we have to allocate Uses for the incoming
2099 // values and pointers to the incoming blocks, all in one allocation.
2100 Use *allocHungoffUses(unsigned) const;
2102 PHINode *clone_impl() const override;
2104 /// Constructors - NumReservedValues is a hint for the number of incoming
2105 /// edges that this phi node will have (use 0 if you really have no idea).
2106 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2107 const Twine &NameStr = "",
2108 Instruction *InsertBefore = nullptr) {
2109 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2111 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2112 const Twine &NameStr, BasicBlock *InsertAtEnd) {
2113 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2117 /// Provide fast operand accessors
2118 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2120 // Block iterator interface. This provides access to the list of incoming
2121 // basic blocks, which parallels the list of incoming values.
2123 typedef BasicBlock **block_iterator;
2124 typedef BasicBlock * const *const_block_iterator;
2126 block_iterator block_begin() {
2128 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2129 return reinterpret_cast<block_iterator>(ref + 1);
2132 const_block_iterator block_begin() const {
2133 const Use::UserRef *ref =
2134 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2135 return reinterpret_cast<const_block_iterator>(ref + 1);
2138 block_iterator block_end() {
2139 return block_begin() + getNumOperands();
2142 const_block_iterator block_end() const {
2143 return block_begin() + getNumOperands();
2146 /// getNumIncomingValues - Return the number of incoming edges
2148 unsigned getNumIncomingValues() const { return getNumOperands(); }
2150 /// getIncomingValue - Return incoming value number x
2152 Value *getIncomingValue(unsigned i) const {
2153 return getOperand(i);
2155 void setIncomingValue(unsigned i, Value *V) {
2158 static unsigned getOperandNumForIncomingValue(unsigned i) {
2161 static unsigned getIncomingValueNumForOperand(unsigned i) {
2165 /// getIncomingBlock - Return incoming basic block number @p i.
2167 BasicBlock *getIncomingBlock(unsigned i) const {
2168 return block_begin()[i];
2171 /// getIncomingBlock - Return incoming basic block corresponding
2172 /// to an operand of the PHI.
2174 BasicBlock *getIncomingBlock(const Use &U) const {
2175 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2176 return getIncomingBlock(unsigned(&U - op_begin()));
2179 /// getIncomingBlock - Return incoming basic block corresponding
2180 /// to value use iterator.
2182 BasicBlock *getIncomingBlock(Value::const_user_iterator I) const {
2183 return getIncomingBlock(I.getUse());
2186 void setIncomingBlock(unsigned i, BasicBlock *BB) {
2187 block_begin()[i] = BB;
2190 /// addIncoming - Add an incoming value to the end of the PHI list
2192 void addIncoming(Value *V, BasicBlock *BB) {
2193 assert(V && "PHI node got a null value!");
2194 assert(BB && "PHI node got a null basic block!");
2195 assert(getType() == V->getType() &&
2196 "All operands to PHI node must be the same type as the PHI node!");
2197 if (NumOperands == ReservedSpace)
2198 growOperands(); // Get more space!
2199 // Initialize some new operands.
2201 setIncomingValue(NumOperands - 1, V);
2202 setIncomingBlock(NumOperands - 1, BB);
2205 /// removeIncomingValue - Remove an incoming value. This is useful if a
2206 /// predecessor basic block is deleted. The value removed is returned.
2208 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2209 /// is true), the PHI node is destroyed and any uses of it are replaced with
2210 /// dummy values. The only time there should be zero incoming values to a PHI
2211 /// node is when the block is dead, so this strategy is sound.
2213 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2215 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2216 int Idx = getBasicBlockIndex(BB);
2217 assert(Idx >= 0 && "Invalid basic block argument to remove!");
2218 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2221 /// getBasicBlockIndex - Return the first index of the specified basic
2222 /// block in the value list for this PHI. Returns -1 if no instance.
2224 int getBasicBlockIndex(const BasicBlock *BB) const {
2225 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2226 if (block_begin()[i] == BB)
2231 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2232 int Idx = getBasicBlockIndex(BB);
2233 assert(Idx >= 0 && "Invalid basic block argument!");
2234 return getIncomingValue(Idx);
2237 /// hasConstantValue - If the specified PHI node always merges together the
2238 /// same value, return the value, otherwise return null.
2239 Value *hasConstantValue() const;
2241 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2242 static inline bool classof(const Instruction *I) {
2243 return I->getOpcode() == Instruction::PHI;
2245 static inline bool classof(const Value *V) {
2246 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2249 void growOperands();
2253 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2256 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
2258 //===----------------------------------------------------------------------===//
2259 // LandingPadInst Class
2260 //===----------------------------------------------------------------------===//
2262 //===---------------------------------------------------------------------------
2263 /// LandingPadInst - The landingpad instruction holds all of the information
2264 /// necessary to generate correct exception handling. The landingpad instruction
2265 /// cannot be moved from the top of a landing pad block, which itself is
2266 /// accessible only from the 'unwind' edge of an invoke. This uses the
2267 /// SubclassData field in Value to store whether or not the landingpad is a
2270 class LandingPadInst : public Instruction {
2271 /// ReservedSpace - The number of operands actually allocated. NumOperands is
2272 /// the number actually in use.
2273 unsigned ReservedSpace;
2274 LandingPadInst(const LandingPadInst &LP);
2276 enum ClauseType { Catch, Filter };
2278 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2279 // Allocate space for exactly zero operands.
2280 void *operator new(size_t s) {
2281 return User::operator new(s, 0);
2283 void growOperands(unsigned Size);
2284 void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
2286 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2287 unsigned NumReservedValues, const Twine &NameStr,
2288 Instruction *InsertBefore);
2289 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2290 unsigned NumReservedValues, const Twine &NameStr,
2291 BasicBlock *InsertAtEnd);
2293 LandingPadInst *clone_impl() const override;
2295 /// Constructors - NumReservedClauses is a hint for the number of incoming
2296 /// clauses that this landingpad will have (use 0 if you really have no idea).
2297 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2298 unsigned NumReservedClauses,
2299 const Twine &NameStr = "",
2300 Instruction *InsertBefore = nullptr);
2301 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2302 unsigned NumReservedClauses,
2303 const Twine &NameStr, BasicBlock *InsertAtEnd);
2306 /// Provide fast operand accessors
2307 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2309 /// getPersonalityFn - Get the personality function associated with this
2311 Value *getPersonalityFn() const { return getOperand(0); }
2313 /// isCleanup - Return 'true' if this landingpad instruction is a
2314 /// cleanup. I.e., it should be run when unwinding even if its landing pad
2315 /// doesn't catch the exception.
2316 bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2318 /// setCleanup - Indicate that this landingpad instruction is a cleanup.
2319 void setCleanup(bool V) {
2320 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2324 /// Add a catch or filter clause to the landing pad.
2325 void addClause(Constant *ClauseVal);
2327 /// Get the value of the clause at index Idx. Use isCatch/isFilter to
2328 /// determine what type of clause this is.
2329 Constant *getClause(unsigned Idx) const {
2330 return cast<Constant>(OperandList[Idx + 1]);
2333 /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
2334 bool isCatch(unsigned Idx) const {
2335 return !isa<ArrayType>(OperandList[Idx + 1]->getType());
2338 /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
2339 bool isFilter(unsigned Idx) const {
2340 return isa<ArrayType>(OperandList[Idx + 1]->getType());
2343 /// getNumClauses - Get the number of clauses for this landing pad.
2344 unsigned getNumClauses() const { return getNumOperands() - 1; }
2346 /// reserveClauses - Grow the size of the operand list to accommodate the new
2347 /// number of clauses.
2348 void reserveClauses(unsigned Size) { growOperands(Size); }
2350 // Methods for support type inquiry through isa, cast, and dyn_cast:
2351 static inline bool classof(const Instruction *I) {
2352 return I->getOpcode() == Instruction::LandingPad;
2354 static inline bool classof(const Value *V) {
2355 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2360 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
2363 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
2365 //===----------------------------------------------------------------------===//
2367 //===----------------------------------------------------------------------===//
2369 //===---------------------------------------------------------------------------
2370 /// ReturnInst - Return a value (possibly void), from a function. Execution
2371 /// does not continue in this function any longer.
2373 class ReturnInst : public TerminatorInst {
2374 ReturnInst(const ReturnInst &RI);
2377 // ReturnInst constructors:
2378 // ReturnInst() - 'ret void' instruction
2379 // ReturnInst( null) - 'ret void' instruction
2380 // ReturnInst(Value* X) - 'ret X' instruction
2381 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
2382 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
2383 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2384 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
2386 // NOTE: If the Value* passed is of type void then the constructor behaves as
2387 // if it was passed NULL.
2388 explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr,
2389 Instruction *InsertBefore = nullptr);
2390 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2391 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2393 ReturnInst *clone_impl() const override;
2395 static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr,
2396 Instruction *InsertBefore = nullptr) {
2397 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2399 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2400 BasicBlock *InsertAtEnd) {
2401 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2403 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2404 return new(0) ReturnInst(C, InsertAtEnd);
2406 virtual ~ReturnInst();
2408 /// Provide fast operand accessors
2409 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2411 /// Convenience accessor. Returns null if there is no return value.
2412 Value *getReturnValue() const {
2413 return getNumOperands() != 0 ? getOperand(0) : nullptr;
2416 unsigned getNumSuccessors() const { return 0; }
2418 // Methods for support type inquiry through isa, cast, and dyn_cast:
2419 static inline bool classof(const Instruction *I) {
2420 return (I->getOpcode() == Instruction::Ret);
2422 static inline bool classof(const Value *V) {
2423 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2426 BasicBlock *getSuccessorV(unsigned idx) const override;
2427 unsigned getNumSuccessorsV() const override;
2428 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2432 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2435 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2437 //===----------------------------------------------------------------------===//
2439 //===----------------------------------------------------------------------===//
2441 //===---------------------------------------------------------------------------
2442 /// BranchInst - Conditional or Unconditional Branch instruction.
2444 class BranchInst : public TerminatorInst {
2445 /// Ops list - Branches are strange. The operands are ordered:
2446 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2447 /// they don't have to check for cond/uncond branchness. These are mostly
2448 /// accessed relative from op_end().
2449 BranchInst(const BranchInst &BI);
2451 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2452 // BranchInst(BB *B) - 'br B'
2453 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2454 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2455 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2456 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2457 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2458 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr);
2459 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2460 Instruction *InsertBefore = nullptr);
2461 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2462 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2463 BasicBlock *InsertAtEnd);
2465 BranchInst *clone_impl() const override;
2467 static BranchInst *Create(BasicBlock *IfTrue,
2468 Instruction *InsertBefore = nullptr) {
2469 return new(1) BranchInst(IfTrue, InsertBefore);
2471 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2472 Value *Cond, Instruction *InsertBefore = nullptr) {
2473 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2475 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2476 return new(1) BranchInst(IfTrue, InsertAtEnd);
2478 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2479 Value *Cond, BasicBlock *InsertAtEnd) {
2480 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2483 /// Transparently provide more efficient getOperand methods.
2484 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2486 bool isUnconditional() const { return getNumOperands() == 1; }
2487 bool isConditional() const { return getNumOperands() == 3; }
2489 Value *getCondition() const {
2490 assert(isConditional() && "Cannot get condition of an uncond branch!");
2494 void setCondition(Value *V) {
2495 assert(isConditional() && "Cannot set condition of unconditional branch!");
2499 unsigned getNumSuccessors() const { return 1+isConditional(); }
2501 BasicBlock *getSuccessor(unsigned i) const {
2502 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2503 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2506 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2507 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2508 *(&Op<-1>() - idx) = (Value*)NewSucc;
2511 /// \brief Swap the successors of this branch instruction.
2513 /// Swaps the successors of the branch instruction. This also swaps any
2514 /// branch weight metadata associated with the instruction so that it
2515 /// continues to map correctly to each operand.
2516 void swapSuccessors();
2518 // Methods for support type inquiry through isa, cast, and dyn_cast:
2519 static inline bool classof(const Instruction *I) {
2520 return (I->getOpcode() == Instruction::Br);
2522 static inline bool classof(const Value *V) {
2523 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2526 BasicBlock *getSuccessorV(unsigned idx) const override;
2527 unsigned getNumSuccessorsV() const override;
2528 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2532 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2535 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2537 //===----------------------------------------------------------------------===//
2539 //===----------------------------------------------------------------------===//
2541 //===---------------------------------------------------------------------------
2542 /// SwitchInst - Multiway switch
2544 class SwitchInst : public TerminatorInst {
2545 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2546 unsigned ReservedSpace;
2547 // Operand[0] = Value to switch on
2548 // Operand[1] = Default basic block destination
2549 // Operand[2n ] = Value to match
2550 // Operand[2n+1] = BasicBlock to go to on match
2551 SwitchInst(const SwitchInst &SI);
2552 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2553 void growOperands();
2554 // allocate space for exactly zero operands
2555 void *operator new(size_t s) {
2556 return User::operator new(s, 0);
2558 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2559 /// switch on and a default destination. The number of additional cases can
2560 /// be specified here to make memory allocation more efficient. This
2561 /// constructor can also autoinsert before another instruction.
2562 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2563 Instruction *InsertBefore);
2565 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2566 /// switch on and a default destination. The number of additional cases can
2567 /// be specified here to make memory allocation more efficient. This
2568 /// constructor also autoinserts at the end of the specified BasicBlock.
2569 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2570 BasicBlock *InsertAtEnd);
2572 SwitchInst *clone_impl() const override;
2576 static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
2578 template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy>
2579 class CaseIteratorT {
2587 typedef CaseIteratorT<SwitchInstTy, ConstantIntTy, BasicBlockTy> Self;
2589 /// Initializes case iterator for given SwitchInst and for given
2591 CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
2596 /// Initializes case iterator for given SwitchInst and for given
2597 /// TerminatorInst's successor index.
2598 static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
2599 assert(SuccessorIndex < SI->getNumSuccessors() &&
2600 "Successor index # out of range!");
2601 return SuccessorIndex != 0 ?
2602 Self(SI, SuccessorIndex - 1) :
2603 Self(SI, DefaultPseudoIndex);
2606 /// Resolves case value for current case.
2607 ConstantIntTy *getCaseValue() {
2608 assert(Index < SI->getNumCases() && "Index out the number of cases.");
2609 return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2));
2612 /// Resolves successor for current case.
2613 BasicBlockTy *getCaseSuccessor() {
2614 assert((Index < SI->getNumCases() ||
2615 Index == DefaultPseudoIndex) &&
2616 "Index out the number of cases.");
2617 return SI->getSuccessor(getSuccessorIndex());
2620 /// Returns number of current case.
2621 unsigned getCaseIndex() const { return Index; }
2623 /// Returns TerminatorInst's successor index for current case successor.
2624 unsigned getSuccessorIndex() const {
2625 assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
2626 "Index out the number of cases.");
2627 return Index != DefaultPseudoIndex ? Index + 1 : 0;
2631 // Check index correctness after increment.
2632 // Note: Index == getNumCases() means end().
2633 assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
2637 Self operator++(int) {
2643 // Check index correctness after decrement.
2644 // Note: Index == getNumCases() means end().
2645 // Also allow "-1" iterator here. That will became valid after ++.
2646 assert((Index == 0 || Index-1 <= SI->getNumCases()) &&
2647 "Index out the number of cases.");
2651 Self operator--(int) {
2656 bool operator==(const Self& RHS) const {
2657 assert(RHS.SI == SI && "Incompatible operators.");
2658 return RHS.Index == Index;
2660 bool operator!=(const Self& RHS) const {
2661 assert(RHS.SI == SI && "Incompatible operators.");
2662 return RHS.Index != Index;
2666 typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock>
2669 class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> {
2671 typedef CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> ParentTy;
2675 CaseIt(const ParentTy& Src) : ParentTy(Src) {}
2676 CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
2678 /// Sets the new value for current case.
2679 void setValue(ConstantInt *V) {
2680 assert(Index < SI->getNumCases() && "Index out the number of cases.");
2681 SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V));
2684 /// Sets the new successor for current case.
2685 void setSuccessor(BasicBlock *S) {
2686 SI->setSuccessor(getSuccessorIndex(), S);
2690 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2692 Instruction *InsertBefore = nullptr) {
2693 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2695 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2696 unsigned NumCases, BasicBlock *InsertAtEnd) {
2697 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2702 /// Provide fast operand accessors
2703 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2705 // Accessor Methods for Switch stmt
2706 Value *getCondition() const { return getOperand(0); }
2707 void setCondition(Value *V) { setOperand(0, V); }
2709 BasicBlock *getDefaultDest() const {
2710 return cast<BasicBlock>(getOperand(1));
2713 void setDefaultDest(BasicBlock *DefaultCase) {
2714 setOperand(1, reinterpret_cast<Value*>(DefaultCase));
2717 /// getNumCases - return the number of 'cases' in this switch instruction,
2718 /// except the default case
2719 unsigned getNumCases() const {
2720 return getNumOperands()/2 - 1;
2723 /// Returns a read/write iterator that points to the first
2724 /// case in SwitchInst.
2725 CaseIt case_begin() {
2726 return CaseIt(this, 0);
2728 /// Returns a read-only iterator that points to the first
2729 /// case in the SwitchInst.
2730 ConstCaseIt case_begin() const {
2731 return ConstCaseIt(this, 0);
2734 /// Returns a read/write iterator that points one past the last
2735 /// in the SwitchInst.
2737 return CaseIt(this, getNumCases());
2739 /// Returns a read-only iterator that points one past the last
2740 /// in the SwitchInst.
2741 ConstCaseIt case_end() const {
2742 return ConstCaseIt(this, getNumCases());
2744 /// Returns an iterator that points to the default case.
2745 /// Note: this iterator allows to resolve successor only. Attempt
2746 /// to resolve case value causes an assertion.
2747 /// Also note, that increment and decrement also causes an assertion and
2748 /// makes iterator invalid.
2749 CaseIt case_default() {
2750 return CaseIt(this, DefaultPseudoIndex);
2752 ConstCaseIt case_default() const {
2753 return ConstCaseIt(this, DefaultPseudoIndex);
2756 /// findCaseValue - Search all of the case values for the specified constant.
2757 /// If it is explicitly handled, return the case iterator of it, otherwise
2758 /// return default case iterator to indicate
2759 /// that it is handled by the default handler.
2760 CaseIt findCaseValue(const ConstantInt *C) {
2761 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
2762 if (i.getCaseValue() == C)
2764 return case_default();
2766 ConstCaseIt findCaseValue(const ConstantInt *C) const {
2767 for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
2768 if (i.getCaseValue() == C)
2770 return case_default();
2773 /// findCaseDest - Finds the unique case value for a given successor. Returns
2774 /// null if the successor is not found, not unique, or is the default case.
2775 ConstantInt *findCaseDest(BasicBlock *BB) {
2776 if (BB == getDefaultDest()) return nullptr;
2778 ConstantInt *CI = nullptr;
2779 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
2780 if (i.getCaseSuccessor() == BB) {
2781 if (CI) return nullptr; // Multiple cases lead to BB.
2782 else CI = i.getCaseValue();
2788 /// addCase - Add an entry to the switch instruction...
2790 /// This action invalidates case_end(). Old case_end() iterator will
2791 /// point to the added case.
2792 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2794 /// removeCase - This method removes the specified case and its successor
2795 /// from the switch instruction. Note that this operation may reorder the
2796 /// remaining cases at index idx and above.
2798 /// This action invalidates iterators for all cases following the one removed,
2799 /// including the case_end() iterator.
2800 void removeCase(CaseIt i);
2802 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2803 BasicBlock *getSuccessor(unsigned idx) const {
2804 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2805 return cast<BasicBlock>(getOperand(idx*2+1));
2807 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2808 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2809 setOperand(idx*2+1, (Value*)NewSucc);
2812 // Methods for support type inquiry through isa, cast, and dyn_cast:
2813 static inline bool classof(const Instruction *I) {
2814 return I->getOpcode() == Instruction::Switch;
2816 static inline bool classof(const Value *V) {
2817 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2820 BasicBlock *getSuccessorV(unsigned idx) const override;
2821 unsigned getNumSuccessorsV() const override;
2822 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2826 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2829 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2832 //===----------------------------------------------------------------------===//
2833 // IndirectBrInst Class
2834 //===----------------------------------------------------------------------===//
2836 //===---------------------------------------------------------------------------
2837 /// IndirectBrInst - Indirect Branch Instruction.
2839 class IndirectBrInst : public TerminatorInst {
2840 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2841 unsigned ReservedSpace;
2842 // Operand[0] = Value to switch on
2843 // Operand[1] = Default basic block destination
2844 // Operand[2n ] = Value to match
2845 // Operand[2n+1] = BasicBlock to go to on match
2846 IndirectBrInst(const IndirectBrInst &IBI);
2847 void init(Value *Address, unsigned NumDests);
2848 void growOperands();
2849 // allocate space for exactly zero operands
2850 void *operator new(size_t s) {
2851 return User::operator new(s, 0);
2853 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2854 /// Address to jump to. The number of expected destinations can be specified
2855 /// here to make memory allocation more efficient. This constructor can also
2856 /// autoinsert before another instruction.
2857 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2859 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2860 /// Address to jump to. The number of expected destinations can be specified
2861 /// here to make memory allocation more efficient. This constructor also
2862 /// autoinserts at the end of the specified BasicBlock.
2863 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2865 IndirectBrInst *clone_impl() const override;
2867 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2868 Instruction *InsertBefore = nullptr) {
2869 return new IndirectBrInst(Address, NumDests, InsertBefore);
2871 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2872 BasicBlock *InsertAtEnd) {
2873 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2877 /// Provide fast operand accessors.
2878 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2880 // Accessor Methods for IndirectBrInst instruction.
2881 Value *getAddress() { return getOperand(0); }
2882 const Value *getAddress() const { return getOperand(0); }
2883 void setAddress(Value *V) { setOperand(0, V); }
2886 /// getNumDestinations - return the number of possible destinations in this
2887 /// indirectbr instruction.
2888 unsigned getNumDestinations() const { return getNumOperands()-1; }
2890 /// getDestination - Return the specified destination.
2891 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2892 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2894 /// addDestination - Add a destination.
2896 void addDestination(BasicBlock *Dest);
2898 /// removeDestination - This method removes the specified successor from the
2899 /// indirectbr instruction.
2900 void removeDestination(unsigned i);
2902 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2903 BasicBlock *getSuccessor(unsigned i) const {
2904 return cast<BasicBlock>(getOperand(i+1));
2906 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2907 setOperand(i+1, (Value*)NewSucc);
2910 // Methods for support type inquiry through isa, cast, and dyn_cast:
2911 static inline bool classof(const Instruction *I) {
2912 return I->getOpcode() == Instruction::IndirectBr;
2914 static inline bool classof(const Value *V) {
2915 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2918 BasicBlock *getSuccessorV(unsigned idx) const override;
2919 unsigned getNumSuccessorsV() const override;
2920 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2924 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2927 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2930 //===----------------------------------------------------------------------===//
2932 //===----------------------------------------------------------------------===//
2934 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2935 /// calling convention of the call.
2937 class InvokeInst : public TerminatorInst {
2938 AttributeSet AttributeList;
2939 InvokeInst(const InvokeInst &BI);
2940 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2941 ArrayRef<Value *> Args, const Twine &NameStr);
2943 /// Construct an InvokeInst given a range of arguments.
2945 /// \brief Construct an InvokeInst from a range of arguments
2946 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2947 ArrayRef<Value *> Args, unsigned Values,
2948 const Twine &NameStr, Instruction *InsertBefore);
2950 /// Construct an InvokeInst given a range of arguments.
2952 /// \brief Construct an InvokeInst from a range of arguments
2953 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2954 ArrayRef<Value *> Args, unsigned Values,
2955 const Twine &NameStr, BasicBlock *InsertAtEnd);
2957 InvokeInst *clone_impl() const override;
2959 static InvokeInst *Create(Value *Func,
2960 BasicBlock *IfNormal, BasicBlock *IfException,
2961 ArrayRef<Value *> Args, const Twine &NameStr = "",
2962 Instruction *InsertBefore = nullptr) {
2963 unsigned Values = unsigned(Args.size()) + 3;
2964 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2965 Values, NameStr, InsertBefore);
2967 static InvokeInst *Create(Value *Func,
2968 BasicBlock *IfNormal, BasicBlock *IfException,
2969 ArrayRef<Value *> Args, const Twine &NameStr,
2970 BasicBlock *InsertAtEnd) {
2971 unsigned Values = unsigned(Args.size()) + 3;
2972 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2973 Values, NameStr, InsertAtEnd);
2976 /// Provide fast operand accessors
2977 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2979 /// getNumArgOperands - Return the number of invoke arguments.
2981 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2983 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2985 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2986 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2988 /// arg_operands - iteration adapter for range-for loops.
2989 iterator_range<op_iterator> arg_operands() {
2990 return iterator_range<op_iterator>(op_begin(), op_end() - 3);
2993 /// arg_operands - iteration adapter for range-for loops.
2994 iterator_range<const_op_iterator> arg_operands() const {
2995 return iterator_range<const_op_iterator>(op_begin(), op_end() - 3);
2998 /// \brief Wrappers for getting the \c Use of a invoke argument.
2999 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
3000 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
3002 /// getCallingConv/setCallingConv - Get or set the calling convention of this
3004 CallingConv::ID getCallingConv() const {
3005 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
3007 void setCallingConv(CallingConv::ID CC) {
3008 setInstructionSubclassData(static_cast<unsigned>(CC));
3011 /// getAttributes - Return the parameter attributes for this invoke.
3013 const AttributeSet &getAttributes() const { return AttributeList; }
3015 /// setAttributes - Set the parameter attributes for this invoke.
3017 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
3019 /// addAttribute - adds the attribute to the list of attributes.
3020 void addAttribute(unsigned i, Attribute::AttrKind attr);
3022 /// removeAttribute - removes the attribute from the list of attributes.
3023 void removeAttribute(unsigned i, Attribute attr);
3025 /// \brief Determine whether this call has the given attribute.
3026 bool hasFnAttr(Attribute::AttrKind A) const {
3027 assert(A != Attribute::NoBuiltin &&
3028 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
3029 return hasFnAttrImpl(A);
3032 /// \brief Determine whether the call or the callee has the given attributes.
3033 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
3035 /// \brief Extract the alignment for a call or parameter (0=unknown).
3036 unsigned getParamAlignment(unsigned i) const {
3037 return AttributeList.getParamAlignment(i);
3040 /// \brief Return true if the call should not be treated as a call to a
3042 bool isNoBuiltin() const {
3043 // We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have
3044 // to check it by hand.
3045 return hasFnAttrImpl(Attribute::NoBuiltin) &&
3046 !hasFnAttrImpl(Attribute::Builtin);
3049 /// \brief Return true if the call should not be inlined.
3050 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
3051 void setIsNoInline() {
3052 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
3055 /// \brief Determine if the call does not access memory.
3056 bool doesNotAccessMemory() const {
3057 return hasFnAttr(Attribute::ReadNone);
3059 void setDoesNotAccessMemory() {
3060 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
3063 /// \brief Determine if the call does not access or only reads memory.
3064 bool onlyReadsMemory() const {
3065 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
3067 void setOnlyReadsMemory() {
3068 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
3071 /// \brief Determine if the call cannot return.
3072 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
3073 void setDoesNotReturn() {
3074 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
3077 /// \brief Determine if the call cannot unwind.
3078 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
3079 void setDoesNotThrow() {
3080 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
3083 /// \brief Determine if the invoke cannot be duplicated.
3084 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
3085 void setCannotDuplicate() {
3086 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
3089 /// \brief Determine if the call returns a structure through first
3090 /// pointer argument.
3091 bool hasStructRetAttr() const {
3092 // Be friendly and also check the callee.
3093 return paramHasAttr(1, Attribute::StructRet);
3096 /// \brief Determine if any call argument is an aggregate passed by value.
3097 bool hasByValArgument() const {
3098 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
3101 /// getCalledFunction - Return the function called, or null if this is an
3102 /// indirect function invocation.
3104 Function *getCalledFunction() const {
3105 return dyn_cast<Function>(Op<-3>());
3108 /// getCalledValue - Get a pointer to the function that is invoked by this
3110 const Value *getCalledValue() const { return Op<-3>(); }
3111 Value *getCalledValue() { return Op<-3>(); }
3113 /// setCalledFunction - Set the function called.
3114 void setCalledFunction(Value* Fn) {
3118 // get*Dest - Return the destination basic blocks...
3119 BasicBlock *getNormalDest() const {
3120 return cast<BasicBlock>(Op<-2>());
3122 BasicBlock *getUnwindDest() const {
3123 return cast<BasicBlock>(Op<-1>());
3125 void setNormalDest(BasicBlock *B) {
3126 Op<-2>() = reinterpret_cast<Value*>(B);
3128 void setUnwindDest(BasicBlock *B) {
3129 Op<-1>() = reinterpret_cast<Value*>(B);
3132 /// getLandingPadInst - Get the landingpad instruction from the landing pad
3133 /// block (the unwind destination).
3134 LandingPadInst *getLandingPadInst() const;
3136 BasicBlock *getSuccessor(unsigned i) const {
3137 assert(i < 2 && "Successor # out of range for invoke!");
3138 return i == 0 ? getNormalDest() : getUnwindDest();
3141 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3142 assert(idx < 2 && "Successor # out of range for invoke!");
3143 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
3146 unsigned getNumSuccessors() const { return 2; }
3148 // Methods for support type inquiry through isa, cast, and dyn_cast:
3149 static inline bool classof(const Instruction *I) {
3150 return (I->getOpcode() == Instruction::Invoke);
3152 static inline bool classof(const Value *V) {
3153 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3157 BasicBlock *getSuccessorV(unsigned idx) const override;
3158 unsigned getNumSuccessorsV() const override;
3159 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3161 bool hasFnAttrImpl(Attribute::AttrKind A) const;
3163 // Shadow Instruction::setInstructionSubclassData with a private forwarding
3164 // method so that subclasses cannot accidentally use it.
3165 void setInstructionSubclassData(unsigned short D) {
3166 Instruction::setInstructionSubclassData(D);
3171 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
3174 InvokeInst::InvokeInst(Value *Func,
3175 BasicBlock *IfNormal, BasicBlock *IfException,
3176 ArrayRef<Value *> Args, unsigned Values,
3177 const Twine &NameStr, Instruction *InsertBefore)
3178 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3179 ->getElementType())->getReturnType(),
3180 Instruction::Invoke,
3181 OperandTraits<InvokeInst>::op_end(this) - Values,
3182 Values, InsertBefore) {
3183 init(Func, IfNormal, IfException, Args, NameStr);
3185 InvokeInst::InvokeInst(Value *Func,
3186 BasicBlock *IfNormal, BasicBlock *IfException,
3187 ArrayRef<Value *> Args, unsigned Values,
3188 const Twine &NameStr, BasicBlock *InsertAtEnd)
3189 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3190 ->getElementType())->getReturnType(),
3191 Instruction::Invoke,
3192 OperandTraits<InvokeInst>::op_end(this) - Values,
3193 Values, InsertAtEnd) {
3194 init(Func, IfNormal, IfException, Args, NameStr);
3197 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
3199 //===----------------------------------------------------------------------===//
3201 //===----------------------------------------------------------------------===//
3203 //===---------------------------------------------------------------------------
3204 /// ResumeInst - Resume the propagation of an exception.
3206 class ResumeInst : public TerminatorInst {
3207 ResumeInst(const ResumeInst &RI);
3209 explicit ResumeInst(Value *Exn, Instruction *InsertBefore=nullptr);
3210 ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
3212 ResumeInst *clone_impl() const override;
3214 static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = nullptr) {
3215 return new(1) ResumeInst(Exn, InsertBefore);
3217 static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
3218 return new(1) ResumeInst(Exn, InsertAtEnd);
3221 /// Provide fast operand accessors
3222 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3224 /// Convenience accessor.
3225 Value *getValue() const { return Op<0>(); }
3227 unsigned getNumSuccessors() const { return 0; }
3229 // Methods for support type inquiry through isa, cast, and dyn_cast:
3230 static inline bool classof(const Instruction *I) {
3231 return I->getOpcode() == Instruction::Resume;
3233 static inline bool classof(const Value *V) {
3234 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3237 BasicBlock *getSuccessorV(unsigned idx) const override;
3238 unsigned getNumSuccessorsV() const override;
3239 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3243 struct OperandTraits<ResumeInst> :
3244 public FixedNumOperandTraits<ResumeInst, 1> {
3247 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
3249 //===----------------------------------------------------------------------===//
3250 // UnreachableInst Class
3251 //===----------------------------------------------------------------------===//
3253 //===---------------------------------------------------------------------------
3254 /// UnreachableInst - This function has undefined behavior. In particular, the
3255 /// presence of this instruction indicates some higher level knowledge that the
3256 /// end of the block cannot be reached.
3258 class UnreachableInst : public TerminatorInst {
3259 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
3261 UnreachableInst *clone_impl() const override;
3264 // allocate space for exactly zero operands
3265 void *operator new(size_t s) {
3266 return User::operator new(s, 0);
3268 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = nullptr);
3269 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
3271 unsigned getNumSuccessors() const { return 0; }
3273 // Methods for support type inquiry through isa, cast, and dyn_cast:
3274 static inline bool classof(const Instruction *I) {
3275 return I->getOpcode() == Instruction::Unreachable;
3277 static inline bool classof(const Value *V) {
3278 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3281 BasicBlock *getSuccessorV(unsigned idx) const override;
3282 unsigned getNumSuccessorsV() const override;
3283 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3286 //===----------------------------------------------------------------------===//
3288 //===----------------------------------------------------------------------===//
3290 /// \brief This class represents a truncation of integer types.
3291 class TruncInst : public CastInst {
3293 /// \brief Clone an identical TruncInst
3294 TruncInst *clone_impl() const override;
3297 /// \brief Constructor with insert-before-instruction semantics
3299 Value *S, ///< The value to be truncated
3300 Type *Ty, ///< The (smaller) type to truncate to
3301 const Twine &NameStr = "", ///< A name for the new instruction
3302 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3305 /// \brief Constructor with insert-at-end-of-block semantics
3307 Value *S, ///< The value to be truncated
3308 Type *Ty, ///< The (smaller) type to truncate to
3309 const Twine &NameStr, ///< A name for the new instruction
3310 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3313 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3314 static inline bool classof(const Instruction *I) {
3315 return I->getOpcode() == Trunc;
3317 static inline bool classof(const Value *V) {
3318 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3322 //===----------------------------------------------------------------------===//
3324 //===----------------------------------------------------------------------===//
3326 /// \brief This class represents zero extension of integer types.
3327 class ZExtInst : public CastInst {
3329 /// \brief Clone an identical ZExtInst
3330 ZExtInst *clone_impl() const override;
3333 /// \brief Constructor with insert-before-instruction semantics
3335 Value *S, ///< The value to be zero extended
3336 Type *Ty, ///< The type to zero extend to
3337 const Twine &NameStr = "", ///< A name for the new instruction
3338 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3341 /// \brief Constructor with insert-at-end semantics.
3343 Value *S, ///< The value to be zero extended
3344 Type *Ty, ///< The type to zero extend to
3345 const Twine &NameStr, ///< A name for the new instruction
3346 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3349 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3350 static inline bool classof(const Instruction *I) {
3351 return I->getOpcode() == ZExt;
3353 static inline bool classof(const Value *V) {
3354 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3358 //===----------------------------------------------------------------------===//
3360 //===----------------------------------------------------------------------===//
3362 /// \brief This class represents a sign extension of integer types.
3363 class SExtInst : public CastInst {
3365 /// \brief Clone an identical SExtInst
3366 SExtInst *clone_impl() const override;
3369 /// \brief Constructor with insert-before-instruction semantics
3371 Value *S, ///< The value to be sign extended
3372 Type *Ty, ///< The type to sign extend to
3373 const Twine &NameStr = "", ///< A name for the new instruction
3374 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3377 /// \brief Constructor with insert-at-end-of-block semantics
3379 Value *S, ///< The value to be sign extended
3380 Type *Ty, ///< The type to sign extend to
3381 const Twine &NameStr, ///< A name for the new instruction
3382 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3385 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3386 static inline bool classof(const Instruction *I) {
3387 return I->getOpcode() == SExt;
3389 static inline bool classof(const Value *V) {
3390 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3394 //===----------------------------------------------------------------------===//
3395 // FPTruncInst Class
3396 //===----------------------------------------------------------------------===//
3398 /// \brief This class represents a truncation of floating point types.
3399 class FPTruncInst : public CastInst {
3401 /// \brief Clone an identical FPTruncInst
3402 FPTruncInst *clone_impl() const override;
3405 /// \brief Constructor with insert-before-instruction semantics
3407 Value *S, ///< The value to be truncated
3408 Type *Ty, ///< The type to truncate to
3409 const Twine &NameStr = "", ///< A name for the new instruction
3410 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3413 /// \brief Constructor with insert-before-instruction semantics
3415 Value *S, ///< The value to be truncated
3416 Type *Ty, ///< The type to truncate to
3417 const Twine &NameStr, ///< A name for the new instruction
3418 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3421 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3422 static inline bool classof(const Instruction *I) {
3423 return I->getOpcode() == FPTrunc;
3425 static inline bool classof(const Value *V) {
3426 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3430 //===----------------------------------------------------------------------===//
3432 //===----------------------------------------------------------------------===//
3434 /// \brief This class represents an extension of floating point types.
3435 class FPExtInst : public CastInst {
3437 /// \brief Clone an identical FPExtInst
3438 FPExtInst *clone_impl() const override;
3441 /// \brief Constructor with insert-before-instruction semantics
3443 Value *S, ///< The value to be extended
3444 Type *Ty, ///< The type to extend to
3445 const Twine &NameStr = "", ///< A name for the new instruction
3446 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3449 /// \brief Constructor with insert-at-end-of-block semantics
3451 Value *S, ///< The value to be extended
3452 Type *Ty, ///< The type to extend to
3453 const Twine &NameStr, ///< A name for the new instruction
3454 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3457 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3458 static inline bool classof(const Instruction *I) {
3459 return I->getOpcode() == FPExt;
3461 static inline bool classof(const Value *V) {
3462 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3466 //===----------------------------------------------------------------------===//
3468 //===----------------------------------------------------------------------===//
3470 /// \brief This class represents a cast unsigned integer to floating point.
3471 class UIToFPInst : public CastInst {
3473 /// \brief Clone an identical UIToFPInst
3474 UIToFPInst *clone_impl() const override;
3477 /// \brief Constructor with insert-before-instruction semantics
3479 Value *S, ///< The value to be converted
3480 Type *Ty, ///< The type to convert to
3481 const Twine &NameStr = "", ///< A name for the new instruction
3482 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3485 /// \brief Constructor with insert-at-end-of-block semantics
3487 Value *S, ///< The value to be converted
3488 Type *Ty, ///< The type to convert to
3489 const Twine &NameStr, ///< A name for the new instruction
3490 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3493 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3494 static inline bool classof(const Instruction *I) {
3495 return I->getOpcode() == UIToFP;
3497 static inline bool classof(const Value *V) {
3498 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3502 //===----------------------------------------------------------------------===//
3504 //===----------------------------------------------------------------------===//
3506 /// \brief This class represents a cast from signed integer to floating point.
3507 class SIToFPInst : public CastInst {
3509 /// \brief Clone an identical SIToFPInst
3510 SIToFPInst *clone_impl() const override;
3513 /// \brief Constructor with insert-before-instruction semantics
3515 Value *S, ///< The value to be converted
3516 Type *Ty, ///< The type to convert to
3517 const Twine &NameStr = "", ///< A name for the new instruction
3518 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3521 /// \brief Constructor with insert-at-end-of-block semantics
3523 Value *S, ///< The value to be converted
3524 Type *Ty, ///< The type to convert to
3525 const Twine &NameStr, ///< A name for the new instruction
3526 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3529 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3530 static inline bool classof(const Instruction *I) {
3531 return I->getOpcode() == SIToFP;
3533 static inline bool classof(const Value *V) {
3534 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3538 //===----------------------------------------------------------------------===//
3540 //===----------------------------------------------------------------------===//
3542 /// \brief This class represents a cast from floating point to unsigned integer
3543 class FPToUIInst : public CastInst {
3545 /// \brief Clone an identical FPToUIInst
3546 FPToUIInst *clone_impl() const override;
3549 /// \brief Constructor with insert-before-instruction semantics
3551 Value *S, ///< The value to be converted
3552 Type *Ty, ///< The type to convert to
3553 const Twine &NameStr = "", ///< A name for the new instruction
3554 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3557 /// \brief Constructor with insert-at-end-of-block semantics
3559 Value *S, ///< The value to be converted
3560 Type *Ty, ///< The type to convert to
3561 const Twine &NameStr, ///< A name for the new instruction
3562 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3565 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3566 static inline bool classof(const Instruction *I) {
3567 return I->getOpcode() == FPToUI;
3569 static inline bool classof(const Value *V) {
3570 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3574 //===----------------------------------------------------------------------===//
3576 //===----------------------------------------------------------------------===//
3578 /// \brief This class represents a cast from floating point to signed integer.
3579 class FPToSIInst : public CastInst {
3581 /// \brief Clone an identical FPToSIInst
3582 FPToSIInst *clone_impl() const override;
3585 /// \brief Constructor with insert-before-instruction semantics
3587 Value *S, ///< The value to be converted
3588 Type *Ty, ///< The type to convert to
3589 const Twine &NameStr = "", ///< A name for the new instruction
3590 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3593 /// \brief Constructor with insert-at-end-of-block semantics
3595 Value *S, ///< The value to be converted
3596 Type *Ty, ///< The type to convert to
3597 const Twine &NameStr, ///< A name for the new instruction
3598 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3601 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3602 static inline bool classof(const Instruction *I) {
3603 return I->getOpcode() == FPToSI;
3605 static inline bool classof(const Value *V) {
3606 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3610 //===----------------------------------------------------------------------===//
3611 // IntToPtrInst Class
3612 //===----------------------------------------------------------------------===//
3614 /// \brief This class represents a cast from an integer to a pointer.
3615 class IntToPtrInst : public CastInst {
3617 /// \brief Constructor with insert-before-instruction semantics
3619 Value *S, ///< The value to be converted
3620 Type *Ty, ///< The type to convert to
3621 const Twine &NameStr = "", ///< A name for the new instruction
3622 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3625 /// \brief Constructor with insert-at-end-of-block semantics
3627 Value *S, ///< The value to be converted
3628 Type *Ty, ///< The type to convert to
3629 const Twine &NameStr, ///< A name for the new instruction
3630 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3633 /// \brief Clone an identical IntToPtrInst
3634 IntToPtrInst *clone_impl() const override;
3636 /// \brief Returns the address space of this instruction's pointer type.
3637 unsigned getAddressSpace() const {
3638 return getType()->getPointerAddressSpace();
3641 // Methods for support type inquiry through isa, cast, and dyn_cast:
3642 static inline bool classof(const Instruction *I) {
3643 return I->getOpcode() == IntToPtr;
3645 static inline bool classof(const Value *V) {
3646 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3650 //===----------------------------------------------------------------------===//
3651 // PtrToIntInst Class
3652 //===----------------------------------------------------------------------===//
3654 /// \brief This class represents a cast from a pointer to an integer
3655 class PtrToIntInst : public CastInst {
3657 /// \brief Clone an identical PtrToIntInst
3658 PtrToIntInst *clone_impl() const override;
3661 /// \brief Constructor with insert-before-instruction semantics
3663 Value *S, ///< The value to be converted
3664 Type *Ty, ///< The type to convert to
3665 const Twine &NameStr = "", ///< A name for the new instruction
3666 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3669 /// \brief Constructor with insert-at-end-of-block semantics
3671 Value *S, ///< The value to be converted
3672 Type *Ty, ///< The type to convert to
3673 const Twine &NameStr, ///< A name for the new instruction
3674 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3677 /// \brief Gets the pointer operand.
3678 Value *getPointerOperand() { return getOperand(0); }
3679 /// \brief Gets the pointer operand.
3680 const Value *getPointerOperand() const { return getOperand(0); }
3681 /// \brief Gets the operand index of the pointer operand.
3682 static unsigned getPointerOperandIndex() { return 0U; }
3684 /// \brief Returns the address space of the pointer operand.
3685 unsigned getPointerAddressSpace() const {
3686 return getPointerOperand()->getType()->getPointerAddressSpace();
3689 // Methods for support type inquiry through isa, cast, and dyn_cast:
3690 static inline bool classof(const Instruction *I) {
3691 return I->getOpcode() == PtrToInt;
3693 static inline bool classof(const Value *V) {
3694 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3698 //===----------------------------------------------------------------------===//
3699 // BitCastInst Class
3700 //===----------------------------------------------------------------------===//
3702 /// \brief This class represents a no-op cast from one type to another.
3703 class BitCastInst : public CastInst {
3705 /// \brief Clone an identical BitCastInst
3706 BitCastInst *clone_impl() const override;
3709 /// \brief Constructor with insert-before-instruction semantics
3711 Value *S, ///< The value to be casted
3712 Type *Ty, ///< The type to casted to
3713 const Twine &NameStr = "", ///< A name for the new instruction
3714 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3717 /// \brief Constructor with insert-at-end-of-block semantics
3719 Value *S, ///< The value to be casted
3720 Type *Ty, ///< The type to casted to
3721 const Twine &NameStr, ///< A name for the new instruction
3722 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3725 // Methods for support type inquiry through isa, cast, and dyn_cast:
3726 static inline bool classof(const Instruction *I) {
3727 return I->getOpcode() == BitCast;
3729 static inline bool classof(const Value *V) {
3730 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3734 //===----------------------------------------------------------------------===//
3735 // AddrSpaceCastInst Class
3736 //===----------------------------------------------------------------------===//
3738 /// \brief This class represents a conversion between pointers from
3739 /// one address space to another.
3740 class AddrSpaceCastInst : public CastInst {
3742 /// \brief Clone an identical AddrSpaceCastInst
3743 AddrSpaceCastInst *clone_impl() const override;
3746 /// \brief Constructor with insert-before-instruction semantics
3748 Value *S, ///< The value to be casted
3749 Type *Ty, ///< The type to casted to
3750 const Twine &NameStr = "", ///< A name for the new instruction
3751 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3754 /// \brief Constructor with insert-at-end-of-block semantics
3756 Value *S, ///< The value to be casted
3757 Type *Ty, ///< The type to casted to
3758 const Twine &NameStr, ///< A name for the new instruction
3759 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3762 // Methods for support type inquiry through isa, cast, and dyn_cast:
3763 static inline bool classof(const Instruction *I) {
3764 return I->getOpcode() == AddrSpaceCast;
3766 static inline bool classof(const Value *V) {
3767 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3771 } // End llvm namespace