1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the class definitions of all of the subclasses of the
11 // Instruction class. This is meant to be an easy way to get access to all
12 // instruction subclasses.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_IR_INSTRUCTIONS_H
17 #define LLVM_IR_INSTRUCTIONS_H
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/iterator_range.h"
22 #include "llvm/IR/Attributes.h"
23 #include "llvm/IR/CallingConv.h"
24 #include "llvm/IR/DerivedTypes.h"
25 #include "llvm/IR/InstrTypes.h"
26 #include "llvm/Support/ErrorHandling.h"
41 // Consume = 3, // Not specified yet.
45 SequentiallyConsistent = 7
48 enum SynchronizationScope {
53 /// Returns true if the ordering is at least as strong as acquire
54 /// (i.e. acquire, acq_rel or seq_cst)
55 inline bool isAtLeastAcquire(AtomicOrdering Ord) {
56 return (Ord == Acquire ||
57 Ord == AcquireRelease ||
58 Ord == SequentiallyConsistent);
61 /// Returns true if the ordering is at least as strong as release
62 /// (i.e. release, acq_rel or seq_cst)
63 inline bool isAtLeastRelease(AtomicOrdering Ord) {
64 return (Ord == Release ||
65 Ord == AcquireRelease ||
66 Ord == SequentiallyConsistent);
69 //===----------------------------------------------------------------------===//
71 //===----------------------------------------------------------------------===//
73 /// AllocaInst - an instruction to allocate memory on the stack
75 class AllocaInst : public UnaryInstruction {
79 AllocaInst *clone_impl() const override;
81 explicit AllocaInst(Type *Ty, Value *ArraySize = nullptr,
82 const Twine &Name = "",
83 Instruction *InsertBefore = nullptr);
84 AllocaInst(Type *Ty, Value *ArraySize,
85 const Twine &Name, BasicBlock *InsertAtEnd);
87 AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = nullptr);
88 AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
90 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
91 const Twine &Name = "", Instruction *InsertBefore = nullptr);
92 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
93 const Twine &Name, BasicBlock *InsertAtEnd);
95 // Out of line virtual method, so the vtable, etc. has a home.
96 ~AllocaInst() override;
98 /// isArrayAllocation - Return true if there is an allocation size parameter
99 /// to the allocation instruction that is not 1.
101 bool isArrayAllocation() const;
103 /// getArraySize - Get the number of elements allocated. For a simple
104 /// allocation of a single element, this will return a constant 1 value.
106 const Value *getArraySize() const { return getOperand(0); }
107 Value *getArraySize() { return getOperand(0); }
109 /// getType - Overload to return most specific pointer type
111 PointerType *getType() const {
112 return cast<PointerType>(Instruction::getType());
115 /// getAllocatedType - Return the type that is being allocated by the
118 Type *getAllocatedType() const { return AllocatedType; }
119 /// \brief for use only in special circumstances that need to generically
120 /// transform a whole instruction (eg: IR linking and vectorization).
121 void setAllocatedType(Type *Ty) { AllocatedType = Ty; }
123 /// getAlignment - Return the alignment of the memory that is being allocated
124 /// by the instruction.
126 unsigned getAlignment() const {
127 return (1u << (getSubclassDataFromInstruction() & 31)) >> 1;
129 void setAlignment(unsigned Align);
131 /// isStaticAlloca - Return true if this alloca is in the entry block of the
132 /// function and is a constant size. If so, the code generator will fold it
133 /// into the prolog/epilog code, so it is basically free.
134 bool isStaticAlloca() const;
136 /// \brief Return true if this alloca is used as an inalloca argument to a
137 /// call. Such allocas are never considered static even if they are in the
139 bool isUsedWithInAlloca() const {
140 return getSubclassDataFromInstruction() & 32;
143 /// \brief Specify whether this alloca is used to represent the arguments to
145 void setUsedWithInAlloca(bool V) {
146 setInstructionSubclassData((getSubclassDataFromInstruction() & ~32) |
150 // Methods for support type inquiry through isa, cast, and dyn_cast:
151 static inline bool classof(const Instruction *I) {
152 return (I->getOpcode() == Instruction::Alloca);
154 static inline bool classof(const Value *V) {
155 return isa<Instruction>(V) && classof(cast<Instruction>(V));
158 // Shadow Instruction::setInstructionSubclassData with a private forwarding
159 // method so that subclasses cannot accidentally use it.
160 void setInstructionSubclassData(unsigned short D) {
161 Instruction::setInstructionSubclassData(D);
166 //===----------------------------------------------------------------------===//
168 //===----------------------------------------------------------------------===//
170 /// LoadInst - an instruction for reading from memory. This uses the
171 /// SubclassData field in Value to store whether or not the load is volatile.
173 class LoadInst : public UnaryInstruction {
176 LoadInst *clone_impl() const override;
178 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
179 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
180 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile = false,
181 Instruction *InsertBefore = nullptr);
182 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
183 Instruction *InsertBefore = nullptr)
184 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
185 NameStr, isVolatile, InsertBefore) {}
186 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
187 BasicBlock *InsertAtEnd);
188 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
189 Instruction *InsertBefore = nullptr)
190 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
191 NameStr, isVolatile, Align, InsertBefore) {}
192 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
193 unsigned Align, Instruction *InsertBefore = nullptr);
194 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
195 unsigned Align, BasicBlock *InsertAtEnd);
196 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
197 AtomicOrdering Order, SynchronizationScope SynchScope = CrossThread,
198 Instruction *InsertBefore = nullptr)
199 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
200 NameStr, isVolatile, Align, Order, SynchScope, InsertBefore) {}
201 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
202 unsigned Align, AtomicOrdering Order,
203 SynchronizationScope SynchScope = CrossThread,
204 Instruction *InsertBefore = nullptr);
205 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
206 unsigned Align, AtomicOrdering Order,
207 SynchronizationScope SynchScope,
208 BasicBlock *InsertAtEnd);
210 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
211 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
212 LoadInst(Type *Ty, Value *Ptr, const char *NameStr = nullptr,
213 bool isVolatile = false, Instruction *InsertBefore = nullptr);
214 explicit LoadInst(Value *Ptr, const char *NameStr = nullptr,
215 bool isVolatile = false,
216 Instruction *InsertBefore = nullptr)
217 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
218 NameStr, isVolatile, InsertBefore) {}
219 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
220 BasicBlock *InsertAtEnd);
222 /// isVolatile - Return true if this is a load from a volatile memory
225 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
227 /// setVolatile - Specify whether this is a volatile load or not.
229 void setVolatile(bool V) {
230 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
234 /// getAlignment - Return the alignment of the access that is being performed
236 unsigned getAlignment() const {
237 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
240 void setAlignment(unsigned Align);
242 /// Returns the ordering effect of this fence.
243 AtomicOrdering getOrdering() const {
244 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
247 /// Set the ordering constraint on this load. May not be Release or
249 void setOrdering(AtomicOrdering Ordering) {
250 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
254 SynchronizationScope getSynchScope() const {
255 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
258 /// Specify whether this load is ordered with respect to all
259 /// concurrently executing threads, or only with respect to signal handlers
260 /// executing in the same thread.
261 void setSynchScope(SynchronizationScope xthread) {
262 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
266 void setAtomic(AtomicOrdering Ordering,
267 SynchronizationScope SynchScope = CrossThread) {
268 setOrdering(Ordering);
269 setSynchScope(SynchScope);
272 bool isSimple() const { return !isAtomic() && !isVolatile(); }
273 bool isUnordered() const {
274 return getOrdering() <= Unordered && !isVolatile();
277 Value *getPointerOperand() { return getOperand(0); }
278 const Value *getPointerOperand() const { return getOperand(0); }
279 static unsigned getPointerOperandIndex() { return 0U; }
281 /// \brief Returns the address space of the pointer operand.
282 unsigned getPointerAddressSpace() const {
283 return getPointerOperand()->getType()->getPointerAddressSpace();
287 // Methods for support type inquiry through isa, cast, and dyn_cast:
288 static inline bool classof(const Instruction *I) {
289 return I->getOpcode() == Instruction::Load;
291 static inline bool classof(const Value *V) {
292 return isa<Instruction>(V) && classof(cast<Instruction>(V));
295 // Shadow Instruction::setInstructionSubclassData with a private forwarding
296 // method so that subclasses cannot accidentally use it.
297 void setInstructionSubclassData(unsigned short D) {
298 Instruction::setInstructionSubclassData(D);
303 //===----------------------------------------------------------------------===//
305 //===----------------------------------------------------------------------===//
307 /// StoreInst - an instruction for storing to memory
309 class StoreInst : public Instruction {
310 void *operator new(size_t, unsigned) = delete;
313 StoreInst *clone_impl() const override;
315 // allocate space for exactly two operands
316 void *operator new(size_t s) {
317 return User::operator new(s, 2);
319 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
320 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
321 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
322 Instruction *InsertBefore = nullptr);
323 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
324 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
325 unsigned Align, Instruction *InsertBefore = nullptr);
326 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
327 unsigned Align, BasicBlock *InsertAtEnd);
328 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
329 unsigned Align, AtomicOrdering Order,
330 SynchronizationScope SynchScope = CrossThread,
331 Instruction *InsertBefore = nullptr);
332 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
333 unsigned Align, AtomicOrdering Order,
334 SynchronizationScope SynchScope,
335 BasicBlock *InsertAtEnd);
338 /// isVolatile - Return true if this is a store to a volatile memory
341 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
343 /// setVolatile - Specify whether this is a volatile store or not.
345 void setVolatile(bool V) {
346 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
350 /// Transparently provide more efficient getOperand methods.
351 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
353 /// getAlignment - Return the alignment of the access that is being performed
355 unsigned getAlignment() const {
356 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
359 void setAlignment(unsigned Align);
361 /// Returns the ordering effect of this store.
362 AtomicOrdering getOrdering() const {
363 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
366 /// Set the ordering constraint on this store. May not be Acquire or
368 void setOrdering(AtomicOrdering Ordering) {
369 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
373 SynchronizationScope getSynchScope() const {
374 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
377 /// Specify whether this store instruction is ordered with respect to all
378 /// concurrently executing threads, or only with respect to signal handlers
379 /// executing in the same thread.
380 void setSynchScope(SynchronizationScope xthread) {
381 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
385 void setAtomic(AtomicOrdering Ordering,
386 SynchronizationScope SynchScope = CrossThread) {
387 setOrdering(Ordering);
388 setSynchScope(SynchScope);
391 bool isSimple() const { return !isAtomic() && !isVolatile(); }
392 bool isUnordered() const {
393 return getOrdering() <= Unordered && !isVolatile();
396 Value *getValueOperand() { return getOperand(0); }
397 const Value *getValueOperand() const { return getOperand(0); }
399 Value *getPointerOperand() { return getOperand(1); }
400 const Value *getPointerOperand() const { return getOperand(1); }
401 static unsigned getPointerOperandIndex() { return 1U; }
403 /// \brief Returns the address space of the pointer operand.
404 unsigned getPointerAddressSpace() const {
405 return getPointerOperand()->getType()->getPointerAddressSpace();
408 // Methods for support type inquiry through isa, cast, and dyn_cast:
409 static inline bool classof(const Instruction *I) {
410 return I->getOpcode() == Instruction::Store;
412 static inline bool classof(const Value *V) {
413 return isa<Instruction>(V) && classof(cast<Instruction>(V));
416 // Shadow Instruction::setInstructionSubclassData with a private forwarding
417 // method so that subclasses cannot accidentally use it.
418 void setInstructionSubclassData(unsigned short D) {
419 Instruction::setInstructionSubclassData(D);
424 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
427 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
429 //===----------------------------------------------------------------------===//
431 //===----------------------------------------------------------------------===//
433 /// FenceInst - an instruction for ordering other memory operations
435 class FenceInst : public Instruction {
436 void *operator new(size_t, unsigned) = delete;
437 void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
439 FenceInst *clone_impl() const override;
441 // allocate space for exactly zero operands
442 void *operator new(size_t s) {
443 return User::operator new(s, 0);
446 // Ordering may only be Acquire, Release, AcquireRelease, or
447 // SequentiallyConsistent.
448 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
449 SynchronizationScope SynchScope = CrossThread,
450 Instruction *InsertBefore = nullptr);
451 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
452 SynchronizationScope SynchScope,
453 BasicBlock *InsertAtEnd);
455 /// Returns the ordering effect of this fence.
456 AtomicOrdering getOrdering() const {
457 return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
460 /// Set the ordering constraint on this fence. May only be Acquire, Release,
461 /// AcquireRelease, or SequentiallyConsistent.
462 void setOrdering(AtomicOrdering Ordering) {
463 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
467 SynchronizationScope getSynchScope() const {
468 return SynchronizationScope(getSubclassDataFromInstruction() & 1);
471 /// Specify whether this fence orders other operations with respect to all
472 /// concurrently executing threads, or only with respect to signal handlers
473 /// executing in the same thread.
474 void setSynchScope(SynchronizationScope xthread) {
475 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
479 // Methods for support type inquiry through isa, cast, and dyn_cast:
480 static inline bool classof(const Instruction *I) {
481 return I->getOpcode() == Instruction::Fence;
483 static inline bool classof(const Value *V) {
484 return isa<Instruction>(V) && classof(cast<Instruction>(V));
487 // Shadow Instruction::setInstructionSubclassData with a private forwarding
488 // method so that subclasses cannot accidentally use it.
489 void setInstructionSubclassData(unsigned short D) {
490 Instruction::setInstructionSubclassData(D);
494 //===----------------------------------------------------------------------===//
495 // AtomicCmpXchgInst Class
496 //===----------------------------------------------------------------------===//
498 /// AtomicCmpXchgInst - an instruction that atomically checks whether a
499 /// specified value is in a memory location, and, if it is, stores a new value
500 /// there. Returns the value that was loaded.
502 class AtomicCmpXchgInst : public Instruction {
503 void *operator new(size_t, unsigned) = delete;
504 void Init(Value *Ptr, Value *Cmp, Value *NewVal,
505 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
506 SynchronizationScope SynchScope);
508 AtomicCmpXchgInst *clone_impl() const override;
510 // allocate space for exactly three operands
511 void *operator new(size_t s) {
512 return User::operator new(s, 3);
514 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
515 AtomicOrdering SuccessOrdering,
516 AtomicOrdering FailureOrdering,
517 SynchronizationScope SynchScope,
518 Instruction *InsertBefore = nullptr);
519 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
520 AtomicOrdering SuccessOrdering,
521 AtomicOrdering FailureOrdering,
522 SynchronizationScope SynchScope,
523 BasicBlock *InsertAtEnd);
525 /// isVolatile - Return true if this is a cmpxchg from a volatile memory
528 bool isVolatile() const {
529 return getSubclassDataFromInstruction() & 1;
532 /// setVolatile - Specify whether this is a volatile cmpxchg.
534 void setVolatile(bool V) {
535 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
539 /// Return true if this cmpxchg may spuriously fail.
540 bool isWeak() const {
541 return getSubclassDataFromInstruction() & 0x100;
544 void setWeak(bool IsWeak) {
545 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x100) |
549 /// Transparently provide more efficient getOperand methods.
550 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
552 /// Set the ordering constraint on this cmpxchg.
553 void setSuccessOrdering(AtomicOrdering Ordering) {
554 assert(Ordering != NotAtomic &&
555 "CmpXchg instructions can only be atomic.");
556 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x1c) |
560 void setFailureOrdering(AtomicOrdering Ordering) {
561 assert(Ordering != NotAtomic &&
562 "CmpXchg instructions can only be atomic.");
563 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0xe0) |
567 /// Specify whether this cmpxchg is atomic and orders other operations with
568 /// respect to all concurrently executing threads, or only with respect to
569 /// signal handlers executing in the same thread.
570 void setSynchScope(SynchronizationScope SynchScope) {
571 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
575 /// Returns the ordering constraint on this cmpxchg.
576 AtomicOrdering getSuccessOrdering() const {
577 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
580 /// Returns the ordering constraint on this cmpxchg.
581 AtomicOrdering getFailureOrdering() const {
582 return AtomicOrdering((getSubclassDataFromInstruction() >> 5) & 7);
585 /// Returns whether this cmpxchg is atomic between threads or only within a
587 SynchronizationScope getSynchScope() const {
588 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
591 Value *getPointerOperand() { return getOperand(0); }
592 const Value *getPointerOperand() const { return getOperand(0); }
593 static unsigned getPointerOperandIndex() { return 0U; }
595 Value *getCompareOperand() { return getOperand(1); }
596 const Value *getCompareOperand() const { return getOperand(1); }
598 Value *getNewValOperand() { return getOperand(2); }
599 const Value *getNewValOperand() const { return getOperand(2); }
601 /// \brief Returns the address space of the pointer operand.
602 unsigned getPointerAddressSpace() const {
603 return getPointerOperand()->getType()->getPointerAddressSpace();
606 /// \brief Returns the strongest permitted ordering on failure, given the
607 /// desired ordering on success.
609 /// If the comparison in a cmpxchg operation fails, there is no atomic store
610 /// so release semantics cannot be provided. So this function drops explicit
611 /// Release requests from the AtomicOrdering. A SequentiallyConsistent
612 /// operation would remain SequentiallyConsistent.
613 static AtomicOrdering
614 getStrongestFailureOrdering(AtomicOrdering SuccessOrdering) {
615 switch (SuccessOrdering) {
616 default: llvm_unreachable("invalid cmpxchg success ordering");
623 case SequentiallyConsistent:
624 return SequentiallyConsistent;
628 // Methods for support type inquiry through isa, cast, and dyn_cast:
629 static inline bool classof(const Instruction *I) {
630 return I->getOpcode() == Instruction::AtomicCmpXchg;
632 static inline bool classof(const Value *V) {
633 return isa<Instruction>(V) && classof(cast<Instruction>(V));
636 // Shadow Instruction::setInstructionSubclassData with a private forwarding
637 // method so that subclasses cannot accidentally use it.
638 void setInstructionSubclassData(unsigned short D) {
639 Instruction::setInstructionSubclassData(D);
644 struct OperandTraits<AtomicCmpXchgInst> :
645 public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
648 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)
650 //===----------------------------------------------------------------------===//
651 // AtomicRMWInst Class
652 //===----------------------------------------------------------------------===//
654 /// AtomicRMWInst - an instruction that atomically reads a memory location,
655 /// combines it with another value, and then stores the result back. Returns
658 class AtomicRMWInst : public Instruction {
659 void *operator new(size_t, unsigned) = delete;
661 AtomicRMWInst *clone_impl() const override;
663 /// This enumeration lists the possible modifications atomicrmw can make. In
664 /// the descriptions, 'p' is the pointer to the instruction's memory location,
665 /// 'old' is the initial value of *p, and 'v' is the other value passed to the
666 /// instruction. These instructions always return 'old'.
682 /// *p = old >signed v ? old : v
684 /// *p = old <signed v ? old : v
686 /// *p = old >unsigned v ? old : v
688 /// *p = old <unsigned v ? old : v
696 // allocate space for exactly two operands
697 void *operator new(size_t s) {
698 return User::operator new(s, 2);
700 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
701 AtomicOrdering Ordering, SynchronizationScope SynchScope,
702 Instruction *InsertBefore = nullptr);
703 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
704 AtomicOrdering Ordering, SynchronizationScope SynchScope,
705 BasicBlock *InsertAtEnd);
707 BinOp getOperation() const {
708 return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
711 void setOperation(BinOp Operation) {
712 unsigned short SubclassData = getSubclassDataFromInstruction();
713 setInstructionSubclassData((SubclassData & 31) |
717 /// isVolatile - Return true if this is a RMW on a volatile memory location.
719 bool isVolatile() const {
720 return getSubclassDataFromInstruction() & 1;
723 /// setVolatile - Specify whether this is a volatile RMW or not.
725 void setVolatile(bool V) {
726 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
730 /// Transparently provide more efficient getOperand methods.
731 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
733 /// Set the ordering constraint on this RMW.
734 void setOrdering(AtomicOrdering Ordering) {
735 assert(Ordering != NotAtomic &&
736 "atomicrmw instructions can only be atomic.");
737 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
741 /// Specify whether this RMW orders other operations with respect to all
742 /// concurrently executing threads, or only with respect to signal handlers
743 /// executing in the same thread.
744 void setSynchScope(SynchronizationScope SynchScope) {
745 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
749 /// Returns the ordering constraint on this RMW.
750 AtomicOrdering getOrdering() const {
751 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
754 /// Returns whether this RMW is atomic between threads or only within a
756 SynchronizationScope getSynchScope() const {
757 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
760 Value *getPointerOperand() { return getOperand(0); }
761 const Value *getPointerOperand() const { return getOperand(0); }
762 static unsigned getPointerOperandIndex() { return 0U; }
764 Value *getValOperand() { return getOperand(1); }
765 const Value *getValOperand() const { return getOperand(1); }
767 /// \brief Returns the address space of the pointer operand.
768 unsigned getPointerAddressSpace() const {
769 return getPointerOperand()->getType()->getPointerAddressSpace();
772 // Methods for support type inquiry through isa, cast, and dyn_cast:
773 static inline bool classof(const Instruction *I) {
774 return I->getOpcode() == Instruction::AtomicRMW;
776 static inline bool classof(const Value *V) {
777 return isa<Instruction>(V) && classof(cast<Instruction>(V));
780 void Init(BinOp Operation, Value *Ptr, Value *Val,
781 AtomicOrdering Ordering, SynchronizationScope SynchScope);
782 // Shadow Instruction::setInstructionSubclassData with a private forwarding
783 // method so that subclasses cannot accidentally use it.
784 void setInstructionSubclassData(unsigned short D) {
785 Instruction::setInstructionSubclassData(D);
790 struct OperandTraits<AtomicRMWInst>
791 : public FixedNumOperandTraits<AtomicRMWInst,2> {
794 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)
796 //===----------------------------------------------------------------------===//
797 // GetElementPtrInst Class
798 //===----------------------------------------------------------------------===//
800 // checkGEPType - Simple wrapper function to give a better assertion failure
801 // message on bad indexes for a gep instruction.
803 inline Type *checkGEPType(Type *Ty) {
804 assert(Ty && "Invalid GetElementPtrInst indices for type!");
808 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
809 /// access elements of arrays and structs
811 class GetElementPtrInst : public Instruction {
812 Type *SourceElementType;
813 Type *ResultElementType;
815 GetElementPtrInst(const GetElementPtrInst &GEPI);
816 void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
818 /// Constructors - Create a getelementptr instruction with a base pointer an
819 /// list of indices. The first ctor can optionally insert before an existing
820 /// instruction, the second appends the new instruction to the specified
822 inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
823 ArrayRef<Value *> IdxList, unsigned Values,
824 const Twine &NameStr, Instruction *InsertBefore);
825 inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
826 ArrayRef<Value *> IdxList, unsigned Values,
827 const Twine &NameStr, BasicBlock *InsertAtEnd);
830 GetElementPtrInst *clone_impl() const override;
832 static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
833 ArrayRef<Value *> IdxList,
834 const Twine &NameStr = "",
835 Instruction *InsertBefore = nullptr) {
836 unsigned Values = 1 + unsigned(IdxList.size());
839 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
843 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
844 return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
845 NameStr, InsertBefore);
847 static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
848 ArrayRef<Value *> IdxList,
849 const Twine &NameStr,
850 BasicBlock *InsertAtEnd) {
851 unsigned Values = 1 + unsigned(IdxList.size());
854 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
858 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
859 return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
860 NameStr, InsertAtEnd);
863 /// Create an "inbounds" getelementptr. See the documentation for the
864 /// "inbounds" flag in LangRef.html for details.
865 static GetElementPtrInst *CreateInBounds(Value *Ptr,
866 ArrayRef<Value *> IdxList,
867 const Twine &NameStr = "",
868 Instruction *InsertBefore = nullptr){
869 return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertBefore);
871 static GetElementPtrInst *
872 CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef<Value *> IdxList,
873 const Twine &NameStr = "",
874 Instruction *InsertBefore = nullptr) {
875 GetElementPtrInst *GEP =
876 Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore);
877 GEP->setIsInBounds(true);
880 static GetElementPtrInst *CreateInBounds(Value *Ptr,
881 ArrayRef<Value *> IdxList,
882 const Twine &NameStr,
883 BasicBlock *InsertAtEnd) {
884 return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertAtEnd);
886 static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr,
887 ArrayRef<Value *> IdxList,
888 const Twine &NameStr,
889 BasicBlock *InsertAtEnd) {
890 GetElementPtrInst *GEP =
891 Create(PointeeType, Ptr, IdxList, NameStr, InsertAtEnd);
892 GEP->setIsInBounds(true);
896 /// Transparently provide more efficient getOperand methods.
897 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
899 // getType - Overload to return most specific sequential type.
900 SequentialType *getType() const {
901 return cast<SequentialType>(Instruction::getType());
904 Type *getSourceElementType() const { return SourceElementType; }
906 void setSourceElementType(Type *Ty) { SourceElementType = Ty; }
907 void setResultElementType(Type *Ty) { ResultElementType = Ty; }
909 Type *getResultElementType() const {
910 assert(ResultElementType ==
911 cast<PointerType>(getType()->getScalarType())->getElementType());
912 return ResultElementType;
915 /// \brief Returns the address space of this instruction's pointer type.
916 unsigned getAddressSpace() const {
917 // Note that this is always the same as the pointer operand's address space
918 // and that is cheaper to compute, so cheat here.
919 return getPointerAddressSpace();
922 /// getIndexedType - Returns the type of the element that would be loaded with
923 /// a load instruction with the specified parameters.
925 /// Null is returned if the indices are invalid for the specified
928 static Type *getIndexedType(Type *Ty, ArrayRef<Value *> IdxList);
929 static Type *getIndexedType(Type *Ty, ArrayRef<Constant *> IdxList);
930 static Type *getIndexedType(Type *Ty, ArrayRef<uint64_t> IdxList);
932 inline op_iterator idx_begin() { return op_begin()+1; }
933 inline const_op_iterator idx_begin() const { return op_begin()+1; }
934 inline op_iterator idx_end() { return op_end(); }
935 inline const_op_iterator idx_end() const { return op_end(); }
937 Value *getPointerOperand() {
938 return getOperand(0);
940 const Value *getPointerOperand() const {
941 return getOperand(0);
943 static unsigned getPointerOperandIndex() {
944 return 0U; // get index for modifying correct operand.
947 /// getPointerOperandType - Method to return the pointer operand as a
949 Type *getPointerOperandType() const {
950 return getPointerOperand()->getType();
953 /// \brief Returns the address space of the pointer operand.
954 unsigned getPointerAddressSpace() const {
955 return getPointerOperandType()->getPointerAddressSpace();
958 /// GetGEPReturnType - Returns the pointer type returned by the GEP
959 /// instruction, which may be a vector of pointers.
960 static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
961 return getGEPReturnType(
962 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType(),
965 static Type *getGEPReturnType(Type *ElTy, Value *Ptr,
966 ArrayRef<Value *> IdxList) {
967 Type *PtrTy = PointerType::get(checkGEPType(getIndexedType(ElTy, IdxList)),
968 Ptr->getType()->getPointerAddressSpace());
970 if (Ptr->getType()->isVectorTy()) {
971 unsigned NumElem = cast<VectorType>(Ptr->getType())->getNumElements();
972 return VectorType::get(PtrTy, NumElem);
979 unsigned getNumIndices() const { // Note: always non-negative
980 return getNumOperands() - 1;
983 bool hasIndices() const {
984 return getNumOperands() > 1;
987 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
988 /// zeros. If so, the result pointer and the first operand have the same
989 /// value, just potentially different types.
990 bool hasAllZeroIndices() const;
992 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
993 /// constant integers. If so, the result pointer and the first operand have
994 /// a constant offset between them.
995 bool hasAllConstantIndices() const;
997 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
998 /// See LangRef.html for the meaning of inbounds on a getelementptr.
999 void setIsInBounds(bool b = true);
1001 /// isInBounds - Determine whether the GEP has the inbounds flag.
1002 bool isInBounds() const;
1004 /// \brief Accumulate the constant address offset of this GEP if possible.
1006 /// This routine accepts an APInt into which it will accumulate the constant
1007 /// offset of this GEP if the GEP is in fact constant. If the GEP is not
1008 /// all-constant, it returns false and the value of the offset APInt is
1009 /// undefined (it is *not* preserved!). The APInt passed into this routine
1010 /// must be at least as wide as the IntPtr type for the address space of
1011 /// the base GEP pointer.
1012 bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
1014 // Methods for support type inquiry through isa, cast, and dyn_cast:
1015 static inline bool classof(const Instruction *I) {
1016 return (I->getOpcode() == Instruction::GetElementPtr);
1018 static inline bool classof(const Value *V) {
1019 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1024 struct OperandTraits<GetElementPtrInst> :
1025 public VariadicOperandTraits<GetElementPtrInst, 1> {
1028 GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
1029 ArrayRef<Value *> IdxList, unsigned Values,
1030 const Twine &NameStr,
1031 Instruction *InsertBefore)
1032 : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
1033 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
1034 Values, InsertBefore),
1035 SourceElementType(PointeeType),
1036 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1037 assert(ResultElementType ==
1038 cast<PointerType>(getType()->getScalarType())->getElementType());
1039 init(Ptr, IdxList, NameStr);
1041 GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
1042 ArrayRef<Value *> IdxList, unsigned Values,
1043 const Twine &NameStr,
1044 BasicBlock *InsertAtEnd)
1045 : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
1046 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
1047 Values, InsertAtEnd),
1048 SourceElementType(PointeeType),
1049 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1050 assert(ResultElementType ==
1051 cast<PointerType>(getType()->getScalarType())->getElementType());
1052 init(Ptr, IdxList, NameStr);
1056 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
1059 //===----------------------------------------------------------------------===//
1061 //===----------------------------------------------------------------------===//
1063 /// This instruction compares its operands according to the predicate given
1064 /// to the constructor. It only operates on integers or pointers. The operands
1065 /// must be identical types.
1066 /// \brief Represent an integer comparison operator.
1067 class ICmpInst: public CmpInst {
1069 assert(getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE &&
1070 getPredicate() <= CmpInst::LAST_ICMP_PREDICATE &&
1071 "Invalid ICmp predicate value");
1072 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1073 "Both operands to ICmp instruction are not of the same type!");
1074 // Check that the operands are the right type
1075 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
1076 getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
1077 "Invalid operand types for ICmp instruction");
1081 /// \brief Clone an identical ICmpInst
1082 ICmpInst *clone_impl() const override;
1084 /// \brief Constructor with insert-before-instruction semantics.
1086 Instruction *InsertBefore, ///< Where to insert
1087 Predicate pred, ///< The predicate to use for the comparison
1088 Value *LHS, ///< The left-hand-side of the expression
1089 Value *RHS, ///< The right-hand-side of the expression
1090 const Twine &NameStr = "" ///< Name of the instruction
1091 ) : CmpInst(makeCmpResultType(LHS->getType()),
1092 Instruction::ICmp, pred, LHS, RHS, NameStr,
1099 /// \brief Constructor with insert-at-end semantics.
1101 BasicBlock &InsertAtEnd, ///< Block to insert into.
1102 Predicate pred, ///< The predicate to use for the comparison
1103 Value *LHS, ///< The left-hand-side of the expression
1104 Value *RHS, ///< The right-hand-side of the expression
1105 const Twine &NameStr = "" ///< Name of the instruction
1106 ) : CmpInst(makeCmpResultType(LHS->getType()),
1107 Instruction::ICmp, pred, LHS, RHS, NameStr,
1114 /// \brief Constructor with no-insertion semantics
1116 Predicate pred, ///< The predicate to use for the comparison
1117 Value *LHS, ///< The left-hand-side of the expression
1118 Value *RHS, ///< The right-hand-side of the expression
1119 const Twine &NameStr = "" ///< Name of the instruction
1120 ) : CmpInst(makeCmpResultType(LHS->getType()),
1121 Instruction::ICmp, pred, LHS, RHS, NameStr) {
1127 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
1128 /// @returns the predicate that would be the result if the operand were
1129 /// regarded as signed.
1130 /// \brief Return the signed version of the predicate
1131 Predicate getSignedPredicate() const {
1132 return getSignedPredicate(getPredicate());
1135 /// This is a static version that you can use without an instruction.
1136 /// \brief Return the signed version of the predicate.
1137 static Predicate getSignedPredicate(Predicate pred);
1139 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
1140 /// @returns the predicate that would be the result if the operand were
1141 /// regarded as unsigned.
1142 /// \brief Return the unsigned version of the predicate
1143 Predicate getUnsignedPredicate() const {
1144 return getUnsignedPredicate(getPredicate());
1147 /// This is a static version that you can use without an instruction.
1148 /// \brief Return the unsigned version of the predicate.
1149 static Predicate getUnsignedPredicate(Predicate pred);
1151 /// isEquality - Return true if this predicate is either EQ or NE. This also
1152 /// tests for commutativity.
1153 static bool isEquality(Predicate P) {
1154 return P == ICMP_EQ || P == ICMP_NE;
1157 /// isEquality - Return true if this predicate is either EQ or NE. This also
1158 /// tests for commutativity.
1159 bool isEquality() const {
1160 return isEquality(getPredicate());
1163 /// @returns true if the predicate of this ICmpInst is commutative
1164 /// \brief Determine if this relation is commutative.
1165 bool isCommutative() const { return isEquality(); }
1167 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1169 bool isRelational() const {
1170 return !isEquality();
1173 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1175 static bool isRelational(Predicate P) {
1176 return !isEquality(P);
1179 /// Initialize a set of values that all satisfy the predicate with C.
1180 /// \brief Make a ConstantRange for a relation with a constant value.
1181 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
1183 /// Exchange the two operands to this instruction in such a way that it does
1184 /// not modify the semantics of the instruction. The predicate value may be
1185 /// changed to retain the same result if the predicate is order dependent
1187 /// \brief Swap operands and adjust predicate.
1188 void swapOperands() {
1189 setPredicate(getSwappedPredicate());
1190 Op<0>().swap(Op<1>());
1193 // Methods for support type inquiry through isa, cast, and dyn_cast:
1194 static inline bool classof(const Instruction *I) {
1195 return I->getOpcode() == Instruction::ICmp;
1197 static inline bool classof(const Value *V) {
1198 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1203 //===----------------------------------------------------------------------===//
1205 //===----------------------------------------------------------------------===//
1207 /// This instruction compares its operands according to the predicate given
1208 /// to the constructor. It only operates on floating point values or packed
1209 /// vectors of floating point values. The operands must be identical types.
1210 /// \brief Represents a floating point comparison operator.
1211 class FCmpInst: public CmpInst {
1213 /// \brief Clone an identical FCmpInst
1214 FCmpInst *clone_impl() const override;
1216 /// \brief Constructor with insert-before-instruction semantics.
1218 Instruction *InsertBefore, ///< Where to insert
1219 Predicate pred, ///< The predicate to use for the comparison
1220 Value *LHS, ///< The left-hand-side of the expression
1221 Value *RHS, ///< The right-hand-side of the expression
1222 const Twine &NameStr = "" ///< Name of the instruction
1223 ) : CmpInst(makeCmpResultType(LHS->getType()),
1224 Instruction::FCmp, pred, LHS, RHS, NameStr,
1226 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1227 "Invalid FCmp predicate value");
1228 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1229 "Both operands to FCmp instruction are not of the same type!");
1230 // Check that the operands are the right type
1231 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1232 "Invalid operand types for FCmp instruction");
1235 /// \brief Constructor with insert-at-end semantics.
1237 BasicBlock &InsertAtEnd, ///< Block to insert into.
1238 Predicate pred, ///< The predicate to use for the comparison
1239 Value *LHS, ///< The left-hand-side of the expression
1240 Value *RHS, ///< The right-hand-side of the expression
1241 const Twine &NameStr = "" ///< Name of the instruction
1242 ) : CmpInst(makeCmpResultType(LHS->getType()),
1243 Instruction::FCmp, pred, LHS, RHS, NameStr,
1245 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1246 "Invalid FCmp predicate value");
1247 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1248 "Both operands to FCmp instruction are not of the same type!");
1249 // Check that the operands are the right type
1250 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1251 "Invalid operand types for FCmp instruction");
1254 /// \brief Constructor with no-insertion semantics
1256 Predicate pred, ///< The predicate to use for the comparison
1257 Value *LHS, ///< The left-hand-side of the expression
1258 Value *RHS, ///< The right-hand-side of the expression
1259 const Twine &NameStr = "" ///< Name of the instruction
1260 ) : CmpInst(makeCmpResultType(LHS->getType()),
1261 Instruction::FCmp, pred, LHS, RHS, NameStr) {
1262 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1263 "Invalid FCmp predicate value");
1264 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1265 "Both operands to FCmp instruction are not of the same type!");
1266 // Check that the operands are the right type
1267 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1268 "Invalid operand types for FCmp instruction");
1271 /// @returns true if the predicate of this instruction is EQ or NE.
1272 /// \brief Determine if this is an equality predicate.
1273 static bool isEquality(Predicate Pred) {
1274 return Pred == FCMP_OEQ || Pred == FCMP_ONE || Pred == FCMP_UEQ ||
1278 /// @returns true if the predicate of this instruction is EQ or NE.
1279 /// \brief Determine if this is an equality predicate.
1280 bool isEquality() const { return isEquality(getPredicate()); }
1282 /// @returns true if the predicate of this instruction is commutative.
1283 /// \brief Determine if this is a commutative predicate.
1284 bool isCommutative() const {
1285 return isEquality() ||
1286 getPredicate() == FCMP_FALSE ||
1287 getPredicate() == FCMP_TRUE ||
1288 getPredicate() == FCMP_ORD ||
1289 getPredicate() == FCMP_UNO;
1292 /// @returns true if the predicate is relational (not EQ or NE).
1293 /// \brief Determine if this a relational predicate.
1294 bool isRelational() const { return !isEquality(); }
1296 /// Exchange the two operands to this instruction in such a way that it does
1297 /// not modify the semantics of the instruction. The predicate value may be
1298 /// changed to retain the same result if the predicate is order dependent
1300 /// \brief Swap operands and adjust predicate.
1301 void swapOperands() {
1302 setPredicate(getSwappedPredicate());
1303 Op<0>().swap(Op<1>());
1306 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
1307 static inline bool classof(const Instruction *I) {
1308 return I->getOpcode() == Instruction::FCmp;
1310 static inline bool classof(const Value *V) {
1311 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1315 //===----------------------------------------------------------------------===//
1316 /// CallInst - This class represents a function call, abstracting a target
1317 /// machine's calling convention. This class uses low bit of the SubClassData
1318 /// field to indicate whether or not this is a tail call. The rest of the bits
1319 /// hold the calling convention of the call.
1321 class CallInst : public Instruction {
1322 AttributeSet AttributeList; ///< parameter attributes for call
1324 CallInst(const CallInst &CI);
1325 void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr) {
1326 init(cast<FunctionType>(
1327 cast<PointerType>(Func->getType())->getElementType()),
1328 Func, Args, NameStr);
1330 void init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
1331 const Twine &NameStr);
1332 void init(Value *Func, const Twine &NameStr);
1334 /// Construct a CallInst given a range of arguments.
1335 /// \brief Construct a CallInst from a range of arguments
1336 inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1337 const Twine &NameStr, Instruction *InsertBefore);
1338 inline CallInst(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr,
1339 Instruction *InsertBefore)
1340 : CallInst(cast<FunctionType>(
1341 cast<PointerType>(Func->getType())->getElementType()),
1342 Func, Args, NameStr, InsertBefore) {}
1344 /// Construct a CallInst given a range of arguments.
1345 /// \brief Construct a CallInst from a range of arguments
1346 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1347 const Twine &NameStr, BasicBlock *InsertAtEnd);
1349 explicit CallInst(Value *F, const Twine &NameStr,
1350 Instruction *InsertBefore);
1351 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1353 CallInst *clone_impl() const override;
1355 static CallInst *Create(Value *Func,
1356 ArrayRef<Value *> Args,
1357 const Twine &NameStr = "",
1358 Instruction *InsertBefore = nullptr) {
1359 return Create(cast<FunctionType>(
1360 cast<PointerType>(Func->getType())->getElementType()),
1361 Func, Args, NameStr, InsertBefore);
1363 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1364 const Twine &NameStr = "",
1365 Instruction *InsertBefore = nullptr) {
1366 return new (unsigned(Args.size() + 1))
1367 CallInst(Ty, Func, Args, NameStr, InsertBefore);
1369 static CallInst *Create(Value *Func,
1370 ArrayRef<Value *> Args,
1371 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1372 return new(unsigned(Args.size() + 1))
1373 CallInst(Func, Args, NameStr, InsertAtEnd);
1375 static CallInst *Create(Value *F, const Twine &NameStr = "",
1376 Instruction *InsertBefore = nullptr) {
1377 return new(1) CallInst(F, NameStr, InsertBefore);
1379 static CallInst *Create(Value *F, const Twine &NameStr,
1380 BasicBlock *InsertAtEnd) {
1381 return new(1) CallInst(F, NameStr, InsertAtEnd);
1383 /// CreateMalloc - Generate the IR for a call to malloc:
1384 /// 1. Compute the malloc call's argument as the specified type's size,
1385 /// possibly multiplied by the array size if the array size is not
1387 /// 2. Call malloc with that argument.
1388 /// 3. Bitcast the result of the malloc call to the specified type.
1389 static Instruction *CreateMalloc(Instruction *InsertBefore,
1390 Type *IntPtrTy, Type *AllocTy,
1391 Value *AllocSize, Value *ArraySize = nullptr,
1392 Function* MallocF = nullptr,
1393 const Twine &Name = "");
1394 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1395 Type *IntPtrTy, Type *AllocTy,
1396 Value *AllocSize, Value *ArraySize = nullptr,
1397 Function* MallocF = nullptr,
1398 const Twine &Name = "");
1399 /// CreateFree - Generate the IR for a call to the builtin free function.
1400 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
1401 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
1403 ~CallInst() override;
1405 FunctionType *getFunctionType() const { return FTy; }
1407 void mutateFunctionType(FunctionType *FTy) {
1408 mutateType(FTy->getReturnType());
1412 // Note that 'musttail' implies 'tail'.
1413 enum TailCallKind { TCK_None = 0, TCK_Tail = 1, TCK_MustTail = 2 };
1414 TailCallKind getTailCallKind() const {
1415 return TailCallKind(getSubclassDataFromInstruction() & 3);
1417 bool isTailCall() const {
1418 return (getSubclassDataFromInstruction() & 3) != TCK_None;
1420 bool isMustTailCall() const {
1421 return (getSubclassDataFromInstruction() & 3) == TCK_MustTail;
1423 void setTailCall(bool isTC = true) {
1424 setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
1425 unsigned(isTC ? TCK_Tail : TCK_None));
1427 void setTailCallKind(TailCallKind TCK) {
1428 setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
1432 /// Provide fast operand accessors
1433 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1435 /// getNumArgOperands - Return the number of call arguments.
1437 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
1439 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1441 Value *getArgOperand(unsigned i) const { return getOperand(i); }
1442 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
1444 /// arg_operands - iteration adapter for range-for loops.
1445 iterator_range<op_iterator> arg_operands() {
1446 // The last operand in the op list is the callee - it's not one of the args
1447 // so we don't want to iterate over it.
1448 return iterator_range<op_iterator>(op_begin(), op_end() - 1);
1451 /// arg_operands - iteration adapter for range-for loops.
1452 iterator_range<const_op_iterator> arg_operands() const {
1453 return iterator_range<const_op_iterator>(op_begin(), op_end() - 1);
1456 /// \brief Wrappers for getting the \c Use of a call argument.
1457 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
1458 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
1460 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1462 CallingConv::ID getCallingConv() const {
1463 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2);
1465 void setCallingConv(CallingConv::ID CC) {
1466 setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
1467 (static_cast<unsigned>(CC) << 2));
1470 /// getAttributes - Return the parameter attributes for this call.
1472 const AttributeSet &getAttributes() const { return AttributeList; }
1474 /// setAttributes - Set the parameter attributes for this call.
1476 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
1478 /// addAttribute - adds the attribute to the list of attributes.
1479 void addAttribute(unsigned i, Attribute::AttrKind attr);
1481 /// removeAttribute - removes the attribute from the list of attributes.
1482 void removeAttribute(unsigned i, Attribute attr);
1484 /// \brief adds the dereferenceable attribute to the list of attributes.
1485 void addDereferenceableAttr(unsigned i, uint64_t Bytes);
1487 /// \brief adds the dereferenceable_or_null attribute to the list of
1489 void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
1491 /// \brief Determine whether this call has the given attribute.
1492 bool hasFnAttr(Attribute::AttrKind A) const {
1493 assert(A != Attribute::NoBuiltin &&
1494 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
1495 return hasFnAttrImpl(A);
1498 /// \brief Determine whether the call or the callee has the given attributes.
1499 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
1501 /// \brief Extract the alignment for a call or parameter (0=unknown).
1502 unsigned getParamAlignment(unsigned i) const {
1503 return AttributeList.getParamAlignment(i);
1506 /// \brief Extract the number of dereferenceable bytes for a call or
1507 /// parameter (0=unknown).
1508 uint64_t getDereferenceableBytes(unsigned i) const {
1509 return AttributeList.getDereferenceableBytes(i);
1512 /// \brief Extract the number of dereferenceable_or_null bytes for a call or
1513 /// parameter (0=unknown).
1514 uint64_t getDereferenceableOrNullBytes(unsigned i) const {
1515 return AttributeList.getDereferenceableOrNullBytes(i);
1518 /// \brief Return true if the call should not be treated as a call to a
1520 bool isNoBuiltin() const {
1521 return hasFnAttrImpl(Attribute::NoBuiltin) &&
1522 !hasFnAttrImpl(Attribute::Builtin);
1525 /// \brief Return true if the call should not be inlined.
1526 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
1527 void setIsNoInline() {
1528 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
1531 /// \brief Return true if the call can return twice
1532 bool canReturnTwice() const {
1533 return hasFnAttr(Attribute::ReturnsTwice);
1535 void setCanReturnTwice() {
1536 addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice);
1539 /// \brief Determine if the call does not access memory.
1540 bool doesNotAccessMemory() const {
1541 return hasFnAttr(Attribute::ReadNone);
1543 void setDoesNotAccessMemory() {
1544 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
1547 /// \brief Determine if the call does not access or only reads memory.
1548 bool onlyReadsMemory() const {
1549 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
1551 void setOnlyReadsMemory() {
1552 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
1555 /// \brief Determine if the call cannot return.
1556 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
1557 void setDoesNotReturn() {
1558 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
1561 /// \brief Determine if the call cannot unwind.
1562 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
1563 void setDoesNotThrow() {
1564 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
1567 /// \brief Determine if the call cannot be duplicated.
1568 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
1569 void setCannotDuplicate() {
1570 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
1573 /// \brief Determine if the call returns a structure through first
1574 /// pointer argument.
1575 bool hasStructRetAttr() const {
1576 // Be friendly and also check the callee.
1577 return paramHasAttr(1, Attribute::StructRet);
1580 /// \brief Determine if any call argument is an aggregate passed by value.
1581 bool hasByValArgument() const {
1582 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1585 /// getCalledFunction - Return the function called, or null if this is an
1586 /// indirect function invocation.
1588 Function *getCalledFunction() const {
1589 return dyn_cast<Function>(Op<-1>());
1592 /// getCalledValue - Get a pointer to the function that is invoked by this
1594 const Value *getCalledValue() const { return Op<-1>(); }
1595 Value *getCalledValue() { return Op<-1>(); }
1597 /// setCalledFunction - Set the function called.
1598 void setCalledFunction(Value* Fn) {
1600 cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()),
1603 void setCalledFunction(FunctionType *FTy, Value *Fn) {
1605 assert(FTy == cast<FunctionType>(
1606 cast<PointerType>(Fn->getType())->getElementType()));
1610 /// isInlineAsm - Check if this call is an inline asm statement.
1611 bool isInlineAsm() const {
1612 return isa<InlineAsm>(Op<-1>());
1615 // Methods for support type inquiry through isa, cast, and dyn_cast:
1616 static inline bool classof(const Instruction *I) {
1617 return I->getOpcode() == Instruction::Call;
1619 static inline bool classof(const Value *V) {
1620 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1624 bool hasFnAttrImpl(Attribute::AttrKind A) const;
1626 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1627 // method so that subclasses cannot accidentally use it.
1628 void setInstructionSubclassData(unsigned short D) {
1629 Instruction::setInstructionSubclassData(D);
1634 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1637 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1638 const Twine &NameStr, BasicBlock *InsertAtEnd)
1639 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1640 ->getElementType())->getReturnType(),
1642 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1643 unsigned(Args.size() + 1), InsertAtEnd) {
1644 init(Func, Args, NameStr);
1647 CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1648 const Twine &NameStr, Instruction *InsertBefore)
1649 : Instruction(Ty->getReturnType(), Instruction::Call,
1650 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1651 unsigned(Args.size() + 1), InsertBefore) {
1652 init(Ty, Func, Args, NameStr);
1656 // Note: if you get compile errors about private methods then
1657 // please update your code to use the high-level operand
1658 // interfaces. See line 943 above.
1659 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1661 //===----------------------------------------------------------------------===//
1663 //===----------------------------------------------------------------------===//
1665 /// SelectInst - This class represents the LLVM 'select' instruction.
1667 class SelectInst : public Instruction {
1668 void init(Value *C, Value *S1, Value *S2) {
1669 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1675 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1676 Instruction *InsertBefore)
1677 : Instruction(S1->getType(), Instruction::Select,
1678 &Op<0>(), 3, InsertBefore) {
1682 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1683 BasicBlock *InsertAtEnd)
1684 : Instruction(S1->getType(), Instruction::Select,
1685 &Op<0>(), 3, InsertAtEnd) {
1690 SelectInst *clone_impl() const override;
1692 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1693 const Twine &NameStr = "",
1694 Instruction *InsertBefore = nullptr) {
1695 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1697 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1698 const Twine &NameStr,
1699 BasicBlock *InsertAtEnd) {
1700 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1703 const Value *getCondition() const { return Op<0>(); }
1704 const Value *getTrueValue() const { return Op<1>(); }
1705 const Value *getFalseValue() const { return Op<2>(); }
1706 Value *getCondition() { return Op<0>(); }
1707 Value *getTrueValue() { return Op<1>(); }
1708 Value *getFalseValue() { return Op<2>(); }
1710 /// areInvalidOperands - Return a string if the specified operands are invalid
1711 /// for a select operation, otherwise return null.
1712 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1714 /// Transparently provide more efficient getOperand methods.
1715 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1717 OtherOps getOpcode() const {
1718 return static_cast<OtherOps>(Instruction::getOpcode());
1721 // Methods for support type inquiry through isa, cast, and dyn_cast:
1722 static inline bool classof(const Instruction *I) {
1723 return I->getOpcode() == Instruction::Select;
1725 static inline bool classof(const Value *V) {
1726 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1731 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1734 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1736 //===----------------------------------------------------------------------===//
1738 //===----------------------------------------------------------------------===//
1740 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1741 /// an argument of the specified type given a va_list and increments that list
1743 class VAArgInst : public UnaryInstruction {
1745 VAArgInst *clone_impl() const override;
1748 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1749 Instruction *InsertBefore = nullptr)
1750 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1753 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1754 BasicBlock *InsertAtEnd)
1755 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1759 Value *getPointerOperand() { return getOperand(0); }
1760 const Value *getPointerOperand() const { return getOperand(0); }
1761 static unsigned getPointerOperandIndex() { return 0U; }
1763 // Methods for support type inquiry through isa, cast, and dyn_cast:
1764 static inline bool classof(const Instruction *I) {
1765 return I->getOpcode() == VAArg;
1767 static inline bool classof(const Value *V) {
1768 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1772 //===----------------------------------------------------------------------===//
1773 // ExtractElementInst Class
1774 //===----------------------------------------------------------------------===//
1776 /// ExtractElementInst - This instruction extracts a single (scalar)
1777 /// element from a VectorType value
1779 class ExtractElementInst : public Instruction {
1780 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1781 Instruction *InsertBefore = nullptr);
1782 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1783 BasicBlock *InsertAtEnd);
1785 ExtractElementInst *clone_impl() const override;
1788 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1789 const Twine &NameStr = "",
1790 Instruction *InsertBefore = nullptr) {
1791 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1793 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1794 const Twine &NameStr,
1795 BasicBlock *InsertAtEnd) {
1796 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1799 /// isValidOperands - Return true if an extractelement instruction can be
1800 /// formed with the specified operands.
1801 static bool isValidOperands(const Value *Vec, const Value *Idx);
1803 Value *getVectorOperand() { return Op<0>(); }
1804 Value *getIndexOperand() { return Op<1>(); }
1805 const Value *getVectorOperand() const { return Op<0>(); }
1806 const Value *getIndexOperand() const { return Op<1>(); }
1808 VectorType *getVectorOperandType() const {
1809 return cast<VectorType>(getVectorOperand()->getType());
1813 /// Transparently provide more efficient getOperand methods.
1814 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1816 // Methods for support type inquiry through isa, cast, and dyn_cast:
1817 static inline bool classof(const Instruction *I) {
1818 return I->getOpcode() == Instruction::ExtractElement;
1820 static inline bool classof(const Value *V) {
1821 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1826 struct OperandTraits<ExtractElementInst> :
1827 public FixedNumOperandTraits<ExtractElementInst, 2> {
1830 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1832 //===----------------------------------------------------------------------===//
1833 // InsertElementInst Class
1834 //===----------------------------------------------------------------------===//
1836 /// InsertElementInst - This instruction inserts a single (scalar)
1837 /// element into a VectorType value
1839 class InsertElementInst : public Instruction {
1840 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1841 const Twine &NameStr = "",
1842 Instruction *InsertBefore = nullptr);
1843 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1844 const Twine &NameStr, BasicBlock *InsertAtEnd);
1846 InsertElementInst *clone_impl() const override;
1849 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1850 const Twine &NameStr = "",
1851 Instruction *InsertBefore = nullptr) {
1852 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1854 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1855 const Twine &NameStr,
1856 BasicBlock *InsertAtEnd) {
1857 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1860 /// isValidOperands - Return true if an insertelement instruction can be
1861 /// formed with the specified operands.
1862 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1865 /// getType - Overload to return most specific vector type.
1867 VectorType *getType() const {
1868 return cast<VectorType>(Instruction::getType());
1871 /// Transparently provide more efficient getOperand methods.
1872 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1874 // Methods for support type inquiry through isa, cast, and dyn_cast:
1875 static inline bool classof(const Instruction *I) {
1876 return I->getOpcode() == Instruction::InsertElement;
1878 static inline bool classof(const Value *V) {
1879 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1884 struct OperandTraits<InsertElementInst> :
1885 public FixedNumOperandTraits<InsertElementInst, 3> {
1888 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1890 //===----------------------------------------------------------------------===//
1891 // ShuffleVectorInst Class
1892 //===----------------------------------------------------------------------===//
1894 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1897 class ShuffleVectorInst : public Instruction {
1899 ShuffleVectorInst *clone_impl() const override;
1902 // allocate space for exactly three operands
1903 void *operator new(size_t s) {
1904 return User::operator new(s, 3);
1906 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1907 const Twine &NameStr = "",
1908 Instruction *InsertBefor = nullptr);
1909 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1910 const Twine &NameStr, BasicBlock *InsertAtEnd);
1912 /// isValidOperands - Return true if a shufflevector instruction can be
1913 /// formed with the specified operands.
1914 static bool isValidOperands(const Value *V1, const Value *V2,
1917 /// getType - Overload to return most specific vector type.
1919 VectorType *getType() const {
1920 return cast<VectorType>(Instruction::getType());
1923 /// Transparently provide more efficient getOperand methods.
1924 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1926 Constant *getMask() const {
1927 return cast<Constant>(getOperand(2));
1930 /// getMaskValue - Return the index from the shuffle mask for the specified
1931 /// output result. This is either -1 if the element is undef or a number less
1932 /// than 2*numelements.
1933 static int getMaskValue(Constant *Mask, unsigned i);
1935 int getMaskValue(unsigned i) const {
1936 return getMaskValue(getMask(), i);
1939 /// getShuffleMask - Return the full mask for this instruction, where each
1940 /// element is the element number and undef's are returned as -1.
1941 static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
1943 void getShuffleMask(SmallVectorImpl<int> &Result) const {
1944 return getShuffleMask(getMask(), Result);
1947 SmallVector<int, 16> getShuffleMask() const {
1948 SmallVector<int, 16> Mask;
1949 getShuffleMask(Mask);
1954 // Methods for support type inquiry through isa, cast, and dyn_cast:
1955 static inline bool classof(const Instruction *I) {
1956 return I->getOpcode() == Instruction::ShuffleVector;
1958 static inline bool classof(const Value *V) {
1959 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1964 struct OperandTraits<ShuffleVectorInst> :
1965 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1968 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1970 //===----------------------------------------------------------------------===//
1971 // ExtractValueInst Class
1972 //===----------------------------------------------------------------------===//
1974 /// ExtractValueInst - This instruction extracts a struct member or array
1975 /// element value from an aggregate value.
1977 class ExtractValueInst : public UnaryInstruction {
1978 SmallVector<unsigned, 4> Indices;
1980 ExtractValueInst(const ExtractValueInst &EVI);
1981 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1983 /// Constructors - Create a extractvalue instruction with a base aggregate
1984 /// value and a list of indices. The first ctor can optionally insert before
1985 /// an existing instruction, the second appends the new instruction to the
1986 /// specified BasicBlock.
1987 inline ExtractValueInst(Value *Agg,
1988 ArrayRef<unsigned> Idxs,
1989 const Twine &NameStr,
1990 Instruction *InsertBefore);
1991 inline ExtractValueInst(Value *Agg,
1992 ArrayRef<unsigned> Idxs,
1993 const Twine &NameStr, BasicBlock *InsertAtEnd);
1995 // allocate space for exactly one operand
1996 void *operator new(size_t s) {
1997 return User::operator new(s, 1);
2000 ExtractValueInst *clone_impl() const override;
2003 static ExtractValueInst *Create(Value *Agg,
2004 ArrayRef<unsigned> Idxs,
2005 const Twine &NameStr = "",
2006 Instruction *InsertBefore = nullptr) {
2008 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
2010 static ExtractValueInst *Create(Value *Agg,
2011 ArrayRef<unsigned> Idxs,
2012 const Twine &NameStr,
2013 BasicBlock *InsertAtEnd) {
2014 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
2017 /// getIndexedType - Returns the type of the element that would be extracted
2018 /// with an extractvalue instruction with the specified parameters.
2020 /// Null is returned if the indices are invalid for the specified type.
2021 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
2023 typedef const unsigned* idx_iterator;
2024 inline idx_iterator idx_begin() const { return Indices.begin(); }
2025 inline idx_iterator idx_end() const { return Indices.end(); }
2026 inline iterator_range<idx_iterator> indices() const {
2027 return iterator_range<idx_iterator>(idx_begin(), idx_end());
2030 Value *getAggregateOperand() {
2031 return getOperand(0);
2033 const Value *getAggregateOperand() const {
2034 return getOperand(0);
2036 static unsigned getAggregateOperandIndex() {
2037 return 0U; // get index for modifying correct operand
2040 ArrayRef<unsigned> getIndices() const {
2044 unsigned getNumIndices() const {
2045 return (unsigned)Indices.size();
2048 bool hasIndices() const {
2052 // Methods for support type inquiry through isa, cast, and dyn_cast:
2053 static inline bool classof(const Instruction *I) {
2054 return I->getOpcode() == Instruction::ExtractValue;
2056 static inline bool classof(const Value *V) {
2057 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2061 ExtractValueInst::ExtractValueInst(Value *Agg,
2062 ArrayRef<unsigned> Idxs,
2063 const Twine &NameStr,
2064 Instruction *InsertBefore)
2065 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
2066 ExtractValue, Agg, InsertBefore) {
2067 init(Idxs, NameStr);
2069 ExtractValueInst::ExtractValueInst(Value *Agg,
2070 ArrayRef<unsigned> Idxs,
2071 const Twine &NameStr,
2072 BasicBlock *InsertAtEnd)
2073 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
2074 ExtractValue, Agg, InsertAtEnd) {
2075 init(Idxs, NameStr);
2079 //===----------------------------------------------------------------------===//
2080 // InsertValueInst Class
2081 //===----------------------------------------------------------------------===//
2083 /// InsertValueInst - This instruction inserts a struct field of array element
2084 /// value into an aggregate value.
2086 class InsertValueInst : public Instruction {
2087 SmallVector<unsigned, 4> Indices;
2089 void *operator new(size_t, unsigned) = delete;
2090 InsertValueInst(const InsertValueInst &IVI);
2091 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
2092 const Twine &NameStr);
2094 /// Constructors - Create a insertvalue instruction with a base aggregate
2095 /// value, a value to insert, and a list of indices. The first ctor can
2096 /// optionally insert before an existing instruction, the second appends
2097 /// the new instruction to the specified BasicBlock.
2098 inline InsertValueInst(Value *Agg, Value *Val,
2099 ArrayRef<unsigned> Idxs,
2100 const Twine &NameStr,
2101 Instruction *InsertBefore);
2102 inline InsertValueInst(Value *Agg, Value *Val,
2103 ArrayRef<unsigned> Idxs,
2104 const Twine &NameStr, BasicBlock *InsertAtEnd);
2106 /// Constructors - These two constructors are convenience methods because one
2107 /// and two index insertvalue instructions are so common.
2108 InsertValueInst(Value *Agg, Value *Val,
2109 unsigned Idx, const Twine &NameStr = "",
2110 Instruction *InsertBefore = nullptr);
2111 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
2112 const Twine &NameStr, BasicBlock *InsertAtEnd);
2114 InsertValueInst *clone_impl() const override;
2116 // allocate space for exactly two operands
2117 void *operator new(size_t s) {
2118 return User::operator new(s, 2);
2121 static InsertValueInst *Create(Value *Agg, Value *Val,
2122 ArrayRef<unsigned> Idxs,
2123 const Twine &NameStr = "",
2124 Instruction *InsertBefore = nullptr) {
2125 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
2127 static InsertValueInst *Create(Value *Agg, Value *Val,
2128 ArrayRef<unsigned> Idxs,
2129 const Twine &NameStr,
2130 BasicBlock *InsertAtEnd) {
2131 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
2134 /// Transparently provide more efficient getOperand methods.
2135 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2137 typedef const unsigned* idx_iterator;
2138 inline idx_iterator idx_begin() const { return Indices.begin(); }
2139 inline idx_iterator idx_end() const { return Indices.end(); }
2140 inline iterator_range<idx_iterator> indices() const {
2141 return iterator_range<idx_iterator>(idx_begin(), idx_end());
2144 Value *getAggregateOperand() {
2145 return getOperand(0);
2147 const Value *getAggregateOperand() const {
2148 return getOperand(0);
2150 static unsigned getAggregateOperandIndex() {
2151 return 0U; // get index for modifying correct operand
2154 Value *getInsertedValueOperand() {
2155 return getOperand(1);
2157 const Value *getInsertedValueOperand() const {
2158 return getOperand(1);
2160 static unsigned getInsertedValueOperandIndex() {
2161 return 1U; // get index for modifying correct operand
2164 ArrayRef<unsigned> getIndices() const {
2168 unsigned getNumIndices() const {
2169 return (unsigned)Indices.size();
2172 bool hasIndices() const {
2176 // Methods for support type inquiry through isa, cast, and dyn_cast:
2177 static inline bool classof(const Instruction *I) {
2178 return I->getOpcode() == Instruction::InsertValue;
2180 static inline bool classof(const Value *V) {
2181 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2186 struct OperandTraits<InsertValueInst> :
2187 public FixedNumOperandTraits<InsertValueInst, 2> {
2190 InsertValueInst::InsertValueInst(Value *Agg,
2192 ArrayRef<unsigned> Idxs,
2193 const Twine &NameStr,
2194 Instruction *InsertBefore)
2195 : Instruction(Agg->getType(), InsertValue,
2196 OperandTraits<InsertValueInst>::op_begin(this),
2198 init(Agg, Val, Idxs, NameStr);
2200 InsertValueInst::InsertValueInst(Value *Agg,
2202 ArrayRef<unsigned> Idxs,
2203 const Twine &NameStr,
2204 BasicBlock *InsertAtEnd)
2205 : Instruction(Agg->getType(), InsertValue,
2206 OperandTraits<InsertValueInst>::op_begin(this),
2208 init(Agg, Val, Idxs, NameStr);
2211 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
2213 //===----------------------------------------------------------------------===//
2215 //===----------------------------------------------------------------------===//
2217 // PHINode - The PHINode class is used to represent the magical mystical PHI
2218 // node, that can not exist in nature, but can be synthesized in a computer
2219 // scientist's overactive imagination.
2221 class PHINode : public Instruction {
2222 void *operator new(size_t, unsigned) = delete;
2223 /// ReservedSpace - The number of operands actually allocated. NumOperands is
2224 /// the number actually in use.
2225 unsigned ReservedSpace;
2226 PHINode(const PHINode &PN);
2227 // allocate space for exactly zero operands
2228 void *operator new(size_t s) {
2229 return User::operator new(s, 0);
2231 explicit PHINode(Type *Ty, unsigned NumReservedValues,
2232 const Twine &NameStr = "",
2233 Instruction *InsertBefore = nullptr)
2234 : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore),
2235 ReservedSpace(NumReservedValues) {
2237 OperandList = allocHungoffUses(ReservedSpace);
2240 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
2241 BasicBlock *InsertAtEnd)
2242 : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd),
2243 ReservedSpace(NumReservedValues) {
2245 OperandList = allocHungoffUses(ReservedSpace);
2248 // allocHungoffUses - this is more complicated than the generic
2249 // User::allocHungoffUses, because we have to allocate Uses for the incoming
2250 // values and pointers to the incoming blocks, all in one allocation.
2251 Use *allocHungoffUses(unsigned) const;
2253 PHINode *clone_impl() const override;
2255 /// Constructors - NumReservedValues is a hint for the number of incoming
2256 /// edges that this phi node will have (use 0 if you really have no idea).
2257 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2258 const Twine &NameStr = "",
2259 Instruction *InsertBefore = nullptr) {
2260 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2262 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2263 const Twine &NameStr, BasicBlock *InsertAtEnd) {
2264 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2266 ~PHINode() override;
2268 /// Provide fast operand accessors
2269 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2271 // Block iterator interface. This provides access to the list of incoming
2272 // basic blocks, which parallels the list of incoming values.
2274 typedef BasicBlock **block_iterator;
2275 typedef BasicBlock * const *const_block_iterator;
2277 block_iterator block_begin() {
2279 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2280 return reinterpret_cast<block_iterator>(ref + 1);
2283 const_block_iterator block_begin() const {
2284 const Use::UserRef *ref =
2285 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2286 return reinterpret_cast<const_block_iterator>(ref + 1);
2289 block_iterator block_end() {
2290 return block_begin() + getNumOperands();
2293 const_block_iterator block_end() const {
2294 return block_begin() + getNumOperands();
2297 op_range incoming_values() { return operands(); }
2299 const_op_range incoming_values() const { return operands(); }
2301 /// getNumIncomingValues - Return the number of incoming edges
2303 unsigned getNumIncomingValues() const { return getNumOperands(); }
2305 /// getIncomingValue - Return incoming value number x
2307 Value *getIncomingValue(unsigned i) const {
2308 return getOperand(i);
2310 void setIncomingValue(unsigned i, Value *V) {
2313 static unsigned getOperandNumForIncomingValue(unsigned i) {
2316 static unsigned getIncomingValueNumForOperand(unsigned i) {
2320 /// getIncomingBlock - Return incoming basic block number @p i.
2322 BasicBlock *getIncomingBlock(unsigned i) const {
2323 return block_begin()[i];
2326 /// getIncomingBlock - Return incoming basic block corresponding
2327 /// to an operand of the PHI.
2329 BasicBlock *getIncomingBlock(const Use &U) const {
2330 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2331 return getIncomingBlock(unsigned(&U - op_begin()));
2334 /// getIncomingBlock - Return incoming basic block corresponding
2335 /// to value use iterator.
2337 BasicBlock *getIncomingBlock(Value::const_user_iterator I) const {
2338 return getIncomingBlock(I.getUse());
2341 void setIncomingBlock(unsigned i, BasicBlock *BB) {
2342 block_begin()[i] = BB;
2345 /// addIncoming - Add an incoming value to the end of the PHI list
2347 void addIncoming(Value *V, BasicBlock *BB) {
2348 assert(V && "PHI node got a null value!");
2349 assert(BB && "PHI node got a null basic block!");
2350 assert(getType() == V->getType() &&
2351 "All operands to PHI node must be the same type as the PHI node!");
2352 if (NumOperands == ReservedSpace)
2353 growOperands(); // Get more space!
2354 // Initialize some new operands.
2356 setIncomingValue(NumOperands - 1, V);
2357 setIncomingBlock(NumOperands - 1, BB);
2360 /// removeIncomingValue - Remove an incoming value. This is useful if a
2361 /// predecessor basic block is deleted. The value removed is returned.
2363 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2364 /// is true), the PHI node is destroyed and any uses of it are replaced with
2365 /// dummy values. The only time there should be zero incoming values to a PHI
2366 /// node is when the block is dead, so this strategy is sound.
2368 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2370 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2371 int Idx = getBasicBlockIndex(BB);
2372 assert(Idx >= 0 && "Invalid basic block argument to remove!");
2373 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2376 /// getBasicBlockIndex - Return the first index of the specified basic
2377 /// block in the value list for this PHI. Returns -1 if no instance.
2379 int getBasicBlockIndex(const BasicBlock *BB) const {
2380 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2381 if (block_begin()[i] == BB)
2386 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2387 int Idx = getBasicBlockIndex(BB);
2388 assert(Idx >= 0 && "Invalid basic block argument!");
2389 return getIncomingValue(Idx);
2392 /// hasConstantValue - If the specified PHI node always merges together the
2393 /// same value, return the value, otherwise return null.
2394 Value *hasConstantValue() const;
2396 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2397 static inline bool classof(const Instruction *I) {
2398 return I->getOpcode() == Instruction::PHI;
2400 static inline bool classof(const Value *V) {
2401 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2404 void growOperands();
2408 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2411 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
2413 //===----------------------------------------------------------------------===//
2414 // LandingPadInst Class
2415 //===----------------------------------------------------------------------===//
2417 //===---------------------------------------------------------------------------
2418 /// LandingPadInst - The landingpad instruction holds all of the information
2419 /// necessary to generate correct exception handling. The landingpad instruction
2420 /// cannot be moved from the top of a landing pad block, which itself is
2421 /// accessible only from the 'unwind' edge of an invoke. This uses the
2422 /// SubclassData field in Value to store whether or not the landingpad is a
2425 class LandingPadInst : public Instruction {
2426 /// ReservedSpace - The number of operands actually allocated. NumOperands is
2427 /// the number actually in use.
2428 unsigned ReservedSpace;
2429 LandingPadInst(const LandingPadInst &LP);
2431 enum ClauseType { Catch, Filter };
2433 void *operator new(size_t, unsigned) = delete;
2434 // Allocate space for exactly zero operands.
2435 void *operator new(size_t s) {
2436 return User::operator new(s, 0);
2438 void growOperands(unsigned Size);
2439 void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
2441 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2442 unsigned NumReservedValues, const Twine &NameStr,
2443 Instruction *InsertBefore);
2444 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2445 unsigned NumReservedValues, const Twine &NameStr,
2446 BasicBlock *InsertAtEnd);
2448 LandingPadInst *clone_impl() const override;
2450 /// Constructors - NumReservedClauses is a hint for the number of incoming
2451 /// clauses that this landingpad will have (use 0 if you really have no idea).
2452 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2453 unsigned NumReservedClauses,
2454 const Twine &NameStr = "",
2455 Instruction *InsertBefore = nullptr);
2456 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2457 unsigned NumReservedClauses,
2458 const Twine &NameStr, BasicBlock *InsertAtEnd);
2459 ~LandingPadInst() override;
2461 /// Provide fast operand accessors
2462 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2464 /// getPersonalityFn - Get the personality function associated with this
2466 Value *getPersonalityFn() const { return getOperand(0); }
2468 /// isCleanup - Return 'true' if this landingpad instruction is a
2469 /// cleanup. I.e., it should be run when unwinding even if its landing pad
2470 /// doesn't catch the exception.
2471 bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2473 /// setCleanup - Indicate that this landingpad instruction is a cleanup.
2474 void setCleanup(bool V) {
2475 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2479 /// Add a catch or filter clause to the landing pad.
2480 void addClause(Constant *ClauseVal);
2482 /// Get the value of the clause at index Idx. Use isCatch/isFilter to
2483 /// determine what type of clause this is.
2484 Constant *getClause(unsigned Idx) const {
2485 return cast<Constant>(OperandList[Idx + 1]);
2488 /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
2489 bool isCatch(unsigned Idx) const {
2490 return !isa<ArrayType>(OperandList[Idx + 1]->getType());
2493 /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
2494 bool isFilter(unsigned Idx) const {
2495 return isa<ArrayType>(OperandList[Idx + 1]->getType());
2498 /// getNumClauses - Get the number of clauses for this landing pad.
2499 unsigned getNumClauses() const { return getNumOperands() - 1; }
2501 /// reserveClauses - Grow the size of the operand list to accommodate the new
2502 /// number of clauses.
2503 void reserveClauses(unsigned Size) { growOperands(Size); }
2505 // Methods for support type inquiry through isa, cast, and dyn_cast:
2506 static inline bool classof(const Instruction *I) {
2507 return I->getOpcode() == Instruction::LandingPad;
2509 static inline bool classof(const Value *V) {
2510 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2515 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
2518 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
2520 //===----------------------------------------------------------------------===//
2522 //===----------------------------------------------------------------------===//
2524 //===---------------------------------------------------------------------------
2525 /// ReturnInst - Return a value (possibly void), from a function. Execution
2526 /// does not continue in this function any longer.
2528 class ReturnInst : public TerminatorInst {
2529 ReturnInst(const ReturnInst &RI);
2532 // ReturnInst constructors:
2533 // ReturnInst() - 'ret void' instruction
2534 // ReturnInst( null) - 'ret void' instruction
2535 // ReturnInst(Value* X) - 'ret X' instruction
2536 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
2537 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
2538 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2539 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
2541 // NOTE: If the Value* passed is of type void then the constructor behaves as
2542 // if it was passed NULL.
2543 explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr,
2544 Instruction *InsertBefore = nullptr);
2545 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2546 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2548 ReturnInst *clone_impl() const override;
2550 static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr,
2551 Instruction *InsertBefore = nullptr) {
2552 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2554 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2555 BasicBlock *InsertAtEnd) {
2556 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2558 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2559 return new(0) ReturnInst(C, InsertAtEnd);
2561 ~ReturnInst() override;
2563 /// Provide fast operand accessors
2564 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2566 /// Convenience accessor. Returns null if there is no return value.
2567 Value *getReturnValue() const {
2568 return getNumOperands() != 0 ? getOperand(0) : nullptr;
2571 unsigned getNumSuccessors() const { return 0; }
2573 // Methods for support type inquiry through isa, cast, and dyn_cast:
2574 static inline bool classof(const Instruction *I) {
2575 return (I->getOpcode() == Instruction::Ret);
2577 static inline bool classof(const Value *V) {
2578 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2581 BasicBlock *getSuccessorV(unsigned idx) const override;
2582 unsigned getNumSuccessorsV() const override;
2583 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2587 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2590 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2592 //===----------------------------------------------------------------------===//
2594 //===----------------------------------------------------------------------===//
2596 //===---------------------------------------------------------------------------
2597 /// BranchInst - Conditional or Unconditional Branch instruction.
2599 class BranchInst : public TerminatorInst {
2600 /// Ops list - Branches are strange. The operands are ordered:
2601 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2602 /// they don't have to check for cond/uncond branchness. These are mostly
2603 /// accessed relative from op_end().
2604 BranchInst(const BranchInst &BI);
2606 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2607 // BranchInst(BB *B) - 'br B'
2608 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2609 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2610 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2611 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2612 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2613 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr);
2614 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2615 Instruction *InsertBefore = nullptr);
2616 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2617 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2618 BasicBlock *InsertAtEnd);
2620 BranchInst *clone_impl() const override;
2622 static BranchInst *Create(BasicBlock *IfTrue,
2623 Instruction *InsertBefore = nullptr) {
2624 return new(1) BranchInst(IfTrue, InsertBefore);
2626 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2627 Value *Cond, Instruction *InsertBefore = nullptr) {
2628 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2630 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2631 return new(1) BranchInst(IfTrue, InsertAtEnd);
2633 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2634 Value *Cond, BasicBlock *InsertAtEnd) {
2635 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2638 /// Transparently provide more efficient getOperand methods.
2639 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2641 bool isUnconditional() const { return getNumOperands() == 1; }
2642 bool isConditional() const { return getNumOperands() == 3; }
2644 Value *getCondition() const {
2645 assert(isConditional() && "Cannot get condition of an uncond branch!");
2649 void setCondition(Value *V) {
2650 assert(isConditional() && "Cannot set condition of unconditional branch!");
2654 unsigned getNumSuccessors() const { return 1+isConditional(); }
2656 BasicBlock *getSuccessor(unsigned i) const {
2657 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2658 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2661 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2662 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2663 *(&Op<-1>() - idx) = (Value*)NewSucc;
2666 /// \brief Swap the successors of this branch instruction.
2668 /// Swaps the successors of the branch instruction. This also swaps any
2669 /// branch weight metadata associated with the instruction so that it
2670 /// continues to map correctly to each operand.
2671 void swapSuccessors();
2673 // Methods for support type inquiry through isa, cast, and dyn_cast:
2674 static inline bool classof(const Instruction *I) {
2675 return (I->getOpcode() == Instruction::Br);
2677 static inline bool classof(const Value *V) {
2678 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2681 BasicBlock *getSuccessorV(unsigned idx) const override;
2682 unsigned getNumSuccessorsV() const override;
2683 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2687 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2690 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2692 //===----------------------------------------------------------------------===//
2694 //===----------------------------------------------------------------------===//
2696 //===---------------------------------------------------------------------------
2697 /// SwitchInst - Multiway switch
2699 class SwitchInst : public TerminatorInst {
2700 void *operator new(size_t, unsigned) = delete;
2701 unsigned ReservedSpace;
2702 // Operand[0] = Value to switch on
2703 // Operand[1] = Default basic block destination
2704 // Operand[2n ] = Value to match
2705 // Operand[2n+1] = BasicBlock to go to on match
2706 SwitchInst(const SwitchInst &SI);
2707 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2708 void growOperands();
2709 // allocate space for exactly zero operands
2710 void *operator new(size_t s) {
2711 return User::operator new(s, 0);
2713 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2714 /// switch on and a default destination. The number of additional cases can
2715 /// be specified here to make memory allocation more efficient. This
2716 /// constructor can also autoinsert before another instruction.
2717 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2718 Instruction *InsertBefore);
2720 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2721 /// switch on and a default destination. The number of additional cases can
2722 /// be specified here to make memory allocation more efficient. This
2723 /// constructor also autoinserts at the end of the specified BasicBlock.
2724 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2725 BasicBlock *InsertAtEnd);
2727 SwitchInst *clone_impl() const override;
2731 static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
2733 template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy>
2734 class CaseIteratorT {
2742 typedef CaseIteratorT<SwitchInstTy, ConstantIntTy, BasicBlockTy> Self;
2744 /// Initializes case iterator for given SwitchInst and for given
2746 CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
2751 /// Initializes case iterator for given SwitchInst and for given
2752 /// TerminatorInst's successor index.
2753 static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
2754 assert(SuccessorIndex < SI->getNumSuccessors() &&
2755 "Successor index # out of range!");
2756 return SuccessorIndex != 0 ?
2757 Self(SI, SuccessorIndex - 1) :
2758 Self(SI, DefaultPseudoIndex);
2761 /// Resolves case value for current case.
2762 ConstantIntTy *getCaseValue() {
2763 assert(Index < SI->getNumCases() && "Index out the number of cases.");
2764 return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2));
2767 /// Resolves successor for current case.
2768 BasicBlockTy *getCaseSuccessor() {
2769 assert((Index < SI->getNumCases() ||
2770 Index == DefaultPseudoIndex) &&
2771 "Index out the number of cases.");
2772 return SI->getSuccessor(getSuccessorIndex());
2775 /// Returns number of current case.
2776 unsigned getCaseIndex() const { return Index; }
2778 /// Returns TerminatorInst's successor index for current case successor.
2779 unsigned getSuccessorIndex() const {
2780 assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
2781 "Index out the number of cases.");
2782 return Index != DefaultPseudoIndex ? Index + 1 : 0;
2786 // Check index correctness after increment.
2787 // Note: Index == getNumCases() means end().
2788 assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
2792 Self operator++(int) {
2798 // Check index correctness after decrement.
2799 // Note: Index == getNumCases() means end().
2800 // Also allow "-1" iterator here. That will became valid after ++.
2801 assert((Index == 0 || Index-1 <= SI->getNumCases()) &&
2802 "Index out the number of cases.");
2806 Self operator--(int) {
2811 bool operator==(const Self& RHS) const {
2812 assert(RHS.SI == SI && "Incompatible operators.");
2813 return RHS.Index == Index;
2815 bool operator!=(const Self& RHS) const {
2816 assert(RHS.SI == SI && "Incompatible operators.");
2817 return RHS.Index != Index;
2824 typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock>
2827 class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> {
2829 typedef CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> ParentTy;
2833 CaseIt(const ParentTy& Src) : ParentTy(Src) {}
2834 CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
2836 /// Sets the new value for current case.
2837 void setValue(ConstantInt *V) {
2838 assert(Index < SI->getNumCases() && "Index out the number of cases.");
2839 SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V));
2842 /// Sets the new successor for current case.
2843 void setSuccessor(BasicBlock *S) {
2844 SI->setSuccessor(getSuccessorIndex(), S);
2848 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2850 Instruction *InsertBefore = nullptr) {
2851 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2853 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2854 unsigned NumCases, BasicBlock *InsertAtEnd) {
2855 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2858 ~SwitchInst() override;
2860 /// Provide fast operand accessors
2861 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2863 // Accessor Methods for Switch stmt
2864 Value *getCondition() const { return getOperand(0); }
2865 void setCondition(Value *V) { setOperand(0, V); }
2867 BasicBlock *getDefaultDest() const {
2868 return cast<BasicBlock>(getOperand(1));
2871 void setDefaultDest(BasicBlock *DefaultCase) {
2872 setOperand(1, reinterpret_cast<Value*>(DefaultCase));
2875 /// getNumCases - return the number of 'cases' in this switch instruction,
2876 /// except the default case
2877 unsigned getNumCases() const {
2878 return getNumOperands()/2 - 1;
2881 /// Returns a read/write iterator that points to the first
2882 /// case in SwitchInst.
2883 CaseIt case_begin() {
2884 return CaseIt(this, 0);
2886 /// Returns a read-only iterator that points to the first
2887 /// case in the SwitchInst.
2888 ConstCaseIt case_begin() const {
2889 return ConstCaseIt(this, 0);
2892 /// Returns a read/write iterator that points one past the last
2893 /// in the SwitchInst.
2895 return CaseIt(this, getNumCases());
2897 /// Returns a read-only iterator that points one past the last
2898 /// in the SwitchInst.
2899 ConstCaseIt case_end() const {
2900 return ConstCaseIt(this, getNumCases());
2903 /// cases - iteration adapter for range-for loops.
2904 iterator_range<CaseIt> cases() {
2905 return iterator_range<CaseIt>(case_begin(), case_end());
2908 /// cases - iteration adapter for range-for loops.
2909 iterator_range<ConstCaseIt> cases() const {
2910 return iterator_range<ConstCaseIt>(case_begin(), case_end());
2913 /// Returns an iterator that points to the default case.
2914 /// Note: this iterator allows to resolve successor only. Attempt
2915 /// to resolve case value causes an assertion.
2916 /// Also note, that increment and decrement also causes an assertion and
2917 /// makes iterator invalid.
2918 CaseIt case_default() {
2919 return CaseIt(this, DefaultPseudoIndex);
2921 ConstCaseIt case_default() const {
2922 return ConstCaseIt(this, DefaultPseudoIndex);
2925 /// findCaseValue - Search all of the case values for the specified constant.
2926 /// If it is explicitly handled, return the case iterator of it, otherwise
2927 /// return default case iterator to indicate
2928 /// that it is handled by the default handler.
2929 CaseIt findCaseValue(const ConstantInt *C) {
2930 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
2931 if (i.getCaseValue() == C)
2933 return case_default();
2935 ConstCaseIt findCaseValue(const ConstantInt *C) const {
2936 for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
2937 if (i.getCaseValue() == C)
2939 return case_default();
2942 /// findCaseDest - Finds the unique case value for a given successor. Returns
2943 /// null if the successor is not found, not unique, or is the default case.
2944 ConstantInt *findCaseDest(BasicBlock *BB) {
2945 if (BB == getDefaultDest()) return nullptr;
2947 ConstantInt *CI = nullptr;
2948 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
2949 if (i.getCaseSuccessor() == BB) {
2950 if (CI) return nullptr; // Multiple cases lead to BB.
2951 else CI = i.getCaseValue();
2957 /// addCase - Add an entry to the switch instruction...
2959 /// This action invalidates case_end(). Old case_end() iterator will
2960 /// point to the added case.
2961 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2963 /// removeCase - This method removes the specified case and its successor
2964 /// from the switch instruction. Note that this operation may reorder the
2965 /// remaining cases at index idx and above.
2967 /// This action invalidates iterators for all cases following the one removed,
2968 /// including the case_end() iterator.
2969 void removeCase(CaseIt i);
2971 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2972 BasicBlock *getSuccessor(unsigned idx) const {
2973 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2974 return cast<BasicBlock>(getOperand(idx*2+1));
2976 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2977 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2978 setOperand(idx*2+1, (Value*)NewSucc);
2981 // Methods for support type inquiry through isa, cast, and dyn_cast:
2982 static inline bool classof(const Instruction *I) {
2983 return I->getOpcode() == Instruction::Switch;
2985 static inline bool classof(const Value *V) {
2986 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2989 BasicBlock *getSuccessorV(unsigned idx) const override;
2990 unsigned getNumSuccessorsV() const override;
2991 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2995 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2998 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
3001 //===----------------------------------------------------------------------===//
3002 // IndirectBrInst Class
3003 //===----------------------------------------------------------------------===//
3005 //===---------------------------------------------------------------------------
3006 /// IndirectBrInst - Indirect Branch Instruction.
3008 class IndirectBrInst : public TerminatorInst {
3009 void *operator new(size_t, unsigned) = delete;
3010 unsigned ReservedSpace;
3011 // Operand[0] = Value to switch on
3012 // Operand[1] = Default basic block destination
3013 // Operand[2n ] = Value to match
3014 // Operand[2n+1] = BasicBlock to go to on match
3015 IndirectBrInst(const IndirectBrInst &IBI);
3016 void init(Value *Address, unsigned NumDests);
3017 void growOperands();
3018 // allocate space for exactly zero operands
3019 void *operator new(size_t s) {
3020 return User::operator new(s, 0);
3022 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
3023 /// Address to jump to. The number of expected destinations can be specified
3024 /// here to make memory allocation more efficient. This constructor can also
3025 /// autoinsert before another instruction.
3026 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
3028 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
3029 /// Address to jump to. The number of expected destinations can be specified
3030 /// here to make memory allocation more efficient. This constructor also
3031 /// autoinserts at the end of the specified BasicBlock.
3032 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
3034 IndirectBrInst *clone_impl() const override;
3036 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
3037 Instruction *InsertBefore = nullptr) {
3038 return new IndirectBrInst(Address, NumDests, InsertBefore);
3040 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
3041 BasicBlock *InsertAtEnd) {
3042 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
3044 ~IndirectBrInst() override;
3046 /// Provide fast operand accessors.
3047 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3049 // Accessor Methods for IndirectBrInst instruction.
3050 Value *getAddress() { return getOperand(0); }
3051 const Value *getAddress() const { return getOperand(0); }
3052 void setAddress(Value *V) { setOperand(0, V); }
3055 /// getNumDestinations - return the number of possible destinations in this
3056 /// indirectbr instruction.
3057 unsigned getNumDestinations() const { return getNumOperands()-1; }
3059 /// getDestination - Return the specified destination.
3060 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
3061 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
3063 /// addDestination - Add a destination.
3065 void addDestination(BasicBlock *Dest);
3067 /// removeDestination - This method removes the specified successor from the
3068 /// indirectbr instruction.
3069 void removeDestination(unsigned i);
3071 unsigned getNumSuccessors() const { return getNumOperands()-1; }
3072 BasicBlock *getSuccessor(unsigned i) const {
3073 return cast<BasicBlock>(getOperand(i+1));
3075 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
3076 setOperand(i+1, (Value*)NewSucc);
3079 // Methods for support type inquiry through isa, cast, and dyn_cast:
3080 static inline bool classof(const Instruction *I) {
3081 return I->getOpcode() == Instruction::IndirectBr;
3083 static inline bool classof(const Value *V) {
3084 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3087 BasicBlock *getSuccessorV(unsigned idx) const override;
3088 unsigned getNumSuccessorsV() const override;
3089 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3093 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
3096 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
3099 //===----------------------------------------------------------------------===//
3101 //===----------------------------------------------------------------------===//
3103 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
3104 /// calling convention of the call.
3106 class InvokeInst : public TerminatorInst {
3107 AttributeSet AttributeList;
3109 InvokeInst(const InvokeInst &BI);
3110 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3111 ArrayRef<Value *> Args, const Twine &NameStr) {
3112 init(cast<FunctionType>(
3113 cast<PointerType>(Func->getType())->getElementType()),
3114 Func, IfNormal, IfException, Args, NameStr);
3116 void init(FunctionType *FTy, Value *Func, BasicBlock *IfNormal,
3117 BasicBlock *IfException, ArrayRef<Value *> Args,
3118 const Twine &NameStr);
3120 /// Construct an InvokeInst given a range of arguments.
3122 /// \brief Construct an InvokeInst from a range of arguments
3123 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3124 ArrayRef<Value *> Args, unsigned Values,
3125 const Twine &NameStr, Instruction *InsertBefore)
3126 : InvokeInst(cast<FunctionType>(
3127 cast<PointerType>(Func->getType())->getElementType()),
3128 Func, IfNormal, IfException, Args, Values, NameStr,
3131 inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3132 BasicBlock *IfException, ArrayRef<Value *> Args,
3133 unsigned Values, const Twine &NameStr,
3134 Instruction *InsertBefore);
3135 /// Construct an InvokeInst given a range of arguments.
3137 /// \brief Construct an InvokeInst from a range of arguments
3138 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3139 ArrayRef<Value *> Args, unsigned Values,
3140 const Twine &NameStr, BasicBlock *InsertAtEnd);
3142 InvokeInst *clone_impl() const override;
3144 static InvokeInst *Create(Value *Func,
3145 BasicBlock *IfNormal, BasicBlock *IfException,
3146 ArrayRef<Value *> Args, const Twine &NameStr = "",
3147 Instruction *InsertBefore = nullptr) {
3148 return Create(cast<FunctionType>(
3149 cast<PointerType>(Func->getType())->getElementType()),
3150 Func, IfNormal, IfException, Args, NameStr, InsertBefore);
3152 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3153 BasicBlock *IfException, ArrayRef<Value *> Args,
3154 const Twine &NameStr = "",
3155 Instruction *InsertBefore = nullptr) {
3156 unsigned Values = unsigned(Args.size()) + 3;
3157 return new (Values) InvokeInst(Ty, Func, IfNormal, IfException, Args,
3158 Values, NameStr, InsertBefore);
3160 static InvokeInst *Create(Value *Func,
3161 BasicBlock *IfNormal, BasicBlock *IfException,
3162 ArrayRef<Value *> Args, const Twine &NameStr,
3163 BasicBlock *InsertAtEnd) {
3164 unsigned Values = unsigned(Args.size()) + 3;
3165 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
3166 Values, NameStr, InsertAtEnd);
3169 /// Provide fast operand accessors
3170 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3172 FunctionType *getFunctionType() const { return FTy; }
3174 void mutateFunctionType(FunctionType *FTy) {
3175 mutateType(FTy->getReturnType());
3179 /// getNumArgOperands - Return the number of invoke arguments.
3181 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
3183 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
3185 Value *getArgOperand(unsigned i) const { return getOperand(i); }
3186 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
3188 /// arg_operands - iteration adapter for range-for loops.
3189 iterator_range<op_iterator> arg_operands() {
3190 return iterator_range<op_iterator>(op_begin(), op_end() - 3);
3193 /// arg_operands - iteration adapter for range-for loops.
3194 iterator_range<const_op_iterator> arg_operands() const {
3195 return iterator_range<const_op_iterator>(op_begin(), op_end() - 3);
3198 /// \brief Wrappers for getting the \c Use of a invoke argument.
3199 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
3200 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
3202 /// getCallingConv/setCallingConv - Get or set the calling convention of this
3204 CallingConv::ID getCallingConv() const {
3205 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
3207 void setCallingConv(CallingConv::ID CC) {
3208 setInstructionSubclassData(static_cast<unsigned>(CC));
3211 /// getAttributes - Return the parameter attributes for this invoke.
3213 const AttributeSet &getAttributes() const { return AttributeList; }
3215 /// setAttributes - Set the parameter attributes for this invoke.
3217 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
3219 /// addAttribute - adds the attribute to the list of attributes.
3220 void addAttribute(unsigned i, Attribute::AttrKind attr);
3222 /// removeAttribute - removes the attribute from the list of attributes.
3223 void removeAttribute(unsigned i, Attribute attr);
3225 /// \brief adds the dereferenceable attribute to the list of attributes.
3226 void addDereferenceableAttr(unsigned i, uint64_t Bytes);
3228 /// \brief adds the dereferenceable_or_null attribute to the list of
3230 void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
3232 /// \brief Determine whether this call has the given attribute.
3233 bool hasFnAttr(Attribute::AttrKind A) const {
3234 assert(A != Attribute::NoBuiltin &&
3235 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
3236 return hasFnAttrImpl(A);
3239 /// \brief Determine whether the call or the callee has the given attributes.
3240 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
3242 /// \brief Extract the alignment for a call or parameter (0=unknown).
3243 unsigned getParamAlignment(unsigned i) const {
3244 return AttributeList.getParamAlignment(i);
3247 /// \brief Extract the number of dereferenceable bytes for a call or
3248 /// parameter (0=unknown).
3249 uint64_t getDereferenceableBytes(unsigned i) const {
3250 return AttributeList.getDereferenceableBytes(i);
3253 /// \brief Extract the number of dereferenceable_or_null bytes for a call or
3254 /// parameter (0=unknown).
3255 uint64_t getDereferenceableOrNullBytes(unsigned i) const {
3256 return AttributeList.getDereferenceableOrNullBytes(i);
3259 /// \brief Return true if the call should not be treated as a call to a
3261 bool isNoBuiltin() const {
3262 // We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have
3263 // to check it by hand.
3264 return hasFnAttrImpl(Attribute::NoBuiltin) &&
3265 !hasFnAttrImpl(Attribute::Builtin);
3268 /// \brief Return true if the call should not be inlined.
3269 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
3270 void setIsNoInline() {
3271 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
3274 /// \brief Determine if the call does not access memory.
3275 bool doesNotAccessMemory() const {
3276 return hasFnAttr(Attribute::ReadNone);
3278 void setDoesNotAccessMemory() {
3279 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
3282 /// \brief Determine if the call does not access or only reads memory.
3283 bool onlyReadsMemory() const {
3284 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
3286 void setOnlyReadsMemory() {
3287 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
3290 /// \brief Determine if the call cannot return.
3291 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
3292 void setDoesNotReturn() {
3293 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
3296 /// \brief Determine if the call cannot unwind.
3297 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
3298 void setDoesNotThrow() {
3299 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
3302 /// \brief Determine if the invoke cannot be duplicated.
3303 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
3304 void setCannotDuplicate() {
3305 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
3308 /// \brief Determine if the call returns a structure through first
3309 /// pointer argument.
3310 bool hasStructRetAttr() const {
3311 // Be friendly and also check the callee.
3312 return paramHasAttr(1, Attribute::StructRet);
3315 /// \brief Determine if any call argument is an aggregate passed by value.
3316 bool hasByValArgument() const {
3317 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
3320 /// getCalledFunction - Return the function called, or null if this is an
3321 /// indirect function invocation.
3323 Function *getCalledFunction() const {
3324 return dyn_cast<Function>(Op<-3>());
3327 /// getCalledValue - Get a pointer to the function that is invoked by this
3329 const Value *getCalledValue() const { return Op<-3>(); }
3330 Value *getCalledValue() { return Op<-3>(); }
3332 /// setCalledFunction - Set the function called.
3333 void setCalledFunction(Value* Fn) {
3335 cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()),
3338 void setCalledFunction(FunctionType *FTy, Value *Fn) {
3340 assert(FTy == cast<FunctionType>(
3341 cast<PointerType>(Fn->getType())->getElementType()));
3345 // get*Dest - Return the destination basic blocks...
3346 BasicBlock *getNormalDest() const {
3347 return cast<BasicBlock>(Op<-2>());
3349 BasicBlock *getUnwindDest() const {
3350 return cast<BasicBlock>(Op<-1>());
3352 void setNormalDest(BasicBlock *B) {
3353 Op<-2>() = reinterpret_cast<Value*>(B);
3355 void setUnwindDest(BasicBlock *B) {
3356 Op<-1>() = reinterpret_cast<Value*>(B);
3359 /// getLandingPadInst - Get the landingpad instruction from the landing pad
3360 /// block (the unwind destination).
3361 LandingPadInst *getLandingPadInst() const;
3363 BasicBlock *getSuccessor(unsigned i) const {
3364 assert(i < 2 && "Successor # out of range for invoke!");
3365 return i == 0 ? getNormalDest() : getUnwindDest();
3368 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3369 assert(idx < 2 && "Successor # out of range for invoke!");
3370 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
3373 unsigned getNumSuccessors() const { return 2; }
3375 // Methods for support type inquiry through isa, cast, and dyn_cast:
3376 static inline bool classof(const Instruction *I) {
3377 return (I->getOpcode() == Instruction::Invoke);
3379 static inline bool classof(const Value *V) {
3380 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3384 BasicBlock *getSuccessorV(unsigned idx) const override;
3385 unsigned getNumSuccessorsV() const override;
3386 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3388 bool hasFnAttrImpl(Attribute::AttrKind A) const;
3390 // Shadow Instruction::setInstructionSubclassData with a private forwarding
3391 // method so that subclasses cannot accidentally use it.
3392 void setInstructionSubclassData(unsigned short D) {
3393 Instruction::setInstructionSubclassData(D);
3398 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
3401 InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3402 BasicBlock *IfException, ArrayRef<Value *> Args,
3403 unsigned Values, const Twine &NameStr,
3404 Instruction *InsertBefore)
3405 : TerminatorInst(Ty->getReturnType(), Instruction::Invoke,
3406 OperandTraits<InvokeInst>::op_end(this) - Values, Values,
3408 init(Ty, Func, IfNormal, IfException, Args, NameStr);
3410 InvokeInst::InvokeInst(Value *Func,
3411 BasicBlock *IfNormal, BasicBlock *IfException,
3412 ArrayRef<Value *> Args, unsigned Values,
3413 const Twine &NameStr, BasicBlock *InsertAtEnd)
3414 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3415 ->getElementType())->getReturnType(),
3416 Instruction::Invoke,
3417 OperandTraits<InvokeInst>::op_end(this) - Values,
3418 Values, InsertAtEnd) {
3419 init(Func, IfNormal, IfException, Args, NameStr);
3422 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
3424 //===----------------------------------------------------------------------===//
3426 //===----------------------------------------------------------------------===//
3428 //===---------------------------------------------------------------------------
3429 /// ResumeInst - Resume the propagation of an exception.
3431 class ResumeInst : public TerminatorInst {
3432 ResumeInst(const ResumeInst &RI);
3434 explicit ResumeInst(Value *Exn, Instruction *InsertBefore=nullptr);
3435 ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
3437 ResumeInst *clone_impl() const override;
3439 static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = nullptr) {
3440 return new(1) ResumeInst(Exn, InsertBefore);
3442 static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
3443 return new(1) ResumeInst(Exn, InsertAtEnd);
3446 /// Provide fast operand accessors
3447 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3449 /// Convenience accessor.
3450 Value *getValue() const { return Op<0>(); }
3452 unsigned getNumSuccessors() const { return 0; }
3454 // Methods for support type inquiry through isa, cast, and dyn_cast:
3455 static inline bool classof(const Instruction *I) {
3456 return I->getOpcode() == Instruction::Resume;
3458 static inline bool classof(const Value *V) {
3459 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3462 BasicBlock *getSuccessorV(unsigned idx) const override;
3463 unsigned getNumSuccessorsV() const override;
3464 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3468 struct OperandTraits<ResumeInst> :
3469 public FixedNumOperandTraits<ResumeInst, 1> {
3472 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
3474 //===----------------------------------------------------------------------===//
3475 // UnreachableInst Class
3476 //===----------------------------------------------------------------------===//
3478 //===---------------------------------------------------------------------------
3479 /// UnreachableInst - This function has undefined behavior. In particular, the
3480 /// presence of this instruction indicates some higher level knowledge that the
3481 /// end of the block cannot be reached.
3483 class UnreachableInst : public TerminatorInst {
3484 void *operator new(size_t, unsigned) = delete;
3486 UnreachableInst *clone_impl() const override;
3489 // allocate space for exactly zero operands
3490 void *operator new(size_t s) {
3491 return User::operator new(s, 0);
3493 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = nullptr);
3494 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
3496 unsigned getNumSuccessors() const { return 0; }
3498 // Methods for support type inquiry through isa, cast, and dyn_cast:
3499 static inline bool classof(const Instruction *I) {
3500 return I->getOpcode() == Instruction::Unreachable;
3502 static inline bool classof(const Value *V) {
3503 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3506 BasicBlock *getSuccessorV(unsigned idx) const override;
3507 unsigned getNumSuccessorsV() const override;
3508 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3511 //===----------------------------------------------------------------------===//
3513 //===----------------------------------------------------------------------===//
3515 /// \brief This class represents a truncation of integer types.
3516 class TruncInst : public CastInst {
3518 /// \brief Clone an identical TruncInst
3519 TruncInst *clone_impl() const override;
3522 /// \brief Constructor with insert-before-instruction semantics
3524 Value *S, ///< The value to be truncated
3525 Type *Ty, ///< The (smaller) type to truncate to
3526 const Twine &NameStr = "", ///< A name for the new instruction
3527 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3530 /// \brief Constructor with insert-at-end-of-block semantics
3532 Value *S, ///< The value to be truncated
3533 Type *Ty, ///< The (smaller) type to truncate to
3534 const Twine &NameStr, ///< A name for the new instruction
3535 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3538 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3539 static inline bool classof(const Instruction *I) {
3540 return I->getOpcode() == Trunc;
3542 static inline bool classof(const Value *V) {
3543 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3547 //===----------------------------------------------------------------------===//
3549 //===----------------------------------------------------------------------===//
3551 /// \brief This class represents zero extension of integer types.
3552 class ZExtInst : public CastInst {
3554 /// \brief Clone an identical ZExtInst
3555 ZExtInst *clone_impl() const override;
3558 /// \brief Constructor with insert-before-instruction semantics
3560 Value *S, ///< The value to be zero extended
3561 Type *Ty, ///< The type to zero extend to
3562 const Twine &NameStr = "", ///< A name for the new instruction
3563 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3566 /// \brief Constructor with insert-at-end semantics.
3568 Value *S, ///< The value to be zero extended
3569 Type *Ty, ///< The type to zero extend to
3570 const Twine &NameStr, ///< A name for the new instruction
3571 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3574 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3575 static inline bool classof(const Instruction *I) {
3576 return I->getOpcode() == ZExt;
3578 static inline bool classof(const Value *V) {
3579 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3583 //===----------------------------------------------------------------------===//
3585 //===----------------------------------------------------------------------===//
3587 /// \brief This class represents a sign extension of integer types.
3588 class SExtInst : public CastInst {
3590 /// \brief Clone an identical SExtInst
3591 SExtInst *clone_impl() const override;
3594 /// \brief Constructor with insert-before-instruction semantics
3596 Value *S, ///< The value to be sign extended
3597 Type *Ty, ///< The type to sign extend to
3598 const Twine &NameStr = "", ///< A name for the new instruction
3599 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3602 /// \brief Constructor with insert-at-end-of-block semantics
3604 Value *S, ///< The value to be sign extended
3605 Type *Ty, ///< The type to sign extend to
3606 const Twine &NameStr, ///< A name for the new instruction
3607 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3610 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3611 static inline bool classof(const Instruction *I) {
3612 return I->getOpcode() == SExt;
3614 static inline bool classof(const Value *V) {
3615 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3619 //===----------------------------------------------------------------------===//
3620 // FPTruncInst Class
3621 //===----------------------------------------------------------------------===//
3623 /// \brief This class represents a truncation of floating point types.
3624 class FPTruncInst : public CastInst {
3626 /// \brief Clone an identical FPTruncInst
3627 FPTruncInst *clone_impl() const override;
3630 /// \brief Constructor with insert-before-instruction semantics
3632 Value *S, ///< The value to be truncated
3633 Type *Ty, ///< The type to truncate to
3634 const Twine &NameStr = "", ///< A name for the new instruction
3635 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3638 /// \brief Constructor with insert-before-instruction semantics
3640 Value *S, ///< The value to be truncated
3641 Type *Ty, ///< The type to truncate to
3642 const Twine &NameStr, ///< A name for the new instruction
3643 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3646 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3647 static inline bool classof(const Instruction *I) {
3648 return I->getOpcode() == FPTrunc;
3650 static inline bool classof(const Value *V) {
3651 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3655 //===----------------------------------------------------------------------===//
3657 //===----------------------------------------------------------------------===//
3659 /// \brief This class represents an extension of floating point types.
3660 class FPExtInst : public CastInst {
3662 /// \brief Clone an identical FPExtInst
3663 FPExtInst *clone_impl() const override;
3666 /// \brief Constructor with insert-before-instruction semantics
3668 Value *S, ///< The value to be extended
3669 Type *Ty, ///< The type to extend to
3670 const Twine &NameStr = "", ///< A name for the new instruction
3671 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3674 /// \brief Constructor with insert-at-end-of-block semantics
3676 Value *S, ///< The value to be extended
3677 Type *Ty, ///< The type to extend to
3678 const Twine &NameStr, ///< A name for the new instruction
3679 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3682 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3683 static inline bool classof(const Instruction *I) {
3684 return I->getOpcode() == FPExt;
3686 static inline bool classof(const Value *V) {
3687 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3691 //===----------------------------------------------------------------------===//
3693 //===----------------------------------------------------------------------===//
3695 /// \brief This class represents a cast unsigned integer to floating point.
3696 class UIToFPInst : public CastInst {
3698 /// \brief Clone an identical UIToFPInst
3699 UIToFPInst *clone_impl() const override;
3702 /// \brief Constructor with insert-before-instruction semantics
3704 Value *S, ///< The value to be converted
3705 Type *Ty, ///< The type to convert to
3706 const Twine &NameStr = "", ///< A name for the new instruction
3707 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3710 /// \brief Constructor with insert-at-end-of-block semantics
3712 Value *S, ///< The value to be converted
3713 Type *Ty, ///< The type to convert to
3714 const Twine &NameStr, ///< A name for the new instruction
3715 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3718 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3719 static inline bool classof(const Instruction *I) {
3720 return I->getOpcode() == UIToFP;
3722 static inline bool classof(const Value *V) {
3723 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3727 //===----------------------------------------------------------------------===//
3729 //===----------------------------------------------------------------------===//
3731 /// \brief This class represents a cast from signed integer to floating point.
3732 class SIToFPInst : public CastInst {
3734 /// \brief Clone an identical SIToFPInst
3735 SIToFPInst *clone_impl() const override;
3738 /// \brief Constructor with insert-before-instruction semantics
3740 Value *S, ///< The value to be converted
3741 Type *Ty, ///< The type to convert to
3742 const Twine &NameStr = "", ///< A name for the new instruction
3743 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3746 /// \brief Constructor with insert-at-end-of-block semantics
3748 Value *S, ///< The value to be converted
3749 Type *Ty, ///< The type to convert to
3750 const Twine &NameStr, ///< A name for the new instruction
3751 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3754 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3755 static inline bool classof(const Instruction *I) {
3756 return I->getOpcode() == SIToFP;
3758 static inline bool classof(const Value *V) {
3759 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3763 //===----------------------------------------------------------------------===//
3765 //===----------------------------------------------------------------------===//
3767 /// \brief This class represents a cast from floating point to unsigned integer
3768 class FPToUIInst : public CastInst {
3770 /// \brief Clone an identical FPToUIInst
3771 FPToUIInst *clone_impl() const override;
3774 /// \brief Constructor with insert-before-instruction semantics
3776 Value *S, ///< The value to be converted
3777 Type *Ty, ///< The type to convert to
3778 const Twine &NameStr = "", ///< A name for the new instruction
3779 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3782 /// \brief Constructor with insert-at-end-of-block semantics
3784 Value *S, ///< The value to be converted
3785 Type *Ty, ///< The type to convert to
3786 const Twine &NameStr, ///< A name for the new instruction
3787 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3790 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3791 static inline bool classof(const Instruction *I) {
3792 return I->getOpcode() == FPToUI;
3794 static inline bool classof(const Value *V) {
3795 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3799 //===----------------------------------------------------------------------===//
3801 //===----------------------------------------------------------------------===//
3803 /// \brief This class represents a cast from floating point to signed integer.
3804 class FPToSIInst : public CastInst {
3806 /// \brief Clone an identical FPToSIInst
3807 FPToSIInst *clone_impl() const override;
3810 /// \brief Constructor with insert-before-instruction semantics
3812 Value *S, ///< The value to be converted
3813 Type *Ty, ///< The type to convert to
3814 const Twine &NameStr = "", ///< A name for the new instruction
3815 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3818 /// \brief Constructor with insert-at-end-of-block semantics
3820 Value *S, ///< The value to be converted
3821 Type *Ty, ///< The type to convert to
3822 const Twine &NameStr, ///< A name for the new instruction
3823 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3826 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3827 static inline bool classof(const Instruction *I) {
3828 return I->getOpcode() == FPToSI;
3830 static inline bool classof(const Value *V) {
3831 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3835 //===----------------------------------------------------------------------===//
3836 // IntToPtrInst Class
3837 //===----------------------------------------------------------------------===//
3839 /// \brief This class represents a cast from an integer to a pointer.
3840 class IntToPtrInst : public CastInst {
3842 /// \brief Constructor with insert-before-instruction semantics
3844 Value *S, ///< The value to be converted
3845 Type *Ty, ///< The type to convert to
3846 const Twine &NameStr = "", ///< A name for the new instruction
3847 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3850 /// \brief Constructor with insert-at-end-of-block semantics
3852 Value *S, ///< The value to be converted
3853 Type *Ty, ///< The type to convert to
3854 const Twine &NameStr, ///< A name for the new instruction
3855 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3858 /// \brief Clone an identical IntToPtrInst
3859 IntToPtrInst *clone_impl() const override;
3861 /// \brief Returns the address space of this instruction's pointer type.
3862 unsigned getAddressSpace() const {
3863 return getType()->getPointerAddressSpace();
3866 // Methods for support type inquiry through isa, cast, and dyn_cast:
3867 static inline bool classof(const Instruction *I) {
3868 return I->getOpcode() == IntToPtr;
3870 static inline bool classof(const Value *V) {
3871 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3875 //===----------------------------------------------------------------------===//
3876 // PtrToIntInst Class
3877 //===----------------------------------------------------------------------===//
3879 /// \brief This class represents a cast from a pointer to an integer
3880 class PtrToIntInst : public CastInst {
3882 /// \brief Clone an identical PtrToIntInst
3883 PtrToIntInst *clone_impl() const override;
3886 /// \brief Constructor with insert-before-instruction semantics
3888 Value *S, ///< The value to be converted
3889 Type *Ty, ///< The type to convert to
3890 const Twine &NameStr = "", ///< A name for the new instruction
3891 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3894 /// \brief Constructor with insert-at-end-of-block semantics
3896 Value *S, ///< The value to be converted
3897 Type *Ty, ///< The type to convert to
3898 const Twine &NameStr, ///< A name for the new instruction
3899 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3902 /// \brief Gets the pointer operand.
3903 Value *getPointerOperand() { return getOperand(0); }
3904 /// \brief Gets the pointer operand.
3905 const Value *getPointerOperand() const { return getOperand(0); }
3906 /// \brief Gets the operand index of the pointer operand.
3907 static unsigned getPointerOperandIndex() { return 0U; }
3909 /// \brief Returns the address space of the pointer operand.
3910 unsigned getPointerAddressSpace() const {
3911 return getPointerOperand()->getType()->getPointerAddressSpace();
3914 // Methods for support type inquiry through isa, cast, and dyn_cast:
3915 static inline bool classof(const Instruction *I) {
3916 return I->getOpcode() == PtrToInt;
3918 static inline bool classof(const Value *V) {
3919 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3923 //===----------------------------------------------------------------------===//
3924 // BitCastInst Class
3925 //===----------------------------------------------------------------------===//
3927 /// \brief This class represents a no-op cast from one type to another.
3928 class BitCastInst : public CastInst {
3930 /// \brief Clone an identical BitCastInst
3931 BitCastInst *clone_impl() const override;
3934 /// \brief Constructor with insert-before-instruction semantics
3936 Value *S, ///< The value to be casted
3937 Type *Ty, ///< The type to casted to
3938 const Twine &NameStr = "", ///< A name for the new instruction
3939 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3942 /// \brief Constructor with insert-at-end-of-block semantics
3944 Value *S, ///< The value to be casted
3945 Type *Ty, ///< The type to casted to
3946 const Twine &NameStr, ///< A name for the new instruction
3947 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3950 // Methods for support type inquiry through isa, cast, and dyn_cast:
3951 static inline bool classof(const Instruction *I) {
3952 return I->getOpcode() == BitCast;
3954 static inline bool classof(const Value *V) {
3955 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3959 //===----------------------------------------------------------------------===//
3960 // AddrSpaceCastInst Class
3961 //===----------------------------------------------------------------------===//
3963 /// \brief This class represents a conversion between pointers from
3964 /// one address space to another.
3965 class AddrSpaceCastInst : public CastInst {
3967 /// \brief Clone an identical AddrSpaceCastInst
3968 AddrSpaceCastInst *clone_impl() const override;
3971 /// \brief Constructor with insert-before-instruction semantics
3973 Value *S, ///< The value to be casted
3974 Type *Ty, ///< The type to casted to
3975 const Twine &NameStr = "", ///< A name for the new instruction
3976 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3979 /// \brief Constructor with insert-at-end-of-block semantics
3981 Value *S, ///< The value to be casted
3982 Type *Ty, ///< The type to casted to
3983 const Twine &NameStr, ///< A name for the new instruction
3984 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3987 // Methods for support type inquiry through isa, cast, and dyn_cast:
3988 static inline bool classof(const Instruction *I) {
3989 return I->getOpcode() == AddrSpaceCast;
3991 static inline bool classof(const Value *V) {
3992 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3996 } // End llvm namespace