1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the class definitions of all of the subclasses of the
11 // Instruction class. This is meant to be an easy way to get access to all
12 // instruction subclasses.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_IR_INSTRUCTIONS_H
17 #define LLVM_IR_INSTRUCTIONS_H
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/iterator_range.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/IR/Attributes.h"
23 #include "llvm/IR/CallingConv.h"
24 #include "llvm/IR/DerivedTypes.h"
25 #include "llvm/IR/InstrTypes.h"
26 #include "llvm/Support/ErrorHandling.h"
41 // Consume = 3, // Not specified yet.
45 SequentiallyConsistent = 7
48 enum SynchronizationScope {
53 //===----------------------------------------------------------------------===//
55 //===----------------------------------------------------------------------===//
57 /// AllocaInst - an instruction to allocate memory on the stack
59 class AllocaInst : public UnaryInstruction {
61 AllocaInst *clone_impl() const override;
63 explicit AllocaInst(Type *Ty, Value *ArraySize = nullptr,
64 const Twine &Name = "",
65 Instruction *InsertBefore = nullptr);
66 AllocaInst(Type *Ty, Value *ArraySize,
67 const Twine &Name, BasicBlock *InsertAtEnd);
69 AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = nullptr);
70 AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
72 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
73 const Twine &Name = "", Instruction *InsertBefore = nullptr);
74 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
75 const Twine &Name, BasicBlock *InsertAtEnd);
77 // Out of line virtual method, so the vtable, etc. has a home.
78 virtual ~AllocaInst();
80 /// isArrayAllocation - Return true if there is an allocation size parameter
81 /// to the allocation instruction that is not 1.
83 bool isArrayAllocation() const;
85 /// getArraySize - Get the number of elements allocated. For a simple
86 /// allocation of a single element, this will return a constant 1 value.
88 const Value *getArraySize() const { return getOperand(0); }
89 Value *getArraySize() { return getOperand(0); }
91 /// getType - Overload to return most specific pointer type
93 PointerType *getType() const {
94 return cast<PointerType>(Instruction::getType());
97 /// getAllocatedType - Return the type that is being allocated by the
100 Type *getAllocatedType() const;
102 /// getAlignment - Return the alignment of the memory that is being allocated
103 /// by the instruction.
105 unsigned getAlignment() const {
106 return (1u << (getSubclassDataFromInstruction() & 31)) >> 1;
108 void setAlignment(unsigned Align);
110 /// isStaticAlloca - Return true if this alloca is in the entry block of the
111 /// function and is a constant size. If so, the code generator will fold it
112 /// into the prolog/epilog code, so it is basically free.
113 bool isStaticAlloca() const;
115 /// \brief Return true if this alloca is used as an inalloca argument to a
116 /// call. Such allocas are never considered static even if they are in the
118 bool isUsedWithInAlloca() const {
119 return getSubclassDataFromInstruction() & 32;
122 /// \brief Specify whether this alloca is used to represent a the arguments to
124 void setUsedWithInAlloca(bool V) {
125 setInstructionSubclassData((getSubclassDataFromInstruction() & ~32) |
129 // Methods for support type inquiry through isa, cast, and dyn_cast:
130 static inline bool classof(const Instruction *I) {
131 return (I->getOpcode() == Instruction::Alloca);
133 static inline bool classof(const Value *V) {
134 return isa<Instruction>(V) && classof(cast<Instruction>(V));
137 // Shadow Instruction::setInstructionSubclassData with a private forwarding
138 // method so that subclasses cannot accidentally use it.
139 void setInstructionSubclassData(unsigned short D) {
140 Instruction::setInstructionSubclassData(D);
145 //===----------------------------------------------------------------------===//
147 //===----------------------------------------------------------------------===//
149 /// LoadInst - an instruction for reading from memory. This uses the
150 /// SubclassData field in Value to store whether or not the load is volatile.
152 class LoadInst : public UnaryInstruction {
155 LoadInst *clone_impl() const override;
157 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
158 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
159 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
160 Instruction *InsertBefore = nullptr);
161 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
162 BasicBlock *InsertAtEnd);
163 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
164 unsigned Align, Instruction *InsertBefore = nullptr);
165 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
166 unsigned Align, BasicBlock *InsertAtEnd);
167 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
168 unsigned Align, AtomicOrdering Order,
169 SynchronizationScope SynchScope = CrossThread,
170 Instruction *InsertBefore = nullptr);
171 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
172 unsigned Align, AtomicOrdering Order,
173 SynchronizationScope SynchScope,
174 BasicBlock *InsertAtEnd);
176 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
177 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
178 explicit LoadInst(Value *Ptr, const char *NameStr = nullptr,
179 bool isVolatile = false,
180 Instruction *InsertBefore = nullptr);
181 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
182 BasicBlock *InsertAtEnd);
184 /// isVolatile - Return true if this is a load from a volatile memory
187 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
189 /// setVolatile - Specify whether this is a volatile load or not.
191 void setVolatile(bool V) {
192 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
196 /// getAlignment - Return the alignment of the access that is being performed
198 unsigned getAlignment() const {
199 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
202 void setAlignment(unsigned Align);
204 /// Returns the ordering effect of this fence.
205 AtomicOrdering getOrdering() const {
206 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
209 /// Set the ordering constraint on this load. May not be Release or
211 void setOrdering(AtomicOrdering Ordering) {
212 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
216 SynchronizationScope getSynchScope() const {
217 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
220 /// Specify whether this load is ordered with respect to all
221 /// concurrently executing threads, or only with respect to signal handlers
222 /// executing in the same thread.
223 void setSynchScope(SynchronizationScope xthread) {
224 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
228 bool isAtomic() const { return getOrdering() != NotAtomic; }
229 void setAtomic(AtomicOrdering Ordering,
230 SynchronizationScope SynchScope = CrossThread) {
231 setOrdering(Ordering);
232 setSynchScope(SynchScope);
235 bool isSimple() const { return !isAtomic() && !isVolatile(); }
236 bool isUnordered() const {
237 return getOrdering() <= Unordered && !isVolatile();
240 Value *getPointerOperand() { return getOperand(0); }
241 const Value *getPointerOperand() const { return getOperand(0); }
242 static unsigned getPointerOperandIndex() { return 0U; }
244 /// \brief Returns the address space of the pointer operand.
245 unsigned getPointerAddressSpace() const {
246 return getPointerOperand()->getType()->getPointerAddressSpace();
250 // Methods for support type inquiry through isa, cast, and dyn_cast:
251 static inline bool classof(const Instruction *I) {
252 return I->getOpcode() == Instruction::Load;
254 static inline bool classof(const Value *V) {
255 return isa<Instruction>(V) && classof(cast<Instruction>(V));
258 // Shadow Instruction::setInstructionSubclassData with a private forwarding
259 // method so that subclasses cannot accidentally use it.
260 void setInstructionSubclassData(unsigned short D) {
261 Instruction::setInstructionSubclassData(D);
266 //===----------------------------------------------------------------------===//
268 //===----------------------------------------------------------------------===//
270 /// StoreInst - an instruction for storing to memory
272 class StoreInst : public Instruction {
273 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
276 StoreInst *clone_impl() const override;
278 // allocate space for exactly two operands
279 void *operator new(size_t s) {
280 return User::operator new(s, 2);
282 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
283 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
284 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
285 Instruction *InsertBefore = nullptr);
286 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
287 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
288 unsigned Align, Instruction *InsertBefore = nullptr);
289 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
290 unsigned Align, BasicBlock *InsertAtEnd);
291 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
292 unsigned Align, AtomicOrdering Order,
293 SynchronizationScope SynchScope = CrossThread,
294 Instruction *InsertBefore = nullptr);
295 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
296 unsigned Align, AtomicOrdering Order,
297 SynchronizationScope SynchScope,
298 BasicBlock *InsertAtEnd);
301 /// isVolatile - Return true if this is a store to a volatile memory
304 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
306 /// setVolatile - Specify whether this is a volatile store or not.
308 void setVolatile(bool V) {
309 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
313 /// Transparently provide more efficient getOperand methods.
314 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
316 /// getAlignment - Return the alignment of the access that is being performed
318 unsigned getAlignment() const {
319 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
322 void setAlignment(unsigned Align);
324 /// Returns the ordering effect of this store.
325 AtomicOrdering getOrdering() const {
326 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
329 /// Set the ordering constraint on this store. May not be Acquire or
331 void setOrdering(AtomicOrdering Ordering) {
332 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
336 SynchronizationScope getSynchScope() const {
337 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
340 /// Specify whether this store instruction is ordered with respect to all
341 /// concurrently executing threads, or only with respect to signal handlers
342 /// executing in the same thread.
343 void setSynchScope(SynchronizationScope xthread) {
344 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
348 bool isAtomic() const { return getOrdering() != NotAtomic; }
349 void setAtomic(AtomicOrdering Ordering,
350 SynchronizationScope SynchScope = CrossThread) {
351 setOrdering(Ordering);
352 setSynchScope(SynchScope);
355 bool isSimple() const { return !isAtomic() && !isVolatile(); }
356 bool isUnordered() const {
357 return getOrdering() <= Unordered && !isVolatile();
360 Value *getValueOperand() { return getOperand(0); }
361 const Value *getValueOperand() const { return getOperand(0); }
363 Value *getPointerOperand() { return getOperand(1); }
364 const Value *getPointerOperand() const { return getOperand(1); }
365 static unsigned getPointerOperandIndex() { return 1U; }
367 /// \brief Returns the address space of the pointer operand.
368 unsigned getPointerAddressSpace() const {
369 return getPointerOperand()->getType()->getPointerAddressSpace();
372 // Methods for support type inquiry through isa, cast, and dyn_cast:
373 static inline bool classof(const Instruction *I) {
374 return I->getOpcode() == Instruction::Store;
376 static inline bool classof(const Value *V) {
377 return isa<Instruction>(V) && classof(cast<Instruction>(V));
380 // Shadow Instruction::setInstructionSubclassData with a private forwarding
381 // method so that subclasses cannot accidentally use it.
382 void setInstructionSubclassData(unsigned short D) {
383 Instruction::setInstructionSubclassData(D);
388 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
391 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
393 //===----------------------------------------------------------------------===//
395 //===----------------------------------------------------------------------===//
397 /// FenceInst - an instruction for ordering other memory operations
399 class FenceInst : public Instruction {
400 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
401 void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
403 FenceInst *clone_impl() const override;
405 // allocate space for exactly zero operands
406 void *operator new(size_t s) {
407 return User::operator new(s, 0);
410 // Ordering may only be Acquire, Release, AcquireRelease, or
411 // SequentiallyConsistent.
412 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
413 SynchronizationScope SynchScope = CrossThread,
414 Instruction *InsertBefore = nullptr);
415 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
416 SynchronizationScope SynchScope,
417 BasicBlock *InsertAtEnd);
419 /// Returns the ordering effect of this fence.
420 AtomicOrdering getOrdering() const {
421 return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
424 /// Set the ordering constraint on this fence. May only be Acquire, Release,
425 /// AcquireRelease, or SequentiallyConsistent.
426 void setOrdering(AtomicOrdering Ordering) {
427 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
431 SynchronizationScope getSynchScope() const {
432 return SynchronizationScope(getSubclassDataFromInstruction() & 1);
435 /// Specify whether this fence orders other operations with respect to all
436 /// concurrently executing threads, or only with respect to signal handlers
437 /// executing in the same thread.
438 void setSynchScope(SynchronizationScope xthread) {
439 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
443 // Methods for support type inquiry through isa, cast, and dyn_cast:
444 static inline bool classof(const Instruction *I) {
445 return I->getOpcode() == Instruction::Fence;
447 static inline bool classof(const Value *V) {
448 return isa<Instruction>(V) && classof(cast<Instruction>(V));
451 // Shadow Instruction::setInstructionSubclassData with a private forwarding
452 // method so that subclasses cannot accidentally use it.
453 void setInstructionSubclassData(unsigned short D) {
454 Instruction::setInstructionSubclassData(D);
458 //===----------------------------------------------------------------------===//
459 // AtomicCmpXchgInst Class
460 //===----------------------------------------------------------------------===//
462 /// AtomicCmpXchgInst - an instruction that atomically checks whether a
463 /// specified value is in a memory location, and, if it is, stores a new value
464 /// there. Returns the value that was loaded.
466 class AtomicCmpXchgInst : public Instruction {
467 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
468 void Init(Value *Ptr, Value *Cmp, Value *NewVal,
469 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
470 SynchronizationScope SynchScope);
472 AtomicCmpXchgInst *clone_impl() const override;
474 // allocate space for exactly three operands
475 void *operator new(size_t s) {
476 return User::operator new(s, 3);
478 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
479 AtomicOrdering SuccessOrdering,
480 AtomicOrdering FailureOrdering,
481 SynchronizationScope SynchScope,
482 Instruction *InsertBefore = nullptr);
483 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
484 AtomicOrdering SuccessOrdering,
485 AtomicOrdering FailureOrdering,
486 SynchronizationScope SynchScope,
487 BasicBlock *InsertAtEnd);
489 /// isVolatile - Return true if this is a cmpxchg from a volatile memory
492 bool isVolatile() const {
493 return getSubclassDataFromInstruction() & 1;
496 /// setVolatile - Specify whether this is a volatile cmpxchg.
498 void setVolatile(bool V) {
499 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
503 /// Transparently provide more efficient getOperand methods.
504 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
506 /// Set the ordering constraint on this cmpxchg.
507 void setSuccessOrdering(AtomicOrdering Ordering) {
508 assert(Ordering != NotAtomic &&
509 "CmpXchg instructions can only be atomic.");
510 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x1c) |
514 void setFailureOrdering(AtomicOrdering Ordering) {
515 assert(Ordering != NotAtomic &&
516 "CmpXchg instructions can only be atomic.");
517 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0xe0) |
521 /// Specify whether this cmpxchg is atomic and orders other operations with
522 /// respect to all concurrently executing threads, or only with respect to
523 /// signal handlers executing in the same thread.
524 void setSynchScope(SynchronizationScope SynchScope) {
525 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
529 /// Returns the ordering constraint on this cmpxchg.
530 AtomicOrdering getSuccessOrdering() const {
531 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
534 /// Returns the ordering constraint on this cmpxchg.
535 AtomicOrdering getFailureOrdering() const {
536 return AtomicOrdering((getSubclassDataFromInstruction() >> 5) & 7);
539 /// Returns whether this cmpxchg is atomic between threads or only within a
541 SynchronizationScope getSynchScope() const {
542 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
545 Value *getPointerOperand() { return getOperand(0); }
546 const Value *getPointerOperand() const { return getOperand(0); }
547 static unsigned getPointerOperandIndex() { return 0U; }
549 Value *getCompareOperand() { return getOperand(1); }
550 const Value *getCompareOperand() const { return getOperand(1); }
552 Value *getNewValOperand() { return getOperand(2); }
553 const Value *getNewValOperand() const { return getOperand(2); }
555 /// \brief Returns the address space of the pointer operand.
556 unsigned getPointerAddressSpace() const {
557 return getPointerOperand()->getType()->getPointerAddressSpace();
560 /// \brief Returns the strongest permitted ordering on failure, given the
561 /// desired ordering on success.
563 /// If the comparison in a cmpxchg operation fails, there is no atomic store
564 /// so release semantics cannot be provided. So this function drops explicit
565 /// Release requests from the AtomicOrdering. A SequentiallyConsistent
566 /// operation would remain SequentiallyConsistent.
567 static AtomicOrdering
568 getStrongestFailureOrdering(AtomicOrdering SuccessOrdering) {
569 switch (SuccessOrdering) {
570 default: llvm_unreachable("invalid cmpxchg success ordering");
577 case SequentiallyConsistent:
578 return SequentiallyConsistent;
582 // Methods for support type inquiry through isa, cast, and dyn_cast:
583 static inline bool classof(const Instruction *I) {
584 return I->getOpcode() == Instruction::AtomicCmpXchg;
586 static inline bool classof(const Value *V) {
587 return isa<Instruction>(V) && classof(cast<Instruction>(V));
590 // Shadow Instruction::setInstructionSubclassData with a private forwarding
591 // method so that subclasses cannot accidentally use it.
592 void setInstructionSubclassData(unsigned short D) {
593 Instruction::setInstructionSubclassData(D);
598 struct OperandTraits<AtomicCmpXchgInst> :
599 public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
602 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)
604 //===----------------------------------------------------------------------===//
605 // AtomicRMWInst Class
606 //===----------------------------------------------------------------------===//
608 /// AtomicRMWInst - an instruction that atomically reads a memory location,
609 /// combines it with another value, and then stores the result back. Returns
612 class AtomicRMWInst : public Instruction {
613 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
615 AtomicRMWInst *clone_impl() const override;
617 /// This enumeration lists the possible modifications atomicrmw can make. In
618 /// the descriptions, 'p' is the pointer to the instruction's memory location,
619 /// 'old' is the initial value of *p, and 'v' is the other value passed to the
620 /// instruction. These instructions always return 'old'.
636 /// *p = old >signed v ? old : v
638 /// *p = old <signed v ? old : v
640 /// *p = old >unsigned v ? old : v
642 /// *p = old <unsigned v ? old : v
650 // allocate space for exactly two operands
651 void *operator new(size_t s) {
652 return User::operator new(s, 2);
654 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
655 AtomicOrdering Ordering, SynchronizationScope SynchScope,
656 Instruction *InsertBefore = nullptr);
657 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
658 AtomicOrdering Ordering, SynchronizationScope SynchScope,
659 BasicBlock *InsertAtEnd);
661 BinOp getOperation() const {
662 return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
665 void setOperation(BinOp Operation) {
666 unsigned short SubclassData = getSubclassDataFromInstruction();
667 setInstructionSubclassData((SubclassData & 31) |
671 /// isVolatile - Return true if this is a RMW on a volatile memory location.
673 bool isVolatile() const {
674 return getSubclassDataFromInstruction() & 1;
677 /// setVolatile - Specify whether this is a volatile RMW or not.
679 void setVolatile(bool V) {
680 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
684 /// Transparently provide more efficient getOperand methods.
685 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
687 /// Set the ordering constraint on this RMW.
688 void setOrdering(AtomicOrdering Ordering) {
689 assert(Ordering != NotAtomic &&
690 "atomicrmw instructions can only be atomic.");
691 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
695 /// Specify whether this RMW orders other operations with respect to all
696 /// concurrently executing threads, or only with respect to signal handlers
697 /// executing in the same thread.
698 void setSynchScope(SynchronizationScope SynchScope) {
699 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
703 /// Returns the ordering constraint on this RMW.
704 AtomicOrdering getOrdering() const {
705 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
708 /// Returns whether this RMW is atomic between threads or only within a
710 SynchronizationScope getSynchScope() const {
711 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
714 Value *getPointerOperand() { return getOperand(0); }
715 const Value *getPointerOperand() const { return getOperand(0); }
716 static unsigned getPointerOperandIndex() { return 0U; }
718 Value *getValOperand() { return getOperand(1); }
719 const Value *getValOperand() const { return getOperand(1); }
721 /// \brief Returns the address space of the pointer operand.
722 unsigned getPointerAddressSpace() const {
723 return getPointerOperand()->getType()->getPointerAddressSpace();
726 // Methods for support type inquiry through isa, cast, and dyn_cast:
727 static inline bool classof(const Instruction *I) {
728 return I->getOpcode() == Instruction::AtomicRMW;
730 static inline bool classof(const Value *V) {
731 return isa<Instruction>(V) && classof(cast<Instruction>(V));
734 void Init(BinOp Operation, Value *Ptr, Value *Val,
735 AtomicOrdering Ordering, SynchronizationScope SynchScope);
736 // Shadow Instruction::setInstructionSubclassData with a private forwarding
737 // method so that subclasses cannot accidentally use it.
738 void setInstructionSubclassData(unsigned short D) {
739 Instruction::setInstructionSubclassData(D);
744 struct OperandTraits<AtomicRMWInst>
745 : public FixedNumOperandTraits<AtomicRMWInst,2> {
748 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)
750 //===----------------------------------------------------------------------===//
751 // GetElementPtrInst Class
752 //===----------------------------------------------------------------------===//
754 // checkGEPType - Simple wrapper function to give a better assertion failure
755 // message on bad indexes for a gep instruction.
757 inline Type *checkGEPType(Type *Ty) {
758 assert(Ty && "Invalid GetElementPtrInst indices for type!");
762 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
763 /// access elements of arrays and structs
765 class GetElementPtrInst : public Instruction {
766 GetElementPtrInst(const GetElementPtrInst &GEPI);
767 void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
769 /// Constructors - Create a getelementptr instruction with a base pointer an
770 /// list of indices. The first ctor can optionally insert before an existing
771 /// instruction, the second appends the new instruction to the specified
773 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
774 unsigned Values, const Twine &NameStr,
775 Instruction *InsertBefore);
776 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
777 unsigned Values, const Twine &NameStr,
778 BasicBlock *InsertAtEnd);
780 GetElementPtrInst *clone_impl() const override;
782 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
783 const Twine &NameStr = "",
784 Instruction *InsertBefore = nullptr) {
785 unsigned Values = 1 + unsigned(IdxList.size());
787 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
789 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
790 const Twine &NameStr,
791 BasicBlock *InsertAtEnd) {
792 unsigned Values = 1 + unsigned(IdxList.size());
794 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
797 /// Create an "inbounds" getelementptr. See the documentation for the
798 /// "inbounds" flag in LangRef.html for details.
799 static GetElementPtrInst *CreateInBounds(Value *Ptr,
800 ArrayRef<Value *> IdxList,
801 const Twine &NameStr = "",
802 Instruction *InsertBefore = nullptr){
803 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
804 GEP->setIsInBounds(true);
807 static GetElementPtrInst *CreateInBounds(Value *Ptr,
808 ArrayRef<Value *> IdxList,
809 const Twine &NameStr,
810 BasicBlock *InsertAtEnd) {
811 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
812 GEP->setIsInBounds(true);
816 /// Transparently provide more efficient getOperand methods.
817 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
819 // getType - Overload to return most specific sequential type.
820 SequentialType *getType() const {
821 return cast<SequentialType>(Instruction::getType());
824 /// \brief Returns the address space of this instruction's pointer type.
825 unsigned getAddressSpace() const {
826 // Note that this is always the same as the pointer operand's address space
827 // and that is cheaper to compute, so cheat here.
828 return getPointerAddressSpace();
831 /// getIndexedType - Returns the type of the element that would be loaded with
832 /// a load instruction with the specified parameters.
834 /// Null is returned if the indices are invalid for the specified
837 static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList);
838 static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList);
839 static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList);
841 inline op_iterator idx_begin() { return op_begin()+1; }
842 inline const_op_iterator idx_begin() const { return op_begin()+1; }
843 inline op_iterator idx_end() { return op_end(); }
844 inline const_op_iterator idx_end() const { return op_end(); }
846 Value *getPointerOperand() {
847 return getOperand(0);
849 const Value *getPointerOperand() const {
850 return getOperand(0);
852 static unsigned getPointerOperandIndex() {
853 return 0U; // get index for modifying correct operand.
856 /// getPointerOperandType - Method to return the pointer operand as a
858 Type *getPointerOperandType() const {
859 return getPointerOperand()->getType();
862 /// \brief Returns the address space of the pointer operand.
863 unsigned getPointerAddressSpace() const {
864 return getPointerOperandType()->getPointerAddressSpace();
867 /// GetGEPReturnType - Returns the pointer type returned by the GEP
868 /// instruction, which may be a vector of pointers.
869 static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
870 Type *PtrTy = PointerType::get(checkGEPType(
871 getIndexedType(Ptr->getType(), IdxList)),
872 Ptr->getType()->getPointerAddressSpace());
874 if (Ptr->getType()->isVectorTy()) {
875 unsigned NumElem = cast<VectorType>(Ptr->getType())->getNumElements();
876 return VectorType::get(PtrTy, NumElem);
883 unsigned getNumIndices() const { // Note: always non-negative
884 return getNumOperands() - 1;
887 bool hasIndices() const {
888 return getNumOperands() > 1;
891 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
892 /// zeros. If so, the result pointer and the first operand have the same
893 /// value, just potentially different types.
894 bool hasAllZeroIndices() const;
896 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
897 /// constant integers. If so, the result pointer and the first operand have
898 /// a constant offset between them.
899 bool hasAllConstantIndices() const;
901 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
902 /// See LangRef.html for the meaning of inbounds on a getelementptr.
903 void setIsInBounds(bool b = true);
905 /// isInBounds - Determine whether the GEP has the inbounds flag.
906 bool isInBounds() const;
908 /// \brief Accumulate the constant address offset of this GEP if possible.
910 /// This routine accepts an APInt into which it will accumulate the constant
911 /// offset of this GEP if the GEP is in fact constant. If the GEP is not
912 /// all-constant, it returns false and the value of the offset APInt is
913 /// undefined (it is *not* preserved!). The APInt passed into this routine
914 /// must be at least as wide as the IntPtr type for the address space of
915 /// the base GEP pointer.
916 bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
918 // Methods for support type inquiry through isa, cast, and dyn_cast:
919 static inline bool classof(const Instruction *I) {
920 return (I->getOpcode() == Instruction::GetElementPtr);
922 static inline bool classof(const Value *V) {
923 return isa<Instruction>(V) && classof(cast<Instruction>(V));
928 struct OperandTraits<GetElementPtrInst> :
929 public VariadicOperandTraits<GetElementPtrInst, 1> {
932 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
933 ArrayRef<Value *> IdxList,
935 const Twine &NameStr,
936 Instruction *InsertBefore)
937 : Instruction(getGEPReturnType(Ptr, IdxList),
939 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
940 Values, InsertBefore) {
941 init(Ptr, IdxList, NameStr);
943 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
944 ArrayRef<Value *> IdxList,
946 const Twine &NameStr,
947 BasicBlock *InsertAtEnd)
948 : Instruction(getGEPReturnType(Ptr, IdxList),
950 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
951 Values, InsertAtEnd) {
952 init(Ptr, IdxList, NameStr);
956 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
959 //===----------------------------------------------------------------------===//
961 //===----------------------------------------------------------------------===//
963 /// This instruction compares its operands according to the predicate given
964 /// to the constructor. It only operates on integers or pointers. The operands
965 /// must be identical types.
966 /// \brief Represent an integer comparison operator.
967 class ICmpInst: public CmpInst {
969 assert(getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE &&
970 getPredicate() <= CmpInst::LAST_ICMP_PREDICATE &&
971 "Invalid ICmp predicate value");
972 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
973 "Both operands to ICmp instruction are not of the same type!");
974 // Check that the operands are the right type
975 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
976 getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
977 "Invalid operand types for ICmp instruction");
981 /// \brief Clone an identical ICmpInst
982 ICmpInst *clone_impl() const override;
984 /// \brief Constructor with insert-before-instruction semantics.
986 Instruction *InsertBefore, ///< Where to insert
987 Predicate pred, ///< The predicate to use for the comparison
988 Value *LHS, ///< The left-hand-side of the expression
989 Value *RHS, ///< The right-hand-side of the expression
990 const Twine &NameStr = "" ///< Name of the instruction
991 ) : CmpInst(makeCmpResultType(LHS->getType()),
992 Instruction::ICmp, pred, LHS, RHS, NameStr,
999 /// \brief Constructor with insert-at-end semantics.
1001 BasicBlock &InsertAtEnd, ///< Block to insert into.
1002 Predicate pred, ///< The predicate to use for the comparison
1003 Value *LHS, ///< The left-hand-side of the expression
1004 Value *RHS, ///< The right-hand-side of the expression
1005 const Twine &NameStr = "" ///< Name of the instruction
1006 ) : CmpInst(makeCmpResultType(LHS->getType()),
1007 Instruction::ICmp, pred, LHS, RHS, NameStr,
1014 /// \brief Constructor with no-insertion semantics
1016 Predicate pred, ///< The predicate to use for the comparison
1017 Value *LHS, ///< The left-hand-side of the expression
1018 Value *RHS, ///< The right-hand-side of the expression
1019 const Twine &NameStr = "" ///< Name of the instruction
1020 ) : CmpInst(makeCmpResultType(LHS->getType()),
1021 Instruction::ICmp, pred, LHS, RHS, NameStr) {
1027 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
1028 /// @returns the predicate that would be the result if the operand were
1029 /// regarded as signed.
1030 /// \brief Return the signed version of the predicate
1031 Predicate getSignedPredicate() const {
1032 return getSignedPredicate(getPredicate());
1035 /// This is a static version that you can use without an instruction.
1036 /// \brief Return the signed version of the predicate.
1037 static Predicate getSignedPredicate(Predicate pred);
1039 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
1040 /// @returns the predicate that would be the result if the operand were
1041 /// regarded as unsigned.
1042 /// \brief Return the unsigned version of the predicate
1043 Predicate getUnsignedPredicate() const {
1044 return getUnsignedPredicate(getPredicate());
1047 /// This is a static version that you can use without an instruction.
1048 /// \brief Return the unsigned version of the predicate.
1049 static Predicate getUnsignedPredicate(Predicate pred);
1051 /// isEquality - Return true if this predicate is either EQ or NE. This also
1052 /// tests for commutativity.
1053 static bool isEquality(Predicate P) {
1054 return P == ICMP_EQ || P == ICMP_NE;
1057 /// isEquality - Return true if this predicate is either EQ or NE. This also
1058 /// tests for commutativity.
1059 bool isEquality() const {
1060 return isEquality(getPredicate());
1063 /// @returns true if the predicate of this ICmpInst is commutative
1064 /// \brief Determine if this relation is commutative.
1065 bool isCommutative() const { return isEquality(); }
1067 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1069 bool isRelational() const {
1070 return !isEquality();
1073 /// isRelational - Return true if the predicate is relational (not EQ or NE).
1075 static bool isRelational(Predicate P) {
1076 return !isEquality(P);
1079 /// Initialize a set of values that all satisfy the predicate with C.
1080 /// \brief Make a ConstantRange for a relation with a constant value.
1081 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
1083 /// Exchange the two operands to this instruction in such a way that it does
1084 /// not modify the semantics of the instruction. The predicate value may be
1085 /// changed to retain the same result if the predicate is order dependent
1087 /// \brief Swap operands and adjust predicate.
1088 void swapOperands() {
1089 setPredicate(getSwappedPredicate());
1090 Op<0>().swap(Op<1>());
1093 // Methods for support type inquiry through isa, cast, and dyn_cast:
1094 static inline bool classof(const Instruction *I) {
1095 return I->getOpcode() == Instruction::ICmp;
1097 static inline bool classof(const Value *V) {
1098 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1103 //===----------------------------------------------------------------------===//
1105 //===----------------------------------------------------------------------===//
1107 /// This instruction compares its operands according to the predicate given
1108 /// to the constructor. It only operates on floating point values or packed
1109 /// vectors of floating point values. The operands must be identical types.
1110 /// \brief Represents a floating point comparison operator.
1111 class FCmpInst: public CmpInst {
1113 /// \brief Clone an identical FCmpInst
1114 FCmpInst *clone_impl() const override;
1116 /// \brief Constructor with insert-before-instruction semantics.
1118 Instruction *InsertBefore, ///< Where to insert
1119 Predicate pred, ///< The predicate to use for the comparison
1120 Value *LHS, ///< The left-hand-side of the expression
1121 Value *RHS, ///< The right-hand-side of the expression
1122 const Twine &NameStr = "" ///< Name of the instruction
1123 ) : CmpInst(makeCmpResultType(LHS->getType()),
1124 Instruction::FCmp, pred, LHS, RHS, NameStr,
1126 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1127 "Invalid FCmp predicate value");
1128 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1129 "Both operands to FCmp instruction are not of the same type!");
1130 // Check that the operands are the right type
1131 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1132 "Invalid operand types for FCmp instruction");
1135 /// \brief Constructor with insert-at-end semantics.
1137 BasicBlock &InsertAtEnd, ///< Block to insert into.
1138 Predicate pred, ///< The predicate to use for the comparison
1139 Value *LHS, ///< The left-hand-side of the expression
1140 Value *RHS, ///< The right-hand-side of the expression
1141 const Twine &NameStr = "" ///< Name of the instruction
1142 ) : CmpInst(makeCmpResultType(LHS->getType()),
1143 Instruction::FCmp, pred, LHS, RHS, NameStr,
1145 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1146 "Invalid FCmp predicate value");
1147 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1148 "Both operands to FCmp instruction are not of the same type!");
1149 // Check that the operands are the right type
1150 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1151 "Invalid operand types for FCmp instruction");
1154 /// \brief Constructor with no-insertion semantics
1156 Predicate pred, ///< The predicate to use for the comparison
1157 Value *LHS, ///< The left-hand-side of the expression
1158 Value *RHS, ///< The right-hand-side of the expression
1159 const Twine &NameStr = "" ///< Name of the instruction
1160 ) : CmpInst(makeCmpResultType(LHS->getType()),
1161 Instruction::FCmp, pred, LHS, RHS, NameStr) {
1162 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1163 "Invalid FCmp predicate value");
1164 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1165 "Both operands to FCmp instruction are not of the same type!");
1166 // Check that the operands are the right type
1167 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1168 "Invalid operand types for FCmp instruction");
1171 /// @returns true if the predicate of this instruction is EQ or NE.
1172 /// \brief Determine if this is an equality predicate.
1173 bool isEquality() const {
1174 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
1175 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
1178 /// @returns true if the predicate of this instruction is commutative.
1179 /// \brief Determine if this is a commutative predicate.
1180 bool isCommutative() const {
1181 return isEquality() ||
1182 getPredicate() == FCMP_FALSE ||
1183 getPredicate() == FCMP_TRUE ||
1184 getPredicate() == FCMP_ORD ||
1185 getPredicate() == FCMP_UNO;
1188 /// @returns true if the predicate is relational (not EQ or NE).
1189 /// \brief Determine if this a relational predicate.
1190 bool isRelational() const { return !isEquality(); }
1192 /// Exchange the two operands to this instruction in such a way that it does
1193 /// not modify the semantics of the instruction. The predicate value may be
1194 /// changed to retain the same result if the predicate is order dependent
1196 /// \brief Swap operands and adjust predicate.
1197 void swapOperands() {
1198 setPredicate(getSwappedPredicate());
1199 Op<0>().swap(Op<1>());
1202 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
1203 static inline bool classof(const Instruction *I) {
1204 return I->getOpcode() == Instruction::FCmp;
1206 static inline bool classof(const Value *V) {
1207 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1211 //===----------------------------------------------------------------------===//
1212 /// CallInst - This class represents a function call, abstracting a target
1213 /// machine's calling convention. This class uses low bit of the SubClassData
1214 /// field to indicate whether or not this is a tail call. The rest of the bits
1215 /// hold the calling convention of the call.
1217 class CallInst : public Instruction {
1218 AttributeSet AttributeList; ///< parameter attributes for call
1219 CallInst(const CallInst &CI);
1220 void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
1221 void init(Value *Func, const Twine &NameStr);
1223 /// Construct a CallInst given a range of arguments.
1224 /// \brief Construct a CallInst from a range of arguments
1225 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1226 const Twine &NameStr, Instruction *InsertBefore);
1228 /// Construct a CallInst given a range of arguments.
1229 /// \brief Construct a CallInst from a range of arguments
1230 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1231 const Twine &NameStr, BasicBlock *InsertAtEnd);
1233 explicit CallInst(Value *F, const Twine &NameStr,
1234 Instruction *InsertBefore);
1235 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1237 CallInst *clone_impl() const override;
1239 static CallInst *Create(Value *Func,
1240 ArrayRef<Value *> Args,
1241 const Twine &NameStr = "",
1242 Instruction *InsertBefore = nullptr) {
1243 return new(unsigned(Args.size() + 1))
1244 CallInst(Func, Args, NameStr, InsertBefore);
1246 static CallInst *Create(Value *Func,
1247 ArrayRef<Value *> Args,
1248 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1249 return new(unsigned(Args.size() + 1))
1250 CallInst(Func, Args, NameStr, InsertAtEnd);
1252 static CallInst *Create(Value *F, const Twine &NameStr = "",
1253 Instruction *InsertBefore = nullptr) {
1254 return new(1) CallInst(F, NameStr, InsertBefore);
1256 static CallInst *Create(Value *F, const Twine &NameStr,
1257 BasicBlock *InsertAtEnd) {
1258 return new(1) CallInst(F, NameStr, InsertAtEnd);
1260 /// CreateMalloc - Generate the IR for a call to malloc:
1261 /// 1. Compute the malloc call's argument as the specified type's size,
1262 /// possibly multiplied by the array size if the array size is not
1264 /// 2. Call malloc with that argument.
1265 /// 3. Bitcast the result of the malloc call to the specified type.
1266 static Instruction *CreateMalloc(Instruction *InsertBefore,
1267 Type *IntPtrTy, Type *AllocTy,
1268 Value *AllocSize, Value *ArraySize = nullptr,
1269 Function* MallocF = nullptr,
1270 const Twine &Name = "");
1271 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1272 Type *IntPtrTy, Type *AllocTy,
1273 Value *AllocSize, Value *ArraySize = nullptr,
1274 Function* MallocF = nullptr,
1275 const Twine &Name = "");
1276 /// CreateFree - Generate the IR for a call to the builtin free function.
1277 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
1278 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
1282 bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
1283 void setTailCall(bool isTC = true) {
1284 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
1288 /// Provide fast operand accessors
1289 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1291 /// getNumArgOperands - Return the number of call arguments.
1293 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
1295 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1297 Value *getArgOperand(unsigned i) const { return getOperand(i); }
1298 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
1300 /// arg_operands - iteration adapter for range-for loops.
1301 iterator_range<op_iterator> arg_operands() {
1302 // The last operand in the op list is the callee - it's not one of the args
1303 // so we don't want to iterate over it.
1304 return iterator_range<op_iterator>(op_begin(), op_end() - 1);
1307 /// arg_operands - iteration adapter for range-for loops.
1308 iterator_range<const_op_iterator> arg_operands() const {
1309 return iterator_range<const_op_iterator>(op_begin(), op_end() - 1);
1312 /// \brief Wrappers for getting the \c Use of a call argument.
1313 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
1314 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
1316 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1318 CallingConv::ID getCallingConv() const {
1319 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
1321 void setCallingConv(CallingConv::ID CC) {
1322 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
1323 (static_cast<unsigned>(CC) << 1));
1326 /// getAttributes - Return the parameter attributes for this call.
1328 const AttributeSet &getAttributes() const { return AttributeList; }
1330 /// setAttributes - Set the parameter attributes for this call.
1332 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
1334 /// addAttribute - adds the attribute to the list of attributes.
1335 void addAttribute(unsigned i, Attribute::AttrKind attr);
1337 /// removeAttribute - removes the attribute from the list of attributes.
1338 void removeAttribute(unsigned i, Attribute attr);
1340 /// \brief Determine whether this call has the given attribute.
1341 bool hasFnAttr(Attribute::AttrKind A) const {
1342 assert(A != Attribute::NoBuiltin &&
1343 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
1344 return hasFnAttrImpl(A);
1347 /// \brief Determine whether the call or the callee has the given attributes.
1348 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
1350 /// \brief Extract the alignment for a call or parameter (0=unknown).
1351 unsigned getParamAlignment(unsigned i) const {
1352 return AttributeList.getParamAlignment(i);
1355 /// \brief Return true if the call should not be treated as a call to a
1357 bool isNoBuiltin() const {
1358 return hasFnAttrImpl(Attribute::NoBuiltin) &&
1359 !hasFnAttrImpl(Attribute::Builtin);
1362 /// \brief Return true if the call should not be inlined.
1363 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
1364 void setIsNoInline() {
1365 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
1368 /// \brief Return true if the call can return twice
1369 bool canReturnTwice() const {
1370 return hasFnAttr(Attribute::ReturnsTwice);
1372 void setCanReturnTwice() {
1373 addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice);
1376 /// \brief Determine if the call does not access memory.
1377 bool doesNotAccessMemory() const {
1378 return hasFnAttr(Attribute::ReadNone);
1380 void setDoesNotAccessMemory() {
1381 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
1384 /// \brief Determine if the call does not access or only reads memory.
1385 bool onlyReadsMemory() const {
1386 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
1388 void setOnlyReadsMemory() {
1389 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
1392 /// \brief Determine if the call cannot return.
1393 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
1394 void setDoesNotReturn() {
1395 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
1398 /// \brief Determine if the call cannot unwind.
1399 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
1400 void setDoesNotThrow() {
1401 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
1404 /// \brief Determine if the call cannot be duplicated.
1405 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
1406 void setCannotDuplicate() {
1407 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
1410 /// \brief Determine if the call returns a structure through first
1411 /// pointer argument.
1412 bool hasStructRetAttr() const {
1413 // Be friendly and also check the callee.
1414 return paramHasAttr(1, Attribute::StructRet);
1417 /// \brief Determine if any call argument is an aggregate passed by value.
1418 bool hasByValArgument() const {
1419 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1422 /// getCalledFunction - Return the function called, or null if this is an
1423 /// indirect function invocation.
1425 Function *getCalledFunction() const {
1426 return dyn_cast<Function>(Op<-1>());
1429 /// getCalledValue - Get a pointer to the function that is invoked by this
1431 const Value *getCalledValue() const { return Op<-1>(); }
1432 Value *getCalledValue() { return Op<-1>(); }
1434 /// setCalledFunction - Set the function called.
1435 void setCalledFunction(Value* Fn) {
1439 /// isInlineAsm - Check if this call is an inline asm statement.
1440 bool isInlineAsm() const {
1441 return isa<InlineAsm>(Op<-1>());
1444 // Methods for support type inquiry through isa, cast, and dyn_cast:
1445 static inline bool classof(const Instruction *I) {
1446 return I->getOpcode() == Instruction::Call;
1448 static inline bool classof(const Value *V) {
1449 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1453 bool hasFnAttrImpl(Attribute::AttrKind A) const;
1455 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1456 // method so that subclasses cannot accidentally use it.
1457 void setInstructionSubclassData(unsigned short D) {
1458 Instruction::setInstructionSubclassData(D);
1463 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1466 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1467 const Twine &NameStr, BasicBlock *InsertAtEnd)
1468 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1469 ->getElementType())->getReturnType(),
1471 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1472 unsigned(Args.size() + 1), InsertAtEnd) {
1473 init(Func, Args, NameStr);
1476 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1477 const Twine &NameStr, Instruction *InsertBefore)
1478 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1479 ->getElementType())->getReturnType(),
1481 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1482 unsigned(Args.size() + 1), InsertBefore) {
1483 init(Func, Args, NameStr);
1487 // Note: if you get compile errors about private methods then
1488 // please update your code to use the high-level operand
1489 // interfaces. See line 943 above.
1490 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1492 //===----------------------------------------------------------------------===//
1494 //===----------------------------------------------------------------------===//
1496 /// SelectInst - This class represents the LLVM 'select' instruction.
1498 class SelectInst : public Instruction {
1499 void init(Value *C, Value *S1, Value *S2) {
1500 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1506 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1507 Instruction *InsertBefore)
1508 : Instruction(S1->getType(), Instruction::Select,
1509 &Op<0>(), 3, InsertBefore) {
1513 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1514 BasicBlock *InsertAtEnd)
1515 : Instruction(S1->getType(), Instruction::Select,
1516 &Op<0>(), 3, InsertAtEnd) {
1521 SelectInst *clone_impl() const override;
1523 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1524 const Twine &NameStr = "",
1525 Instruction *InsertBefore = nullptr) {
1526 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1528 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1529 const Twine &NameStr,
1530 BasicBlock *InsertAtEnd) {
1531 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1534 const Value *getCondition() const { return Op<0>(); }
1535 const Value *getTrueValue() const { return Op<1>(); }
1536 const Value *getFalseValue() const { return Op<2>(); }
1537 Value *getCondition() { return Op<0>(); }
1538 Value *getTrueValue() { return Op<1>(); }
1539 Value *getFalseValue() { return Op<2>(); }
1541 /// areInvalidOperands - Return a string if the specified operands are invalid
1542 /// for a select operation, otherwise return null.
1543 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1545 /// Transparently provide more efficient getOperand methods.
1546 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1548 OtherOps getOpcode() const {
1549 return static_cast<OtherOps>(Instruction::getOpcode());
1552 // Methods for support type inquiry through isa, cast, and dyn_cast:
1553 static inline bool classof(const Instruction *I) {
1554 return I->getOpcode() == Instruction::Select;
1556 static inline bool classof(const Value *V) {
1557 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1562 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1565 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1567 //===----------------------------------------------------------------------===//
1569 //===----------------------------------------------------------------------===//
1571 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1572 /// an argument of the specified type given a va_list and increments that list
1574 class VAArgInst : public UnaryInstruction {
1576 VAArgInst *clone_impl() const override;
1579 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1580 Instruction *InsertBefore = nullptr)
1581 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1584 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1585 BasicBlock *InsertAtEnd)
1586 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1590 Value *getPointerOperand() { return getOperand(0); }
1591 const Value *getPointerOperand() const { return getOperand(0); }
1592 static unsigned getPointerOperandIndex() { return 0U; }
1594 // Methods for support type inquiry through isa, cast, and dyn_cast:
1595 static inline bool classof(const Instruction *I) {
1596 return I->getOpcode() == VAArg;
1598 static inline bool classof(const Value *V) {
1599 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1603 //===----------------------------------------------------------------------===//
1604 // ExtractElementInst Class
1605 //===----------------------------------------------------------------------===//
1607 /// ExtractElementInst - This instruction extracts a single (scalar)
1608 /// element from a VectorType value
1610 class ExtractElementInst : public Instruction {
1611 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1612 Instruction *InsertBefore = nullptr);
1613 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1614 BasicBlock *InsertAtEnd);
1616 ExtractElementInst *clone_impl() const override;
1619 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1620 const Twine &NameStr = "",
1621 Instruction *InsertBefore = nullptr) {
1622 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1624 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1625 const Twine &NameStr,
1626 BasicBlock *InsertAtEnd) {
1627 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1630 /// isValidOperands - Return true if an extractelement instruction can be
1631 /// formed with the specified operands.
1632 static bool isValidOperands(const Value *Vec, const Value *Idx);
1634 Value *getVectorOperand() { return Op<0>(); }
1635 Value *getIndexOperand() { return Op<1>(); }
1636 const Value *getVectorOperand() const { return Op<0>(); }
1637 const Value *getIndexOperand() const { return Op<1>(); }
1639 VectorType *getVectorOperandType() const {
1640 return cast<VectorType>(getVectorOperand()->getType());
1644 /// Transparently provide more efficient getOperand methods.
1645 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1647 // Methods for support type inquiry through isa, cast, and dyn_cast:
1648 static inline bool classof(const Instruction *I) {
1649 return I->getOpcode() == Instruction::ExtractElement;
1651 static inline bool classof(const Value *V) {
1652 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1657 struct OperandTraits<ExtractElementInst> :
1658 public FixedNumOperandTraits<ExtractElementInst, 2> {
1661 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1663 //===----------------------------------------------------------------------===//
1664 // InsertElementInst Class
1665 //===----------------------------------------------------------------------===//
1667 /// InsertElementInst - This instruction inserts a single (scalar)
1668 /// element into a VectorType value
1670 class InsertElementInst : public Instruction {
1671 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1672 const Twine &NameStr = "",
1673 Instruction *InsertBefore = nullptr);
1674 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1675 const Twine &NameStr, BasicBlock *InsertAtEnd);
1677 InsertElementInst *clone_impl() const override;
1680 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1681 const Twine &NameStr = "",
1682 Instruction *InsertBefore = nullptr) {
1683 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1685 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1686 const Twine &NameStr,
1687 BasicBlock *InsertAtEnd) {
1688 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1691 /// isValidOperands - Return true if an insertelement instruction can be
1692 /// formed with the specified operands.
1693 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1696 /// getType - Overload to return most specific vector type.
1698 VectorType *getType() const {
1699 return cast<VectorType>(Instruction::getType());
1702 /// Transparently provide more efficient getOperand methods.
1703 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1705 // Methods for support type inquiry through isa, cast, and dyn_cast:
1706 static inline bool classof(const Instruction *I) {
1707 return I->getOpcode() == Instruction::InsertElement;
1709 static inline bool classof(const Value *V) {
1710 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1715 struct OperandTraits<InsertElementInst> :
1716 public FixedNumOperandTraits<InsertElementInst, 3> {
1719 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1721 //===----------------------------------------------------------------------===//
1722 // ShuffleVectorInst Class
1723 //===----------------------------------------------------------------------===//
1725 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1728 class ShuffleVectorInst : public Instruction {
1730 ShuffleVectorInst *clone_impl() const override;
1733 // allocate space for exactly three operands
1734 void *operator new(size_t s) {
1735 return User::operator new(s, 3);
1737 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1738 const Twine &NameStr = "",
1739 Instruction *InsertBefor = nullptr);
1740 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1741 const Twine &NameStr, BasicBlock *InsertAtEnd);
1743 /// isValidOperands - Return true if a shufflevector instruction can be
1744 /// formed with the specified operands.
1745 static bool isValidOperands(const Value *V1, const Value *V2,
1748 /// getType - Overload to return most specific vector type.
1750 VectorType *getType() const {
1751 return cast<VectorType>(Instruction::getType());
1754 /// Transparently provide more efficient getOperand methods.
1755 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1757 Constant *getMask() const {
1758 return cast<Constant>(getOperand(2));
1761 /// getMaskValue - Return the index from the shuffle mask for the specified
1762 /// output result. This is either -1 if the element is undef or a number less
1763 /// than 2*numelements.
1764 static int getMaskValue(Constant *Mask, unsigned i);
1766 int getMaskValue(unsigned i) const {
1767 return getMaskValue(getMask(), i);
1770 /// getShuffleMask - Return the full mask for this instruction, where each
1771 /// element is the element number and undef's are returned as -1.
1772 static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
1774 void getShuffleMask(SmallVectorImpl<int> &Result) const {
1775 return getShuffleMask(getMask(), Result);
1778 SmallVector<int, 16> getShuffleMask() const {
1779 SmallVector<int, 16> Mask;
1780 getShuffleMask(Mask);
1785 // Methods for support type inquiry through isa, cast, and dyn_cast:
1786 static inline bool classof(const Instruction *I) {
1787 return I->getOpcode() == Instruction::ShuffleVector;
1789 static inline bool classof(const Value *V) {
1790 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1795 struct OperandTraits<ShuffleVectorInst> :
1796 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1799 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1801 //===----------------------------------------------------------------------===//
1802 // ExtractValueInst Class
1803 //===----------------------------------------------------------------------===//
1805 /// ExtractValueInst - This instruction extracts a struct member or array
1806 /// element value from an aggregate value.
1808 class ExtractValueInst : public UnaryInstruction {
1809 SmallVector<unsigned, 4> Indices;
1811 ExtractValueInst(const ExtractValueInst &EVI);
1812 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1814 /// Constructors - Create a extractvalue instruction with a base aggregate
1815 /// value and a list of indices. The first ctor can optionally insert before
1816 /// an existing instruction, the second appends the new instruction to the
1817 /// specified BasicBlock.
1818 inline ExtractValueInst(Value *Agg,
1819 ArrayRef<unsigned> Idxs,
1820 const Twine &NameStr,
1821 Instruction *InsertBefore);
1822 inline ExtractValueInst(Value *Agg,
1823 ArrayRef<unsigned> Idxs,
1824 const Twine &NameStr, BasicBlock *InsertAtEnd);
1826 // allocate space for exactly one operand
1827 void *operator new(size_t s) {
1828 return User::operator new(s, 1);
1831 ExtractValueInst *clone_impl() const override;
1834 static ExtractValueInst *Create(Value *Agg,
1835 ArrayRef<unsigned> Idxs,
1836 const Twine &NameStr = "",
1837 Instruction *InsertBefore = nullptr) {
1839 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1841 static ExtractValueInst *Create(Value *Agg,
1842 ArrayRef<unsigned> Idxs,
1843 const Twine &NameStr,
1844 BasicBlock *InsertAtEnd) {
1845 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1848 /// getIndexedType - Returns the type of the element that would be extracted
1849 /// with an extractvalue instruction with the specified parameters.
1851 /// Null is returned if the indices are invalid for the specified type.
1852 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
1854 typedef const unsigned* idx_iterator;
1855 inline idx_iterator idx_begin() const { return Indices.begin(); }
1856 inline idx_iterator idx_end() const { return Indices.end(); }
1858 Value *getAggregateOperand() {
1859 return getOperand(0);
1861 const Value *getAggregateOperand() const {
1862 return getOperand(0);
1864 static unsigned getAggregateOperandIndex() {
1865 return 0U; // get index for modifying correct operand
1868 ArrayRef<unsigned> getIndices() const {
1872 unsigned getNumIndices() const {
1873 return (unsigned)Indices.size();
1876 bool hasIndices() const {
1880 // Methods for support type inquiry through isa, cast, and dyn_cast:
1881 static inline bool classof(const Instruction *I) {
1882 return I->getOpcode() == Instruction::ExtractValue;
1884 static inline bool classof(const Value *V) {
1885 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1889 ExtractValueInst::ExtractValueInst(Value *Agg,
1890 ArrayRef<unsigned> Idxs,
1891 const Twine &NameStr,
1892 Instruction *InsertBefore)
1893 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1894 ExtractValue, Agg, InsertBefore) {
1895 init(Idxs, NameStr);
1897 ExtractValueInst::ExtractValueInst(Value *Agg,
1898 ArrayRef<unsigned> Idxs,
1899 const Twine &NameStr,
1900 BasicBlock *InsertAtEnd)
1901 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1902 ExtractValue, Agg, InsertAtEnd) {
1903 init(Idxs, NameStr);
1907 //===----------------------------------------------------------------------===//
1908 // InsertValueInst Class
1909 //===----------------------------------------------------------------------===//
1911 /// InsertValueInst - This instruction inserts a struct field of array element
1912 /// value into an aggregate value.
1914 class InsertValueInst : public Instruction {
1915 SmallVector<unsigned, 4> Indices;
1917 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1918 InsertValueInst(const InsertValueInst &IVI);
1919 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1920 const Twine &NameStr);
1922 /// Constructors - Create a insertvalue instruction with a base aggregate
1923 /// value, a value to insert, and a list of indices. The first ctor can
1924 /// optionally insert before an existing instruction, the second appends
1925 /// the new instruction to the specified BasicBlock.
1926 inline InsertValueInst(Value *Agg, Value *Val,
1927 ArrayRef<unsigned> Idxs,
1928 const Twine &NameStr,
1929 Instruction *InsertBefore);
1930 inline InsertValueInst(Value *Agg, Value *Val,
1931 ArrayRef<unsigned> Idxs,
1932 const Twine &NameStr, BasicBlock *InsertAtEnd);
1934 /// Constructors - These two constructors are convenience methods because one
1935 /// and two index insertvalue instructions are so common.
1936 InsertValueInst(Value *Agg, Value *Val,
1937 unsigned Idx, const Twine &NameStr = "",
1938 Instruction *InsertBefore = nullptr);
1939 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1940 const Twine &NameStr, BasicBlock *InsertAtEnd);
1942 InsertValueInst *clone_impl() const override;
1944 // allocate space for exactly two operands
1945 void *operator new(size_t s) {
1946 return User::operator new(s, 2);
1949 static InsertValueInst *Create(Value *Agg, Value *Val,
1950 ArrayRef<unsigned> Idxs,
1951 const Twine &NameStr = "",
1952 Instruction *InsertBefore = nullptr) {
1953 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1955 static InsertValueInst *Create(Value *Agg, Value *Val,
1956 ArrayRef<unsigned> Idxs,
1957 const Twine &NameStr,
1958 BasicBlock *InsertAtEnd) {
1959 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1962 /// Transparently provide more efficient getOperand methods.
1963 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1965 typedef const unsigned* idx_iterator;
1966 inline idx_iterator idx_begin() const { return Indices.begin(); }
1967 inline idx_iterator idx_end() const { return Indices.end(); }
1969 Value *getAggregateOperand() {
1970 return getOperand(0);
1972 const Value *getAggregateOperand() const {
1973 return getOperand(0);
1975 static unsigned getAggregateOperandIndex() {
1976 return 0U; // get index for modifying correct operand
1979 Value *getInsertedValueOperand() {
1980 return getOperand(1);
1982 const Value *getInsertedValueOperand() const {
1983 return getOperand(1);
1985 static unsigned getInsertedValueOperandIndex() {
1986 return 1U; // get index for modifying correct operand
1989 ArrayRef<unsigned> getIndices() const {
1993 unsigned getNumIndices() const {
1994 return (unsigned)Indices.size();
1997 bool hasIndices() const {
2001 // Methods for support type inquiry through isa, cast, and dyn_cast:
2002 static inline bool classof(const Instruction *I) {
2003 return I->getOpcode() == Instruction::InsertValue;
2005 static inline bool classof(const Value *V) {
2006 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2011 struct OperandTraits<InsertValueInst> :
2012 public FixedNumOperandTraits<InsertValueInst, 2> {
2015 InsertValueInst::InsertValueInst(Value *Agg,
2017 ArrayRef<unsigned> Idxs,
2018 const Twine &NameStr,
2019 Instruction *InsertBefore)
2020 : Instruction(Agg->getType(), InsertValue,
2021 OperandTraits<InsertValueInst>::op_begin(this),
2023 init(Agg, Val, Idxs, NameStr);
2025 InsertValueInst::InsertValueInst(Value *Agg,
2027 ArrayRef<unsigned> Idxs,
2028 const Twine &NameStr,
2029 BasicBlock *InsertAtEnd)
2030 : Instruction(Agg->getType(), InsertValue,
2031 OperandTraits<InsertValueInst>::op_begin(this),
2033 init(Agg, Val, Idxs, NameStr);
2036 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
2038 //===----------------------------------------------------------------------===//
2040 //===----------------------------------------------------------------------===//
2042 // PHINode - The PHINode class is used to represent the magical mystical PHI
2043 // node, that can not exist in nature, but can be synthesized in a computer
2044 // scientist's overactive imagination.
2046 class PHINode : public Instruction {
2047 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2048 /// ReservedSpace - The number of operands actually allocated. NumOperands is
2049 /// the number actually in use.
2050 unsigned ReservedSpace;
2051 PHINode(const PHINode &PN);
2052 // allocate space for exactly zero operands
2053 void *operator new(size_t s) {
2054 return User::operator new(s, 0);
2056 explicit PHINode(Type *Ty, unsigned NumReservedValues,
2057 const Twine &NameStr = "",
2058 Instruction *InsertBefore = nullptr)
2059 : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore),
2060 ReservedSpace(NumReservedValues) {
2062 OperandList = allocHungoffUses(ReservedSpace);
2065 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
2066 BasicBlock *InsertAtEnd)
2067 : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd),
2068 ReservedSpace(NumReservedValues) {
2070 OperandList = allocHungoffUses(ReservedSpace);
2073 // allocHungoffUses - this is more complicated than the generic
2074 // User::allocHungoffUses, because we have to allocate Uses for the incoming
2075 // values and pointers to the incoming blocks, all in one allocation.
2076 Use *allocHungoffUses(unsigned) const;
2078 PHINode *clone_impl() const override;
2080 /// Constructors - NumReservedValues is a hint for the number of incoming
2081 /// edges that this phi node will have (use 0 if you really have no idea).
2082 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2083 const Twine &NameStr = "",
2084 Instruction *InsertBefore = nullptr) {
2085 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2087 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2088 const Twine &NameStr, BasicBlock *InsertAtEnd) {
2089 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2093 /// Provide fast operand accessors
2094 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2096 // Block iterator interface. This provides access to the list of incoming
2097 // basic blocks, which parallels the list of incoming values.
2099 typedef BasicBlock **block_iterator;
2100 typedef BasicBlock * const *const_block_iterator;
2102 block_iterator block_begin() {
2104 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2105 return reinterpret_cast<block_iterator>(ref + 1);
2108 const_block_iterator block_begin() const {
2109 const Use::UserRef *ref =
2110 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2111 return reinterpret_cast<const_block_iterator>(ref + 1);
2114 block_iterator block_end() {
2115 return block_begin() + getNumOperands();
2118 const_block_iterator block_end() const {
2119 return block_begin() + getNumOperands();
2122 /// getNumIncomingValues - Return the number of incoming edges
2124 unsigned getNumIncomingValues() const { return getNumOperands(); }
2126 /// getIncomingValue - Return incoming value number x
2128 Value *getIncomingValue(unsigned i) const {
2129 return getOperand(i);
2131 void setIncomingValue(unsigned i, Value *V) {
2134 static unsigned getOperandNumForIncomingValue(unsigned i) {
2137 static unsigned getIncomingValueNumForOperand(unsigned i) {
2141 /// getIncomingBlock - Return incoming basic block number @p i.
2143 BasicBlock *getIncomingBlock(unsigned i) const {
2144 return block_begin()[i];
2147 /// getIncomingBlock - Return incoming basic block corresponding
2148 /// to an operand of the PHI.
2150 BasicBlock *getIncomingBlock(const Use &U) const {
2151 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2152 return getIncomingBlock(unsigned(&U - op_begin()));
2155 /// getIncomingBlock - Return incoming basic block corresponding
2156 /// to value use iterator.
2158 BasicBlock *getIncomingBlock(Value::const_user_iterator I) const {
2159 return getIncomingBlock(I.getUse());
2162 void setIncomingBlock(unsigned i, BasicBlock *BB) {
2163 block_begin()[i] = BB;
2166 /// addIncoming - Add an incoming value to the end of the PHI list
2168 void addIncoming(Value *V, BasicBlock *BB) {
2169 assert(V && "PHI node got a null value!");
2170 assert(BB && "PHI node got a null basic block!");
2171 assert(getType() == V->getType() &&
2172 "All operands to PHI node must be the same type as the PHI node!");
2173 if (NumOperands == ReservedSpace)
2174 growOperands(); // Get more space!
2175 // Initialize some new operands.
2177 setIncomingValue(NumOperands - 1, V);
2178 setIncomingBlock(NumOperands - 1, BB);
2181 /// removeIncomingValue - Remove an incoming value. This is useful if a
2182 /// predecessor basic block is deleted. The value removed is returned.
2184 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2185 /// is true), the PHI node is destroyed and any uses of it are replaced with
2186 /// dummy values. The only time there should be zero incoming values to a PHI
2187 /// node is when the block is dead, so this strategy is sound.
2189 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2191 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2192 int Idx = getBasicBlockIndex(BB);
2193 assert(Idx >= 0 && "Invalid basic block argument to remove!");
2194 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2197 /// getBasicBlockIndex - Return the first index of the specified basic
2198 /// block in the value list for this PHI. Returns -1 if no instance.
2200 int getBasicBlockIndex(const BasicBlock *BB) const {
2201 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2202 if (block_begin()[i] == BB)
2207 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2208 int Idx = getBasicBlockIndex(BB);
2209 assert(Idx >= 0 && "Invalid basic block argument!");
2210 return getIncomingValue(Idx);
2213 /// hasConstantValue - If the specified PHI node always merges together the
2214 /// same value, return the value, otherwise return null.
2215 Value *hasConstantValue() const;
2217 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2218 static inline bool classof(const Instruction *I) {
2219 return I->getOpcode() == Instruction::PHI;
2221 static inline bool classof(const Value *V) {
2222 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2225 void growOperands();
2229 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2232 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
2234 //===----------------------------------------------------------------------===//
2235 // LandingPadInst Class
2236 //===----------------------------------------------------------------------===//
2238 //===---------------------------------------------------------------------------
2239 /// LandingPadInst - The landingpad instruction holds all of the information
2240 /// necessary to generate correct exception handling. The landingpad instruction
2241 /// cannot be moved from the top of a landing pad block, which itself is
2242 /// accessible only from the 'unwind' edge of an invoke. This uses the
2243 /// SubclassData field in Value to store whether or not the landingpad is a
2246 class LandingPadInst : public Instruction {
2247 /// ReservedSpace - The number of operands actually allocated. NumOperands is
2248 /// the number actually in use.
2249 unsigned ReservedSpace;
2250 LandingPadInst(const LandingPadInst &LP);
2252 enum ClauseType { Catch, Filter };
2254 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2255 // Allocate space for exactly zero operands.
2256 void *operator new(size_t s) {
2257 return User::operator new(s, 0);
2259 void growOperands(unsigned Size);
2260 void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
2262 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2263 unsigned NumReservedValues, const Twine &NameStr,
2264 Instruction *InsertBefore);
2265 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2266 unsigned NumReservedValues, const Twine &NameStr,
2267 BasicBlock *InsertAtEnd);
2269 LandingPadInst *clone_impl() const override;
2271 /// Constructors - NumReservedClauses is a hint for the number of incoming
2272 /// clauses that this landingpad will have (use 0 if you really have no idea).
2273 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2274 unsigned NumReservedClauses,
2275 const Twine &NameStr = "",
2276 Instruction *InsertBefore = nullptr);
2277 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2278 unsigned NumReservedClauses,
2279 const Twine &NameStr, BasicBlock *InsertAtEnd);
2282 /// Provide fast operand accessors
2283 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2285 /// getPersonalityFn - Get the personality function associated with this
2287 Value *getPersonalityFn() const { return getOperand(0); }
2289 /// isCleanup - Return 'true' if this landingpad instruction is a
2290 /// cleanup. I.e., it should be run when unwinding even if its landing pad
2291 /// doesn't catch the exception.
2292 bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2294 /// setCleanup - Indicate that this landingpad instruction is a cleanup.
2295 void setCleanup(bool V) {
2296 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2300 /// addClause - Add a catch or filter clause to the landing pad.
2301 void addClause(Value *ClauseVal);
2303 /// getClause - Get the value of the clause at index Idx. Use isCatch/isFilter
2304 /// to determine what type of clause this is.
2305 Value *getClause(unsigned Idx) const { return OperandList[Idx + 1]; }
2307 /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
2308 bool isCatch(unsigned Idx) const {
2309 return !isa<ArrayType>(OperandList[Idx + 1]->getType());
2312 /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
2313 bool isFilter(unsigned Idx) const {
2314 return isa<ArrayType>(OperandList[Idx + 1]->getType());
2317 /// getNumClauses - Get the number of clauses for this landing pad.
2318 unsigned getNumClauses() const { return getNumOperands() - 1; }
2320 /// reserveClauses - Grow the size of the operand list to accommodate the new
2321 /// number of clauses.
2322 void reserveClauses(unsigned Size) { growOperands(Size); }
2324 // Methods for support type inquiry through isa, cast, and dyn_cast:
2325 static inline bool classof(const Instruction *I) {
2326 return I->getOpcode() == Instruction::LandingPad;
2328 static inline bool classof(const Value *V) {
2329 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2334 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
2337 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
2339 //===----------------------------------------------------------------------===//
2341 //===----------------------------------------------------------------------===//
2343 //===---------------------------------------------------------------------------
2344 /// ReturnInst - Return a value (possibly void), from a function. Execution
2345 /// does not continue in this function any longer.
2347 class ReturnInst : public TerminatorInst {
2348 ReturnInst(const ReturnInst &RI);
2351 // ReturnInst constructors:
2352 // ReturnInst() - 'ret void' instruction
2353 // ReturnInst( null) - 'ret void' instruction
2354 // ReturnInst(Value* X) - 'ret X' instruction
2355 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
2356 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
2357 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2358 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
2360 // NOTE: If the Value* passed is of type void then the constructor behaves as
2361 // if it was passed NULL.
2362 explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr,
2363 Instruction *InsertBefore = nullptr);
2364 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2365 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2367 ReturnInst *clone_impl() const override;
2369 static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr,
2370 Instruction *InsertBefore = nullptr) {
2371 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2373 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2374 BasicBlock *InsertAtEnd) {
2375 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2377 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2378 return new(0) ReturnInst(C, InsertAtEnd);
2380 virtual ~ReturnInst();
2382 /// Provide fast operand accessors
2383 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2385 /// Convenience accessor. Returns null if there is no return value.
2386 Value *getReturnValue() const {
2387 return getNumOperands() != 0 ? getOperand(0) : nullptr;
2390 unsigned getNumSuccessors() const { return 0; }
2392 // Methods for support type inquiry through isa, cast, and dyn_cast:
2393 static inline bool classof(const Instruction *I) {
2394 return (I->getOpcode() == Instruction::Ret);
2396 static inline bool classof(const Value *V) {
2397 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2400 BasicBlock *getSuccessorV(unsigned idx) const override;
2401 unsigned getNumSuccessorsV() const override;
2402 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2406 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2409 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2411 //===----------------------------------------------------------------------===//
2413 //===----------------------------------------------------------------------===//
2415 //===---------------------------------------------------------------------------
2416 /// BranchInst - Conditional or Unconditional Branch instruction.
2418 class BranchInst : public TerminatorInst {
2419 /// Ops list - Branches are strange. The operands are ordered:
2420 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2421 /// they don't have to check for cond/uncond branchness. These are mostly
2422 /// accessed relative from op_end().
2423 BranchInst(const BranchInst &BI);
2425 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2426 // BranchInst(BB *B) - 'br B'
2427 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2428 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2429 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2430 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2431 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
2432 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr);
2433 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2434 Instruction *InsertBefore = nullptr);
2435 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2436 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2437 BasicBlock *InsertAtEnd);
2439 BranchInst *clone_impl() const override;
2441 static BranchInst *Create(BasicBlock *IfTrue,
2442 Instruction *InsertBefore = nullptr) {
2443 return new(1) BranchInst(IfTrue, InsertBefore);
2445 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2446 Value *Cond, Instruction *InsertBefore = nullptr) {
2447 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2449 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2450 return new(1) BranchInst(IfTrue, InsertAtEnd);
2452 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2453 Value *Cond, BasicBlock *InsertAtEnd) {
2454 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2457 /// Transparently provide more efficient getOperand methods.
2458 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2460 bool isUnconditional() const { return getNumOperands() == 1; }
2461 bool isConditional() const { return getNumOperands() == 3; }
2463 Value *getCondition() const {
2464 assert(isConditional() && "Cannot get condition of an uncond branch!");
2468 void setCondition(Value *V) {
2469 assert(isConditional() && "Cannot set condition of unconditional branch!");
2473 unsigned getNumSuccessors() const { return 1+isConditional(); }
2475 BasicBlock *getSuccessor(unsigned i) const {
2476 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2477 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2480 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2481 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2482 *(&Op<-1>() - idx) = (Value*)NewSucc;
2485 /// \brief Swap the successors of this branch instruction.
2487 /// Swaps the successors of the branch instruction. This also swaps any
2488 /// branch weight metadata associated with the instruction so that it
2489 /// continues to map correctly to each operand.
2490 void swapSuccessors();
2492 // Methods for support type inquiry through isa, cast, and dyn_cast:
2493 static inline bool classof(const Instruction *I) {
2494 return (I->getOpcode() == Instruction::Br);
2496 static inline bool classof(const Value *V) {
2497 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2500 BasicBlock *getSuccessorV(unsigned idx) const override;
2501 unsigned getNumSuccessorsV() const override;
2502 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2506 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2509 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2511 //===----------------------------------------------------------------------===//
2513 //===----------------------------------------------------------------------===//
2515 //===---------------------------------------------------------------------------
2516 /// SwitchInst - Multiway switch
2518 class SwitchInst : public TerminatorInst {
2519 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2520 unsigned ReservedSpace;
2521 // Operand[0] = Value to switch on
2522 // Operand[1] = Default basic block destination
2523 // Operand[2n ] = Value to match
2524 // Operand[2n+1] = BasicBlock to go to on match
2525 SwitchInst(const SwitchInst &SI);
2526 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2527 void growOperands();
2528 // allocate space for exactly zero operands
2529 void *operator new(size_t s) {
2530 return User::operator new(s, 0);
2532 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2533 /// switch on and a default destination. The number of additional cases can
2534 /// be specified here to make memory allocation more efficient. This
2535 /// constructor can also autoinsert before another instruction.
2536 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2537 Instruction *InsertBefore);
2539 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2540 /// switch on and a default destination. The number of additional cases can
2541 /// be specified here to make memory allocation more efficient. This
2542 /// constructor also autoinserts at the end of the specified BasicBlock.
2543 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2544 BasicBlock *InsertAtEnd);
2546 SwitchInst *clone_impl() const override;
2550 static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
2552 template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy>
2553 class CaseIteratorT {
2561 typedef CaseIteratorT<SwitchInstTy, ConstantIntTy, BasicBlockTy> Self;
2563 /// Initializes case iterator for given SwitchInst and for given
2565 CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
2570 /// Initializes case iterator for given SwitchInst and for given
2571 /// TerminatorInst's successor index.
2572 static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
2573 assert(SuccessorIndex < SI->getNumSuccessors() &&
2574 "Successor index # out of range!");
2575 return SuccessorIndex != 0 ?
2576 Self(SI, SuccessorIndex - 1) :
2577 Self(SI, DefaultPseudoIndex);
2580 /// Resolves case value for current case.
2581 ConstantIntTy *getCaseValue() {
2582 assert(Index < SI->getNumCases() && "Index out the number of cases.");
2583 return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2));
2586 /// Resolves successor for current case.
2587 BasicBlockTy *getCaseSuccessor() {
2588 assert((Index < SI->getNumCases() ||
2589 Index == DefaultPseudoIndex) &&
2590 "Index out the number of cases.");
2591 return SI->getSuccessor(getSuccessorIndex());
2594 /// Returns number of current case.
2595 unsigned getCaseIndex() const { return Index; }
2597 /// Returns TerminatorInst's successor index for current case successor.
2598 unsigned getSuccessorIndex() const {
2599 assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
2600 "Index out the number of cases.");
2601 return Index != DefaultPseudoIndex ? Index + 1 : 0;
2605 // Check index correctness after increment.
2606 // Note: Index == getNumCases() means end().
2607 assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
2611 Self operator++(int) {
2617 // Check index correctness after decrement.
2618 // Note: Index == getNumCases() means end().
2619 // Also allow "-1" iterator here. That will became valid after ++.
2620 assert((Index == 0 || Index-1 <= SI->getNumCases()) &&
2621 "Index out the number of cases.");
2625 Self operator--(int) {
2630 bool operator==(const Self& RHS) const {
2631 assert(RHS.SI == SI && "Incompatible operators.");
2632 return RHS.Index == Index;
2634 bool operator!=(const Self& RHS) const {
2635 assert(RHS.SI == SI && "Incompatible operators.");
2636 return RHS.Index != Index;
2640 typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock>
2643 class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> {
2645 typedef CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> ParentTy;
2649 CaseIt(const ParentTy& Src) : ParentTy(Src) {}
2650 CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
2652 /// Sets the new value for current case.
2653 void setValue(ConstantInt *V) {
2654 assert(Index < SI->getNumCases() && "Index out the number of cases.");
2655 SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V));
2658 /// Sets the new successor for current case.
2659 void setSuccessor(BasicBlock *S) {
2660 SI->setSuccessor(getSuccessorIndex(), S);
2664 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2666 Instruction *InsertBefore = nullptr) {
2667 return new SwitchInst(Value, Default, NumCases, InsertBefore);
2669 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2670 unsigned NumCases, BasicBlock *InsertAtEnd) {
2671 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2676 /// Provide fast operand accessors
2677 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2679 // Accessor Methods for Switch stmt
2680 Value *getCondition() const { return getOperand(0); }
2681 void setCondition(Value *V) { setOperand(0, V); }
2683 BasicBlock *getDefaultDest() const {
2684 return cast<BasicBlock>(getOperand(1));
2687 void setDefaultDest(BasicBlock *DefaultCase) {
2688 setOperand(1, reinterpret_cast<Value*>(DefaultCase));
2691 /// getNumCases - return the number of 'cases' in this switch instruction,
2692 /// except the default case
2693 unsigned getNumCases() const {
2694 return getNumOperands()/2 - 1;
2697 /// Returns a read/write iterator that points to the first
2698 /// case in SwitchInst.
2699 CaseIt case_begin() {
2700 return CaseIt(this, 0);
2702 /// Returns a read-only iterator that points to the first
2703 /// case in the SwitchInst.
2704 ConstCaseIt case_begin() const {
2705 return ConstCaseIt(this, 0);
2708 /// Returns a read/write iterator that points one past the last
2709 /// in the SwitchInst.
2711 return CaseIt(this, getNumCases());
2713 /// Returns a read-only iterator that points one past the last
2714 /// in the SwitchInst.
2715 ConstCaseIt case_end() const {
2716 return ConstCaseIt(this, getNumCases());
2718 /// Returns an iterator that points to the default case.
2719 /// Note: this iterator allows to resolve successor only. Attempt
2720 /// to resolve case value causes an assertion.
2721 /// Also note, that increment and decrement also causes an assertion and
2722 /// makes iterator invalid.
2723 CaseIt case_default() {
2724 return CaseIt(this, DefaultPseudoIndex);
2726 ConstCaseIt case_default() const {
2727 return ConstCaseIt(this, DefaultPseudoIndex);
2730 /// findCaseValue - Search all of the case values for the specified constant.
2731 /// If it is explicitly handled, return the case iterator of it, otherwise
2732 /// return default case iterator to indicate
2733 /// that it is handled by the default handler.
2734 CaseIt findCaseValue(const ConstantInt *C) {
2735 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
2736 if (i.getCaseValue() == C)
2738 return case_default();
2740 ConstCaseIt findCaseValue(const ConstantInt *C) const {
2741 for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
2742 if (i.getCaseValue() == C)
2744 return case_default();
2747 /// findCaseDest - Finds the unique case value for a given successor. Returns
2748 /// null if the successor is not found, not unique, or is the default case.
2749 ConstantInt *findCaseDest(BasicBlock *BB) {
2750 if (BB == getDefaultDest()) return nullptr;
2752 ConstantInt *CI = nullptr;
2753 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
2754 if (i.getCaseSuccessor() == BB) {
2755 if (CI) return nullptr; // Multiple cases lead to BB.
2756 else CI = i.getCaseValue();
2762 /// addCase - Add an entry to the switch instruction...
2764 /// This action invalidates case_end(). Old case_end() iterator will
2765 /// point to the added case.
2766 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2768 /// removeCase - This method removes the specified case and its successor
2769 /// from the switch instruction. Note that this operation may reorder the
2770 /// remaining cases at index idx and above.
2772 /// This action invalidates iterators for all cases following the one removed,
2773 /// including the case_end() iterator.
2774 void removeCase(CaseIt i);
2776 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2777 BasicBlock *getSuccessor(unsigned idx) const {
2778 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2779 return cast<BasicBlock>(getOperand(idx*2+1));
2781 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2782 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2783 setOperand(idx*2+1, (Value*)NewSucc);
2786 // Methods for support type inquiry through isa, cast, and dyn_cast:
2787 static inline bool classof(const Instruction *I) {
2788 return I->getOpcode() == Instruction::Switch;
2790 static inline bool classof(const Value *V) {
2791 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2794 BasicBlock *getSuccessorV(unsigned idx) const override;
2795 unsigned getNumSuccessorsV() const override;
2796 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2800 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2803 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2806 //===----------------------------------------------------------------------===//
2807 // IndirectBrInst Class
2808 //===----------------------------------------------------------------------===//
2810 //===---------------------------------------------------------------------------
2811 /// IndirectBrInst - Indirect Branch Instruction.
2813 class IndirectBrInst : public TerminatorInst {
2814 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2815 unsigned ReservedSpace;
2816 // Operand[0] = Value to switch on
2817 // Operand[1] = Default basic block destination
2818 // Operand[2n ] = Value to match
2819 // Operand[2n+1] = BasicBlock to go to on match
2820 IndirectBrInst(const IndirectBrInst &IBI);
2821 void init(Value *Address, unsigned NumDests);
2822 void growOperands();
2823 // allocate space for exactly zero operands
2824 void *operator new(size_t s) {
2825 return User::operator new(s, 0);
2827 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2828 /// Address to jump to. The number of expected destinations can be specified
2829 /// here to make memory allocation more efficient. This constructor can also
2830 /// autoinsert before another instruction.
2831 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2833 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2834 /// Address to jump to. The number of expected destinations can be specified
2835 /// here to make memory allocation more efficient. This constructor also
2836 /// autoinserts at the end of the specified BasicBlock.
2837 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2839 IndirectBrInst *clone_impl() const override;
2841 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2842 Instruction *InsertBefore = nullptr) {
2843 return new IndirectBrInst(Address, NumDests, InsertBefore);
2845 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2846 BasicBlock *InsertAtEnd) {
2847 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2851 /// Provide fast operand accessors.
2852 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2854 // Accessor Methods for IndirectBrInst instruction.
2855 Value *getAddress() { return getOperand(0); }
2856 const Value *getAddress() const { return getOperand(0); }
2857 void setAddress(Value *V) { setOperand(0, V); }
2860 /// getNumDestinations - return the number of possible destinations in this
2861 /// indirectbr instruction.
2862 unsigned getNumDestinations() const { return getNumOperands()-1; }
2864 /// getDestination - Return the specified destination.
2865 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2866 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2868 /// addDestination - Add a destination.
2870 void addDestination(BasicBlock *Dest);
2872 /// removeDestination - This method removes the specified successor from the
2873 /// indirectbr instruction.
2874 void removeDestination(unsigned i);
2876 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2877 BasicBlock *getSuccessor(unsigned i) const {
2878 return cast<BasicBlock>(getOperand(i+1));
2880 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2881 setOperand(i+1, (Value*)NewSucc);
2884 // Methods for support type inquiry through isa, cast, and dyn_cast:
2885 static inline bool classof(const Instruction *I) {
2886 return I->getOpcode() == Instruction::IndirectBr;
2888 static inline bool classof(const Value *V) {
2889 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2892 BasicBlock *getSuccessorV(unsigned idx) const override;
2893 unsigned getNumSuccessorsV() const override;
2894 void setSuccessorV(unsigned idx, BasicBlock *B) override;
2898 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2901 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2904 //===----------------------------------------------------------------------===//
2906 //===----------------------------------------------------------------------===//
2908 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2909 /// calling convention of the call.
2911 class InvokeInst : public TerminatorInst {
2912 AttributeSet AttributeList;
2913 InvokeInst(const InvokeInst &BI);
2914 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2915 ArrayRef<Value *> Args, const Twine &NameStr);
2917 /// Construct an InvokeInst given a range of arguments.
2919 /// \brief Construct an InvokeInst from a range of arguments
2920 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2921 ArrayRef<Value *> Args, unsigned Values,
2922 const Twine &NameStr, Instruction *InsertBefore);
2924 /// Construct an InvokeInst given a range of arguments.
2926 /// \brief Construct an InvokeInst from a range of arguments
2927 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2928 ArrayRef<Value *> Args, unsigned Values,
2929 const Twine &NameStr, BasicBlock *InsertAtEnd);
2931 InvokeInst *clone_impl() const override;
2933 static InvokeInst *Create(Value *Func,
2934 BasicBlock *IfNormal, BasicBlock *IfException,
2935 ArrayRef<Value *> Args, const Twine &NameStr = "",
2936 Instruction *InsertBefore = nullptr) {
2937 unsigned Values = unsigned(Args.size()) + 3;
2938 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2939 Values, NameStr, InsertBefore);
2941 static InvokeInst *Create(Value *Func,
2942 BasicBlock *IfNormal, BasicBlock *IfException,
2943 ArrayRef<Value *> Args, const Twine &NameStr,
2944 BasicBlock *InsertAtEnd) {
2945 unsigned Values = unsigned(Args.size()) + 3;
2946 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2947 Values, NameStr, InsertAtEnd);
2950 /// Provide fast operand accessors
2951 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2953 /// getNumArgOperands - Return the number of invoke arguments.
2955 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2957 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2959 Value *getArgOperand(unsigned i) const { return getOperand(i); }
2960 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2962 /// arg_operands - iteration adapter for range-for loops.
2963 iterator_range<op_iterator> arg_operands() {
2964 return iterator_range<op_iterator>(op_begin(), op_end() - 3);
2967 /// arg_operands - iteration adapter for range-for loops.
2968 iterator_range<const_op_iterator> arg_operands() const {
2969 return iterator_range<const_op_iterator>(op_begin(), op_end() - 3);
2972 /// \brief Wrappers for getting the \c Use of a invoke argument.
2973 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
2974 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
2976 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2978 CallingConv::ID getCallingConv() const {
2979 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2981 void setCallingConv(CallingConv::ID CC) {
2982 setInstructionSubclassData(static_cast<unsigned>(CC));
2985 /// getAttributes - Return the parameter attributes for this invoke.
2987 const AttributeSet &getAttributes() const { return AttributeList; }
2989 /// setAttributes - Set the parameter attributes for this invoke.
2991 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
2993 /// addAttribute - adds the attribute to the list of attributes.
2994 void addAttribute(unsigned i, Attribute::AttrKind attr);
2996 /// removeAttribute - removes the attribute from the list of attributes.
2997 void removeAttribute(unsigned i, Attribute attr);
2999 /// \brief Determine whether this call has the given attribute.
3000 bool hasFnAttr(Attribute::AttrKind A) const {
3001 assert(A != Attribute::NoBuiltin &&
3002 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
3003 return hasFnAttrImpl(A);
3006 /// \brief Determine whether the call or the callee has the given attributes.
3007 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
3009 /// \brief Extract the alignment for a call or parameter (0=unknown).
3010 unsigned getParamAlignment(unsigned i) const {
3011 return AttributeList.getParamAlignment(i);
3014 /// \brief Return true if the call should not be treated as a call to a
3016 bool isNoBuiltin() const {
3017 // We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have
3018 // to check it by hand.
3019 return hasFnAttrImpl(Attribute::NoBuiltin) &&
3020 !hasFnAttrImpl(Attribute::Builtin);
3023 /// \brief Return true if the call should not be inlined.
3024 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
3025 void setIsNoInline() {
3026 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
3029 /// \brief Determine if the call does not access memory.
3030 bool doesNotAccessMemory() const {
3031 return hasFnAttr(Attribute::ReadNone);
3033 void setDoesNotAccessMemory() {
3034 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
3037 /// \brief Determine if the call does not access or only reads memory.
3038 bool onlyReadsMemory() const {
3039 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
3041 void setOnlyReadsMemory() {
3042 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
3045 /// \brief Determine if the call cannot return.
3046 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
3047 void setDoesNotReturn() {
3048 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
3051 /// \brief Determine if the call cannot unwind.
3052 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
3053 void setDoesNotThrow() {
3054 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
3057 /// \brief Determine if the invoke cannot be duplicated.
3058 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
3059 void setCannotDuplicate() {
3060 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
3063 /// \brief Determine if the call returns a structure through first
3064 /// pointer argument.
3065 bool hasStructRetAttr() const {
3066 // Be friendly and also check the callee.
3067 return paramHasAttr(1, Attribute::StructRet);
3070 /// \brief Determine if any call argument is an aggregate passed by value.
3071 bool hasByValArgument() const {
3072 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
3075 /// getCalledFunction - Return the function called, or null if this is an
3076 /// indirect function invocation.
3078 Function *getCalledFunction() const {
3079 return dyn_cast<Function>(Op<-3>());
3082 /// getCalledValue - Get a pointer to the function that is invoked by this
3084 const Value *getCalledValue() const { return Op<-3>(); }
3085 Value *getCalledValue() { return Op<-3>(); }
3087 /// setCalledFunction - Set the function called.
3088 void setCalledFunction(Value* Fn) {
3092 // get*Dest - Return the destination basic blocks...
3093 BasicBlock *getNormalDest() const {
3094 return cast<BasicBlock>(Op<-2>());
3096 BasicBlock *getUnwindDest() const {
3097 return cast<BasicBlock>(Op<-1>());
3099 void setNormalDest(BasicBlock *B) {
3100 Op<-2>() = reinterpret_cast<Value*>(B);
3102 void setUnwindDest(BasicBlock *B) {
3103 Op<-1>() = reinterpret_cast<Value*>(B);
3106 /// getLandingPadInst - Get the landingpad instruction from the landing pad
3107 /// block (the unwind destination).
3108 LandingPadInst *getLandingPadInst() const;
3110 BasicBlock *getSuccessor(unsigned i) const {
3111 assert(i < 2 && "Successor # out of range for invoke!");
3112 return i == 0 ? getNormalDest() : getUnwindDest();
3115 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3116 assert(idx < 2 && "Successor # out of range for invoke!");
3117 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
3120 unsigned getNumSuccessors() const { return 2; }
3122 // Methods for support type inquiry through isa, cast, and dyn_cast:
3123 static inline bool classof(const Instruction *I) {
3124 return (I->getOpcode() == Instruction::Invoke);
3126 static inline bool classof(const Value *V) {
3127 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3131 BasicBlock *getSuccessorV(unsigned idx) const override;
3132 unsigned getNumSuccessorsV() const override;
3133 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3135 bool hasFnAttrImpl(Attribute::AttrKind A) const;
3137 // Shadow Instruction::setInstructionSubclassData with a private forwarding
3138 // method so that subclasses cannot accidentally use it.
3139 void setInstructionSubclassData(unsigned short D) {
3140 Instruction::setInstructionSubclassData(D);
3145 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
3148 InvokeInst::InvokeInst(Value *Func,
3149 BasicBlock *IfNormal, BasicBlock *IfException,
3150 ArrayRef<Value *> Args, unsigned Values,
3151 const Twine &NameStr, Instruction *InsertBefore)
3152 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3153 ->getElementType())->getReturnType(),
3154 Instruction::Invoke,
3155 OperandTraits<InvokeInst>::op_end(this) - Values,
3156 Values, InsertBefore) {
3157 init(Func, IfNormal, IfException, Args, NameStr);
3159 InvokeInst::InvokeInst(Value *Func,
3160 BasicBlock *IfNormal, BasicBlock *IfException,
3161 ArrayRef<Value *> Args, unsigned Values,
3162 const Twine &NameStr, BasicBlock *InsertAtEnd)
3163 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3164 ->getElementType())->getReturnType(),
3165 Instruction::Invoke,
3166 OperandTraits<InvokeInst>::op_end(this) - Values,
3167 Values, InsertAtEnd) {
3168 init(Func, IfNormal, IfException, Args, NameStr);
3171 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
3173 //===----------------------------------------------------------------------===//
3175 //===----------------------------------------------------------------------===//
3177 //===---------------------------------------------------------------------------
3178 /// ResumeInst - Resume the propagation of an exception.
3180 class ResumeInst : public TerminatorInst {
3181 ResumeInst(const ResumeInst &RI);
3183 explicit ResumeInst(Value *Exn, Instruction *InsertBefore=nullptr);
3184 ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
3186 ResumeInst *clone_impl() const override;
3188 static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = nullptr) {
3189 return new(1) ResumeInst(Exn, InsertBefore);
3191 static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
3192 return new(1) ResumeInst(Exn, InsertAtEnd);
3195 /// Provide fast operand accessors
3196 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3198 /// Convenience accessor.
3199 Value *getValue() const { return Op<0>(); }
3201 unsigned getNumSuccessors() const { return 0; }
3203 // Methods for support type inquiry through isa, cast, and dyn_cast:
3204 static inline bool classof(const Instruction *I) {
3205 return I->getOpcode() == Instruction::Resume;
3207 static inline bool classof(const Value *V) {
3208 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3211 BasicBlock *getSuccessorV(unsigned idx) const override;
3212 unsigned getNumSuccessorsV() const override;
3213 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3217 struct OperandTraits<ResumeInst> :
3218 public FixedNumOperandTraits<ResumeInst, 1> {
3221 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
3223 //===----------------------------------------------------------------------===//
3224 // UnreachableInst Class
3225 //===----------------------------------------------------------------------===//
3227 //===---------------------------------------------------------------------------
3228 /// UnreachableInst - This function has undefined behavior. In particular, the
3229 /// presence of this instruction indicates some higher level knowledge that the
3230 /// end of the block cannot be reached.
3232 class UnreachableInst : public TerminatorInst {
3233 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
3235 UnreachableInst *clone_impl() const override;
3238 // allocate space for exactly zero operands
3239 void *operator new(size_t s) {
3240 return User::operator new(s, 0);
3242 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = nullptr);
3243 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
3245 unsigned getNumSuccessors() const { return 0; }
3247 // Methods for support type inquiry through isa, cast, and dyn_cast:
3248 static inline bool classof(const Instruction *I) {
3249 return I->getOpcode() == Instruction::Unreachable;
3251 static inline bool classof(const Value *V) {
3252 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3255 BasicBlock *getSuccessorV(unsigned idx) const override;
3256 unsigned getNumSuccessorsV() const override;
3257 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3260 //===----------------------------------------------------------------------===//
3262 //===----------------------------------------------------------------------===//
3264 /// \brief This class represents a truncation of integer types.
3265 class TruncInst : public CastInst {
3267 /// \brief Clone an identical TruncInst
3268 TruncInst *clone_impl() const override;
3271 /// \brief Constructor with insert-before-instruction semantics
3273 Value *S, ///< The value to be truncated
3274 Type *Ty, ///< The (smaller) type to truncate to
3275 const Twine &NameStr = "", ///< A name for the new instruction
3276 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3279 /// \brief Constructor with insert-at-end-of-block semantics
3281 Value *S, ///< The value to be truncated
3282 Type *Ty, ///< The (smaller) type to truncate to
3283 const Twine &NameStr, ///< A name for the new instruction
3284 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3287 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3288 static inline bool classof(const Instruction *I) {
3289 return I->getOpcode() == Trunc;
3291 static inline bool classof(const Value *V) {
3292 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3296 //===----------------------------------------------------------------------===//
3298 //===----------------------------------------------------------------------===//
3300 /// \brief This class represents zero extension of integer types.
3301 class ZExtInst : public CastInst {
3303 /// \brief Clone an identical ZExtInst
3304 ZExtInst *clone_impl() const override;
3307 /// \brief Constructor with insert-before-instruction semantics
3309 Value *S, ///< The value to be zero extended
3310 Type *Ty, ///< The type to zero extend to
3311 const Twine &NameStr = "", ///< A name for the new instruction
3312 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3315 /// \brief Constructor with insert-at-end semantics.
3317 Value *S, ///< The value to be zero extended
3318 Type *Ty, ///< The type to zero extend to
3319 const Twine &NameStr, ///< A name for the new instruction
3320 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3323 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3324 static inline bool classof(const Instruction *I) {
3325 return I->getOpcode() == ZExt;
3327 static inline bool classof(const Value *V) {
3328 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3332 //===----------------------------------------------------------------------===//
3334 //===----------------------------------------------------------------------===//
3336 /// \brief This class represents a sign extension of integer types.
3337 class SExtInst : public CastInst {
3339 /// \brief Clone an identical SExtInst
3340 SExtInst *clone_impl() const override;
3343 /// \brief Constructor with insert-before-instruction semantics
3345 Value *S, ///< The value to be sign extended
3346 Type *Ty, ///< The type to sign extend to
3347 const Twine &NameStr = "", ///< A name for the new instruction
3348 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3351 /// \brief Constructor with insert-at-end-of-block semantics
3353 Value *S, ///< The value to be sign extended
3354 Type *Ty, ///< The type to sign extend to
3355 const Twine &NameStr, ///< A name for the new instruction
3356 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3359 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3360 static inline bool classof(const Instruction *I) {
3361 return I->getOpcode() == SExt;
3363 static inline bool classof(const Value *V) {
3364 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3368 //===----------------------------------------------------------------------===//
3369 // FPTruncInst Class
3370 //===----------------------------------------------------------------------===//
3372 /// \brief This class represents a truncation of floating point types.
3373 class FPTruncInst : public CastInst {
3375 /// \brief Clone an identical FPTruncInst
3376 FPTruncInst *clone_impl() const override;
3379 /// \brief Constructor with insert-before-instruction semantics
3381 Value *S, ///< The value to be truncated
3382 Type *Ty, ///< The type to truncate to
3383 const Twine &NameStr = "", ///< A name for the new instruction
3384 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3387 /// \brief Constructor with insert-before-instruction semantics
3389 Value *S, ///< The value to be truncated
3390 Type *Ty, ///< The type to truncate to
3391 const Twine &NameStr, ///< A name for the new instruction
3392 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3395 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3396 static inline bool classof(const Instruction *I) {
3397 return I->getOpcode() == FPTrunc;
3399 static inline bool classof(const Value *V) {
3400 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3404 //===----------------------------------------------------------------------===//
3406 //===----------------------------------------------------------------------===//
3408 /// \brief This class represents an extension of floating point types.
3409 class FPExtInst : public CastInst {
3411 /// \brief Clone an identical FPExtInst
3412 FPExtInst *clone_impl() const override;
3415 /// \brief Constructor with insert-before-instruction semantics
3417 Value *S, ///< The value to be extended
3418 Type *Ty, ///< The type to extend to
3419 const Twine &NameStr = "", ///< A name for the new instruction
3420 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3423 /// \brief Constructor with insert-at-end-of-block semantics
3425 Value *S, ///< The value to be extended
3426 Type *Ty, ///< The type to extend to
3427 const Twine &NameStr, ///< A name for the new instruction
3428 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3431 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3432 static inline bool classof(const Instruction *I) {
3433 return I->getOpcode() == FPExt;
3435 static inline bool classof(const Value *V) {
3436 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3440 //===----------------------------------------------------------------------===//
3442 //===----------------------------------------------------------------------===//
3444 /// \brief This class represents a cast unsigned integer to floating point.
3445 class UIToFPInst : public CastInst {
3447 /// \brief Clone an identical UIToFPInst
3448 UIToFPInst *clone_impl() const override;
3451 /// \brief Constructor with insert-before-instruction semantics
3453 Value *S, ///< The value to be converted
3454 Type *Ty, ///< The type to convert to
3455 const Twine &NameStr = "", ///< A name for the new instruction
3456 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3459 /// \brief Constructor with insert-at-end-of-block semantics
3461 Value *S, ///< The value to be converted
3462 Type *Ty, ///< The type to convert to
3463 const Twine &NameStr, ///< A name for the new instruction
3464 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3467 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3468 static inline bool classof(const Instruction *I) {
3469 return I->getOpcode() == UIToFP;
3471 static inline bool classof(const Value *V) {
3472 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3476 //===----------------------------------------------------------------------===//
3478 //===----------------------------------------------------------------------===//
3480 /// \brief This class represents a cast from signed integer to floating point.
3481 class SIToFPInst : public CastInst {
3483 /// \brief Clone an identical SIToFPInst
3484 SIToFPInst *clone_impl() const override;
3487 /// \brief Constructor with insert-before-instruction semantics
3489 Value *S, ///< The value to be converted
3490 Type *Ty, ///< The type to convert to
3491 const Twine &NameStr = "", ///< A name for the new instruction
3492 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3495 /// \brief Constructor with insert-at-end-of-block semantics
3497 Value *S, ///< The value to be converted
3498 Type *Ty, ///< The type to convert to
3499 const Twine &NameStr, ///< A name for the new instruction
3500 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3503 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3504 static inline bool classof(const Instruction *I) {
3505 return I->getOpcode() == SIToFP;
3507 static inline bool classof(const Value *V) {
3508 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3512 //===----------------------------------------------------------------------===//
3514 //===----------------------------------------------------------------------===//
3516 /// \brief This class represents a cast from floating point to unsigned integer
3517 class FPToUIInst : public CastInst {
3519 /// \brief Clone an identical FPToUIInst
3520 FPToUIInst *clone_impl() const override;
3523 /// \brief Constructor with insert-before-instruction semantics
3525 Value *S, ///< The value to be converted
3526 Type *Ty, ///< The type to convert to
3527 const Twine &NameStr = "", ///< A name for the new instruction
3528 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3531 /// \brief Constructor with insert-at-end-of-block semantics
3533 Value *S, ///< The value to be converted
3534 Type *Ty, ///< The type to convert to
3535 const Twine &NameStr, ///< A name for the new instruction
3536 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3539 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3540 static inline bool classof(const Instruction *I) {
3541 return I->getOpcode() == FPToUI;
3543 static inline bool classof(const Value *V) {
3544 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3548 //===----------------------------------------------------------------------===//
3550 //===----------------------------------------------------------------------===//
3552 /// \brief This class represents a cast from floating point to signed integer.
3553 class FPToSIInst : public CastInst {
3555 /// \brief Clone an identical FPToSIInst
3556 FPToSIInst *clone_impl() const override;
3559 /// \brief Constructor with insert-before-instruction semantics
3561 Value *S, ///< The value to be converted
3562 Type *Ty, ///< The type to convert to
3563 const Twine &NameStr = "", ///< A name for the new instruction
3564 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3567 /// \brief Constructor with insert-at-end-of-block semantics
3569 Value *S, ///< The value to be converted
3570 Type *Ty, ///< The type to convert to
3571 const Twine &NameStr, ///< A name for the new instruction
3572 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3575 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3576 static inline bool classof(const Instruction *I) {
3577 return I->getOpcode() == FPToSI;
3579 static inline bool classof(const Value *V) {
3580 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3584 //===----------------------------------------------------------------------===//
3585 // IntToPtrInst Class
3586 //===----------------------------------------------------------------------===//
3588 /// \brief This class represents a cast from an integer to a pointer.
3589 class IntToPtrInst : public CastInst {
3591 /// \brief Constructor with insert-before-instruction semantics
3593 Value *S, ///< The value to be converted
3594 Type *Ty, ///< The type to convert to
3595 const Twine &NameStr = "", ///< A name for the new instruction
3596 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3599 /// \brief Constructor with insert-at-end-of-block semantics
3601 Value *S, ///< The value to be converted
3602 Type *Ty, ///< The type to convert to
3603 const Twine &NameStr, ///< A name for the new instruction
3604 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3607 /// \brief Clone an identical IntToPtrInst
3608 IntToPtrInst *clone_impl() const override;
3610 /// \brief Returns the address space of this instruction's pointer type.
3611 unsigned getAddressSpace() const {
3612 return getType()->getPointerAddressSpace();
3615 // Methods for support type inquiry through isa, cast, and dyn_cast:
3616 static inline bool classof(const Instruction *I) {
3617 return I->getOpcode() == IntToPtr;
3619 static inline bool classof(const Value *V) {
3620 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3624 //===----------------------------------------------------------------------===//
3625 // PtrToIntInst Class
3626 //===----------------------------------------------------------------------===//
3628 /// \brief This class represents a cast from a pointer to an integer
3629 class PtrToIntInst : public CastInst {
3631 /// \brief Clone an identical PtrToIntInst
3632 PtrToIntInst *clone_impl() const override;
3635 /// \brief Constructor with insert-before-instruction semantics
3637 Value *S, ///< The value to be converted
3638 Type *Ty, ///< The type to convert to
3639 const Twine &NameStr = "", ///< A name for the new instruction
3640 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3643 /// \brief Constructor with insert-at-end-of-block semantics
3645 Value *S, ///< The value to be converted
3646 Type *Ty, ///< The type to convert to
3647 const Twine &NameStr, ///< A name for the new instruction
3648 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3651 /// \brief Gets the pointer operand.
3652 Value *getPointerOperand() { return getOperand(0); }
3653 /// \brief Gets the pointer operand.
3654 const Value *getPointerOperand() const { return getOperand(0); }
3655 /// \brief Gets the operand index of the pointer operand.
3656 static unsigned getPointerOperandIndex() { return 0U; }
3658 /// \brief Returns the address space of the pointer operand.
3659 unsigned getPointerAddressSpace() const {
3660 return getPointerOperand()->getType()->getPointerAddressSpace();
3663 // Methods for support type inquiry through isa, cast, and dyn_cast:
3664 static inline bool classof(const Instruction *I) {
3665 return I->getOpcode() == PtrToInt;
3667 static inline bool classof(const Value *V) {
3668 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3672 //===----------------------------------------------------------------------===//
3673 // BitCastInst Class
3674 //===----------------------------------------------------------------------===//
3676 /// \brief This class represents a no-op cast from one type to another.
3677 class BitCastInst : public CastInst {
3679 /// \brief Clone an identical BitCastInst
3680 BitCastInst *clone_impl() const override;
3683 /// \brief Constructor with insert-before-instruction semantics
3685 Value *S, ///< The value to be casted
3686 Type *Ty, ///< The type to casted to
3687 const Twine &NameStr = "", ///< A name for the new instruction
3688 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3691 /// \brief Constructor with insert-at-end-of-block semantics
3693 Value *S, ///< The value to be casted
3694 Type *Ty, ///< The type to casted to
3695 const Twine &NameStr, ///< A name for the new instruction
3696 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3699 // Methods for support type inquiry through isa, cast, and dyn_cast:
3700 static inline bool classof(const Instruction *I) {
3701 return I->getOpcode() == BitCast;
3703 static inline bool classof(const Value *V) {
3704 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3708 //===----------------------------------------------------------------------===//
3709 // AddrSpaceCastInst Class
3710 //===----------------------------------------------------------------------===//
3712 /// \brief This class represents a conversion between pointers from
3713 /// one address space to another.
3714 class AddrSpaceCastInst : public CastInst {
3716 /// \brief Clone an identical AddrSpaceCastInst
3717 AddrSpaceCastInst *clone_impl() const override;
3720 /// \brief Constructor with insert-before-instruction semantics
3722 Value *S, ///< The value to be casted
3723 Type *Ty, ///< The type to casted to
3724 const Twine &NameStr = "", ///< A name for the new instruction
3725 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
3728 /// \brief Constructor with insert-at-end-of-block semantics
3730 Value *S, ///< The value to be casted
3731 Type *Ty, ///< The type to casted to
3732 const Twine &NameStr, ///< A name for the new instruction
3733 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3736 // Methods for support type inquiry through isa, cast, and dyn_cast:
3737 static inline bool classof(const Instruction *I) {
3738 return I->getOpcode() == AddrSpaceCast;
3740 static inline bool classof(const Value *V) {
3741 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3745 } // End llvm namespace