LLVM 23.0.0git
Instructions.h
Go to the documentation of this file.
1//===- llvm/Instructions.h - Instruction subclass definitions ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file exposes the class definitions of all of the subclasses of the
10// Instruction class. This is meant to be an easy way to get access to all
11// instruction subclasses.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_IR_INSTRUCTIONS_H
16#define LLVM_IR_INSTRUCTIONS_H
17
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/Bitfields.h"
20#include "llvm/ADT/MapVector.h"
21#include "llvm/ADT/STLExtras.h"
23#include "llvm/ADT/Twine.h"
24#include "llvm/ADT/iterator.h"
26#include "llvm/IR/CFG.h"
28#include "llvm/IR/Constant.h"
31#include "llvm/IR/InstrTypes.h"
32#include "llvm/IR/Instruction.h"
33#include "llvm/IR/Intrinsics.h"
36#include "llvm/IR/Use.h"
37#include "llvm/IR/User.h"
41#include <cassert>
42#include <cstddef>
43#include <cstdint>
44#include <iterator>
45#include <optional>
46
47namespace llvm {
48
49class APFloat;
50class APInt;
51class BasicBlock;
52class ConstantInt;
53class DataLayout;
54struct KnownBits;
55class StringRef;
56class Type;
57class Value;
58class UnreachableInst;
59
60//===----------------------------------------------------------------------===//
61// AllocaInst Class
62//===----------------------------------------------------------------------===//
63
64/// an instruction to allocate memory on the stack
66 Type *AllocatedType;
67
68 using AlignmentField = AlignmentBitfieldElementT<0>;
69 using UsedWithInAllocaField = BoolBitfieldElementT<AlignmentField::NextBit>;
71 static_assert(Bitfield::areContiguous<AlignmentField, UsedWithInAllocaField,
72 SwiftErrorField>(),
73 "Bitfields must be contiguous");
74
75protected:
76 // Note: Instruction needs to be a friend here to call cloneImpl.
77 friend class Instruction;
78
80
81public:
82 LLVM_ABI explicit AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
83 const Twine &Name, InsertPosition InsertBefore);
84
85 LLVM_ABI AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
86 InsertPosition InsertBefore);
87
88 LLVM_ABI AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
89 Align Align, const Twine &Name = "",
90 InsertPosition InsertBefore = nullptr);
91
92 /// Return true if there is an allocation size parameter to the allocation
93 /// instruction that is not 1.
94 LLVM_ABI bool isArrayAllocation() const;
95
96 /// Get the number of elements allocated. For a simple allocation of a single
97 /// element, this will return a constant 1 value.
98 const Value *getArraySize() const { return getOperand(0); }
99 Value *getArraySize() { return getOperand(0); }
100
101 /// Overload to return most specific pointer type.
105
106 /// Return the address space for the allocation.
107 unsigned getAddressSpace() const {
108 return getType()->getAddressSpace();
109 }
110
111 /// Get allocation size in bytes. Returns std::nullopt if size can't be
112 /// determined, e.g. in case of a VLA.
113 LLVM_ABI std::optional<TypeSize>
114 getAllocationSize(const DataLayout &DL) const;
115
116 /// Get allocation size in bits. Returns std::nullopt if size can't be
117 /// determined, e.g. in case of a VLA.
118 LLVM_ABI std::optional<TypeSize>
120
121 /// Return the type that is being allocated by the instruction.
122 Type *getAllocatedType() const { return AllocatedType; }
123 /// for use only in special circumstances that need to generically
124 /// transform a whole instruction (eg: IR linking and vectorization).
125 void setAllocatedType(Type *Ty) { AllocatedType = Ty; }
126
127 /// Return the alignment of the memory that is being allocated by the
128 /// instruction.
129 Align getAlign() const {
130 return Align(1ULL << getSubclassData<AlignmentField>());
131 }
132
134 setSubclassData<AlignmentField>(Log2(Align));
135 }
136
137 /// Return true if this alloca is in the entry block of the function and is a
138 /// constant size. If so, the code generator will fold it into the
139 /// prolog/epilog code, so it is basically free.
140 LLVM_ABI bool isStaticAlloca() const;
141
142 /// Return true if this alloca is used as an inalloca argument to a call. Such
143 /// allocas are never considered static even if they are in the entry block.
147
148 /// Specify whether this alloca is used to represent the arguments to a call.
149 void setUsedWithInAlloca(bool V) {
150 setSubclassData<UsedWithInAllocaField>(V);
151 }
152
153 /// Return true if this alloca is used as a swifterror argument to a call.
155 /// Specify whether this alloca is used to represent a swifterror.
156 void setSwiftError(bool V) { setSubclassData<SwiftErrorField>(V); }
157
158 // Methods for support type inquiry through isa, cast, and dyn_cast:
159 static bool classof(const Instruction *I) {
160 return (I->getOpcode() == Instruction::Alloca);
161 }
162 static bool classof(const Value *V) {
164 }
165
166private:
167 // Shadow Instruction::setInstructionSubclassData with a private forwarding
168 // method so that subclasses cannot accidentally use it.
169 template <typename Bitfield>
170 void setSubclassData(typename Bitfield::Type Value) {
172 }
173};
174
175//===----------------------------------------------------------------------===//
176// LoadInst Class
177//===----------------------------------------------------------------------===//
178
179/// An instruction for reading from memory. This uses the SubclassData field in
180/// Value to store whether or not the load is volatile.
182 using VolatileField = BoolBitfieldElementT<0>;
185 static_assert(
187 "Bitfields must be contiguous");
188
189 void AssertOK();
190
191protected:
192 // Note: Instruction needs to be a friend here to call cloneImpl.
193 friend class Instruction;
194
195 LLVM_ABI LoadInst *cloneImpl() const;
196
197public:
198 LLVM_ABI LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr,
199 InsertPosition InsertBefore);
200 LLVM_ABI LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
201 InsertPosition InsertBefore);
202 LLVM_ABI LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
203 Align Align, InsertPosition InsertBefore = nullptr);
204 LLVM_ABI LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
207 InsertPosition InsertBefore = nullptr);
208
209 /// Return true if this is a load from a volatile memory location.
211
212 /// Specify whether this is a volatile load or not.
213 void setVolatile(bool V) { setSubclassData<VolatileField>(V); }
214
215 /// Return the alignment of the access that is being performed.
216 Align getAlign() const {
217 return Align(1ULL << (getSubclassData<AlignmentField>()));
218 }
219
221 setSubclassData<AlignmentField>(Log2(Align));
222 }
223
224 /// Returns the ordering constraint of this load instruction.
228 /// Sets the ordering constraint of this load instruction. May not be Release
229 /// or AcquireRelease.
231 setSubclassData<OrderingField>(Ordering);
232 }
233
234 /// Returns the synchronization scope ID of this load instruction.
236 return SSID;
237 }
238
239 /// Sets the synchronization scope ID of this load instruction.
241 this->SSID = SSID;
242 }
243
244 /// Sets the ordering constraint and the synchronization scope ID of this load
245 /// instruction.
248 setOrdering(Ordering);
249 setSyncScopeID(SSID);
250 }
251
252 bool isSimple() const { return !isAtomic() && !isVolatile(); }
253
254 bool isUnordered() const {
257 !isVolatile();
258 }
259
261 const Value *getPointerOperand() const { return getOperand(0); }
262 static unsigned getPointerOperandIndex() { return 0U; }
264
265 /// Returns the address space of the pointer operand.
266 unsigned getPointerAddressSpace() const {
268 }
269
270 // Methods for support type inquiry through isa, cast, and dyn_cast:
271 static bool classof(const Instruction *I) {
272 return I->getOpcode() == Instruction::Load;
273 }
274 static bool classof(const Value *V) {
276 }
277
278private:
279 // Shadow Instruction::setInstructionSubclassData with a private forwarding
280 // method so that subclasses cannot accidentally use it.
281 template <typename Bitfield>
282 void setSubclassData(typename Bitfield::Type Value) {
284 }
285
286 /// The synchronization scope ID of this load instruction. Not quite enough
287 /// room in SubClassData for everything, so synchronization scope ID gets its
288 /// own field.
289 SyncScope::ID SSID;
290};
291
292//===----------------------------------------------------------------------===//
293// StoreInst Class
294//===----------------------------------------------------------------------===//
295
296/// An instruction for storing to memory.
297class StoreInst : public Instruction {
298 using VolatileField = BoolBitfieldElementT<0>;
301 static_assert(
303 "Bitfields must be contiguous");
304
305 void AssertOK();
306
307 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
308
309protected:
310 // Note: Instruction needs to be a friend here to call cloneImpl.
311 friend class Instruction;
312
314
315public:
316 LLVM_ABI StoreInst(Value *Val, Value *Ptr, InsertPosition InsertBefore);
317 LLVM_ABI StoreInst(Value *Val, Value *Ptr, bool isVolatile,
318 InsertPosition InsertBefore);
320 InsertPosition InsertBefore = nullptr);
322 AtomicOrdering Order,
324 InsertPosition InsertBefore = nullptr);
325
326 // allocate space for exactly two operands
327 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
328 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
329
330 /// Return true if this is a store to a volatile memory location.
332
333 /// Specify whether this is a volatile store or not.
334 void setVolatile(bool V) { setSubclassData<VolatileField>(V); }
335
336 /// Transparently provide more efficient getOperand methods.
338
339 Align getAlign() const {
340 return Align(1ULL << (getSubclassData<AlignmentField>()));
341 }
342
344 setSubclassData<AlignmentField>(Log2(Align));
345 }
346
347 /// Returns the ordering constraint of this store instruction.
351
352 /// Sets the ordering constraint of this store instruction. May not be
353 /// Acquire or AcquireRelease.
355 setSubclassData<OrderingField>(Ordering);
356 }
357
358 /// Returns the synchronization scope ID of this store instruction.
360 return SSID;
361 }
362
363 /// Sets the synchronization scope ID of this store instruction.
365 this->SSID = SSID;
366 }
367
368 /// Sets the ordering constraint and the synchronization scope ID of this
369 /// store instruction.
372 setOrdering(Ordering);
373 setSyncScopeID(SSID);
374 }
375
376 bool isSimple() const { return !isAtomic() && !isVolatile(); }
377
378 bool isUnordered() const {
381 !isVolatile();
382 }
383
385 const Value *getValueOperand() const { return getOperand(0); }
386
388 const Value *getPointerOperand() const { return getOperand(1); }
389 static unsigned getPointerOperandIndex() { return 1U; }
391
392 /// Returns the address space of the pointer operand.
393 unsigned getPointerAddressSpace() const {
395 }
396
397 // Methods for support type inquiry through isa, cast, and dyn_cast:
398 static bool classof(const Instruction *I) {
399 return I->getOpcode() == Instruction::Store;
400 }
401 static bool classof(const Value *V) {
403 }
404
405private:
406 // Shadow Instruction::setInstructionSubclassData with a private forwarding
407 // method so that subclasses cannot accidentally use it.
408 template <typename Bitfield>
409 void setSubclassData(typename Bitfield::Type Value) {
411 }
412
413 /// The synchronization scope ID of this store instruction. Not quite enough
414 /// room in SubClassData for everything, so synchronization scope ID gets its
415 /// own field.
416 SyncScope::ID SSID;
417};
418
419template <>
420struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
421};
422
424
425//===----------------------------------------------------------------------===//
426// FenceInst Class
427//===----------------------------------------------------------------------===//
428
429/// An instruction for ordering other memory operations.
430class FenceInst : public Instruction {
431 using OrderingField = AtomicOrderingBitfieldElementT<0>;
432
433 constexpr static IntrusiveOperandsAllocMarker AllocMarker{0};
434
435 void Init(AtomicOrdering Ordering, SyncScope::ID SSID);
436
437protected:
438 // Note: Instruction needs to be a friend here to call cloneImpl.
439 friend class Instruction;
440
442
443public:
444 // Ordering may only be Acquire, Release, AcquireRelease, or
445 // SequentiallyConsistent.
448 InsertPosition InsertBefore = nullptr);
449
450 // allocate space for exactly zero operands
451 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
452 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
453
454 /// Returns the ordering constraint of this fence instruction.
458
459 /// Sets the ordering constraint of this fence instruction. May only be
460 /// Acquire, Release, AcquireRelease, or SequentiallyConsistent.
462 setSubclassData<OrderingField>(Ordering);
463 }
464
465 /// Returns the synchronization scope ID of this fence instruction.
467 return SSID;
468 }
469
470 /// Sets the synchronization scope ID of this fence instruction.
472 this->SSID = SSID;
473 }
474
475 // Methods for support type inquiry through isa, cast, and dyn_cast:
476 static bool classof(const Instruction *I) {
477 return I->getOpcode() == Instruction::Fence;
478 }
479 static bool classof(const Value *V) {
481 }
482
483private:
484 // Shadow Instruction::setInstructionSubclassData with a private forwarding
485 // method so that subclasses cannot accidentally use it.
486 template <typename Bitfield>
487 void setSubclassData(typename Bitfield::Type Value) {
489 }
490
491 /// The synchronization scope ID of this fence instruction. Not quite enough
492 /// room in SubClassData for everything, so synchronization scope ID gets its
493 /// own field.
494 SyncScope::ID SSID;
495};
496
497//===----------------------------------------------------------------------===//
498// AtomicCmpXchgInst Class
499//===----------------------------------------------------------------------===//
500
501/// An instruction that atomically checks whether a
502/// specified value is in a memory location, and, if it is, stores a new value
503/// there. The value returned by this instruction is a pair containing the
504/// original value as first element, and an i1 indicating success (true) or
505/// failure (false) as second element.
506///
508 void Init(Value *Ptr, Value *Cmp, Value *NewVal, Align Align,
509 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
510 SyncScope::ID SSID);
511
512 template <unsigned Offset>
513 using AtomicOrderingBitfieldElement =
516
517 constexpr static IntrusiveOperandsAllocMarker AllocMarker{3};
518
519protected:
520 // Note: Instruction needs to be a friend here to call cloneImpl.
521 friend class Instruction;
522
524
525public:
526 LLVM_ABI AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
527 Align Alignment, AtomicOrdering SuccessOrdering,
528 AtomicOrdering FailureOrdering, SyncScope::ID SSID,
529 InsertPosition InsertBefore = nullptr);
530
531 // allocate space for exactly three operands
532 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
533 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
534
543 static_assert(
546 "Bitfields must be contiguous");
547
548 /// Return the alignment of the memory that is being allocated by the
549 /// instruction.
550 Align getAlign() const {
551 return Align(1ULL << getSubclassData<AlignmentField>());
552 }
553
555 setSubclassData<AlignmentField>(Log2(Align));
556 }
557
558 /// Return true if this is a cmpxchg from a volatile memory
559 /// location.
560 ///
562
563 /// Specify whether this is a volatile cmpxchg.
564 ///
565 void setVolatile(bool V) { setSubclassData<VolatileField>(V); }
566
567 /// Return true if this cmpxchg may spuriously fail.
568 bool isWeak() const { return getSubclassData<WeakField>(); }
569
570 void setWeak(bool IsWeak) { setSubclassData<WeakField>(IsWeak); }
571
572 /// Transparently provide more efficient getOperand methods.
574
576 return Ordering != AtomicOrdering::NotAtomic &&
577 Ordering != AtomicOrdering::Unordered;
578 }
579
581 return Ordering != AtomicOrdering::NotAtomic &&
582 Ordering != AtomicOrdering::Unordered &&
583 Ordering != AtomicOrdering::AcquireRelease &&
584 Ordering != AtomicOrdering::Release;
585 }
586
587 /// Returns the success ordering constraint of this cmpxchg instruction.
591
592 /// Sets the success ordering constraint of this cmpxchg instruction.
594 assert(isValidSuccessOrdering(Ordering) &&
595 "invalid CmpXchg success ordering");
596 setSubclassData<SuccessOrderingField>(Ordering);
597 }
598
599 /// Returns the failure ordering constraint of this cmpxchg instruction.
603
604 /// Sets the failure ordering constraint of this cmpxchg instruction.
606 assert(isValidFailureOrdering(Ordering) &&
607 "invalid CmpXchg failure ordering");
608 setSubclassData<FailureOrderingField>(Ordering);
609 }
610
611 /// Returns a single ordering which is at least as strong as both the
612 /// success and failure orderings for this cmpxchg.
624
625 /// Returns the synchronization scope ID of this cmpxchg instruction.
627 return SSID;
628 }
629
630 /// Sets the synchronization scope ID of this cmpxchg instruction.
632 this->SSID = SSID;
633 }
634
636 const Value *getPointerOperand() const { return getOperand(0); }
637 static unsigned getPointerOperandIndex() { return 0U; }
638
640 const Value *getCompareOperand() const { return getOperand(1); }
641
643 const Value *getNewValOperand() const { return getOperand(2); }
644
645 /// Returns the address space of the pointer operand.
646 unsigned getPointerAddressSpace() const {
648 }
649
650 /// Returns the strongest permitted ordering on failure, given the
651 /// desired ordering on success.
652 ///
653 /// If the comparison in a cmpxchg operation fails, there is no atomic store
654 /// so release semantics cannot be provided. So this function drops explicit
655 /// Release requests from the AtomicOrdering. A SequentiallyConsistent
656 /// operation would remain SequentiallyConsistent.
657 static AtomicOrdering
659 switch (SuccessOrdering) {
660 default:
661 llvm_unreachable("invalid cmpxchg success ordering");
670 }
671 }
672
673 // Methods for support type inquiry through isa, cast, and dyn_cast:
674 static bool classof(const Instruction *I) {
675 return I->getOpcode() == Instruction::AtomicCmpXchg;
676 }
677 static bool classof(const Value *V) {
679 }
680
681private:
682 // Shadow Instruction::setInstructionSubclassData with a private forwarding
683 // method so that subclasses cannot accidentally use it.
684 template <typename Bitfield>
685 void setSubclassData(typename Bitfield::Type Value) {
687 }
688
689 /// The synchronization scope ID of this cmpxchg instruction. Not quite
690 /// enough room in SubClassData for everything, so synchronization scope ID
691 /// gets its own field.
692 SyncScope::ID SSID;
693};
694
695template <>
697 public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
698};
699
701
702//===----------------------------------------------------------------------===//
703// AtomicRMWInst Class
704//===----------------------------------------------------------------------===//
705
706/// an instruction that atomically reads a memory location,
707/// combines it with another value, and then stores the result back. Returns
708/// the old value.
709///
711protected:
712 // Note: Instruction needs to be a friend here to call cloneImpl.
713 friend class Instruction;
714
716
717public:
718 /// This enumeration lists the possible modifications atomicrmw can make. In
719 /// the descriptions, 'p' is the pointer to the instruction's memory location,
720 /// 'old' is the initial value of *p, and 'v' is the other value passed to the
721 /// instruction. These instructions always return 'old'.
722 enum BinOp : unsigned {
723 /// *p = v
725 /// *p = old + v
727 /// *p = old - v
729 /// *p = old & v
731 /// *p = ~(old & v)
733 /// *p = old | v
735 /// *p = old ^ v
737 /// *p = old >signed v ? old : v
739 /// *p = old <signed v ? old : v
741 /// *p = old >unsigned v ? old : v
743 /// *p = old <unsigned v ? old : v
745
746 /// *p = old + v
748
749 /// *p = old - v
751
752 /// *p = maxnum(old, v)
753 /// \p maxnum matches the behavior of \p llvm.maxnum.*.
755
756 /// *p = minnum(old, v)
757 /// \p minnum matches the behavior of \p llvm.minnum.*.
759
760 /// *p = maximum(old, v)
761 /// \p maximum matches the behavior of \p llvm.maximum.*.
763
764 /// *p = minimum(old, v)
765 /// \p minimum matches the behavior of \p llvm.minimum.*.
767
768 /// *p = maximumnum(old, v)
769 /// \p maximumnum matches the behavior of \p llvm.maximumnum.*.
771
772 /// *p = minimumnum(old, v)
773 /// \p minimumnum matches the behavior of \p llvm.minimumnum.*.
775
776 /// Increment one up to a maximum value.
777 /// *p = (old u>= v) ? 0 : (old + 1)
779
780 /// Decrement one until a minimum value or zero.
781 /// *p = ((old == 0) || (old u> v)) ? v : (old - 1)
783
784 /// Subtract only if no unsigned overflow.
785 /// *p = (old u>= v) ? old - v : old
787
788 /// *p = usub.sat(old, v)
789 /// \p usub.sat matches the behavior of \p llvm.usub.sat.*.
791
795 };
796
797private:
798 template <unsigned Offset>
799 using AtomicOrderingBitfieldElement =
802
803 template <unsigned Offset>
804 using BinOpBitfieldElement =
806
807 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
808
809public:
810 LLVM_ABI AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
811 Align Alignment, AtomicOrdering Ordering,
812 SyncScope::ID SSID,
813 InsertPosition InsertBefore = nullptr);
814
815 // allocate space for exactly two operands
816 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
817 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
818
822 using OperationField = BinOpBitfieldElement<AtomicOrderingField::NextBit>;
826 "Bitfields must be contiguous");
827
829
830 LLVM_ABI static StringRef getOperationName(BinOp Op);
831
832 static bool isFPOperation(BinOp Op) {
833 switch (Op) {
842 return true;
843 default:
844 return false;
845 }
846 }
847
849 setSubclassData<OperationField>(Operation);
850 }
851
852 /// Return the alignment of the memory that is being allocated by the
853 /// instruction.
854 Align getAlign() const {
855 return Align(1ULL << getSubclassData<AlignmentField>());
856 }
857
859 setSubclassData<AlignmentField>(Log2(Align));
860 }
861
862 /// Return true if this is a RMW on a volatile memory location.
863 ///
865
866 /// Specify whether this is a volatile RMW or not.
867 ///
868 void setVolatile(bool V) { setSubclassData<VolatileField>(V); }
869
870 /// Transparently provide more efficient getOperand methods.
872
873 /// Returns the ordering constraint of this rmw instruction.
877
878 /// Sets the ordering constraint of this rmw instruction.
880 assert(Ordering != AtomicOrdering::NotAtomic &&
881 "atomicrmw instructions can only be atomic.");
882 assert(Ordering != AtomicOrdering::Unordered &&
883 "atomicrmw instructions cannot be unordered.");
884 setSubclassData<AtomicOrderingField>(Ordering);
885 }
886
887 /// Returns the synchronization scope ID of this rmw instruction.
889 return SSID;
890 }
891
892 /// Sets the synchronization scope ID of this rmw instruction.
894 this->SSID = SSID;
895 }
896
898 const Value *getPointerOperand() const { return getOperand(0); }
899 static unsigned getPointerOperandIndex() { return 0U; }
900
902 const Value *getValOperand() const { return getOperand(1); }
903
904 /// Returns the address space of the pointer operand.
905 unsigned getPointerAddressSpace() const {
907 }
908
910 return isFPOperation(getOperation());
911 }
912
913 // Methods for support type inquiry through isa, cast, and dyn_cast:
914 static bool classof(const Instruction *I) {
915 return I->getOpcode() == Instruction::AtomicRMW;
916 }
917 static bool classof(const Value *V) {
919 }
920
921private:
922 void Init(BinOp Operation, Value *Ptr, Value *Val, Align Align,
923 AtomicOrdering Ordering, SyncScope::ID SSID);
924
925 // Shadow Instruction::setInstructionSubclassData with a private forwarding
926 // method so that subclasses cannot accidentally use it.
927 template <typename Bitfield>
928 void setSubclassData(typename Bitfield::Type Value) {
930 }
931
932 /// The synchronization scope ID of this rmw instruction. Not quite enough
933 /// room in SubClassData for everything, so synchronization scope ID gets its
934 /// own field.
935 SyncScope::ID SSID;
936};
937
938template <>
940 : public FixedNumOperandTraits<AtomicRMWInst,2> {
941};
942
944
945//===----------------------------------------------------------------------===//
946// GetElementPtrInst Class
947//===----------------------------------------------------------------------===//
948
949// checkGEPType - Simple wrapper function to give a better assertion failure
950// message on bad indexes for a gep instruction.
951//
953 assert(Ty && "Invalid GetElementPtrInst indices for type!");
954 return Ty;
955}
956
957/// an instruction for type-safe pointer arithmetic to
958/// access elements of arrays and structs
959///
960class GetElementPtrInst : public Instruction {
961 Type *SourceElementType;
962 Type *ResultElementType;
963
964 GetElementPtrInst(const GetElementPtrInst &GEPI, AllocInfo AllocInfo);
965
966 /// Constructors - Create a getelementptr instruction with a base pointer an
967 /// list of indices. The first and second ctor can optionally insert before an
968 /// existing instruction, the third appends the new instruction to the
969 /// specified BasicBlock.
970 inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
972 const Twine &NameStr, InsertPosition InsertBefore);
973
974 LLVM_ABI void init(Value *Ptr, ArrayRef<Value *> IdxList,
975 const Twine &NameStr);
976
977protected:
978 // Note: Instruction needs to be a friend here to call cloneImpl.
979 friend class Instruction;
980
981 LLVM_ABI GetElementPtrInst *cloneImpl() const;
982
983public:
984 static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
985 ArrayRef<Value *> IdxList,
986 const Twine &NameStr = "",
987 InsertPosition InsertBefore = nullptr) {
988 unsigned Values = 1 + unsigned(IdxList.size());
989 assert(PointeeType && "Must specify element type");
990 IntrusiveOperandsAllocMarker AllocMarker{Values};
991 return new (AllocMarker) GetElementPtrInst(
992 PointeeType, Ptr, IdxList, AllocMarker, NameStr, InsertBefore);
993 }
994
995 static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
997 const Twine &NameStr = "",
998 InsertPosition InsertBefore = nullptr) {
999 GetElementPtrInst *GEP =
1000 Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore);
1001 GEP->setNoWrapFlags(NW);
1002 return GEP;
1003 }
1004
1005 /// Create an "inbounds" getelementptr. See the documentation for the
1006 /// "inbounds" flag in LangRef.html for details.
1007 static GetElementPtrInst *
1008 CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef<Value *> IdxList,
1009 const Twine &NameStr = "",
1010 InsertPosition InsertBefore = nullptr) {
1011 return Create(PointeeType, Ptr, IdxList, GEPNoWrapFlags::inBounds(),
1012 NameStr, InsertBefore);
1013 }
1014
1015 /// Transparently provide more efficient getOperand methods.
1017
1018 Type *getSourceElementType() const { return SourceElementType; }
1019
1020 void setSourceElementType(Type *Ty) { SourceElementType = Ty; }
1021 void setResultElementType(Type *Ty) { ResultElementType = Ty; }
1022
1024 return ResultElementType;
1025 }
1026
1027 /// Returns the address space of this instruction's pointer type.
1028 unsigned getAddressSpace() const {
1029 // Note that this is always the same as the pointer operand's address space
1030 // and that is cheaper to compute, so cheat here.
1031 return getPointerAddressSpace();
1032 }
1033
1034 /// Returns the result type of a getelementptr with the given source
1035 /// element type and indexes.
1036 ///
1037 /// Null is returned if the indices are invalid for the specified
1038 /// source element type.
1039 LLVM_ABI static Type *getIndexedType(Type *Ty, ArrayRef<Value *> IdxList);
1041 LLVM_ABI static Type *getIndexedType(Type *Ty, ArrayRef<uint64_t> IdxList);
1042
1043 /// Return the type of the element at the given index of an indexable
1044 /// type. This is equivalent to "getIndexedType(Agg, {Zero, Idx})".
1045 ///
1046 /// Returns null if the type can't be indexed, or the given index is not
1047 /// legal for the given type.
1048 LLVM_ABI static Type *getTypeAtIndex(Type *Ty, Value *Idx);
1049 LLVM_ABI static Type *getTypeAtIndex(Type *Ty, uint64_t Idx);
1050
1051 inline op_iterator idx_begin() { return op_begin()+1; }
1052 inline const_op_iterator idx_begin() const { return op_begin()+1; }
1053 inline op_iterator idx_end() { return op_end(); }
1054 inline const_op_iterator idx_end() const { return op_end(); }
1055
1059
1061 return make_range(idx_begin(), idx_end());
1062 }
1063
1065 return getOperand(0);
1066 }
1067 const Value *getPointerOperand() const {
1068 return getOperand(0);
1069 }
1070 static unsigned getPointerOperandIndex() {
1071 return 0U; // get index for modifying correct operand.
1072 }
1073
1074 /// Method to return the pointer operand as a
1075 /// PointerType.
1077 return getPointerOperand()->getType();
1078 }
1079
1080 /// Returns the address space of the pointer operand.
1081 unsigned getPointerAddressSpace() const {
1083 }
1084
1085 /// Returns the pointer type returned by the GEP
1086 /// instruction, which may be a vector of pointers.
1088 // Vector GEP
1089 Type *Ty = Ptr->getType();
1090 if (Ty->isVectorTy())
1091 return Ty;
1092
1093 for (Value *Index : IdxList)
1094 if (auto *IndexVTy = dyn_cast<VectorType>(Index->getType())) {
1095 ElementCount EltCount = IndexVTy->getElementCount();
1096 return VectorType::get(Ty, EltCount);
1097 }
1098 // Scalar GEP
1099 return Ty;
1100 }
1101
1102 unsigned getNumIndices() const { // Note: always non-negative
1103 return getNumOperands() - 1;
1104 }
1105
1106 bool hasIndices() const {
1107 return getNumOperands() > 1;
1108 }
1109
1110 /// Return true if all of the indices of this GEP are
1111 /// zeros. If so, the result pointer and the first operand have the same
1112 /// value, just potentially different types.
1113 LLVM_ABI bool hasAllZeroIndices() const;
1114
1115 /// Return true if all of the indices of this GEP are
1116 /// constant integers. If so, the result pointer and the first operand have
1117 /// a constant offset between them.
1118 LLVM_ABI bool hasAllConstantIndices() const;
1119
1120 /// Set nowrap flags for GEP instruction.
1122
1123 /// Set or clear the inbounds flag on this GEP instruction.
1124 /// See LangRef.html for the meaning of inbounds on a getelementptr.
1125 /// TODO: Remove this method in favor of setNoWrapFlags().
1126 LLVM_ABI void setIsInBounds(bool b = true);
1127
1128 /// Get the nowrap flags for the GEP instruction.
1130
1131 /// Determine whether the GEP has the inbounds flag.
1132 LLVM_ABI bool isInBounds() const;
1133
1134 /// Determine whether the GEP has the nusw flag.
1135 LLVM_ABI bool hasNoUnsignedSignedWrap() const;
1136
1137 /// Determine whether the GEP has the nuw flag.
1138 LLVM_ABI bool hasNoUnsignedWrap() const;
1139
1140 /// Accumulate the constant address offset of this GEP if possible.
1141 ///
1142 /// This routine accepts an APInt into which it will accumulate the constant
1143 /// offset of this GEP if the GEP is in fact constant. If the GEP is not
1144 /// all-constant, it returns false and the value of the offset APInt is
1145 /// undefined (it is *not* preserved!). The APInt passed into this routine
1146 /// must be at least as wide as the IntPtr type for the address space of
1147 /// the base GEP pointer.
1149 APInt &Offset) const;
1150 LLVM_ABI bool
1151 collectOffset(const DataLayout &DL, unsigned BitWidth,
1152 SmallMapVector<Value *, APInt, 4> &VariableOffsets,
1153 APInt &ConstantOffset) const;
1154 // Methods for support type inquiry through isa, cast, and dyn_cast:
1155 static bool classof(const Instruction *I) {
1156 return (I->getOpcode() == Instruction::GetElementPtr);
1157 }
1158 static bool classof(const Value *V) {
1160 }
1161};
1162
1163template <>
1165 : public VariadicOperandTraits<GetElementPtrInst> {};
1166
1167GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
1168 ArrayRef<Value *> IdxList,
1169 AllocInfo AllocInfo, const Twine &NameStr,
1170 InsertPosition InsertBefore)
1171 : Instruction(getGEPReturnType(Ptr, IdxList), GetElementPtr, AllocInfo,
1172 InsertBefore),
1173 SourceElementType(PointeeType),
1174 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1175 init(Ptr, IdxList, NameStr);
1176}
1177
1178DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
1179
1180//===----------------------------------------------------------------------===//
1181// ICmpInst Class
1182//===----------------------------------------------------------------------===//
1183
1184/// This instruction compares its operands according to the predicate given
1185/// to the constructor. It only operates on integers or pointers. The operands
1186/// must be identical types.
1187/// Represent an integer comparison operator.
1188class ICmpInst: public CmpInst {
1189 void AssertOK() {
1191 "Invalid ICmp predicate value");
1192 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1193 "Both operands to ICmp instruction are not of the same type!");
1194 // Check that the operands are the right type
1195 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
1196 getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
1197 "Invalid operand types for ICmp instruction");
1198 }
1199
1200 enum { SameSign = (1 << 0) };
1201
1202protected:
1203 // Note: Instruction needs to be a friend here to call cloneImpl.
1204 friend class Instruction;
1205
1206 /// Clone an identical ICmpInst
1207 LLVM_ABI ICmpInst *cloneImpl() const;
1208
1209public:
1210 /// Constructor with insertion semantics.
1211 ICmpInst(InsertPosition InsertBefore, ///< Where to insert
1212 Predicate pred, ///< The predicate to use for the comparison
1213 Value *LHS, ///< The left-hand-side of the expression
1214 Value *RHS, ///< The right-hand-side of the expression
1215 const Twine &NameStr = "" ///< Name of the instruction
1216 )
1217 : CmpInst(makeCmpResultType(LHS->getType()), Instruction::ICmp, pred, LHS,
1218 RHS, NameStr, InsertBefore) {
1219#ifndef NDEBUG
1220 AssertOK();
1221#endif
1222 }
1223
1224 /// Constructor with no-insertion semantics
1226 Predicate pred, ///< The predicate to use for the comparison
1227 Value *LHS, ///< The left-hand-side of the expression
1228 Value *RHS, ///< The right-hand-side of the expression
1229 const Twine &NameStr = "" ///< Name of the instruction
1231 Instruction::ICmp, pred, LHS, RHS, NameStr) {
1232#ifndef NDEBUG
1233 AssertOK();
1234#endif
1235 }
1236
1237 /// @returns the predicate along with samesign information.
1239 return {getPredicate(), hasSameSign()};
1240 }
1241
1242 /// @returns the inverse predicate along with samesign information: static
1243 /// variant.
1245 return {getInversePredicate(Pred), Pred.hasSameSign()};
1246 }
1247
1248 /// @returns the inverse predicate along with samesign information.
1252
1253 /// @returns the swapped predicate along with samesign information: static
1254 /// variant.
1256 return {getSwappedPredicate(Pred), Pred.hasSameSign()};
1257 }
1258
1259 /// @returns the swapped predicate along with samesign information.
1263
1264 /// @returns the non-strict predicate along with samesign information: static
1265 /// variant.
1267 return {getNonStrictPredicate(Pred), Pred.hasSameSign()};
1268 }
1269
1270 /// For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
1271 /// @returns the non-strict predicate along with samesign information.
1275
1276 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
1277 /// @returns the predicate that would be the result if the operand were
1278 /// regarded as signed.
1279 /// Return the signed version of the predicate.
1283
1284 /// Return the signed version of the predicate: static variant.
1285 LLVM_ABI static Predicate getSignedPredicate(Predicate Pred);
1286
1287 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
1288 /// @returns the predicate that would be the result if the operand were
1289 /// regarded as unsigned.
1290 /// Return the unsigned version of the predicate.
1294
1295 /// Return the unsigned version of the predicate: static variant.
1296 LLVM_ABI static Predicate getUnsignedPredicate(Predicate Pred);
1297
1298 /// For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->EQ
1299 /// @returns the unsigned version of the signed predicate pred or
1300 /// the signed version of the signed predicate pred.
1301 /// Static variant.
1302 LLVM_ABI static Predicate getFlippedSignednessPredicate(Predicate Pred);
1303
1304 /// For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->EQ
1305 /// @returns the unsigned version of the signed predicate pred or
1306 /// the signed version of the signed predicate pred.
1310
1311 /// Determine if Pred1 implies Pred2 is true, false, or if nothing can be
1312 /// inferred about the implication, when two compares have matching operands.
1313 LLVM_ABI static std::optional<bool>
1314 isImpliedByMatchingCmp(CmpPredicate Pred1, CmpPredicate Pred2);
1315
1316 void setSameSign(bool B = true) {
1317 SubclassOptionalData = (SubclassOptionalData & ~SameSign) | (B * SameSign);
1318 }
1319
1320 /// An icmp instruction, which can be marked as "samesign", indicating that
1321 /// the two operands have the same sign. This means that we can convert
1322 /// "slt" to "ult" and vice versa, which enables more optimizations.
1323 bool hasSameSign() const { return SubclassOptionalData & SameSign; }
1324
1325 /// Return true if this predicate is either EQ or NE. This also
1326 /// tests for commutativity.
1327 static bool isEquality(Predicate P) {
1328 return P == ICMP_EQ || P == ICMP_NE;
1329 }
1330
1331 /// Return true if this predicate is either EQ or NE. This also
1332 /// tests for commutativity.
1333 bool isEquality() const {
1334 return isEquality(getPredicate());
1335 }
1336
1337 /// @returns true if the predicate is commutative
1338 /// Determine if this relation is commutative.
1339 static bool isCommutative(Predicate P) { return isEquality(P); }
1340
1341 /// @returns true if the predicate of this ICmpInst is commutative
1342 /// Determine if this relation is commutative.
1343 bool isCommutative() const { return isCommutative(getPredicate()); }
1344
1345 /// Return true if the predicate is relational (not EQ or NE).
1346 ///
1347 bool isRelational() const {
1348 return !isEquality();
1349 }
1350
1351 /// Return true if the predicate is relational (not EQ or NE).
1352 ///
1353 static bool isRelational(Predicate P) {
1354 return !isEquality(P);
1355 }
1356
1357 /// Return true if the predicate is SGT or UGT.
1358 ///
1359 static bool isGT(Predicate P) {
1360 return P == ICMP_SGT || P == ICMP_UGT;
1361 }
1362
1363 /// Return true if the predicate is SLT or ULT.
1364 ///
1365 static bool isLT(Predicate P) {
1366 return P == ICMP_SLT || P == ICMP_ULT;
1367 }
1368
1369 /// Return true if the predicate is SGE or UGE.
1370 ///
1371 static bool isGE(Predicate P) {
1372 return P == ICMP_SGE || P == ICMP_UGE;
1373 }
1374
1375 /// Return true if the predicate is SLE or ULE.
1376 ///
1377 static bool isLE(Predicate P) {
1378 return P == ICMP_SLE || P == ICMP_ULE;
1379 }
1380
1381 /// Returns the sequence of all ICmp predicates.
1382 ///
1383 static auto predicates() { return ICmpPredicates(); }
1384
1385 /// Exchange the two operands to this instruction in such a way that it does
1386 /// not modify the semantics of the instruction. The predicate value may be
1387 /// changed to retain the same result if the predicate is order dependent
1388 /// (e.g. ult).
1389 /// Swap operands and adjust predicate.
1392 Op<0>().swap(Op<1>());
1393 }
1394
1395 /// Return result of `LHS Pred RHS` comparison.
1396 LLVM_ABI static bool compare(const APInt &LHS, const APInt &RHS,
1397 ICmpInst::Predicate Pred);
1398
1399 /// Return result of `LHS Pred RHS`, if it can be determined from the
1400 /// KnownBits. Otherwise return nullopt.
1401 LLVM_ABI static std::optional<bool>
1402 compare(const KnownBits &LHS, const KnownBits &RHS, ICmpInst::Predicate Pred);
1403
1404 // Methods for support type inquiry through isa, cast, and dyn_cast:
1405 static bool classof(const Instruction *I) {
1406 return I->getOpcode() == Instruction::ICmp;
1407 }
1408 static bool classof(const Value *V) {
1410 }
1411};
1412
1413//===----------------------------------------------------------------------===//
1414// FCmpInst Class
1415//===----------------------------------------------------------------------===//
1416
1417/// This instruction compares its operands according to the predicate given
1418/// to the constructor. It only operates on floating point values or packed
1419/// vectors of floating point values. The operands must be identical types.
1420/// Represents a floating point comparison operator.
1421class FCmpInst: public CmpInst {
1422 void AssertOK() {
1423 assert(isFPPredicate() && "Invalid FCmp predicate value");
1424 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1425 "Both operands to FCmp instruction are not of the same type!");
1426 // Check that the operands are the right type
1427 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1428 "Invalid operand types for FCmp instruction");
1429 }
1430
1431protected:
1432 // Note: Instruction needs to be a friend here to call cloneImpl.
1433 friend class Instruction;
1434
1435 /// Clone an identical FCmpInst
1436 LLVM_ABI FCmpInst *cloneImpl() const;
1437
1438public:
1439 /// Constructor with insertion semantics.
1440 FCmpInst(InsertPosition InsertBefore, ///< Where to insert
1441 Predicate pred, ///< The predicate to use for the comparison
1442 Value *LHS, ///< The left-hand-side of the expression
1443 Value *RHS, ///< The right-hand-side of the expression
1444 const Twine &NameStr = "" ///< Name of the instruction
1445 )
1446 : CmpInst(makeCmpResultType(LHS->getType()), Instruction::FCmp, pred, LHS,
1447 RHS, NameStr, InsertBefore) {
1448 AssertOK();
1449 }
1450
1451 /// Constructor with no-insertion semantics
1452 FCmpInst(Predicate Pred, ///< The predicate to use for the comparison
1453 Value *LHS, ///< The left-hand-side of the expression
1454 Value *RHS, ///< The right-hand-side of the expression
1455 const Twine &NameStr = "", ///< Name of the instruction
1456 Instruction *FlagsSource = nullptr)
1457 : CmpInst(makeCmpResultType(LHS->getType()), Instruction::FCmp, Pred, LHS,
1458 RHS, NameStr, nullptr, FlagsSource) {
1459 AssertOK();
1460 }
1461
1462 /// @returns true if the predicate is EQ or NE.
1463 /// Determine if this is an equality predicate.
1464 static bool isEquality(Predicate Pred) {
1465 return Pred == FCMP_OEQ || Pred == FCMP_ONE || Pred == FCMP_UEQ ||
1466 Pred == FCMP_UNE;
1467 }
1468
1469 /// @returns true if the predicate of this instruction is EQ or NE.
1470 /// Determine if this is an equality predicate.
1471 bool isEquality() const { return isEquality(getPredicate()); }
1472
1473 /// @returns true if the predicate is commutative.
1474 /// Determine if this is a commutative predicate.
1475 static bool isCommutative(Predicate Pred) {
1476 return isEquality(Pred) || Pred == FCMP_FALSE || Pred == FCMP_TRUE ||
1477 Pred == FCMP_ORD || Pred == FCMP_UNO;
1478 }
1479
1480 /// @returns true if the predicate of this instruction is commutative.
1481 /// Determine if this is a commutative predicate.
1482 bool isCommutative() const { return isCommutative(getPredicate()); }
1483
1484 /// @returns true if the predicate is relational (not EQ or NE).
1485 /// Determine if this a relational predicate.
1486 bool isRelational() const { return !isEquality(); }
1487
1488 /// Exchange the two operands to this instruction in such a way that it does
1489 /// not modify the semantics of the instruction. The predicate value may be
1490 /// changed to retain the same result if the predicate is order dependent
1491 /// (e.g. ult).
1492 /// Swap operands and adjust predicate.
1495 Op<0>().swap(Op<1>());
1496 }
1497
1498 /// Returns the sequence of all FCmp predicates.
1499 ///
1500 static auto predicates() { return FCmpPredicates(); }
1501
1502 /// Return result of `LHS Pred RHS` comparison.
1503 LLVM_ABI static bool compare(const APFloat &LHS, const APFloat &RHS,
1504 FCmpInst::Predicate Pred);
1505
1506 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1507 static bool classof(const Instruction *I) {
1508 return I->getOpcode() == Instruction::FCmp;
1509 }
1510 static bool classof(const Value *V) {
1512 }
1513};
1514
1515//===----------------------------------------------------------------------===//
1516/// This class represents a function call, abstracting a target
1517/// machine's calling convention. This class uses low bit of the SubClassData
1518/// field to indicate whether or not this is a tail call. The rest of the bits
1519/// hold the calling convention of the call.
1520///
1521class CallInst : public CallBase {
1522 CallInst(const CallInst &CI, AllocInfo AllocInfo);
1523
1524 /// Construct a CallInst from a range of arguments
1525 inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1526 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1527 AllocInfo AllocInfo, InsertPosition InsertBefore);
1528
1529 inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1530 const Twine &NameStr, AllocInfo AllocInfo,
1531 InsertPosition InsertBefore)
1532 : CallInst(Ty, Func, Args, {}, NameStr, AllocInfo, InsertBefore) {}
1533
1534 LLVM_ABI explicit CallInst(FunctionType *Ty, Value *F, const Twine &NameStr,
1535 AllocInfo AllocInfo, InsertPosition InsertBefore);
1536
1537 LLVM_ABI void init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
1538 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
1539 void init(FunctionType *FTy, Value *Func, const Twine &NameStr);
1540
1541 /// Compute the number of operands to allocate.
1542 static unsigned ComputeNumOperands(unsigned NumArgs,
1543 unsigned NumBundleInputs = 0) {
1544 // We need one operand for the called function, plus the input operand
1545 // counts provided.
1546 return 1 + NumArgs + NumBundleInputs;
1547 }
1548
1549protected:
1550 // Note: Instruction needs to be a friend here to call cloneImpl.
1551 friend class Instruction;
1552
1553 LLVM_ABI CallInst *cloneImpl() const;
1554
1555public:
1556 static CallInst *Create(FunctionType *Ty, Value *F, const Twine &NameStr = "",
1557 InsertPosition InsertBefore = nullptr) {
1558 IntrusiveOperandsAllocMarker AllocMarker{ComputeNumOperands(0)};
1559 return new (AllocMarker)
1560 CallInst(Ty, F, NameStr, AllocMarker, InsertBefore);
1561 }
1562
1563 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1564 const Twine &NameStr,
1565 InsertPosition InsertBefore = nullptr) {
1566 IntrusiveOperandsAllocMarker AllocMarker{ComputeNumOperands(Args.size())};
1567 return new (AllocMarker)
1568 CallInst(Ty, Func, Args, {}, NameStr, AllocMarker, InsertBefore);
1569 }
1570
1571 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1572 ArrayRef<OperandBundleDef> Bundles = {},
1573 const Twine &NameStr = "",
1574 InsertPosition InsertBefore = nullptr) {
1575 IntrusiveOperandsAndDescriptorAllocMarker AllocMarker{
1576 ComputeNumOperands(unsigned(Args.size()), CountBundleInputs(Bundles)),
1577 unsigned(Bundles.size() * sizeof(BundleOpInfo))};
1578
1579 return new (AllocMarker)
1580 CallInst(Ty, Func, Args, Bundles, NameStr, AllocMarker, InsertBefore);
1581 }
1582
1583 static CallInst *Create(FunctionCallee Func, const Twine &NameStr = "",
1584 InsertPosition InsertBefore = nullptr) {
1585 return Create(Func.getFunctionType(), Func.getCallee(), NameStr,
1586 InsertBefore);
1587 }
1588
1589 static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
1590 ArrayRef<OperandBundleDef> Bundles = {},
1591 const Twine &NameStr = "",
1592 InsertPosition InsertBefore = nullptr) {
1593 return Create(Func.getFunctionType(), Func.getCallee(), Args, Bundles,
1594 NameStr, InsertBefore);
1595 }
1596
1597 static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
1598 const Twine &NameStr,
1599 InsertPosition InsertBefore = nullptr) {
1600 return Create(Func.getFunctionType(), Func.getCallee(), Args, NameStr,
1601 InsertBefore);
1602 }
1603
1604 /// Create a clone of \p CI with a different set of operand bundles and
1605 /// insert it before \p InsertBefore.
1606 ///
1607 /// The returned call instruction is identical \p CI in every way except that
1608 /// the operand bundles for the new instruction are set to the operand bundles
1609 /// in \p Bundles.
1610 LLVM_ABI static CallInst *Create(CallInst *CI,
1612 InsertPosition InsertPt = nullptr);
1613
1614 // Note that 'musttail' implies 'tail'.
1622
1624 static_assert(
1626 "Bitfields must be contiguous");
1627
1631
1632 bool isTailCall() const {
1634 return Kind == TCK_Tail || Kind == TCK_MustTail;
1635 }
1636
1637 bool isMustTailCall() const { return getTailCallKind() == TCK_MustTail; }
1638
1639 bool isNoTailCall() const { return getTailCallKind() == TCK_NoTail; }
1640
1642 setSubclassData<TailCallKindField>(TCK);
1643 }
1644
1645 void setTailCall(bool IsTc = true) {
1647 }
1648
1649 /// Return true if the call can return twice
1650 bool canReturnTwice() const { return hasFnAttr(Attribute::ReturnsTwice); }
1651 void setCanReturnTwice() { addFnAttr(Attribute::ReturnsTwice); }
1652
1653 /// Return true if the call is for a noreturn trap intrinsic.
1655 switch (getIntrinsicID()) {
1656 case Intrinsic::trap:
1657 case Intrinsic::ubsantrap:
1658 return !hasFnAttr("trap-func-name");
1659 default:
1660 return false;
1661 }
1662 }
1663
1664 // Methods for support type inquiry through isa, cast, and dyn_cast:
1665 static bool classof(const Instruction *I) {
1666 return I->getOpcode() == Instruction::Call;
1667 }
1668 static bool classof(const Value *V) {
1670 }
1671
1672 /// Updates profile metadata by scaling it by \p S / \p T.
1674
1675private:
1676 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1677 // method so that subclasses cannot accidentally use it.
1678 template <typename Bitfield>
1679 void setSubclassData(typename Bitfield::Type Value) {
1681 }
1682};
1683
1684CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1685 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1686 AllocInfo AllocInfo, InsertPosition InsertBefore)
1687 : CallBase(Ty->getReturnType(), Instruction::Call, AllocInfo,
1688 InsertBefore) {
1690 unsigned(Args.size() + CountBundleInputs(Bundles) + 1));
1691 init(Ty, Func, Args, Bundles, NameStr);
1692}
1693
1694//===----------------------------------------------------------------------===//
1695// SelectInst Class
1696//===----------------------------------------------------------------------===//
1697
1698/// This class represents the LLVM 'select' instruction.
1699///
1700class SelectInst : public Instruction {
1701 constexpr static IntrusiveOperandsAllocMarker AllocMarker{3};
1702
1703 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1704 InsertPosition InsertBefore)
1705 : Instruction(S1->getType(), Instruction::Select, AllocMarker,
1706 InsertBefore) {
1707 init(C, S1, S2);
1708 setName(NameStr);
1709 }
1710
1711 void init(Value *C, Value *S1, Value *S2) {
1712 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1713 Op<0>() = C;
1714 Op<1>() = S1;
1715 Op<2>() = S2;
1716 }
1717
1718protected:
1719 // Note: Instruction needs to be a friend here to call cloneImpl.
1720 friend class Instruction;
1721
1722 LLVM_ABI SelectInst *cloneImpl() const;
1723
1724public:
1725 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1726 const Twine &NameStr = "",
1727 InsertPosition InsertBefore = nullptr,
1728 const Instruction *MDFrom = nullptr) {
1729 SelectInst *Sel =
1730 new (AllocMarker) SelectInst(C, S1, S2, NameStr, InsertBefore);
1731 if (MDFrom)
1732 Sel->copyMetadata(*MDFrom);
1733 return Sel;
1734 }
1735
1736 const Value *getCondition() const { return Op<0>(); }
1737 const Value *getTrueValue() const { return Op<1>(); }
1738 const Value *getFalseValue() const { return Op<2>(); }
1739 Value *getCondition() { return Op<0>(); }
1740 Value *getTrueValue() { return Op<1>(); }
1741 Value *getFalseValue() { return Op<2>(); }
1742
1743 void setCondition(Value *V) { Op<0>() = V; }
1744 void setTrueValue(Value *V) { Op<1>() = V; }
1745 void setFalseValue(Value *V) { Op<2>() = V; }
1746
1747 /// Swap the true and false values of the select instruction.
1748 /// This doesn't swap prof metadata.
1749 void swapValues() { Op<1>().swap(Op<2>()); }
1750
1751 /// Return a string if the specified operands are invalid
1752 /// for a select operation, otherwise return null.
1753 LLVM_ABI static const char *areInvalidOperands(Value *Cond, Value *True,
1754 Value *False);
1755
1756 /// Transparently provide more efficient getOperand methods.
1758
1760 return static_cast<OtherOps>(Instruction::getOpcode());
1761 }
1762
1763 // Methods for support type inquiry through isa, cast, and dyn_cast:
1764 static bool classof(const Instruction *I) {
1765 return I->getOpcode() == Instruction::Select;
1766 }
1767 static bool classof(const Value *V) {
1769 }
1770};
1771
1772template <>
1773struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1774};
1775
1777
1778//===----------------------------------------------------------------------===//
1779// VAArgInst Class
1780//===----------------------------------------------------------------------===//
1781
1782/// This class represents the va_arg llvm instruction, which returns
1783/// an argument of the specified type given a va_list and increments that list
1784///
1786protected:
1787 // Note: Instruction needs to be a friend here to call cloneImpl.
1788 friend class Instruction;
1789
1790 LLVM_ABI VAArgInst *cloneImpl() const;
1791
1792public:
1793 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1794 InsertPosition InsertBefore = nullptr)
1795 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1796 setName(NameStr);
1797 }
1798
1800 const Value *getPointerOperand() const { return getOperand(0); }
1801 static unsigned getPointerOperandIndex() { return 0U; }
1802
1803 // Methods for support type inquiry through isa, cast, and dyn_cast:
1804 static bool classof(const Instruction *I) {
1805 return I->getOpcode() == VAArg;
1806 }
1807 static bool classof(const Value *V) {
1809 }
1810};
1811
1812//===----------------------------------------------------------------------===//
1813// ExtractElementInst Class
1814//===----------------------------------------------------------------------===//
1815
1816/// This instruction extracts a single (scalar)
1817/// element from a VectorType value
1818///
1819class ExtractElementInst : public Instruction {
1820 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
1821
1822 LLVM_ABI ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1823 InsertPosition InsertBefore = nullptr);
1824
1825protected:
1826 // Note: Instruction needs to be a friend here to call cloneImpl.
1827 friend class Instruction;
1828
1829 LLVM_ABI ExtractElementInst *cloneImpl() const;
1830
1831public:
1832 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1833 const Twine &NameStr = "",
1834 InsertPosition InsertBefore = nullptr) {
1835 return new (AllocMarker)
1836 ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1837 }
1838
1839 /// Return true if an extractelement instruction can be
1840 /// formed with the specified operands.
1841 LLVM_ABI static bool isValidOperands(const Value *Vec, const Value *Idx);
1842
1844 Value *getIndexOperand() { return Op<1>(); }
1845 const Value *getVectorOperand() const { return Op<0>(); }
1846 const Value *getIndexOperand() const { return Op<1>(); }
1847
1851
1852 /// Transparently provide more efficient getOperand methods.
1854
1855 // Methods for support type inquiry through isa, cast, and dyn_cast:
1856 static bool classof(const Instruction *I) {
1857 return I->getOpcode() == Instruction::ExtractElement;
1858 }
1859 static bool classof(const Value *V) {
1861 }
1862};
1863
1864template <>
1866 public FixedNumOperandTraits<ExtractElementInst, 2> {
1867};
1868
1870
1871//===----------------------------------------------------------------------===//
1872// InsertElementInst Class
1873//===----------------------------------------------------------------------===//
1874
1875/// This instruction inserts a single (scalar)
1876/// element into a VectorType value
1877///
1878class InsertElementInst : public Instruction {
1879 constexpr static IntrusiveOperandsAllocMarker AllocMarker{3};
1880
1881 LLVM_ABI InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1882 const Twine &NameStr = "",
1883 InsertPosition InsertBefore = nullptr);
1884
1885protected:
1886 // Note: Instruction needs to be a friend here to call cloneImpl.
1887 friend class Instruction;
1888
1889 LLVM_ABI InsertElementInst *cloneImpl() const;
1890
1891public:
1892 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1893 const Twine &NameStr = "",
1894 InsertPosition InsertBefore = nullptr) {
1895 return new (AllocMarker)
1896 InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1897 }
1898
1899 /// Return true if an insertelement instruction can be
1900 /// formed with the specified operands.
1901 LLVM_ABI static bool isValidOperands(const Value *Vec, const Value *NewElt,
1902 const Value *Idx);
1903
1904 /// Overload to return most specific vector type.
1905 ///
1908 }
1909
1910 /// Transparently provide more efficient getOperand methods.
1912
1913 // Methods for support type inquiry through isa, cast, and dyn_cast:
1914 static bool classof(const Instruction *I) {
1915 return I->getOpcode() == Instruction::InsertElement;
1916 }
1917 static bool classof(const Value *V) {
1919 }
1920};
1921
1922template <>
1924 public FixedNumOperandTraits<InsertElementInst, 3> {
1925};
1926
1928
1929//===----------------------------------------------------------------------===//
1930// ShuffleVectorInst Class
1931//===----------------------------------------------------------------------===//
1932
1933constexpr int PoisonMaskElem = -1;
1934
1935/// This instruction constructs a fixed permutation of two
1936/// input vectors.
1937///
1938/// For each element of the result vector, the shuffle mask selects an element
1939/// from one of the input vectors to copy to the result. Non-negative elements
1940/// in the mask represent an index into the concatenated pair of input vectors.
1941/// PoisonMaskElem (-1) specifies that the result element is poison.
1942///
1943/// For scalable vectors, all the elements of the mask must be 0 or -1. This
1944/// requirement may be relaxed in the future.
1946 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
1947
1948 SmallVector<int, 4> ShuffleMask;
1949 Constant *ShuffleMaskForBitcode;
1950
1951protected:
1952 // Note: Instruction needs to be a friend here to call cloneImpl.
1953 friend class Instruction;
1954
1956
1957public:
1958 LLVM_ABI ShuffleVectorInst(Value *V1, Value *Mask, const Twine &NameStr = "",
1959 InsertPosition InsertBefore = nullptr);
1961 const Twine &NameStr = "",
1962 InsertPosition InsertBefore = nullptr);
1963 LLVM_ABI ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1964 const Twine &NameStr = "",
1965 InsertPosition InsertBefore = nullptr);
1967 const Twine &NameStr = "",
1968 InsertPosition InsertBefore = nullptr);
1969
1970 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
1971 void operator delete(void *Ptr) {
1972 return User::operator delete(Ptr, AllocMarker);
1973 }
1974
1975 /// Swap the operands and adjust the mask to preserve the semantics
1976 /// of the instruction.
1977 LLVM_ABI void commute();
1978
1979 /// Return true if a shufflevector instruction can be
1980 /// formed with the specified operands.
1981 LLVM_ABI static bool isValidOperands(const Value *V1, const Value *V2,
1982 const Value *Mask);
1983 LLVM_ABI static bool isValidOperands(const Value *V1, const Value *V2,
1984 ArrayRef<int> Mask);
1985
1986 /// Overload to return most specific vector type.
1987 ///
1990 }
1991
1992 /// Transparently provide more efficient getOperand methods.
1994
1995 /// Return the shuffle mask value of this instruction for the given element
1996 /// index. Return PoisonMaskElem if the element is undef.
1997 int getMaskValue(unsigned Elt) const { return ShuffleMask[Elt]; }
1998
1999 /// Convert the input shuffle mask operand to a vector of integers. Undefined
2000 /// elements of the mask are returned as PoisonMaskElem.
2001 LLVM_ABI static void getShuffleMask(const Constant *Mask,
2002 SmallVectorImpl<int> &Result);
2003
2004 /// Return the mask for this instruction as a vector of integers. Undefined
2005 /// elements of the mask are returned as PoisonMaskElem.
2007 Result.assign(ShuffleMask.begin(), ShuffleMask.end());
2008 }
2009
2010 /// Return the mask for this instruction, for use in bitcode.
2011 ///
2012 /// TODO: This is temporary until we decide a new bitcode encoding for
2013 /// shufflevector.
2014 Constant *getShuffleMaskForBitcode() const { return ShuffleMaskForBitcode; }
2015
2016 LLVM_ABI static Constant *convertShuffleMaskForBitcode(ArrayRef<int> Mask,
2017 Type *ResultTy);
2018
2019 LLVM_ABI void setShuffleMask(ArrayRef<int> Mask);
2020
2021 ArrayRef<int> getShuffleMask() const { return ShuffleMask; }
2022
2023 /// Return true if this shuffle returns a vector with a different number of
2024 /// elements than its source vectors.
2025 /// Examples: shufflevector <4 x n> A, <4 x n> B, <1,2,3>
2026 /// shufflevector <4 x n> A, <4 x n> B, <1,2,3,4,5>
2027 bool changesLength() const {
2028 unsigned NumSourceElts = cast<VectorType>(Op<0>()->getType())
2029 ->getElementCount()
2030 .getKnownMinValue();
2031 unsigned NumMaskElts = ShuffleMask.size();
2032 return NumSourceElts != NumMaskElts;
2033 }
2034
2035 /// Return true if this shuffle returns a vector with a greater number of
2036 /// elements than its source vectors.
2037 /// Example: shufflevector <2 x n> A, <2 x n> B, <1,2,3>
2038 bool increasesLength() const {
2039 unsigned NumSourceElts = cast<VectorType>(Op<0>()->getType())
2040 ->getElementCount()
2041 .getKnownMinValue();
2042 unsigned NumMaskElts = ShuffleMask.size();
2043 return NumSourceElts < NumMaskElts;
2044 }
2045
2046 /// Return true if this shuffle mask chooses elements from exactly one source
2047 /// vector.
2048 /// Example: <7,5,undef,7>
2049 /// This assumes that vector operands (of length \p NumSrcElts) are the same
2050 /// length as the mask.
2051 LLVM_ABI static bool isSingleSourceMask(ArrayRef<int> Mask, int NumSrcElts);
2052 static bool isSingleSourceMask(const Constant *Mask, int NumSrcElts) {
2053 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2054 SmallVector<int, 16> MaskAsInts;
2055 getShuffleMask(Mask, MaskAsInts);
2056 return isSingleSourceMask(MaskAsInts, NumSrcElts);
2057 }
2058
2059 /// Return true if this shuffle chooses elements from exactly one source
2060 /// vector without changing the length of that vector.
2061 /// Example: shufflevector <4 x n> A, <4 x n> B, <3,0,undef,3>
2062 /// TODO: Optionally allow length-changing shuffles.
2063 bool isSingleSource() const {
2064 return !changesLength() &&
2065 isSingleSourceMask(ShuffleMask, ShuffleMask.size());
2066 }
2067
2068 /// Return true if this shuffle mask chooses elements from exactly one source
2069 /// vector without lane crossings. A shuffle using this mask is not
2070 /// necessarily a no-op because it may change the number of elements from its
2071 /// input vectors or it may provide demanded bits knowledge via undef lanes.
2072 /// Example: <undef,undef,2,3>
2073 LLVM_ABI static bool isIdentityMask(ArrayRef<int> Mask, int NumSrcElts);
2074 static bool isIdentityMask(const Constant *Mask, int NumSrcElts) {
2075 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2076
2077 // Not possible to express a shuffle mask for a scalable vector for this
2078 // case.
2079 if (isa<ScalableVectorType>(Mask->getType()))
2080 return false;
2081
2082 SmallVector<int, 16> MaskAsInts;
2083 getShuffleMask(Mask, MaskAsInts);
2084 return isIdentityMask(MaskAsInts, NumSrcElts);
2085 }
2086
2087 /// Return true if this shuffle chooses elements from exactly one source
2088 /// vector without lane crossings and does not change the number of elements
2089 /// from its input vectors.
2090 /// Example: shufflevector <4 x n> A, <4 x n> B, <4,undef,6,undef>
2091 bool isIdentity() const {
2092 // Not possible to express a shuffle mask for a scalable vector for this
2093 // case.
2095 return false;
2096
2097 return !changesLength() && isIdentityMask(ShuffleMask, ShuffleMask.size());
2098 }
2099
2100 /// Return true if this shuffle lengthens exactly one source vector with
2101 /// undefs in the high elements.
2102 LLVM_ABI bool isIdentityWithPadding() const;
2103
2104 /// Return true if this shuffle extracts the first N elements of exactly one
2105 /// source vector.
2106 LLVM_ABI bool isIdentityWithExtract() const;
2107
2108 /// Return true if this shuffle concatenates its 2 source vectors. This
2109 /// returns false if either input is undefined. In that case, the shuffle is
2110 /// is better classified as an identity with padding operation.
2111 LLVM_ABI bool isConcat() const;
2112
2113 /// Return true if this shuffle mask chooses elements from its source vectors
2114 /// without lane crossings. A shuffle using this mask would be
2115 /// equivalent to a vector select with a constant condition operand.
2116 /// Example: <4,1,6,undef>
2117 /// This returns false if the mask does not choose from both input vectors.
2118 /// In that case, the shuffle is better classified as an identity shuffle.
2119 /// This assumes that vector operands are the same length as the mask
2120 /// (a length-changing shuffle can never be equivalent to a vector select).
2121 LLVM_ABI static bool isSelectMask(ArrayRef<int> Mask, int NumSrcElts);
2122 static bool isSelectMask(const Constant *Mask, int NumSrcElts) {
2123 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2124 SmallVector<int, 16> MaskAsInts;
2125 getShuffleMask(Mask, MaskAsInts);
2126 return isSelectMask(MaskAsInts, NumSrcElts);
2127 }
2128
2129 /// Return true if this shuffle chooses elements from its source vectors
2130 /// without lane crossings and all operands have the same number of elements.
2131 /// In other words, this shuffle is equivalent to a vector select with a
2132 /// constant condition operand.
2133 /// Example: shufflevector <4 x n> A, <4 x n> B, <undef,1,6,3>
2134 /// This returns false if the mask does not choose from both input vectors.
2135 /// In that case, the shuffle is better classified as an identity shuffle.
2136 /// TODO: Optionally allow length-changing shuffles.
2137 bool isSelect() const {
2138 return !changesLength() && isSelectMask(ShuffleMask, ShuffleMask.size());
2139 }
2140
2141 /// Return true if this shuffle mask swaps the order of elements from exactly
2142 /// one source vector.
2143 /// Example: <7,6,undef,4>
2144 /// This assumes that vector operands (of length \p NumSrcElts) are the same
2145 /// length as the mask.
2146 LLVM_ABI static bool isReverseMask(ArrayRef<int> Mask, int NumSrcElts);
2147 static bool isReverseMask(const Constant *Mask, int NumSrcElts) {
2148 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2149 SmallVector<int, 16> MaskAsInts;
2150 getShuffleMask(Mask, MaskAsInts);
2151 return isReverseMask(MaskAsInts, NumSrcElts);
2152 }
2153
2154 /// Return true if this shuffle swaps the order of elements from exactly
2155 /// one source vector.
2156 /// Example: shufflevector <4 x n> A, <4 x n> B, <3,undef,1,undef>
2157 /// TODO: Optionally allow length-changing shuffles.
2158 bool isReverse() const {
2159 return !changesLength() && isReverseMask(ShuffleMask, ShuffleMask.size());
2160 }
2161
2162 /// Return true if this shuffle mask chooses all elements with the same value
2163 /// as the first element of exactly one source vector.
2164 /// Example: <4,undef,undef,4>
2165 /// This assumes that vector operands (of length \p NumSrcElts) are the same
2166 /// length as the mask.
2167 LLVM_ABI static bool isZeroEltSplatMask(ArrayRef<int> Mask, int NumSrcElts);
2168 static bool isZeroEltSplatMask(const Constant *Mask, int NumSrcElts) {
2169 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2170 SmallVector<int, 16> MaskAsInts;
2171 getShuffleMask(Mask, MaskAsInts);
2172 return isZeroEltSplatMask(MaskAsInts, NumSrcElts);
2173 }
2174
2175 /// Return true if all elements of this shuffle are the same value as the
2176 /// first element of exactly one source vector without changing the length
2177 /// of that vector.
2178 /// Example: shufflevector <4 x n> A, <4 x n> B, <undef,0,undef,0>
2179 /// TODO: Optionally allow length-changing shuffles.
2180 /// TODO: Optionally allow splats from other elements.
2181 bool isZeroEltSplat() const {
2182 return !changesLength() &&
2183 isZeroEltSplatMask(ShuffleMask, ShuffleMask.size());
2184 }
2185
2186 /// Return true if this shuffle mask is a transpose mask.
2187 /// Transpose vector masks transpose a 2xn matrix. They read corresponding
2188 /// even- or odd-numbered vector elements from two n-dimensional source
2189 /// vectors and write each result into consecutive elements of an
2190 /// n-dimensional destination vector. Two shuffles are necessary to complete
2191 /// the transpose, one for the even elements and another for the odd elements.
2192 /// This description closely follows how the TRN1 and TRN2 AArch64
2193 /// instructions operate.
2194 ///
2195 /// For example, a simple 2x2 matrix can be transposed with:
2196 ///
2197 /// ; Original matrix
2198 /// m0 = < a, b >
2199 /// m1 = < c, d >
2200 ///
2201 /// ; Transposed matrix
2202 /// t0 = < a, c > = shufflevector m0, m1, < 0, 2 >
2203 /// t1 = < b, d > = shufflevector m0, m1, < 1, 3 >
2204 ///
2205 /// For matrices having greater than n columns, the resulting nx2 transposed
2206 /// matrix is stored in two result vectors such that one vector contains
2207 /// interleaved elements from all the even-numbered rows and the other vector
2208 /// contains interleaved elements from all the odd-numbered rows. For example,
2209 /// a 2x4 matrix can be transposed with:
2210 ///
2211 /// ; Original matrix
2212 /// m0 = < a, b, c, d >
2213 /// m1 = < e, f, g, h >
2214 ///
2215 /// ; Transposed matrix
2216 /// t0 = < a, e, c, g > = shufflevector m0, m1 < 0, 4, 2, 6 >
2217 /// t1 = < b, f, d, h > = shufflevector m0, m1 < 1, 5, 3, 7 >
2218 LLVM_ABI static bool isTransposeMask(ArrayRef<int> Mask, int NumSrcElts);
2219 static bool isTransposeMask(const Constant *Mask, int NumSrcElts) {
2220 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2221 SmallVector<int, 16> MaskAsInts;
2222 getShuffleMask(Mask, MaskAsInts);
2223 return isTransposeMask(MaskAsInts, NumSrcElts);
2224 }
2225
2226 /// Return true if this shuffle transposes the elements of its inputs without
2227 /// changing the length of the vectors. This operation may also be known as a
2228 /// merge or interleave. See the description for isTransposeMask() for the
2229 /// exact specification.
2230 /// Example: shufflevector <4 x n> A, <4 x n> B, <0,4,2,6>
2231 bool isTranspose() const {
2232 return !changesLength() && isTransposeMask(ShuffleMask, ShuffleMask.size());
2233 }
2234
2235 /// Return true if this shuffle mask is a splice mask, concatenating the two
2236 /// inputs together and then extracts an original width vector starting from
2237 /// the splice index.
2238 /// Example: shufflevector <4 x n> A, <4 x n> B, <1,2,3,4>
2239 /// This assumes that vector operands (of length \p NumSrcElts) are the same
2240 /// length as the mask.
2241 LLVM_ABI static bool isSpliceMask(ArrayRef<int> Mask, int NumSrcElts,
2242 int &Index);
2243 static bool isSpliceMask(const Constant *Mask, int NumSrcElts, int &Index) {
2244 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2245 SmallVector<int, 16> MaskAsInts;
2246 getShuffleMask(Mask, MaskAsInts);
2247 return isSpliceMask(MaskAsInts, NumSrcElts, Index);
2248 }
2249
2250 /// Return true if this shuffle splices two inputs without changing the length
2251 /// of the vectors. This operation concatenates the two inputs together and
2252 /// then extracts an original width vector starting from the splice index.
2253 /// Example: shufflevector <4 x n> A, <4 x n> B, <1,2,3,4>
2254 bool isSplice(int &Index) const {
2255 return !changesLength() &&
2256 isSpliceMask(ShuffleMask, ShuffleMask.size(), Index);
2257 }
2258
2259 /// Return true if this shuffle mask is an extract subvector mask.
2260 /// A valid extract subvector mask returns a smaller vector from a single
2261 /// source operand. The base extraction index is returned as well.
2262 LLVM_ABI static bool isExtractSubvectorMask(ArrayRef<int> Mask,
2263 int NumSrcElts, int &Index);
2264 static bool isExtractSubvectorMask(const Constant *Mask, int NumSrcElts,
2265 int &Index) {
2266 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2267 // Not possible to express a shuffle mask for a scalable vector for this
2268 // case.
2269 if (isa<ScalableVectorType>(Mask->getType()))
2270 return false;
2271 SmallVector<int, 16> MaskAsInts;
2272 getShuffleMask(Mask, MaskAsInts);
2273 return isExtractSubvectorMask(MaskAsInts, NumSrcElts, Index);
2274 }
2275
2276 /// Return true if this shuffle mask is an extract subvector mask.
2277 bool isExtractSubvectorMask(int &Index) const {
2278 // Not possible to express a shuffle mask for a scalable vector for this
2279 // case.
2281 return false;
2282
2283 int NumSrcElts =
2284 cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
2285 return isExtractSubvectorMask(ShuffleMask, NumSrcElts, Index);
2286 }
2287
2288 /// Return true if this shuffle mask is an insert subvector mask.
2289 /// A valid insert subvector mask inserts the lowest elements of a second
2290 /// source operand into an in-place first source operand.
2291 /// Both the sub vector width and the insertion index is returned.
2292 LLVM_ABI static bool isInsertSubvectorMask(ArrayRef<int> Mask, int NumSrcElts,
2293 int &NumSubElts, int &Index);
2294 static bool isInsertSubvectorMask(const Constant *Mask, int NumSrcElts,
2295 int &NumSubElts, int &Index) {
2296 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2297 // Not possible to express a shuffle mask for a scalable vector for this
2298 // case.
2299 if (isa<ScalableVectorType>(Mask->getType()))
2300 return false;
2301 SmallVector<int, 16> MaskAsInts;
2302 getShuffleMask(Mask, MaskAsInts);
2303 return isInsertSubvectorMask(MaskAsInts, NumSrcElts, NumSubElts, Index);
2304 }
2305
2306 /// Return true if this shuffle mask is an insert subvector mask.
2307 bool isInsertSubvectorMask(int &NumSubElts, int &Index) const {
2308 // Not possible to express a shuffle mask for a scalable vector for this
2309 // case.
2311 return false;
2312
2313 int NumSrcElts =
2314 cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
2315 return isInsertSubvectorMask(ShuffleMask, NumSrcElts, NumSubElts, Index);
2316 }
2317
2318 /// Return true if this shuffle mask replicates each of the \p VF elements
2319 /// in a vector \p ReplicationFactor times.
2320 /// For example, the mask for \p ReplicationFactor=3 and \p VF=4 is:
2321 /// <0,0,0,1,1,1,2,2,2,3,3,3>
2322 LLVM_ABI static bool isReplicationMask(ArrayRef<int> Mask,
2323 int &ReplicationFactor, int &VF);
2324 static bool isReplicationMask(const Constant *Mask, int &ReplicationFactor,
2325 int &VF) {
2326 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2327 // Not possible to express a shuffle mask for a scalable vector for this
2328 // case.
2329 if (isa<ScalableVectorType>(Mask->getType()))
2330 return false;
2331 SmallVector<int, 16> MaskAsInts;
2332 getShuffleMask(Mask, MaskAsInts);
2333 return isReplicationMask(MaskAsInts, ReplicationFactor, VF);
2334 }
2335
2336 /// Return true if this shuffle mask is a replication mask.
2337 LLVM_ABI bool isReplicationMask(int &ReplicationFactor, int &VF) const;
2338
2339 /// Return true if this shuffle mask represents "clustered" mask of size VF,
2340 /// i.e. each index between [0..VF) is used exactly once in each submask of
2341 /// size VF.
2342 /// For example, the mask for \p VF=4 is:
2343 /// 0, 1, 2, 3, 3, 2, 0, 1 - "clustered", because each submask of size 4
2344 /// (0,1,2,3 and 3,2,0,1) uses indices [0..VF) exactly one time.
2345 /// 0, 1, 2, 3, 3, 3, 1, 0 - not "clustered", because
2346 /// element 3 is used twice in the second submask
2347 /// (3,3,1,0) and index 2 is not used at all.
2348 LLVM_ABI static bool isOneUseSingleSourceMask(ArrayRef<int> Mask, int VF);
2349
2350 /// Return true if this shuffle mask is a one-use-single-source("clustered")
2351 /// mask.
2352 LLVM_ABI bool isOneUseSingleSourceMask(int VF) const;
2353
2354 /// Change values in a shuffle permute mask assuming the two vector operands
2355 /// of length InVecNumElts have swapped position.
2357 unsigned InVecNumElts) {
2358 for (int &Idx : Mask) {
2359 if (Idx == -1)
2360 continue;
2361 Idx = Idx < (int)InVecNumElts ? Idx + InVecNumElts : Idx - InVecNumElts;
2362 assert(Idx >= 0 && Idx < (int)InVecNumElts * 2 &&
2363 "shufflevector mask index out of range");
2364 }
2365 }
2366
2367 /// Return if this shuffle interleaves its two input vectors together.
2368 LLVM_ABI bool isInterleave(unsigned Factor);
2369
2370 /// Return true if the mask interleaves one or more input vectors together.
2371 ///
2372 /// I.e. <0, LaneLen, ... , LaneLen*(Factor - 1), 1, LaneLen + 1, ...>
2373 /// E.g. For a Factor of 2 (LaneLen=4):
2374 /// <0, 4, 1, 5, 2, 6, 3, 7>
2375 /// E.g. For a Factor of 3 (LaneLen=4):
2376 /// <4, 0, 9, 5, 1, 10, 6, 2, 11, 7, 3, 12>
2377 /// E.g. For a Factor of 4 (LaneLen=2):
2378 /// <0, 2, 6, 4, 1, 3, 7, 5>
2379 ///
2380 /// NumInputElts is the total number of elements in the input vectors.
2381 ///
2382 /// StartIndexes are the first indexes of each vector being interleaved,
2383 /// substituting any indexes that were undef
2384 /// E.g. <4, -1, 2, 5, 1, 3> (Factor=3): StartIndexes=<4, 0, 2>
2385 ///
2386 /// Note that this does not check if the input vectors are consecutive:
2387 /// It will return true for masks such as
2388 /// <0, 4, 6, 1, 5, 7> (Factor=3, LaneLen=2)
2389 LLVM_ABI static bool
2390 isInterleaveMask(ArrayRef<int> Mask, unsigned Factor, unsigned NumInputElts,
2391 SmallVectorImpl<unsigned> &StartIndexes);
2392 static bool isInterleaveMask(ArrayRef<int> Mask, unsigned Factor,
2393 unsigned NumInputElts) {
2394 SmallVector<unsigned, 8> StartIndexes;
2395 return isInterleaveMask(Mask, Factor, NumInputElts, StartIndexes);
2396 }
2397
2398 /// Check if the mask is a DE-interleave mask of the given factor
2399 /// \p Factor like:
2400 /// <Index, Index+Factor, ..., Index+(NumElts-1)*Factor>
2401 LLVM_ABI static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask,
2402 unsigned Factor,
2403 unsigned &Index);
2404 static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask, unsigned Factor) {
2405 unsigned Unused;
2406 return isDeInterleaveMaskOfFactor(Mask, Factor, Unused);
2407 }
2408
2409 /// Checks if the shuffle is a bit rotation of the first operand across
2410 /// multiple subelements, e.g:
2411 ///
2412 /// shuffle <8 x i8> %a, <8 x i8> poison, <8 x i32> <1, 0, 3, 2, 5, 4, 7, 6>
2413 ///
2414 /// could be expressed as
2415 ///
2416 /// rotl <4 x i16> %a, 8
2417 ///
2418 /// If it can be expressed as a rotation, returns the number of subelements to
2419 /// group by in NumSubElts and the number of bits to rotate left in RotateAmt.
2420 LLVM_ABI static bool isBitRotateMask(ArrayRef<int> Mask,
2421 unsigned EltSizeInBits,
2422 unsigned MinSubElts, unsigned MaxSubElts,
2423 unsigned &NumSubElts,
2424 unsigned &RotateAmt);
2425
2426 // Methods for support type inquiry through isa, cast, and dyn_cast:
2427 static bool classof(const Instruction *I) {
2428 return I->getOpcode() == Instruction::ShuffleVector;
2429 }
2430 static bool classof(const Value *V) {
2432 }
2433};
2434
2435template <>
2437 : public FixedNumOperandTraits<ShuffleVectorInst, 2> {};
2438
2440
2441//===----------------------------------------------------------------------===//
2442// ExtractValueInst Class
2443//===----------------------------------------------------------------------===//
2444
2445/// This instruction extracts a struct member or array
2446/// element value from an aggregate value.
2447///
2448class ExtractValueInst : public UnaryInstruction {
2450
2451 ExtractValueInst(const ExtractValueInst &EVI);
2452
2453 /// Constructors - Create a extractvalue instruction with a base aggregate
2454 /// value and a list of indices. The first and second ctor can optionally
2455 /// insert before an existing instruction, the third appends the new
2456 /// instruction to the specified BasicBlock.
2457 inline ExtractValueInst(Value *Agg, ArrayRef<unsigned> Idxs,
2458 const Twine &NameStr, InsertPosition InsertBefore);
2459
2460 LLVM_ABI void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
2461
2462protected:
2463 // Note: Instruction needs to be a friend here to call cloneImpl.
2464 friend class Instruction;
2465
2466 LLVM_ABI ExtractValueInst *cloneImpl() const;
2467
2468public:
2469 static ExtractValueInst *Create(Value *Agg, ArrayRef<unsigned> Idxs,
2470 const Twine &NameStr = "",
2471 InsertPosition InsertBefore = nullptr) {
2472 return new
2473 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
2474 }
2475
2476 /// Returns the type of the element that would be extracted
2477 /// with an extractvalue instruction with the specified parameters.
2478 ///
2479 /// Null is returned if the indices are invalid for the specified type.
2480 LLVM_ABI static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
2481
2482 using idx_iterator = const unsigned*;
2483
2484 inline idx_iterator idx_begin() const { return Indices.begin(); }
2485 inline idx_iterator idx_end() const { return Indices.end(); }
2487 return make_range(idx_begin(), idx_end());
2488 }
2489
2491 return getOperand(0);
2492 }
2494 return getOperand(0);
2495 }
2496 static unsigned getAggregateOperandIndex() {
2497 return 0U; // get index for modifying correct operand
2498 }
2499
2501 return Indices;
2502 }
2503
2504 unsigned getNumIndices() const {
2505 return (unsigned)Indices.size();
2506 }
2507
2508 bool hasIndices() const {
2509 return true;
2510 }
2511
2512 // Methods for support type inquiry through isa, cast, and dyn_cast:
2513 static bool classof(const Instruction *I) {
2514 return I->getOpcode() == Instruction::ExtractValue;
2515 }
2516 static bool classof(const Value *V) {
2518 }
2519};
2520
2521ExtractValueInst::ExtractValueInst(Value *Agg, ArrayRef<unsigned> Idxs,
2522 const Twine &NameStr,
2523 InsertPosition InsertBefore)
2524 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
2525 ExtractValue, Agg, InsertBefore) {
2526 init(Idxs, NameStr);
2527}
2528
2529//===----------------------------------------------------------------------===//
2530// InsertValueInst Class
2531//===----------------------------------------------------------------------===//
2532
2533/// This instruction inserts a struct field of array element
2534/// value into an aggregate value.
2535///
2536class InsertValueInst : public Instruction {
2537 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
2538
2540
2541 InsertValueInst(const InsertValueInst &IVI);
2542
2543 /// Constructors - Create a insertvalue instruction with a base aggregate
2544 /// value, a value to insert, and a list of indices. The first and second ctor
2545 /// can optionally insert before an existing instruction, the third appends
2546 /// the new instruction to the specified BasicBlock.
2547 inline InsertValueInst(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
2548 const Twine &NameStr, InsertPosition InsertBefore);
2549
2550 /// Constructors - These three constructors are convenience methods because
2551 /// one and two index insertvalue instructions are so common.
2552 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
2553 const Twine &NameStr = "",
2554 InsertPosition InsertBefore = nullptr);
2555
2556 LLVM_ABI void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
2557 const Twine &NameStr);
2558
2559protected:
2560 // Note: Instruction needs to be a friend here to call cloneImpl.
2561 friend class Instruction;
2562
2563 LLVM_ABI InsertValueInst *cloneImpl() const;
2564
2565public:
2566 // allocate space for exactly two operands
2567 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
2568 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
2569
2570 static InsertValueInst *Create(Value *Agg, Value *Val,
2571 ArrayRef<unsigned> Idxs,
2572 const Twine &NameStr = "",
2573 InsertPosition InsertBefore = nullptr) {
2574 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
2575 }
2576
2577 /// Transparently provide more efficient getOperand methods.
2579
2580 using idx_iterator = const unsigned*;
2581
2582 inline idx_iterator idx_begin() const { return Indices.begin(); }
2583 inline idx_iterator idx_end() const { return Indices.end(); }
2585 return make_range(idx_begin(), idx_end());
2586 }
2587
2589 return getOperand(0);
2590 }
2592 return getOperand(0);
2593 }
2594 static unsigned getAggregateOperandIndex() {
2595 return 0U; // get index for modifying correct operand
2596 }
2597
2599 return getOperand(1);
2600 }
2602 return getOperand(1);
2603 }
2605 return 1U; // get index for modifying correct operand
2606 }
2607
2609 return Indices;
2610 }
2611
2612 unsigned getNumIndices() const {
2613 return (unsigned)Indices.size();
2614 }
2615
2616 bool hasIndices() const {
2617 return true;
2618 }
2619
2620 // Methods for support type inquiry through isa, cast, and dyn_cast:
2621 static bool classof(const Instruction *I) {
2622 return I->getOpcode() == Instruction::InsertValue;
2623 }
2624 static bool classof(const Value *V) {
2626 }
2627};
2628
2629template <>
2631 public FixedNumOperandTraits<InsertValueInst, 2> {
2632};
2633
2634InsertValueInst::InsertValueInst(Value *Agg, Value *Val,
2635 ArrayRef<unsigned> Idxs, const Twine &NameStr,
2636 InsertPosition InsertBefore)
2637 : Instruction(Agg->getType(), InsertValue, AllocMarker, InsertBefore) {
2638 init(Agg, Val, Idxs, NameStr);
2639}
2640
2641DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
2642
2643//===----------------------------------------------------------------------===//
2644// PHINode Class
2645//===----------------------------------------------------------------------===//
2646
2647// PHINode - The PHINode class is used to represent the magical mystical PHI
2648// node, that can not exist in nature, but can be synthesized in a computer
2649// scientist's overactive imagination.
2650//
2651class PHINode : public Instruction {
2652 constexpr static HungOffOperandsAllocMarker AllocMarker{};
2653
2654 /// The number of operands actually allocated. NumOperands is
2655 /// the number actually in use.
2656 unsigned ReservedSpace;
2657
2658 PHINode(const PHINode &PN);
2659
2660 explicit PHINode(Type *Ty, unsigned NumReservedValues,
2661 const Twine &NameStr = "",
2662 InsertPosition InsertBefore = nullptr)
2663 : Instruction(Ty, Instruction::PHI, AllocMarker, InsertBefore),
2664 ReservedSpace(NumReservedValues) {
2665 setName(NameStr);
2666 allocHungoffUses(ReservedSpace);
2667 }
2668
2669protected:
2670 // Note: Instruction needs to be a friend here to call cloneImpl.
2671 friend class Instruction;
2672
2673 LLVM_ABI PHINode *cloneImpl() const;
2674
2675 // allocHungoffUses - this is more complicated than the generic
2676 // User::allocHungoffUses, because we have to allocate Uses for the incoming
2677 // values and pointers to the incoming blocks, all in one allocation.
2678 void allocHungoffUses(unsigned N) {
2679 User::allocHungoffUses(N, /*WithExtraValues=*/true);
2680 }
2681
2682public:
2683 /// Constructors - NumReservedValues is a hint for the number of incoming
2684 /// edges that this phi node will have (use 0 if you really have no idea).
2685 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2686 const Twine &NameStr = "",
2687 InsertPosition InsertBefore = nullptr) {
2688 return new (AllocMarker)
2689 PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2690 }
2691
2692 /// Provide fast operand accessors
2694
2695 // Block iterator interface. This provides access to the list of incoming
2696 // basic blocks, which parallels the list of incoming values.
2697 // Please note that we are not providing non-const iterators for blocks to
2698 // force all updates go through an interface function.
2699
2702
2704 return reinterpret_cast<const_block_iterator>(op_begin() + ReservedSpace);
2705 }
2706
2708 return block_begin() + getNumOperands();
2709 }
2710
2714
2716
2718
2719 /// Return the number of incoming edges
2720 ///
2721 unsigned getNumIncomingValues() const { return getNumOperands(); }
2722
2723 /// Return incoming value number x
2724 ///
2725 Value *getIncomingValue(unsigned i) const {
2726 return getOperand(i);
2727 }
2728 void setIncomingValue(unsigned i, Value *V) {
2729 assert(V && "PHI node got a null value!");
2730 assert(getType() == V->getType() &&
2731 "All operands to PHI node must be the same type as the PHI node!");
2732 setOperand(i, V);
2733 }
2734
2735 static unsigned getOperandNumForIncomingValue(unsigned i) {
2736 return i;
2737 }
2738
2739 static unsigned getIncomingValueNumForOperand(unsigned i) {
2740 return i;
2741 }
2742
2743 /// Return incoming basic block number @p i.
2744 ///
2745 BasicBlock *getIncomingBlock(unsigned i) const {
2746 return block_begin()[i];
2747 }
2748
2749 /// Return incoming basic block corresponding
2750 /// to an operand of the PHI.
2751 ///
2753 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2754 return getIncomingBlock(unsigned(&U - op_begin()));
2755 }
2756
2757 /// Return incoming basic block corresponding
2758 /// to value use iterator.
2759 ///
2763
2764 void setIncomingBlock(unsigned i, BasicBlock *BB) {
2765 const_cast<block_iterator>(block_begin())[i] = BB;
2766 }
2767
2768 /// Copies the basic blocks from \p BBRange to the incoming basic block list
2769 /// of this PHINode, starting at \p ToIdx.
2771 uint32_t ToIdx = 0) {
2772 copy(BBRange, const_cast<block_iterator>(block_begin()) + ToIdx);
2773 }
2774
2775 /// Replace every incoming basic block \p Old to basic block \p New.
2777 assert(New && Old && "PHI node got a null basic block!");
2778 for (unsigned Op = 0, NumOps = getNumOperands(); Op != NumOps; ++Op)
2779 if (getIncomingBlock(Op) == Old)
2780 setIncomingBlock(Op, New);
2781 }
2782
2783 /// Add an incoming value to the end of the PHI list
2784 ///
2786 if (getNumOperands() == ReservedSpace)
2787 growOperands(); // Get more space!
2788 // Initialize some new operands.
2792 }
2793
2794 /// Remove an incoming value. This is useful if a
2795 /// predecessor basic block is deleted. The value removed is returned.
2796 ///
2797 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2798 /// is true), the PHI node is destroyed and any uses of it are replaced with
2799 /// dummy values. The only time there should be zero incoming values to a PHI
2800 /// node is when the block is dead, so this strategy is sound.
2801 LLVM_ABI Value *removeIncomingValue(unsigned Idx,
2802 bool DeletePHIIfEmpty = true);
2803
2804 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2805 int Idx = getBasicBlockIndex(BB);
2806 assert(Idx >= 0 && "Invalid basic block argument to remove!");
2807 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2808 }
2809
2810 /// Remove all incoming values for which the predicate returns true.
2811 /// The predicate accepts the incoming value index.
2812 LLVM_ABI void removeIncomingValueIf(function_ref<bool(unsigned)> Predicate,
2813 bool DeletePHIIfEmpty = true);
2814
2815 /// Return the first index of the specified basic
2816 /// block in the value list for this PHI. Returns -1 if no instance.
2817 ///
2818 int getBasicBlockIndex(const BasicBlock *BB) const {
2819 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2820 if (block_begin()[i] == BB)
2821 return i;
2822 return -1;
2823 }
2824
2826 int Idx = getBasicBlockIndex(BB);
2827 assert(Idx >= 0 && "Invalid basic block argument!");
2828 return getIncomingValue(Idx);
2829 }
2830
2831 /// Set every incoming value(s) for block \p BB to \p V.
2833 assert(BB && "PHI node got a null basic block!");
2834 bool Found = false;
2835 for (unsigned Op = 0, NumOps = getNumOperands(); Op != NumOps; ++Op)
2836 if (getIncomingBlock(Op) == BB) {
2837 Found = true;
2838 setIncomingValue(Op, V);
2839 }
2840 (void)Found;
2841 assert(Found && "Invalid basic block argument to set!");
2842 }
2843
2844 /// If the specified PHI node always merges together the
2845 /// same value, return the value, otherwise return null.
2846 LLVM_ABI Value *hasConstantValue() const;
2847
2848 /// Whether the specified PHI node always merges
2849 /// together the same value, assuming undefs are equal to a unique
2850 /// non-undef value.
2851 LLVM_ABI bool hasConstantOrUndefValue() const;
2852
2853 /// If the PHI node is complete which means all of its parent's predecessors
2854 /// have incoming value in this PHI, return true, otherwise return false.
2855 bool isComplete() const {
2857 [this](const BasicBlock *Pred) {
2858 return getBasicBlockIndex(Pred) >= 0;
2859 });
2860 }
2861
2862 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2863 static bool classof(const Instruction *I) {
2864 return I->getOpcode() == Instruction::PHI;
2865 }
2866 static bool classof(const Value *V) {
2868 }
2869
2870private:
2871 LLVM_ABI void growOperands();
2872};
2873
2874template <> struct OperandTraits<PHINode> : public HungoffOperandTraits {};
2875
2877
2878//===----------------------------------------------------------------------===//
2879// LandingPadInst Class
2880//===----------------------------------------------------------------------===//
2881
2882//===---------------------------------------------------------------------------
2883/// The landingpad instruction holds all of the information
2884/// necessary to generate correct exception handling. The landingpad instruction
2885/// cannot be moved from the top of a landing pad block, which itself is
2886/// accessible only from the 'unwind' edge of an invoke. This uses the
2887/// SubclassData field in Value to store whether or not the landingpad is a
2888/// cleanup.
2889///
2890class LandingPadInst : public Instruction {
2891 using CleanupField = BoolBitfieldElementT<0>;
2892
2893 constexpr static HungOffOperandsAllocMarker AllocMarker{};
2894
2895 /// The number of operands actually allocated. NumOperands is
2896 /// the number actually in use.
2897 unsigned ReservedSpace;
2898
2899 LandingPadInst(const LandingPadInst &LP);
2900
2901public:
2903
2904private:
2905 explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
2906 const Twine &NameStr, InsertPosition InsertBefore);
2907
2908 // Allocate space for exactly zero operands.
2909 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
2910
2911 LLVM_ABI void growOperands(unsigned Size);
2912 void init(unsigned NumReservedValues, const Twine &NameStr);
2913
2914protected:
2915 // Note: Instruction needs to be a friend here to call cloneImpl.
2916 friend class Instruction;
2917
2918 LLVM_ABI LandingPadInst *cloneImpl() const;
2919
2920public:
2921 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
2922
2923 /// Constructors - NumReservedClauses is a hint for the number of incoming
2924 /// clauses that this landingpad will have (use 0 if you really have no idea).
2925 LLVM_ABI static LandingPadInst *Create(Type *RetTy,
2926 unsigned NumReservedClauses,
2927 const Twine &NameStr = "",
2928 InsertPosition InsertBefore = nullptr);
2929
2930 /// Provide fast operand accessors
2932
2933 /// Return 'true' if this landingpad instruction is a
2934 /// cleanup. I.e., it should be run when unwinding even if its landing pad
2935 /// doesn't catch the exception.
2936 bool isCleanup() const { return getSubclassData<CleanupField>(); }
2937
2938 /// Indicate that this landingpad instruction is a cleanup.
2940
2941 /// Add a catch or filter clause to the landing pad.
2942 LLVM_ABI void addClause(Constant *ClauseVal);
2943
2944 /// Get the value of the clause at index Idx. Use isCatch/isFilter to
2945 /// determine what type of clause this is.
2946 Constant *getClause(unsigned Idx) const {
2947 return cast<Constant>(getOperandList()[Idx]);
2948 }
2949
2950 /// Return 'true' if the clause and index Idx is a catch clause.
2951 bool isCatch(unsigned Idx) const {
2952 return !isa<ArrayType>(getOperandList()[Idx]->getType());
2953 }
2954
2955 /// Return 'true' if the clause and index Idx is a filter clause.
2956 bool isFilter(unsigned Idx) const {
2957 return isa<ArrayType>(getOperandList()[Idx]->getType());
2958 }
2959
2960 /// Get the number of clauses for this landing pad.
2961 unsigned getNumClauses() const { return getNumOperands(); }
2962
2963 /// Grow the size of the operand list to accommodate the new
2964 /// number of clauses.
2965 void reserveClauses(unsigned Size) { growOperands(Size); }
2966
2967 // Methods for support type inquiry through isa, cast, and dyn_cast:
2968 static bool classof(const Instruction *I) {
2969 return I->getOpcode() == Instruction::LandingPad;
2970 }
2971 static bool classof(const Value *V) {
2973 }
2974};
2975
2976template <>
2978
2980
2981//===----------------------------------------------------------------------===//
2982// ReturnInst Class
2983//===----------------------------------------------------------------------===//
2984
2985//===---------------------------------------------------------------------------
2986/// Return a value (possibly void), from a function. Execution
2987/// does not continue in this function any longer.
2988///
2989class ReturnInst : public Instruction {
2990 ReturnInst(const ReturnInst &RI, AllocInfo AllocInfo);
2991
2992private:
2993 // ReturnInst constructors:
2994 // ReturnInst() - 'ret void' instruction
2995 // ReturnInst( null) - 'ret void' instruction
2996 // ReturnInst(Value* X) - 'ret X' instruction
2997 // ReturnInst(null, Iterator It) - 'ret void' instruction, insert before I
2998 // ReturnInst(Value* X, Iterator It) - 'ret X' instruction, insert before I
2999 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
3000 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
3001 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
3002 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
3003 //
3004 // NOTE: If the Value* passed is of type void then the constructor behaves as
3005 // if it was passed NULL.
3006 LLVM_ABI explicit ReturnInst(LLVMContext &C, Value *retVal,
3008 InsertPosition InsertBefore);
3009
3010protected:
3011 // Note: Instruction needs to be a friend here to call cloneImpl.
3012 friend class Instruction;
3013
3014 LLVM_ABI ReturnInst *cloneImpl() const;
3015
3016public:
3017 static ReturnInst *Create(LLVMContext &C, Value *retVal = nullptr,
3018 InsertPosition InsertBefore = nullptr) {
3019 IntrusiveOperandsAllocMarker AllocMarker{retVal ? 1U : 0U};
3020 return new (AllocMarker) ReturnInst(C, retVal, AllocMarker, InsertBefore);
3021 }
3022
3023 static ReturnInst *Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
3024 IntrusiveOperandsAllocMarker AllocMarker{0};
3025 return new (AllocMarker) ReturnInst(C, nullptr, AllocMarker, InsertAtEnd);
3026 }
3027
3028 /// Provide fast operand accessors
3030
3031 /// Convenience accessor. Returns null if there is no return value.
3033 return getNumOperands() != 0 ? getOperand(0) : nullptr;
3034 }
3035
3042
3043 unsigned getNumSuccessors() const { return 0; }
3044
3045 // Methods for support type inquiry through isa, cast, and dyn_cast:
3046 static bool classof(const Instruction *I) {
3047 return (I->getOpcode() == Instruction::Ret);
3048 }
3049 static bool classof(const Value *V) {
3051 }
3052
3053private:
3054 BasicBlock *getSuccessor(unsigned idx) const {
3055 llvm_unreachable("ReturnInst has no successors!");
3056 }
3057
3058 void setSuccessor(unsigned idx, BasicBlock *B) {
3059 llvm_unreachable("ReturnInst has no successors!");
3060 }
3061};
3062
3063template <>
3064struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {};
3065
3067
3068//===----------------------------------------------------------------------===//
3069// BranchInst Class
3070//===----------------------------------------------------------------------===//
3071
3072//===---------------------------------------------------------------------------
3073/// Conditional or Unconditional Branch instruction.
3074///
3075class BranchInst : public Instruction {
3076protected:
3077 BranchInst(Type *Ty, unsigned Opcode, AllocInfo AllocInfo,
3078 InsertPosition InsertBefore = nullptr)
3079 : Instruction(Ty, Opcode, AllocInfo, InsertBefore) {}
3080
3081public:
3082 static BranchInst *Create(BasicBlock *IfTrue,
3083 InsertPosition InsertBefore = nullptr);
3084
3085 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
3086 Value *Cond, InsertPosition InsertBefore = nullptr);
3087
3088 /// Transparently provide more efficient getOperand methods.
3090
3091 // Defined out-of-line below to access CondBrInst.
3092 bool isUnconditional() const;
3093 bool isConditional() const;
3094
3095 Value *getCondition() const;
3096 void setCondition(Value *V);
3097
3098 /// Swap the successors of this branch instruction.
3099 ///
3100 /// Swaps the successors of the branch instruction. This also swaps any
3101 /// branch weight metadata associated with the instruction so that it
3102 /// continues to map correctly to each operand.
3103 void swapSuccessors();
3104
3105 // Methods for support type inquiry through isa, cast, and dyn_cast:
3106 static bool classof(const Instruction *I) {
3107 return (I->getOpcode() == Instruction::UncondBr ||
3108 I->getOpcode() == Instruction::CondBr);
3109 }
3110 static bool classof(const Value *V) {
3112 }
3113};
3114
3115template <>
3116struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst> {};
3117
3119
3120//===----------------------------------------------------------------------===//
3121// UncondBrInst Class
3122//===----------------------------------------------------------------------===//
3123
3124//===---------------------------------------------------------------------------
3125/// Unconditional Branch instruction.
3126///
3127class UncondBrInst : public BranchInst {
3128 constexpr static IntrusiveOperandsAllocMarker AllocMarker{1};
3129
3130 UncondBrInst(const UncondBrInst &BI);
3131 LLVM_ABI explicit UncondBrInst(BasicBlock *IfTrue,
3132 InsertPosition InsertBefore);
3133
3134protected:
3135 // Note: Instruction needs to be a friend here to call cloneImpl.
3136 friend class Instruction;
3137
3138 LLVM_ABI UncondBrInst *cloneImpl() const;
3139
3140public:
3141 static UncondBrInst *Create(BasicBlock *IfTrue,
3142 InsertPosition InsertBefore = nullptr) {
3143 return new (AllocMarker) UncondBrInst(IfTrue, InsertBefore);
3144 }
3145
3146 /// Transparently provide more efficient getOperand methods.
3148
3149private:
3150 // Hide methods.
3156
3157public:
3158 unsigned getNumSuccessors() const { return 1; }
3159
3160 BasicBlock *getSuccessor(unsigned i = 0) const {
3161 assert(i == 0 && "Successor # out of range for Branch!");
3163 }
3164
3165 void setSuccessor(BasicBlock *NewSucc) { Op<-1>() = NewSucc; }
3166 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3167 assert(idx == 0 && "Successor # out of range for Branch!");
3168 Op<-1>() = NewSucc;
3169 }
3170
3174
3179
3180 // Methods for support type inquiry through isa, cast, and dyn_cast:
3181 static bool classof(const Instruction *I) {
3182 return (I->getOpcode() == Instruction::UncondBr);
3183 }
3184 static bool classof(const Value *V) {
3186 }
3187};
3188
3189template <>
3191 : public FixedNumOperandTraits<UncondBrInst, 1> {};
3192
3194
3195//===----------------------------------------------------------------------===//
3196// CondBrInst Class
3197//===----------------------------------------------------------------------===//
3198
3199//===---------------------------------------------------------------------------
3200/// Conditional Branch instruction.
3201///
3202class CondBrInst : public BranchInst {
3203 constexpr static IntrusiveOperandsAllocMarker AllocMarker{3};
3204
3205 CondBrInst(const CondBrInst &BI);
3206 LLVM_ABI CondBrInst(Value *Cond, BasicBlock *IfTrue, BasicBlock *IfFalse,
3207 InsertPosition InsertBefore);
3208
3209 void AssertOK();
3210
3211protected:
3212 // Note: Instruction needs to be a friend here to call cloneImpl.
3213 friend class Instruction;
3214
3215 LLVM_ABI CondBrInst *cloneImpl() const;
3216
3217private:
3218 // Hide methods.
3221
3222public:
3223 static CondBrInst *Create(Value *Cond, BasicBlock *IfTrue,
3224 BasicBlock *IfFalse,
3225 InsertPosition InsertBefore = nullptr) {
3226 return new (AllocMarker) CondBrInst(Cond, IfTrue, IfFalse, InsertBefore);
3227 }
3228
3229 /// Transparently provide more efficient getOperand methods.
3231
3232 Value *getCondition() const { return Op<-3>(); }
3233 void setCondition(Value *V) { Op<-3>() = V; }
3234
3235 unsigned getNumSuccessors() const { return 2; }
3236
3237 BasicBlock *getSuccessor(unsigned i) const {
3238 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
3239 return cast_or_null<BasicBlock>((&Op<-2>() + i)->get());
3240 }
3241
3242 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3243 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
3244 *(&Op<-2>() + idx) = NewSucc;
3245 }
3246
3247 /// Swap the successors of this branch instruction.
3248 ///
3249 /// Swaps the successors of the branch instruction. This also swaps any
3250 /// branch weight metadata associated with the instruction so that it
3251 /// continues to map correctly to each operand.
3252 LLVM_ABI void swapSuccessors();
3253
3258
3263
3264 // Methods for support type inquiry through isa, cast, and dyn_cast:
3265 static bool classof(const Instruction *I) {
3266 return (I->getOpcode() == Instruction::CondBr);
3267 }
3268 static bool classof(const Value *V) {
3270 }
3271};
3272
3273template <>
3274struct OperandTraits<CondBrInst> : public FixedNumOperandTraits<CondBrInst, 3> {
3275};
3276
3278
3279//===----------------------------------------------------------------------===//
3280// BranchInst Out-Of-Line Functions
3281//===----------------------------------------------------------------------===//
3282
3284 InsertPosition InsertBefore) {
3285 return UncondBrInst::Create(IfTrue, InsertBefore);
3286}
3287
3289 Value *Cond,
3290 InsertPosition InsertBefore) {
3291 return CondBrInst::Create(Cond, IfTrue, IfFalse, InsertBefore);
3292}
3293
3294inline bool BranchInst::isConditional() const { return isa<CondBrInst>(this); }
3295inline bool BranchInst::isUnconditional() const {
3296 return isa<UncondBrInst>(this);
3297}
3298
3300 return cast<CondBrInst>(this)->getCondition();
3301}
3303 cast<CondBrInst>(this)->setCondition(V);
3304}
3305
3307 cast<CondBrInst>(this)->swapSuccessors();
3308}
3309
3310//===----------------------------------------------------------------------===//
3311// SwitchInst Class
3312//===----------------------------------------------------------------------===//
3313
3314//===---------------------------------------------------------------------------
3315/// Multiway switch
3316///
3317class SwitchInst : public Instruction {
3318 constexpr static HungOffOperandsAllocMarker AllocMarker{};
3319
3320 unsigned ReservedSpace;
3321
3322 // Operand[0] = Value to switch on
3323 // Operand[1] = Default basic block destination
3324 // Operand[n] = BasicBlock to go to on match
3325 // Values are stored after the Uses similar to PHINode's basic blocks.
3326 SwitchInst(const SwitchInst &SI);
3327
3328 /// Create a new switch instruction, specifying a value to switch on and a
3329 /// default destination. The number of additional cases can be specified here
3330 /// to make memory allocation more efficient. This constructor can also
3331 /// auto-insert before another instruction.
3332 LLVM_ABI SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
3333 InsertPosition InsertBefore);
3334
3335 // allocate space for exactly zero operands
3336 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
3337
3338 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
3339 void growOperands();
3340
3341protected:
3342 // Note: Instruction needs to be a friend here to call cloneImpl.
3343 friend class Instruction;
3344
3345 LLVM_ABI SwitchInst *cloneImpl() const;
3346
3347 void allocHungoffUses(unsigned N) {
3348 User::allocHungoffUses(N, /*WithExtraValues=*/true);
3349 }
3350
3351 ConstantInt *const *case_values() const {
3352 return reinterpret_cast<ConstantInt *const *>(op_begin() + ReservedSpace);
3353 }
3355 return reinterpret_cast<ConstantInt **>(op_begin() + ReservedSpace);
3356 }
3357
3358public:
3359 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
3360
3361 // -2
3362 static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
3363
3364 template <typename CaseHandleT> class CaseIteratorImpl;
3365
3366 /// A handle to a particular switch case. It exposes a convenient interface
3367 /// to both the case value and the successor block.
3368 ///
3369 /// We define this as a template and instantiate it to form both a const and
3370 /// non-const handle.
3371 template <typename SwitchInstT, typename ConstantIntT, typename BasicBlockT>
3373 // Directly befriend both const and non-const iterators.
3374 friend class SwitchInst::CaseIteratorImpl<
3375 CaseHandleImpl<SwitchInstT, ConstantIntT, BasicBlockT>>;
3376
3377 protected:
3378 // Expose the switch type we're parameterized with to the iterator.
3379 using SwitchInstType = SwitchInstT;
3380
3381 SwitchInstT *SI;
3383
3384 CaseHandleImpl() = default;
3386
3387 public:
3388 /// Resolves case value for current case.
3389 ConstantIntT *getCaseValue() const {
3390 assert((unsigned)Index < SI->getNumCases() &&
3391 "Index out the number of cases.");
3392 return SI->case_values()[Index];
3393 }
3394
3395 /// Resolves successor for current case.
3396 BasicBlockT *getCaseSuccessor() const {
3397 assert(((unsigned)Index < SI->getNumCases() ||
3398 (unsigned)Index == DefaultPseudoIndex) &&
3399 "Index out the number of cases.");
3400 return SI->getSuccessor(getSuccessorIndex());
3401 }
3402
3403 /// Returns number of current case.
3404 unsigned getCaseIndex() const { return Index; }
3405
3406 /// Returns successor index for current case successor.
3407 unsigned getSuccessorIndex() const {
3408 assert(((unsigned)Index == DefaultPseudoIndex ||
3409 (unsigned)Index < SI->getNumCases()) &&
3410 "Index out the number of cases.");
3411 return (unsigned)Index != DefaultPseudoIndex ? Index + 1 : 0;
3412 }
3413
3414 bool operator==(const CaseHandleImpl &RHS) const {
3415 assert(SI == RHS.SI && "Incompatible operators.");
3416 return Index == RHS.Index;
3417 }
3418 };
3419
3422
3424 : public CaseHandleImpl<SwitchInst, ConstantInt, BasicBlock> {
3426
3427 public:
3429
3430 /// Sets the new value for current case.
3431 void setValue(ConstantInt *V) const {
3432 assert((unsigned)Index < SI->getNumCases() &&
3433 "Index out the number of cases.");
3434 SI->case_values()[Index] = V;
3435 }
3436
3437 /// Sets the new successor for current case.
3438 void setSuccessor(BasicBlock *S) const {
3439 SI->setSuccessor(getSuccessorIndex(), S);
3440 }
3441 };
3442
3443 template <typename CaseHandleT>
3445 : public iterator_facade_base<CaseIteratorImpl<CaseHandleT>,
3446 std::random_access_iterator_tag,
3447 const CaseHandleT> {
3448 using SwitchInstT = typename CaseHandleT::SwitchInstType;
3449
3450 CaseHandleT Case;
3451
3452 public:
3453 /// Default constructed iterator is in an invalid state until assigned to
3454 /// a case for a particular switch.
3455 CaseIteratorImpl() = default;
3456
3457 /// Initializes case iterator for given SwitchInst and for given
3458 /// case number.
3459 CaseIteratorImpl(SwitchInstT *SI, unsigned CaseNum) : Case(SI, CaseNum) {}
3460
3461 /// Initializes case iterator for given SwitchInst and for given
3462 /// successor index.
3464 unsigned SuccessorIndex) {
3465 assert(SuccessorIndex < SI->getNumSuccessors() &&
3466 "Successor index # out of range!");
3467 return SuccessorIndex != 0 ? CaseIteratorImpl(SI, SuccessorIndex - 1)
3469 }
3470
3471 /// Support converting to the const variant. This will be a no-op for const
3472 /// variant.
3474 return CaseIteratorImpl<ConstCaseHandle>(Case.SI, Case.Index);
3475 }
3476
3478 // Check index correctness after addition.
3479 // Note: Index == getNumCases() means end().
3480 assert(Case.Index + N >= 0 &&
3481 (unsigned)(Case.Index + N) <= Case.SI->getNumCases() &&
3482 "Case.Index out the number of cases.");
3483 Case.Index += N;
3484 return *this;
3485 }
3487 // Check index correctness after subtraction.
3488 // Note: Case.Index == getNumCases() means end().
3489 assert(Case.Index - N >= 0 &&
3490 (unsigned)(Case.Index - N) <= Case.SI->getNumCases() &&
3491 "Case.Index out the number of cases.");
3492 Case.Index -= N;
3493 return *this;
3494 }
3496 assert(Case.SI == RHS.Case.SI && "Incompatible operators.");
3497 return Case.Index - RHS.Case.Index;
3498 }
3499 bool operator==(const CaseIteratorImpl &RHS) const {
3500 return Case == RHS.Case;
3501 }
3502 bool operator<(const CaseIteratorImpl &RHS) const {
3503 assert(Case.SI == RHS.Case.SI && "Incompatible operators.");
3504 return Case.Index < RHS.Case.Index;
3505 }
3506 const CaseHandleT &operator*() const { return Case; }
3507 };
3508
3511
3512 static SwitchInst *Create(Value *Value, BasicBlock *Default,
3513 unsigned NumCases,
3514 InsertPosition InsertBefore = nullptr) {
3515 return new SwitchInst(Value, Default, NumCases, InsertBefore);
3516 }
3517
3518 /// Provide fast operand accessors
3520
3521 // Accessor Methods for Switch stmt
3522 Value *getCondition() const { return getOperand(0); }
3523 void setCondition(Value *V) { setOperand(0, V); }
3524
3526 return cast<BasicBlock>(getOperand(1));
3527 }
3528
3529 /// Returns true if the default branch must result in immediate undefined
3530 /// behavior, false otherwise.
3532 return isa<UnreachableInst>(getDefaultDest()->getFirstNonPHIOrDbg());
3533 }
3534
3535 void setDefaultDest(BasicBlock *DefaultCase) {
3536 setOperand(1, reinterpret_cast<Value*>(DefaultCase));
3537 }
3538
3539 /// Return the number of 'cases' in this switch instruction, excluding the
3540 /// default case.
3541 unsigned getNumCases() const { return getNumOperands() - 2; }
3542
3543 /// Returns a read/write iterator that points to the first case in the
3544 /// SwitchInst.
3546 return CaseIt(this, 0);
3547 }
3548
3549 /// Returns a read-only iterator that points to the first case in the
3550 /// SwitchInst.
3552 return ConstCaseIt(this, 0);
3553 }
3554
3555 /// Returns a read/write iterator that points one past the last in the
3556 /// SwitchInst.
3558 return CaseIt(this, getNumCases());
3559 }
3560
3561 /// Returns a read-only iterator that points one past the last in the
3562 /// SwitchInst.
3564 return ConstCaseIt(this, getNumCases());
3565 }
3566
3567 /// Iteration adapter for range-for loops.
3571
3572 /// Constant iteration adapter for range-for loops.
3576
3577 /// Returns an iterator that points to the default case.
3578 /// Note: this iterator allows to resolve successor only. Attempt
3579 /// to resolve case value causes an assertion.
3580 /// Also note, that increment and decrement also causes an assertion and
3581 /// makes iterator invalid.
3583 return CaseIt(this, DefaultPseudoIndex);
3584 }
3586 return ConstCaseIt(this, DefaultPseudoIndex);
3587 }
3588
3589 /// Search all of the case values for the specified constant. If it is
3590 /// explicitly handled, return the case iterator of it, otherwise return
3591 /// default case iterator to indicate that it is handled by the default
3592 /// handler.
3594 return CaseIt(
3595 this,
3596 const_cast<const SwitchInst *>(this)->findCaseValue(C)->getCaseIndex());
3597 }
3599 ConstCaseIt I = llvm::find_if(cases(), [C](const ConstCaseHandle &Case) {
3600 return Case.getCaseValue() == C;
3601 });
3602 if (I != case_end())
3603 return I;
3604
3605 return case_default();
3606 }
3607
3608 /// Finds the unique case value for a given successor. Returns null if the
3609 /// successor is not found, not unique, or is the default case.
3611 if (BB == getDefaultDest())
3612 return nullptr;
3613
3614 ConstantInt *CI = nullptr;
3615 for (auto Case : cases()) {
3616 if (Case.getCaseSuccessor() != BB)
3617 continue;
3618
3619 if (CI)
3620 return nullptr; // Multiple cases lead to BB.
3621
3622 CI = Case.getCaseValue();
3623 }
3624
3625 return CI;
3626 }
3627
3628 /// Add an entry to the switch instruction.
3629 /// Note:
3630 /// This action invalidates case_end(). Old case_end() iterator will
3631 /// point to the added case.
3632 LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest);
3633
3634 /// This method removes the specified case and its successor from the switch
3635 /// instruction. Note that this operation may reorder the remaining cases at
3636 /// index idx and above.
3637 /// Note:
3638 /// This action invalidates iterators for all cases following the one removed,
3639 /// including the case_end() iterator. It returns an iterator for the next
3640 /// case.
3642
3644 return make_range(std::next(op_begin()), op_end());
3645 }
3647 return make_range(std::next(op_begin()), op_end());
3648 }
3649
3650 unsigned getNumSuccessors() const { return getNumOperands() - 1; }
3651 BasicBlock *getSuccessor(unsigned idx) const {
3652 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
3653 return cast<BasicBlock>(getOperand(idx + 1));
3654 }
3655 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3656 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
3657 setOperand(idx + 1, NewSucc);
3658 }
3659
3660 // Methods for support type inquiry through isa, cast, and dyn_cast:
3661 static bool classof(const Instruction *I) {
3662 return I->getOpcode() == Instruction::Switch;
3663 }
3664 static bool classof(const Value *V) {
3666 }
3667};
3668
3669/// A wrapper class to simplify modification of SwitchInst cases along with
3670/// their prof branch_weights metadata.
3672 SwitchInst &SI;
3673 std::optional<SmallVector<uint32_t, 8>> Weights;
3674 bool Changed = false;
3675
3676protected:
3677 LLVM_ABI void init();
3678
3679public:
3680 using CaseWeightOpt = std::optional<uint32_t>;
3681 SwitchInst *operator->() { return &SI; }
3682 SwitchInst &operator*() { return SI; }
3683 operator SwitchInst *() { return &SI; }
3684
3686
3688 if (Changed && Weights.has_value() && Weights->size() >= 2)
3689 setBranchWeights(SI, Weights.value(), /*IsExpected=*/false);
3690 }
3691
3692 /// Delegate the call to the underlying SwitchInst::removeCase() and remove
3693 /// correspondent branch weight.
3695
3696 /// Replace the default destination by given case. Delegate the call to
3697 /// the underlying SwitchInst::setDefaultDest and remove correspondent branch
3698 /// weight.
3700
3701 /// Delegate the call to the underlying SwitchInst::addCase() and set the
3702 /// specified branch weight for the added case.
3703 LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest, CaseWeightOpt W);
3704
3705 /// Delegate the call to the underlying SwitchInst::eraseFromParent() and mark
3706 /// this object to not touch the underlying SwitchInst in destructor.
3708
3709 LLVM_ABI void setSuccessorWeight(unsigned idx, CaseWeightOpt W);
3711
3713 unsigned idx);
3714};
3715
3716template <> struct OperandTraits<SwitchInst> : public HungoffOperandTraits {};
3717
3719
3720//===----------------------------------------------------------------------===//
3721// IndirectBrInst Class
3722//===----------------------------------------------------------------------===//
3723
3724//===---------------------------------------------------------------------------
3725/// Indirect Branch Instruction.
3726///
3727class IndirectBrInst : public Instruction {
3728 constexpr static HungOffOperandsAllocMarker AllocMarker{};
3729
3730 unsigned ReservedSpace;
3731
3732 // Operand[0] = Address to jump to
3733 // Operand[n+1] = n-th destination
3734 IndirectBrInst(const IndirectBrInst &IBI);
3735
3736 /// Create a new indirectbr instruction, specifying an
3737 /// Address to jump to. The number of expected destinations can be specified
3738 /// here to make memory allocation more efficient. This constructor can also
3739 /// autoinsert before another instruction.
3740 LLVM_ABI IndirectBrInst(Value *Address, unsigned NumDests,
3741 InsertPosition InsertBefore);
3742
3743 // allocate space for exactly zero operands
3744 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
3745
3746 void init(Value *Address, unsigned NumDests);
3747 void growOperands();
3748
3749protected:
3750 // Note: Instruction needs to be a friend here to call cloneImpl.
3751 friend class Instruction;
3752
3753 LLVM_ABI IndirectBrInst *cloneImpl() const;
3754
3755public:
3756 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
3757
3758 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
3759 InsertPosition InsertBefore = nullptr) {
3760 return new IndirectBrInst(Address, NumDests, InsertBefore);
3761 }
3762
3763 /// Provide fast operand accessors.
3765
3766 // Accessor Methods for IndirectBrInst instruction.
3767 Value *getAddress() { return getOperand(0); }
3768 const Value *getAddress() const { return getOperand(0); }
3769 void setAddress(Value *V) { setOperand(0, V); }
3770
3771 /// return the number of possible destinations in this
3772 /// indirectbr instruction.
3773 unsigned getNumDestinations() const { return getNumOperands()-1; }
3774
3775 /// Return the specified destination.
3776 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
3777 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
3778
3779 /// Add a destination.
3780 ///
3781 LLVM_ABI void addDestination(BasicBlock *Dest);
3782
3783 /// This method removes the specified successor from the
3784 /// indirectbr instruction.
3785 LLVM_ABI void removeDestination(unsigned i);
3786
3787 unsigned getNumSuccessors() const { return getNumOperands()-1; }
3788 BasicBlock *getSuccessor(unsigned i) const {
3789 return cast<BasicBlock>(getOperand(i+1));
3790 }
3791 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
3792 setOperand(i + 1, NewSucc);
3793 }
3794
3799
3804
3805 // Methods for support type inquiry through isa, cast, and dyn_cast:
3806 static bool classof(const Instruction *I) {
3807 return I->getOpcode() == Instruction::IndirectBr;
3808 }
3809 static bool classof(const Value *V) {
3811 }
3812};
3813
3814template <>
3816
3818
3819//===----------------------------------------------------------------------===//
3820// InvokeInst Class
3821//===----------------------------------------------------------------------===//
3822
3823/// Invoke instruction. The SubclassData field is used to hold the
3824/// calling convention of the call.
3825///
3826class InvokeInst : public CallBase {
3827 /// The number of operands for this call beyond the called function,
3828 /// arguments, and operand bundles.
3829 static constexpr int NumExtraOperands = 2;
3830
3831 /// The index from the end of the operand array to the normal destination.
3832 static constexpr int NormalDestOpEndIdx = -3;
3833
3834 /// The index from the end of the operand array to the unwind destination.
3835 static constexpr int UnwindDestOpEndIdx = -2;
3836
3837 InvokeInst(const InvokeInst &BI, AllocInfo AllocInfo);
3838
3839 /// Construct an InvokeInst given a range of arguments.
3840 ///
3841 /// Construct an InvokeInst from a range of arguments
3842 inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3843 BasicBlock *IfException, ArrayRef<Value *> Args,
3845 const Twine &NameStr, InsertPosition InsertBefore);
3846
3847 LLVM_ABI void init(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3848 BasicBlock *IfException, ArrayRef<Value *> Args,
3849 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
3850
3851 /// Compute the number of operands to allocate.
3852 static unsigned ComputeNumOperands(unsigned NumArgs,
3853 size_t NumBundleInputs = 0) {
3854 // We need one operand for the called function, plus our extra operands and
3855 // the input operand counts provided.
3856 return 1 + NumExtraOperands + NumArgs + unsigned(NumBundleInputs);
3857 }
3858
3859protected:
3860 // Note: Instruction needs to be a friend here to call cloneImpl.
3861 friend class Instruction;
3862
3863 LLVM_ABI InvokeInst *cloneImpl() const;
3864
3865public:
3866 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3867 BasicBlock *IfException, ArrayRef<Value *> Args,
3868 const Twine &NameStr,
3869 InsertPosition InsertBefore = nullptr) {
3870 IntrusiveOperandsAllocMarker AllocMarker{
3871 ComputeNumOperands(unsigned(Args.size()))};
3872 return new (AllocMarker) InvokeInst(Ty, Func, IfNormal, IfException, Args,
3873 {}, AllocMarker, NameStr, InsertBefore);
3874 }
3875
3876 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3877 BasicBlock *IfException, ArrayRef<Value *> Args,
3878 ArrayRef<OperandBundleDef> Bundles = {},
3879 const Twine &NameStr = "",
3880 InsertPosition InsertBefore = nullptr) {
3881 IntrusiveOperandsAndDescriptorAllocMarker AllocMarker{
3882 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles)),
3883 unsigned(Bundles.size() * sizeof(BundleOpInfo))};
3884
3885 return new (AllocMarker)
3886 InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, AllocMarker,
3887 NameStr, InsertBefore);
3888 }
3889
3890 static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
3891 BasicBlock *IfException, ArrayRef<Value *> Args,
3892 const Twine &NameStr,
3893 InsertPosition InsertBefore = nullptr) {
3894 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3895 IfException, Args, {}, NameStr, InsertBefore);
3896 }
3897
3898 static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
3899 BasicBlock *IfException, ArrayRef<Value *> Args,
3900 ArrayRef<OperandBundleDef> Bundles = {},
3901 const Twine &NameStr = "",
3902 InsertPosition InsertBefore = nullptr) {
3903 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3904 IfException, Args, Bundles, NameStr, InsertBefore);
3905 }
3906
3907 /// Create a clone of \p II with a different set of operand bundles and
3908 /// insert it before \p InsertBefore.
3909 ///
3910 /// The returned invoke instruction is identical to \p II in every way except
3911 /// that the operand bundles for the new instruction are set to the operand
3912 /// bundles in \p Bundles.
3913 LLVM_ABI static InvokeInst *Create(InvokeInst *II,
3915 InsertPosition InsertPt = nullptr);
3916
3917 // get*Dest - Return the destination basic blocks...
3925 Op<NormalDestOpEndIdx>() = reinterpret_cast<Value *>(B);
3926 }
3928 Op<UnwindDestOpEndIdx>() = reinterpret_cast<Value *>(B);
3929 }
3930
3931 /// Get the landingpad instruction from the landing pad
3932 /// block (the unwind destination).
3933 LLVM_ABI LandingPadInst *getLandingPadInst() const;
3934
3935 BasicBlock *getSuccessor(unsigned i) const {
3936 assert(i < 2 && "Successor # out of range for invoke!");
3937 return i == 0 ? getNormalDest() : getUnwindDest();
3938 }
3939
3940 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
3941 assert(i < 2 && "Successor # out of range for invoke!");
3942 if (i == 0)
3943 setNormalDest(NewSucc);
3944 else
3945 setUnwindDest(NewSucc);
3946 }
3947
3948 unsigned getNumSuccessors() const { return 2; }
3949
3958
3959 /// Updates profile metadata by scaling it by \p S / \p T.
3960 LLVM_ABI void updateProfWeight(uint64_t S, uint64_t T);
3961
3962 // Methods for support type inquiry through isa, cast, and dyn_cast:
3963 static bool classof(const Instruction *I) {
3964 return (I->getOpcode() == Instruction::Invoke);
3965 }
3966 static bool classof(const Value *V) {
3968 }
3969
3970private:
3971 // Shadow Instruction::setInstructionSubclassData with a private forwarding
3972 // method so that subclasses cannot accidentally use it.
3973 template <typename Bitfield>
3974 void setSubclassData(typename Bitfield::Type Value) {
3976 }
3977};
3978
3979InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3980 BasicBlock *IfException, ArrayRef<Value *> Args,
3982 const Twine &NameStr, InsertPosition InsertBefore)
3983 : CallBase(Ty->getReturnType(), Instruction::Invoke, AllocInfo,
3984 InsertBefore) {
3985 init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
3986}
3987
3988//===----------------------------------------------------------------------===//
3989// CallBrInst Class
3990//===----------------------------------------------------------------------===//
3991
3992/// CallBr instruction, tracking function calls that may not return control but
3993/// instead transfer it to a third location. The SubclassData field is used to
3994/// hold the calling convention of the call.
3995///
3996class CallBrInst : public CallBase {
3997
3998 unsigned NumIndirectDests;
3999
4000 CallBrInst(const CallBrInst &BI, AllocInfo AllocInfo);
4001
4002 /// Construct a CallBrInst given a range of arguments.
4003 ///
4004 /// Construct a CallBrInst from a range of arguments
4005 inline CallBrInst(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
4006 ArrayRef<BasicBlock *> IndirectDests,
4008 AllocInfo AllocInfo, const Twine &NameStr,
4009 InsertPosition InsertBefore);
4010
4011 LLVM_ABI void init(FunctionType *FTy, Value *Func, BasicBlock *DefaultDest,
4012 ArrayRef<BasicBlock *> IndirectDests,
4014 const Twine &NameStr);
4015
4016 /// Compute the number of operands to allocate.
4017 static unsigned ComputeNumOperands(int NumArgs, int NumIndirectDests,
4018 int NumBundleInputs = 0) {
4019 // We need one operand for the called function, plus our extra operands and
4020 // the input operand counts provided.
4021 return unsigned(2 + NumIndirectDests + NumArgs + NumBundleInputs);
4022 }
4023
4024protected:
4025 // Note: Instruction needs to be a friend here to call cloneImpl.
4026 friend class Instruction;
4027
4028 LLVM_ABI CallBrInst *cloneImpl() const;
4029
4030public:
4031 static CallBrInst *Create(FunctionType *Ty, Value *Func,
4032 BasicBlock *DefaultDest,
4033 ArrayRef<BasicBlock *> IndirectDests,
4034 ArrayRef<Value *> Args, const Twine &NameStr,
4035 InsertPosition InsertBefore = nullptr) {
4036 IntrusiveOperandsAllocMarker AllocMarker{
4037 ComputeNumOperands(Args.size(), IndirectDests.size())};
4038 return new (AllocMarker)
4039 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, {}, AllocMarker,
4040 NameStr, InsertBefore);
4041 }
4042
4043 static CallBrInst *
4044 Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
4045 ArrayRef<BasicBlock *> IndirectDests, ArrayRef<Value *> Args,
4046 ArrayRef<OperandBundleDef> Bundles = {}, const Twine &NameStr = "",
4047 InsertPosition InsertBefore = nullptr) {
4048 IntrusiveOperandsAndDescriptorAllocMarker AllocMarker{
4049 ComputeNumOperands(Args.size(), IndirectDests.size(),
4050 CountBundleInputs(Bundles)),
4051 unsigned(Bundles.size() * sizeof(BundleOpInfo))};
4052
4053 return new (AllocMarker)
4054 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, Bundles,
4055 AllocMarker, NameStr, InsertBefore);
4056 }
4057
4058 static CallBrInst *Create(FunctionCallee Func, BasicBlock *DefaultDest,
4059 ArrayRef<BasicBlock *> IndirectDests,
4060 ArrayRef<Value *> Args, const Twine &NameStr,
4061 InsertPosition InsertBefore = nullptr) {
4062 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4063 IndirectDests, Args, NameStr, InsertBefore);
4064 }
4065
4066 static CallBrInst *Create(FunctionCallee Func, BasicBlock *DefaultDest,
4067 ArrayRef<BasicBlock *> IndirectDests,
4068 ArrayRef<Value *> Args,
4069 ArrayRef<OperandBundleDef> Bundles = {},
4070 const Twine &NameStr = "",
4071 InsertPosition InsertBefore = nullptr) {
4072 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4073 IndirectDests, Args, Bundles, NameStr, InsertBefore);
4074 }
4075
4076 /// Create a clone of \p CBI with a different set of operand bundles and
4077 /// insert it before \p InsertBefore.
4078 ///
4079 /// The returned callbr instruction is identical to \p CBI in every way
4080 /// except that the operand bundles for the new instruction are set to the
4081 /// operand bundles in \p Bundles.
4082 LLVM_ABI static CallBrInst *Create(CallBrInst *CBI,
4084 InsertPosition InsertBefore = nullptr);
4085
4086 /// Return the number of callbr indirect dest labels.
4087 ///
4088 unsigned getNumIndirectDests() const { return NumIndirectDests; }
4089
4090 /// getIndirectDestLabel - Return the i-th indirect dest label.
4091 ///
4092 Value *getIndirectDestLabel(unsigned i) const {
4093 assert(i < getNumIndirectDests() && "Out of bounds!");
4094 return getOperand(i + arg_size() + getNumTotalBundleOperands() + 1);
4095 }
4096
4097 Value *getIndirectDestLabelUse(unsigned i) const {
4098 assert(i < getNumIndirectDests() && "Out of bounds!");
4099 return getOperandUse(i + arg_size() + getNumTotalBundleOperands() + 1);
4100 }
4101
4102 // Return the destination basic blocks...
4104 return cast<BasicBlock>(*(&Op<-1>() - getNumIndirectDests() - 1));
4105 }
4106 BasicBlock *getIndirectDest(unsigned i) const {
4108 }
4110 SmallVector<BasicBlock *, 16> IndirectDests;
4111 for (unsigned i = 0, e = getNumIndirectDests(); i < e; ++i)
4112 IndirectDests.push_back(getIndirectDest(i));
4113 return IndirectDests;
4114 }
4116 *(&Op<-1>() - getNumIndirectDests() - 1) = reinterpret_cast<Value *>(B);
4117 }
4118 void setIndirectDest(unsigned i, BasicBlock *B) {
4119 *(&Op<-1>() - getNumIndirectDests() + i) = reinterpret_cast<Value *>(B);
4120 }
4121
4122 BasicBlock *getSuccessor(unsigned i) const {
4123 assert(i < getNumSuccessors() + 1 &&
4124 "Successor # out of range for callbr!");
4125 return i == 0 ? getDefaultDest() : getIndirectDest(i - 1);
4126 }
4127
4128 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
4129 assert(i < getNumIndirectDests() + 1 &&
4130 "Successor # out of range for callbr!");
4131 return i == 0 ? setDefaultDest(NewSucc) : setIndirectDest(i - 1, NewSucc);
4132 }
4133
4134 unsigned getNumSuccessors() const { return getNumIndirectDests() + 1; }
4135
4144
4145 // Methods for support type inquiry through isa, cast, and dyn_cast:
4146 static bool classof(const Instruction *I) {
4147 return (I->getOpcode() == Instruction::CallBr);
4148 }
4149 static bool classof(const Value *V) {
4151 }
4152
4153private:
4154 // Shadow Instruction::setInstructionSubclassData with a private forwarding
4155 // method so that subclasses cannot accidentally use it.
4156 template <typename Bitfield>
4157 void setSubclassData(typename Bitfield::Type Value) {
4159 }
4160};
4161
4162CallBrInst::CallBrInst(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
4163 ArrayRef<BasicBlock *> IndirectDests,
4164 ArrayRef<Value *> Args,
4166 const Twine &NameStr, InsertPosition InsertBefore)
4167 : CallBase(Ty->getReturnType(), Instruction::CallBr, AllocInfo,
4168 InsertBefore) {
4169 init(Ty, Func, DefaultDest, IndirectDests, Args, Bundles, NameStr);
4170}
4171
4172//===----------------------------------------------------------------------===//
4173// ResumeInst Class
4174//===----------------------------------------------------------------------===//
4175
4176//===---------------------------------------------------------------------------
4177/// Resume the propagation of an exception.
4178///
4179class ResumeInst : public Instruction {
4180 constexpr static IntrusiveOperandsAllocMarker AllocMarker{1};
4181
4182 ResumeInst(const ResumeInst &RI);
4183
4184 LLVM_ABI explicit ResumeInst(Value *Exn,
4185 InsertPosition InsertBefore = nullptr);
4186
4187protected:
4188 // Note: Instruction needs to be a friend here to call cloneImpl.
4189 friend class Instruction;
4190
4191 LLVM_ABI ResumeInst *cloneImpl() const;
4192
4193public:
4194 static ResumeInst *Create(Value *Exn, InsertPosition InsertBefore = nullptr) {
4195 return new (AllocMarker) ResumeInst(Exn, InsertBefore);
4196 }
4197
4198 /// Provide fast operand accessors
4200
4201 /// Convenience accessor.
4202 Value *getValue() const { return Op<0>(); }
4203
4204 unsigned getNumSuccessors() const { return 0; }
4205
4206 // Methods for support type inquiry through isa, cast, and dyn_cast:
4207 static bool classof(const Instruction *I) {
4208 return I->getOpcode() == Instruction::Resume;
4209 }
4210 static bool classof(const Value *V) {
4212 }
4213
4214private:
4215 BasicBlock *getSuccessor(unsigned idx) const {
4216 llvm_unreachable("ResumeInst has no successors!");
4217 }
4218
4219 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
4220 llvm_unreachable("ResumeInst has no successors!");
4221 }
4222
4223 iterator_range<succ_iterator> successors() {
4224 return {succ_iterator(op_end()), succ_iterator(op_end())};
4225 }
4226 iterator_range<const_succ_iterator> successors() const {
4228 }
4229};
4230
4231template <>
4233 public FixedNumOperandTraits<ResumeInst, 1> {
4234};
4235
4237
4238//===----------------------------------------------------------------------===//
4239// CatchSwitchInst Class
4240//===----------------------------------------------------------------------===//
4241class CatchSwitchInst : public Instruction {
4242 using UnwindDestField = BoolBitfieldElementT<0>;
4243
4244 constexpr static HungOffOperandsAllocMarker AllocMarker{};
4245
4246 /// The number of operands actually allocated. NumOperands is
4247 /// the number actually in use.
4248 unsigned ReservedSpace;
4249
4250 // Operand[0] = Outer scope
4251 // Operand[1] = Unwind block destination
4252 // Operand[n] = BasicBlock to go to on match
4253 CatchSwitchInst(const CatchSwitchInst &CSI);
4254
4255 /// Create a new switch instruction, specifying a
4256 /// default destination. The number of additional handlers can be specified
4257 /// here to make memory allocation more efficient.
4258 /// This constructor can also autoinsert before another instruction.
4259 LLVM_ABI CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
4260 unsigned NumHandlers, const Twine &NameStr,
4261 InsertPosition InsertBefore);
4262
4263 // allocate space for exactly zero operands
4264 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
4265
4266 void init(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumReserved);
4267 void growOperands(unsigned Size);
4268
4269protected:
4270 // Note: Instruction needs to be a friend here to call cloneImpl.
4271 friend class Instruction;
4272
4273 LLVM_ABI CatchSwitchInst *cloneImpl() const;
4274
4275public:
4276 void operator delete(void *Ptr) {
4277 return User::operator delete(Ptr, AllocMarker);
4278 }
4279
4280 static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest,
4281 unsigned NumHandlers,
4282 const Twine &NameStr = "",
4283 InsertPosition InsertBefore = nullptr) {
4284 return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
4285 InsertBefore);
4286 }
4287
4288 /// Provide fast operand accessors
4290
4291 // Accessor Methods for CatchSwitch stmt
4292 Value *getParentPad() const { return getOperand(0); }
4293 void setParentPad(Value *ParentPad) { setOperand(0, ParentPad); }
4294
4295 // Accessor Methods for CatchSwitch stmt
4297 bool unwindsToCaller() const { return !hasUnwindDest(); }
4299 if (hasUnwindDest())
4300 return cast<BasicBlock>(getOperand(1));
4301 return nullptr;
4302 }
4303 void setUnwindDest(BasicBlock *UnwindDest) {
4304 assert(UnwindDest);
4306 setOperand(1, UnwindDest);
4307 }
4308
4309 /// return the number of 'handlers' in this catchswitch
4310 /// instruction, except the default handler
4311 unsigned getNumHandlers() const {
4312 if (hasUnwindDest())
4313 return getNumOperands() - 2;
4314 return getNumOperands() - 1;
4315 }
4316
4317private:
4318 static BasicBlock *handler_helper(Value *V) { return cast<BasicBlock>(V); }
4319 static const BasicBlock *handler_helper(const Value *V) {
4320 return cast<BasicBlock>(V);
4321 }
4322
4323public:
4324 using DerefFnTy = BasicBlock *(*)(Value *);
4327 using ConstDerefFnTy = const BasicBlock *(*)(const Value *);
4331
4332 /// Returns an iterator that points to the first handler in CatchSwitchInst.
4334 op_iterator It = op_begin() + 1;
4335 if (hasUnwindDest())
4336 ++It;
4337 return handler_iterator(It, DerefFnTy(handler_helper));
4338 }
4339
4340 /// Returns an iterator that points to the first handler in the
4341 /// CatchSwitchInst.
4343 const_op_iterator It = op_begin() + 1;
4344 if (hasUnwindDest())
4345 ++It;
4346 return const_handler_iterator(It, ConstDerefFnTy(handler_helper));
4347 }
4348
4349 /// Returns a read-only iterator that points one past the last
4350 /// handler in the CatchSwitchInst.
4352 return handler_iterator(op_end(), DerefFnTy(handler_helper));
4353 }
4354
4355 /// Returns an iterator that points one past the last handler in the
4356 /// CatchSwitchInst.
4358 return const_handler_iterator(op_end(), ConstDerefFnTy(handler_helper));
4359 }
4360
4361 /// iteration adapter for range-for loops.
4365
4366 /// iteration adapter for range-for loops.
4370
4371 /// Add an entry to the switch instruction...
4372 /// Note:
4373 /// This action invalidates handler_end(). Old handler_end() iterator will
4374 /// point to the added handler.
4375 LLVM_ABI void addHandler(BasicBlock *Dest);
4376
4377 LLVM_ABI void removeHandler(handler_iterator HI);
4378
4379 unsigned getNumSuccessors() const { return getNumOperands() - 1; }
4380 BasicBlock *getSuccessor(unsigned Idx) const {
4381 assert(Idx < getNumSuccessors() &&
4382 "Successor # out of range for catchswitch!");
4383 return cast<BasicBlock>(getOperand(Idx + 1));
4384 }
4385 void setSuccessor(unsigned Idx, BasicBlock *NewSucc) {
4386 assert(Idx < getNumSuccessors() &&
4387 "Successor # out of range for catchswitch!");
4388 setOperand(Idx + 1, NewSucc);
4389 }
4390
4398
4399 // Methods for support type inquiry through isa, cast, and dyn_cast:
4400 static bool classof(const Instruction *I) {
4401 return I->getOpcode() == Instruction::CatchSwitch;
4402 }
4403 static bool classof(const Value *V) {
4405 }
4406};
4407
4408template <>
4410
4412
4413//===----------------------------------------------------------------------===//
4414// CleanupPadInst Class
4415//===----------------------------------------------------------------------===//
4416class CleanupPadInst : public FuncletPadInst {
4417private:
4418 explicit CleanupPadInst(Value *ParentPad, ArrayRef<Value *> Args,
4419 AllocInfo AllocInfo, const Twine &NameStr,
4420 InsertPosition InsertBefore)
4421 : FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, AllocInfo,
4422 NameStr, InsertBefore) {}
4423
4424public:
4425 static CleanupPadInst *Create(Value *ParentPad, ArrayRef<Value *> Args = {},
4426 const Twine &NameStr = "",
4427 InsertPosition InsertBefore = nullptr) {
4428 IntrusiveOperandsAllocMarker AllocMarker{unsigned(1 + Args.size())};
4429 return new (AllocMarker)
4430 CleanupPadInst(ParentPad, Args, AllocMarker, NameStr, InsertBefore);
4431 }
4432
4433 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4434 static bool classof(const Instruction *I) {
4435 return I->getOpcode() == Instruction::CleanupPad;
4436 }
4437 static bool classof(const Value *V) {
4439 }
4440};
4441
4442//===----------------------------------------------------------------------===//
4443// CatchPadInst Class
4444//===----------------------------------------------------------------------===//
4445class CatchPadInst : public FuncletPadInst {
4446private:
4447 explicit CatchPadInst(Value *CatchSwitch, ArrayRef<Value *> Args,
4448 AllocInfo AllocInfo, const Twine &NameStr,
4449 InsertPosition InsertBefore)
4450 : FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, AllocInfo,
4451 NameStr, InsertBefore) {}
4452
4453public:
4454 static CatchPadInst *Create(Value *CatchSwitch, ArrayRef<Value *> Args,
4455 const Twine &NameStr = "",
4456 InsertPosition InsertBefore = nullptr) {
4457 IntrusiveOperandsAllocMarker AllocMarker{unsigned(1 + Args.size())};
4458 return new (AllocMarker)
4459 CatchPadInst(CatchSwitch, Args, AllocMarker, NameStr, InsertBefore);
4460 }
4461
4462 /// Convenience accessors
4466 void setCatchSwitch(Value *CatchSwitch) {
4467 assert(CatchSwitch);
4468 Op<-1>() = CatchSwitch;
4469 }
4470
4471 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4472 static bool classof(const Instruction *I) {
4473 return I->getOpcode() == Instruction::CatchPad;
4474 }
4475 static bool classof(const Value *V) {
4477 }
4478};
4479
4480//===----------------------------------------------------------------------===//
4481// CatchReturnInst Class
4482//===----------------------------------------------------------------------===//
4483
4484class CatchReturnInst : public Instruction {
4485 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
4486
4487 CatchReturnInst(const CatchReturnInst &RI);
4488 LLVM_ABI CatchReturnInst(Value *CatchPad, BasicBlock *BB,
4489 InsertPosition InsertBefore);
4490
4491 void init(Value *CatchPad, BasicBlock *BB);
4492
4493protected:
4494 // Note: Instruction needs to be a friend here to call cloneImpl.
4495 friend class Instruction;
4496
4497 LLVM_ABI CatchReturnInst *cloneImpl() const;
4498
4499public:
4500 static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB,
4501 InsertPosition InsertBefore = nullptr) {
4502 assert(CatchPad);
4503 assert(BB);
4504 return new (AllocMarker) CatchReturnInst(CatchPad, BB, InsertBefore);
4505 }
4506
4507 /// Provide fast operand accessors
4509
4510 /// Convenience accessors.
4512 void setCatchPad(CatchPadInst *CatchPad) {
4513 assert(CatchPad);
4514 Op<0>() = CatchPad;
4515 }
4516
4518 void setSuccessor(BasicBlock *NewSucc) {
4519 assert(NewSucc);
4520 Op<1>() = NewSucc;
4521 }
4522 unsigned getNumSuccessors() const { return 1; }
4523
4524 /// Get the parentPad of this catchret's catchpad's catchswitch.
4525 /// The successor block is implicitly a member of this funclet.
4529
4530 // Methods for support type inquiry through isa, cast, and dyn_cast:
4531 static bool classof(const Instruction *I) {
4532 return (I->getOpcode() == Instruction::CatchRet);
4533 }
4534 static bool classof(const Value *V) {
4536 }
4537
4538private:
4539 BasicBlock *getSuccessor(unsigned Idx) const {
4540 assert(Idx < getNumSuccessors() && "Successor # out of range for catchret!");
4541 return getSuccessor();
4542 }
4543
4544 void setSuccessor(unsigned Idx, BasicBlock *B) {
4545 assert(Idx < getNumSuccessors() && "Successor # out of range for catchret!");
4546 setSuccessor(B);
4547 }
4548
4549 iterator_range<succ_iterator> successors() {
4550 return {succ_iterator(std::next(op_begin())), succ_iterator(op_end())};
4551 }
4552 iterator_range<const_succ_iterator> successors() const {
4553 return {const_succ_iterator(std::next(op_begin())),
4555 }
4556};
4557
4558template <>
4560 : public FixedNumOperandTraits<CatchReturnInst, 2> {};
4561
4563
4564//===----------------------------------------------------------------------===//
4565// CleanupReturnInst Class
4566//===----------------------------------------------------------------------===//
4567
4568class CleanupReturnInst : public Instruction {
4569 using UnwindDestField = BoolBitfieldElementT<0>;
4570
4571private:
4572 CleanupReturnInst(const CleanupReturnInst &RI, AllocInfo AllocInfo);
4573 LLVM_ABI CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB,
4575 InsertPosition InsertBefore = nullptr);
4576
4577 void init(Value *CleanupPad, BasicBlock *UnwindBB);
4578
4579protected:
4580 // Note: Instruction needs to be a friend here to call cloneImpl.
4581 friend class Instruction;
4582
4583 LLVM_ABI CleanupReturnInst *cloneImpl() const;
4584
4585public:
4586 static CleanupReturnInst *Create(Value *CleanupPad,
4587 BasicBlock *UnwindBB = nullptr,
4588 InsertPosition InsertBefore = nullptr) {
4589 assert(CleanupPad);
4590 unsigned Values = 1;
4591 if (UnwindBB)
4592 ++Values;
4593 IntrusiveOperandsAllocMarker AllocMarker{Values};
4594 return new (AllocMarker)
4595 CleanupReturnInst(CleanupPad, UnwindBB, AllocMarker, InsertBefore);
4596 }
4597
4598 /// Provide fast operand accessors
4600
4602 bool unwindsToCaller() const { return !hasUnwindDest(); }
4603
4604 /// Convenience accessor.
4606 return cast<CleanupPadInst>(Op<0>());
4607 }
4608 void setCleanupPad(CleanupPadInst *CleanupPad) {
4609 assert(CleanupPad);
4610 Op<0>() = CleanupPad;
4611 }
4612
4613 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
4614
4616 return hasUnwindDest() ? cast<BasicBlock>(Op<1>()) : nullptr;
4617 }
4618 void setUnwindDest(BasicBlock *NewDest) {
4619 assert(NewDest);
4621 Op<1>() = NewDest;
4622 }
4623
4624 // Methods for support type inquiry through isa, cast, and dyn_cast:
4625 static bool classof(const Instruction *I) {
4626 return (I->getOpcode() == Instruction::CleanupRet);
4627 }
4628 static bool classof(const Value *V) {
4630 }
4631
4632private:
4633 BasicBlock *getSuccessor(unsigned Idx) const {
4634 assert(Idx == 0);
4635 return getUnwindDest();
4636 }
4637
4638 void setSuccessor(unsigned Idx, BasicBlock *B) {
4639 assert(Idx == 0);
4640 setUnwindDest(B);
4641 }
4642
4644 return {succ_iterator(std::next(op_begin())), succ_iterator(op_end())};
4645 }
4647 return {const_succ_iterator(std::next(op_begin())),
4648 const_succ_iterator(op_end())};
4649 }
4650
4651 // Shadow Instruction::setInstructionSubclassData with a private forwarding
4652 // method so that subclasses cannot accidentally use it.
4653 template <typename Bitfield>
4654 void setSubclassData(typename Bitfield::Type Value) {
4656 }
4657};
4658
4659template <>
4661 : public VariadicOperandTraits<CleanupReturnInst> {};
4662
4664
4665//===----------------------------------------------------------------------===//
4666// UnreachableInst Class
4667//===----------------------------------------------------------------------===//
4668
4669//===---------------------------------------------------------------------------
4670/// This function has undefined behavior. In particular, the
4671/// presence of this instruction indicates some higher level knowledge that the
4672/// end of the block cannot be reached.
4673///
4675 constexpr static IntrusiveOperandsAllocMarker AllocMarker{0};
4676
4677protected:
4678 // Note: Instruction needs to be a friend here to call cloneImpl.
4679 friend class Instruction;
4680
4682
4683public:
4685 InsertPosition InsertBefore = nullptr);
4686
4687 // allocate space for exactly zero operands
4688 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
4689 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
4690
4691 unsigned getNumSuccessors() const { return 0; }
4692
4693 // Methods for support type inquiry through isa, cast, and dyn_cast:
4694 static bool classof(const Instruction *I) {
4695 return I->getOpcode() == Instruction::Unreachable;
4696 }
4697 static bool classof(const Value *V) {
4699 }
4700
4701 // Whether to do target lowering in SelectionDAG.
4702 LLVM_ABI bool shouldLowerToTrap(bool TrapUnreachable,
4703 bool NoTrapAfterNoreturn) const;
4704
4705private:
4706 BasicBlock *getSuccessor(unsigned idx) const {
4707 llvm_unreachable("UnreachableInst has no successors!");
4708 }
4709
4710 void setSuccessor(unsigned idx, BasicBlock *B) {
4711 llvm_unreachable("UnreachableInst has no successors!");
4712 }
4713
4715 return {succ_iterator(op_end()), succ_iterator(op_end())};
4716 }
4718 return {const_succ_iterator(op_end()), const_succ_iterator(op_end())};
4719 }
4720};
4721
4722//===----------------------------------------------------------------------===//
4723// TruncInst Class
4724//===----------------------------------------------------------------------===//
4725
4726/// This class represents a truncation of integer types.
4727class TruncInst : public CastInst {
4728protected:
4729 // Note: Instruction needs to be a friend here to call cloneImpl.
4730 friend class Instruction;
4731
4732 /// Clone an identical TruncInst
4733 LLVM_ABI TruncInst *cloneImpl() const;
4734
4735public:
4736 enum { AnyWrap = 0, NoUnsignedWrap = (1 << 0), NoSignedWrap = (1 << 1) };
4737
4738 /// Constructor with insert-before-instruction semantics
4739 LLVM_ABI
4740 TruncInst(Value *S, ///< The value to be truncated
4741 Type *Ty, ///< The (smaller) type to truncate to
4742 const Twine &NameStr = "", ///< A name for the new instruction
4743 InsertPosition InsertBefore =
4744 nullptr ///< Where to insert the new instruction
4745 );
4746
4747 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4748 static bool classof(const Instruction *I) {
4749 return I->getOpcode() == Trunc;
4750 }
4751 static bool classof(const Value *V) {
4753 }
4754
4763
4764 /// Test whether this operation is known to never
4765 /// undergo unsigned overflow, aka the nuw property.
4766 bool hasNoUnsignedWrap() const {
4768 }
4769
4770 /// Test whether this operation is known to never
4771 /// undergo signed overflow, aka the nsw property.
4772 bool hasNoSignedWrap() const {
4773 return (SubclassOptionalData & NoSignedWrap) != 0;
4774 }
4775
4776 /// Returns the no-wrap kind of the operation.
4777 unsigned getNoWrapKind() const {
4778 unsigned NoWrapKind = 0;
4779 if (hasNoUnsignedWrap())
4780 NoWrapKind |= NoUnsignedWrap;
4781
4782 if (hasNoSignedWrap())
4783 NoWrapKind |= NoSignedWrap;
4784
4785 return NoWrapKind;
4786 }
4787};
4788
4789//===----------------------------------------------------------------------===//
4790// ZExtInst Class
4791//===----------------------------------------------------------------------===//
4792
4793/// This class represents zero extension of integer types.
4794class ZExtInst : public CastInst {
4795protected:
4796 // Note: Instruction needs to be a friend here to call cloneImpl.
4797 friend class Instruction;
4798
4799 /// Clone an identical ZExtInst
4800 LLVM_ABI ZExtInst *cloneImpl() const;
4801
4802public:
4803 /// Constructor with insert-before-instruction semantics
4804 LLVM_ABI
4805 ZExtInst(Value *S, ///< The value to be zero extended
4806 Type *Ty, ///< The type to zero extend to
4807 const Twine &NameStr = "", ///< A name for the new instruction
4808 InsertPosition InsertBefore =
4809 nullptr ///< Where to insert the new instruction
4810 );
4811
4812 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4813 static bool classof(const Instruction *I) {
4814 return I->getOpcode() == ZExt;
4815 }
4816 static bool classof(const Value *V) {
4818 }
4819};
4820
4821//===----------------------------------------------------------------------===//
4822// SExtInst Class
4823//===----------------------------------------------------------------------===//
4824
4825/// This class represents a sign extension of integer types.
4826class SExtInst : public CastInst {
4827protected:
4828 // Note: Instruction needs to be a friend here to call cloneImpl.
4829 friend class Instruction;
4830
4831 /// Clone an identical SExtInst
4832 LLVM_ABI SExtInst *cloneImpl() const;
4833
4834public:
4835 /// Constructor with insert-before-instruction semantics
4836 LLVM_ABI
4837 SExtInst(Value *S, ///< The value to be sign extended
4838 Type *Ty, ///< The type to sign extend to
4839 const Twine &NameStr = "", ///< A name for the new instruction
4840 InsertPosition InsertBefore =
4841 nullptr ///< Where to insert the new instruction
4842 );
4843
4844 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4845 static bool classof(const Instruction *I) {
4846 return I->getOpcode() == SExt;
4847 }
4848 static bool classof(const Value *V) {
4850 }
4851};
4852
4853//===----------------------------------------------------------------------===//
4854// FPTruncInst Class
4855//===----------------------------------------------------------------------===//
4856
4857/// This class represents a truncation of floating point types.
4858class FPTruncInst : public CastInst {
4859protected:
4860 // Note: Instruction needs to be a friend here to call cloneImpl.
4861 friend class Instruction;
4862
4863 /// Clone an identical FPTruncInst
4865
4866public: /// Constructor with insert-before-instruction semantics
4867 LLVM_ABI
4868 FPTruncInst(Value *S, ///< The value to be truncated
4869 Type *Ty, ///< The type to truncate to
4870 const Twine &NameStr = "", ///< A name for the new instruction
4871 InsertPosition InsertBefore =
4872 nullptr ///< Where to insert the new instruction
4873 );
4874
4875 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4876 static bool classof(const Instruction *I) {
4877 return I->getOpcode() == FPTrunc;
4878 }
4879 static bool classof(const Value *V) {
4881 }
4882};
4883
4884//===----------------------------------------------------------------------===//
4885// FPExtInst Class
4886//===----------------------------------------------------------------------===//
4887
4888/// This class represents an extension of floating point types.
4889class FPExtInst : public CastInst {
4890protected:
4891 // Note: Instruction needs to be a friend here to call cloneImpl.
4892 friend class Instruction;
4893
4894 /// Clone an identical FPExtInst
4895 LLVM_ABI FPExtInst *cloneImpl() const;
4896
4897public:
4898 /// Constructor with insert-before-instruction semantics
4899 LLVM_ABI
4900 FPExtInst(Value *S, ///< The value to be extended
4901 Type *Ty, ///< The type to extend to
4902 const Twine &NameStr = "", ///< A name for the new instruction
4903 InsertPosition InsertBefore =
4904 nullptr ///< Where to insert the new instruction
4905 );
4906
4907 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4908 static bool classof(const Instruction *I) {
4909 return I->getOpcode() == FPExt;
4910 }
4911 static bool classof(const Value *V) {
4913 }
4914};
4915
4916//===----------------------------------------------------------------------===//
4917// UIToFPInst Class
4918//===----------------------------------------------------------------------===//
4919
4920/// This class represents a cast unsigned integer to floating point.
4921class UIToFPInst : public CastInst {
4922protected:
4923 // Note: Instruction needs to be a friend here to call cloneImpl.
4924 friend class Instruction;
4925
4926 /// Clone an identical UIToFPInst
4927 LLVM_ABI UIToFPInst *cloneImpl() const;
4928
4929public:
4930 /// Constructor with insert-before-instruction semantics
4931 LLVM_ABI
4932 UIToFPInst(Value *S, ///< The value to be converted
4933 Type *Ty, ///< The type to convert to
4934 const Twine &NameStr = "", ///< A name for the new instruction
4935 InsertPosition InsertBefore =
4936 nullptr ///< Where to insert the new instruction
4937 );
4938
4939 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4940 static bool classof(const Instruction *I) {
4941 return I->getOpcode() == UIToFP;
4942 }
4943 static bool classof(const Value *V) {
4945 }
4946};
4947
4948//===----------------------------------------------------------------------===//
4949// SIToFPInst Class
4950//===----------------------------------------------------------------------===//
4951
4952/// This class represents a cast from signed integer to floating point.
4953class SIToFPInst : public CastInst {
4954protected:
4955 // Note: Instruction needs to be a friend here to call cloneImpl.
4956 friend class Instruction;
4957
4958 /// Clone an identical SIToFPInst
4959 LLVM_ABI SIToFPInst *cloneImpl() const;
4960
4961public:
4962 /// Constructor with insert-before-instruction semantics
4963 LLVM_ABI
4964 SIToFPInst(Value *S, ///< The value to be converted
4965 Type *Ty, ///< The type to convert to
4966 const Twine &NameStr = "", ///< A name for the new instruction
4967 InsertPosition InsertBefore =
4968 nullptr ///< Where to insert the new instruction
4969 );
4970
4971 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4972 static bool classof(const Instruction *I) {
4973 return I->getOpcode() == SIToFP;
4974 }
4975 static bool classof(const Value *V) {
4977 }
4978};
4979
4980//===----------------------------------------------------------------------===//
4981// FPToUIInst Class
4982//===----------------------------------------------------------------------===//
4983
4984/// This class represents a cast from floating point to unsigned integer
4985class FPToUIInst : public CastInst {
4986protected:
4987 // Note: Instruction needs to be a friend here to call cloneImpl.
4988 friend class Instruction;
4989
4990 /// Clone an identical FPToUIInst
4991 LLVM_ABI FPToUIInst *cloneImpl() const;
4992
4993public:
4994 /// Constructor with insert-before-instruction semantics
4995 LLVM_ABI
4996 FPToUIInst(Value *S, ///< The value to be converted
4997 Type *Ty, ///< The type to convert to
4998 const Twine &NameStr = "", ///< A name for the new instruction
4999 InsertPosition InsertBefore =
5000 nullptr ///< Where to insert the new instruction
5001 );
5002
5003 /// Methods for support type inquiry through isa, cast, and dyn_cast:
5004 static bool classof(const Instruction *I) {
5005 return I->getOpcode() == FPToUI;
5006 }
5007 static bool classof(const Value *V) {
5009 }
5010};
5011
5012//===----------------------------------------------------------------------===//
5013// FPToSIInst Class
5014//===----------------------------------------------------------------------===//
5015
5016/// This class represents a cast from floating point to signed integer.
5017class FPToSIInst : public CastInst {
5018protected:
5019 // Note: Instruction needs to be a friend here to call cloneImpl.
5020 friend class Instruction;
5021
5022 /// Clone an identical FPToSIInst
5023 LLVM_ABI FPToSIInst *cloneImpl() const;
5024
5025public:
5026 /// Constructor with insert-before-instruction semantics
5027 LLVM_ABI
5028 FPToSIInst(Value *S, ///< The value to be converted
5029 Type *Ty, ///< The type to convert to
5030 const Twine &NameStr = "", ///< A name for the new instruction
5031 InsertPosition InsertBefore =
5032 nullptr ///< Where to insert the new instruction
5033 );
5034
5035 /// Methods for support type inquiry through isa, cast, and dyn_cast:
5036 static bool classof(const Instruction *I) {
5037 return I->getOpcode() == FPToSI;
5038 }
5039 static bool classof(const Value *V) {
5041 }
5042};
5043
5044//===----------------------------------------------------------------------===//
5045// IntToPtrInst Class
5046//===----------------------------------------------------------------------===//
5047
5048/// This class represents a cast from an integer to a pointer.
5049class IntToPtrInst : public CastInst {
5050public:
5051 // Note: Instruction needs to be a friend here to call cloneImpl.
5052 friend class Instruction;
5053
5054 /// Constructor with insert-before-instruction semantics
5055 LLVM_ABI
5056 IntToPtrInst(Value *S, ///< The value to be converted
5057 Type *Ty, ///< The type to convert to
5058 const Twine &NameStr = "", ///< A name for the new instruction
5059 InsertPosition InsertBefore =
5060 nullptr ///< Where to insert the new instruction
5061 );
5062
5063 /// Clone an identical IntToPtrInst.
5065
5066 /// Returns the address space of this instruction's pointer type.
5067 unsigned getAddressSpace() const {
5068 return getType()->getPointerAddressSpace();
5069 }
5070
5071 // Methods for support type inquiry through isa, cast, and dyn_cast:
5072 static bool classof(const Instruction *I) {
5073 return I->getOpcode() == IntToPtr;
5074 }
5075 static bool classof(const Value *V) {
5077 }
5078};
5079
5080//===----------------------------------------------------------------------===//
5081// PtrToIntInst Class
5082//===----------------------------------------------------------------------===//
5083
5084/// This class represents a cast from a pointer to an integer.
5085class PtrToIntInst : public CastInst {
5086protected:
5087 // Note: Instruction needs to be a friend here to call cloneImpl.
5088 friend class Instruction;
5089
5090 /// Clone an identical PtrToIntInst.
5092
5093public:
5094 /// Constructor with insert-before-instruction semantics
5095 LLVM_ABI
5096 PtrToIntInst(Value *S, ///< The value to be converted
5097 Type *Ty, ///< The type to convert to
5098 const Twine &NameStr = "", ///< A name for the new instruction
5099 InsertPosition InsertBefore =
5100 nullptr ///< Where to insert the new instruction
5101 );
5102
5103 /// Gets the pointer operand.
5105 /// Gets the pointer operand.
5106 const Value *getPointerOperand() const { return getOperand(0); }
5107 /// Gets the operand index of the pointer operand.
5108 static unsigned getPointerOperandIndex() { return 0U; }
5109
5110 /// Returns the address space of the pointer operand.
5111 unsigned getPointerAddressSpace() const {
5113 }
5114
5115 // Methods for support type inquiry through isa, cast, and dyn_cast:
5116 static bool classof(const Instruction *I) {
5117 return I->getOpcode() == PtrToInt;
5118 }
5119 static bool classof(const Value *V) {
5121 }
5122};
5123
5124/// This class represents a cast from a pointer to an address (non-capturing
5125/// ptrtoint).
5126class PtrToAddrInst : public CastInst {
5127protected:
5128 // Note: Instruction needs to be a friend here to call cloneImpl.
5129 friend class Instruction;
5130
5131 /// Clone an identical PtrToAddrInst.
5132 PtrToAddrInst *cloneImpl() const;
5133
5134public:
5135 /// Constructor with insert-before-instruction semantics
5136 PtrToAddrInst(Value *S, ///< The value to be converted
5137 Type *Ty, ///< The type to convert to
5138 const Twine &NameStr = "", ///< A name for the new instruction
5139 InsertPosition InsertBefore =
5140 nullptr ///< Where to insert the new instruction
5141 );
5142
5143 /// Gets the pointer operand.
5145 /// Gets the pointer operand.
5146 const Value *getPointerOperand() const { return getOperand(0); }
5147 /// Gets the operand index of the pointer operand.
5148 static unsigned getPointerOperandIndex() { return 0U; }
5149
5150 /// Returns the address space of the pointer operand.
5151 unsigned getPointerAddressSpace() const {
5153 }
5154
5155 // Methods for support type inquiry through isa, cast, and dyn_cast:
5156 static bool classof(const Instruction *I) {
5157 return I->getOpcode() == PtrToAddr;
5158 }
5159 static bool classof(const Value *V) {
5161 }
5162};
5163
5164//===----------------------------------------------------------------------===//
5165// BitCastInst Class
5166//===----------------------------------------------------------------------===//
5167
5168/// This class represents a no-op cast from one type to another.
5169class BitCastInst : public CastInst {
5170protected:
5171 // Note: Instruction needs to be a friend here to call cloneImpl.
5172 friend class Instruction;
5173
5174 /// Clone an identical BitCastInst.
5176
5177public:
5178 /// Constructor with insert-before-instruction semantics
5179 LLVM_ABI
5180 BitCastInst(Value *S, ///< The value to be casted
5181 Type *Ty, ///< The type to casted to
5182 const Twine &NameStr = "", ///< A name for the new instruction
5183 InsertPosition InsertBefore =
5184 nullptr ///< Where to insert the new instruction
5185 );
5186
5187 // Methods for support type inquiry through isa, cast, and dyn_cast:
5188 static bool classof(const Instruction *I) {
5189 return I->getOpcode() == BitCast;
5190 }
5191 static bool classof(const Value *V) {
5193 }
5194};
5195
5196//===----------------------------------------------------------------------===//
5197// AddrSpaceCastInst Class
5198//===----------------------------------------------------------------------===//
5199
5200/// This class represents a conversion between pointers from one address space
5201/// to another.
5203protected:
5204 // Note: Instruction needs to be a friend here to call cloneImpl.
5205 friend class Instruction;
5206
5207 /// Clone an identical AddrSpaceCastInst.
5209
5210public:
5211 /// Constructor with insert-before-instruction semantics
5213 Value *S, ///< The value to be casted
5214 Type *Ty, ///< The type to casted to
5215 const Twine &NameStr = "", ///< A name for the new instruction
5216 InsertPosition InsertBefore =
5217 nullptr ///< Where to insert the new instruction
5218 );
5219
5220 // Methods for support type inquiry through isa, cast, and dyn_cast:
5221 static bool classof(const Instruction *I) {
5222 return I->getOpcode() == AddrSpaceCast;
5223 }
5224 static bool classof(const Value *V) {
5226 }
5227
5228 /// Gets the pointer operand.
5230 return getOperand(0);
5231 }
5232
5233 /// Gets the pointer operand.
5234 const Value *getPointerOperand() const {
5235 return getOperand(0);
5236 }
5237
5238 /// Gets the operand index of the pointer operand.
5239 static unsigned getPointerOperandIndex() {
5240 return 0U;
5241 }
5242
5243 /// Returns the address space of the pointer operand.
5244 unsigned getSrcAddressSpace() const {
5246 }
5247
5248 /// Returns the address space of the result.
5249 unsigned getDestAddressSpace() const {
5250 return getType()->getPointerAddressSpace();
5251 }
5252};
5253
5254//===----------------------------------------------------------------------===//
5255// Helper functions
5256//===----------------------------------------------------------------------===//
5257
5258/// A helper function that returns the pointer operand of a load or store
5259/// instruction. Returns nullptr if not load or store.
5260inline const Value *getLoadStorePointerOperand(const Value *V) {
5261 if (auto *Load = dyn_cast<LoadInst>(V))
5262 return Load->getPointerOperand();
5263 if (auto *Store = dyn_cast<StoreInst>(V))
5264 return Store->getPointerOperand();
5265 return nullptr;
5266}
5268 return const_cast<Value *>(
5269 getLoadStorePointerOperand(static_cast<const Value *>(V)));
5270}
5271
5272/// A helper function that returns the pointer operand of a load, store
5273/// or GEP instruction. Returns nullptr if not load, store, or GEP.
5274inline const Value *getPointerOperand(const Value *V) {
5275 if (auto *Ptr = getLoadStorePointerOperand(V))
5276 return Ptr;
5277 if (auto *Gep = dyn_cast<GetElementPtrInst>(V))
5278 return Gep->getPointerOperand();
5279 return nullptr;
5280}
5282 return const_cast<Value *>(getPointerOperand(static_cast<const Value *>(V)));
5283}
5284
5285/// A helper function that returns the alignment of load or store instruction.
5288 "Expected Load or Store instruction");
5289 if (auto *LI = dyn_cast<LoadInst>(I))
5290 return LI->getAlign();
5291 return cast<StoreInst>(I)->getAlign();
5292}
5293
5294/// A helper function that set the alignment of load or store instruction.
5295inline void setLoadStoreAlignment(Value *I, Align NewAlign) {
5297 "Expected Load or Store instruction");
5298 if (auto *LI = dyn_cast<LoadInst>(I))
5299 LI->setAlignment(NewAlign);
5300 else
5301 cast<StoreInst>(I)->setAlignment(NewAlign);
5302}
5303
5304/// A helper function that returns the address space of the pointer operand of
5305/// load or store instruction.
5306inline unsigned getLoadStoreAddressSpace(const Value *I) {
5308 "Expected Load or Store instruction");
5309 if (auto *LI = dyn_cast<LoadInst>(I))
5310 return LI->getPointerAddressSpace();
5311 return cast<StoreInst>(I)->getPointerAddressSpace();
5312}
5313
5314/// A helper function that returns the type of a load or store instruction.
5315inline Type *getLoadStoreType(const Value *I) {
5317 "Expected Load or Store instruction");
5318 if (auto *LI = dyn_cast<LoadInst>(I))
5319 return LI->getType();
5320 return cast<StoreInst>(I)->getValueOperand()->getType();
5321}
5322
5323/// A helper function that returns an atomic operation's sync scope; returns
5324/// std::nullopt if it is not an atomic operation.
5325inline std::optional<SyncScope::ID> getAtomicSyncScopeID(const Instruction *I) {
5326 if (!I->isAtomic())
5327 return std::nullopt;
5328 if (auto *AI = dyn_cast<LoadInst>(I))
5329 return AI->getSyncScopeID();
5330 if (auto *AI = dyn_cast<StoreInst>(I))
5331 return AI->getSyncScopeID();
5332 if (auto *AI = dyn_cast<FenceInst>(I))
5333 return AI->getSyncScopeID();
5334 if (auto *AI = dyn_cast<AtomicCmpXchgInst>(I))
5335 return AI->getSyncScopeID();
5336 if (auto *AI = dyn_cast<AtomicRMWInst>(I))
5337 return AI->getSyncScopeID();
5338 llvm_unreachable("unhandled atomic operation");
5339}
5340
5341/// A helper function that sets an atomic operation's sync scope.
5343 assert(I->isAtomic());
5344 if (auto *AI = dyn_cast<LoadInst>(I))
5345 AI->setSyncScopeID(SSID);
5346 else if (auto *AI = dyn_cast<StoreInst>(I))
5347 AI->setSyncScopeID(SSID);
5348 else if (auto *AI = dyn_cast<FenceInst>(I))
5349 AI->setSyncScopeID(SSID);
5350 else if (auto *AI = dyn_cast<AtomicCmpXchgInst>(I))
5351 AI->setSyncScopeID(SSID);
5352 else if (auto *AI = dyn_cast<AtomicRMWInst>(I))
5353 AI->setSyncScopeID(SSID);
5354 else
5355 llvm_unreachable("unhandled atomic operation");
5356}
5357
5358//===----------------------------------------------------------------------===//
5359// FreezeInst Class
5360//===----------------------------------------------------------------------===//
5361
5362/// This class represents a freeze function that returns random concrete
5363/// value if an operand is either a poison value or an undef value
5365protected:
5366 // Note: Instruction needs to be a friend here to call cloneImpl.
5367 friend class Instruction;
5368
5369 /// Clone an identical FreezeInst
5370 LLVM_ABI FreezeInst *cloneImpl() const;
5371
5372public:
5373 LLVM_ABI explicit FreezeInst(Value *S, const Twine &NameStr = "",
5374 InsertPosition InsertBefore = nullptr);
5375
5376 // Methods for support type inquiry through isa, cast, and dyn_cast:
5377 static inline bool classof(const Instruction *I) {
5378 return I->getOpcode() == Freeze;
5379 }
5380 static inline bool classof(const Value *V) {
5382 }
5383};
5384
5385} // end namespace llvm
5386
5387#endif // LLVM_IR_INSTRUCTIONS_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
constexpr LLT S1
static bool isReverseMask(ArrayRef< int > M, EVT VT)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
always inline
Atomic ordering constants.
static const Function * getParent(const Value *V)
This file implements methods to test, set and extract typed bits from packed unsigned integers.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
static Value * getCondition(Instruction *I)
static void setCondition(Instruction *I, Value *NewCond)
Hexagon Common GEP
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This defines the Use class.
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file implements a map that provides insertion order iteration.
#define T
uint64_t IntrinsicInst * II
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
#define P(N)
PowerPC Reduce CR logical Operation
This file contains the declarations for profiling metadata utility functions.
const SmallVectorImpl< MachineOperand > & Cond
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallVector class.
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
const Value * getPointerOperand() const
Gets the pointer operand.
LLVM_ABI AddrSpaceCastInst * cloneImpl() const
Clone an identical AddrSpaceCastInst.
Value * getPointerOperand()
Gets the pointer operand.
static bool classof(const Instruction *I)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Value *V)
unsigned getSrcAddressSpace() const
Returns the address space of the pointer operand.
LLVM_ABI AddrSpaceCastInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
unsigned getDestAddressSpace() const
Returns the address space of the result.
static unsigned getPointerOperandIndex()
Gets the operand index of the pointer operand.
LLVM_ABI std::optional< TypeSize > getAllocationSizeInBits(const DataLayout &DL) const
Get allocation size in bits.
static bool classof(const Value *V)
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
void setSwiftError(bool V)
Specify whether this alloca is used to represent a swifterror.
LLVM_ABI bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
void setAllocatedType(Type *Ty)
for use only in special circumstances that need to generically transform a whole instruction (eg: IR ...
static bool classof(const Instruction *I)
PointerType * getType() const
Overload to return most specific pointer type.
void setUsedWithInAlloca(bool V)
Specify whether this alloca is used to represent the arguments to a call.
LLVM_ABI AllocaInst * cloneImpl() const
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
Value * getArraySize()
unsigned getAddressSpace() const
Return the address space for the allocation.
LLVM_ABI std::optional< TypeSize > getAllocationSize(const DataLayout &DL) const
Get allocation size in bytes.
LLVM_ABI bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1.
void setAlignment(Align Align)
const Value * getArraySize() const
Get the number of elements allocated.
LLVM_ABI AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, const Twine &Name, InsertPosition InsertBefore)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
size - Get the array size.
Definition ArrayRef.h:142
An instruction that atomically checks whether a specified value is in a memory location,...
BoolBitfieldElementT< 0 > VolatileField
const Value * getCompareOperand() const
AlignmentBitfieldElementT< FailureOrderingField::NextBit > AlignmentField
void setSyncScopeID(SyncScope::ID SSID)
Sets the synchronization scope ID of this cmpxchg instruction.
AtomicOrdering getMergedOrdering() const
Returns a single ordering which is at least as strong as both the success and failure orderings for t...
void setWeak(bool IsWeak)
bool isVolatile() const
Return true if this is a cmpxchg from a volatile memory location.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
BoolBitfieldElementT< VolatileField::NextBit > WeakField
void setFailureOrdering(AtomicOrdering Ordering)
Sets the failure ordering constraint of this cmpxchg instruction.
AtomicOrderingBitfieldElementT< SuccessOrderingField::NextBit > FailureOrderingField
static bool isValidFailureOrdering(AtomicOrdering Ordering)
AtomicOrderingBitfieldElementT< WeakField::NextBit > SuccessOrderingField
AtomicOrdering getFailureOrdering() const
Returns the failure ordering constraint of this cmpxchg instruction.
void setSuccessOrdering(AtomicOrdering Ordering)
Sets the success ordering constraint of this cmpxchg instruction.
static AtomicOrdering getStrongestFailureOrdering(AtomicOrdering SuccessOrdering)
Returns the strongest permitted ordering on failure, given the desired ordering on success.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
LLVM_ABI AtomicCmpXchgInst * cloneImpl() const
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
const Value * getPointerOperand() const
static bool classof(const Value *V)
bool isWeak() const
Return true if this cmpxchg may spuriously fail.
void setAlignment(Align Align)
void setVolatile(bool V)
Specify whether this is a volatile cmpxchg.
static bool isValidSuccessOrdering(AtomicOrdering Ordering)
AtomicOrdering getSuccessOrdering() const
Returns the success ordering constraint of this cmpxchg instruction.
static unsigned getPointerOperandIndex()
const Value * getNewValOperand() const
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this cmpxchg instruction.
LLVM_ABI AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, Align Alignment, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID, InsertPosition InsertBefore=nullptr)
static bool classof(const Instruction *I)
an instruction that atomically reads a memory location, combines it with another value,...
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
static bool isFPOperation(BinOp Op)
LLVM_ABI AtomicRMWInst * cloneImpl() const
static unsigned getPointerOperandIndex()
bool isVolatile() const
Return true if this is a RMW on a volatile memory location.
void setVolatile(bool V)
Specify whether this is a volatile RMW or not.
BinOpBitfieldElement< AtomicOrderingField::NextBit > OperationField
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ Add
*p = old + v
@ FAdd
*p = old + v
@ USubCond
Subtract only if no unsigned overflow.
@ FMinimum
*p = minimum(old, v) minimum matches the behavior of llvm.minimum.
@ Min
*p = old <signed v ? old : v
@ Sub
*p = old - v
@ And
*p = old & v
@ Xor
*p = old ^ v
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
@ FMaximum
*p = maximum(old, v) maximum matches the behavior of llvm.maximum.
@ FSub
*p = old - v
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMaximumNum
*p = maximumnum(old, v) maximumnum matches the behavior of llvm.maximumnum.
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
@ FMinimumNum
*p = minimumnum(old, v) minimumnum matches the behavior of llvm.minimumnum.
@ Nand
*p = ~(old & v)
void setSyncScopeID(SyncScope::ID SSID)
Sets the synchronization scope ID of this rmw instruction.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
Value * getPointerOperand()
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this rmw instruction.
bool isFloatingPointOperation() const
static bool classof(const Instruction *I)
const Value * getPointerOperand() const
void setOperation(BinOp Operation)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Value *V)
BinOp getOperation() const
const Value * getValOperand() const
LLVM_ABI AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, Align Alignment, AtomicOrdering Ordering, SyncScope::ID SSID, InsertPosition InsertBefore=nullptr)
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this rmw instruction.
void setAlignment(Align Align)
AtomicOrdering getOrdering() const
Returns the ordering constraint of this rmw instruction.
AlignmentBitfieldElementT< OperationField::NextBit > AlignmentField
BoolBitfieldElementT< 0 > VolatileField
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
AtomicOrderingBitfieldElementT< VolatileField::NextBit > AtomicOrderingField
LLVM Basic Block Representation.
Definition BasicBlock.h:62
static bool classof(const Instruction *I)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Value *V)
LLVM_ABI BitCastInst * cloneImpl() const
Clone an identical BitCastInst.
LLVM_ABI BitCastInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
Conditional or Unconditional Branch instruction.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
void setCondition(Value *V)
static bool classof(const Instruction *I)
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
bool isConditional() const
static bool classof(const Value *V)
BranchInst(Type *Ty, unsigned Opcode, AllocInfo AllocInfo, InsertPosition InsertBefore=nullptr)
bool isUnconditional() const
Value * getCondition() const
void swapSuccessors()
Swap the successors of this branch instruction.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
void addFnAttr(Attribute::AttrKind Kind)
Adds the attribute to the function.
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
CallBase(AttributeList const &A, FunctionType *FT, ArgsTy &&... Args)
FunctionType * FTy
LLVM_ABI Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
static unsigned CountBundleInputs(ArrayRef< OperandBundleDef > Bundles)
Return the total number of values used in Bundles.
unsigned arg_size() const
unsigned getNumTotalBundleOperands() const
Return the total number operands (not operand bundles) used by every operand bundle in this OperandBu...
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
static bool classof(const Value *V)
static CallBrInst * Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles={}, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
iterator_range< succ_iterator > successors()
static bool classof(const Instruction *I)
static CallBrInst * Create(FunctionCallee Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles={}, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
SmallVector< BasicBlock *, 16 > getIndirectDests() const
iterator_range< const_succ_iterator > successors() const
static CallBrInst * Create(FunctionCallee Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
void setSuccessor(unsigned i, BasicBlock *NewSucc)
BasicBlock * getSuccessor(unsigned i) const
Value * getIndirectDestLabelUse(unsigned i) const
BasicBlock * getIndirectDest(unsigned i) const
friend class Instruction
Iterator for Instructions in a `BasicBlock.
void setDefaultDest(BasicBlock *B)
unsigned getNumSuccessors() const
void setIndirectDest(unsigned i, BasicBlock *B)
Value * getIndirectDestLabel(unsigned i) const
getIndirectDestLabel - Return the i-th indirect dest label.
BasicBlock * getDefaultDest() const
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
static CallBrInst * Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
LLVM_ABI CallBrInst * cloneImpl() const
This class represents a function call, abstracting a target machine's calling convention.
bool isNoTailCall() const
LLVM_ABI void updateProfWeight(uint64_t S, uint64_t T)
Updates profile metadata by scaling it by S / T.
static bool classof(const Value *V)
bool isTailCall() const
void setCanReturnTwice()
void setTailCallKind(TailCallKind TCK)
Bitfield::Element< TailCallKind, 0, 2, TCK_LAST > TailCallKindField
static CallInst * Create(FunctionType *Ty, Value *Func, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles={}, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CallInst * Create(FunctionType *Ty, Value *Func, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
bool canReturnTwice() const
Return true if the call can return twice.
TailCallKind getTailCallKind() const
LLVM_ABI CallInst * cloneImpl() const
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
void setTailCall(bool IsTc=true)
bool isMustTailCall() const
static CallInst * Create(FunctionCallee Func, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
static bool classof(const Instruction *I)
bool isNonContinuableTrap() const
Return true if the call is for a noreturn trap intrinsic.
static CallInst * Create(FunctionCallee Func, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CallInst * Create(FunctionCallee Func, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles={}, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics for subclasses.
Definition InstrTypes.h:451
CatchSwitchInst * getCatchSwitch() const
Convenience accessors.
void setCatchSwitch(Value *CatchSwitch)
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
static CatchPadInst * Create(Value *CatchSwitch, ArrayRef< Value * > Args, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static bool classof(const Value *V)
static bool classof(const Instruction *I)
BasicBlock * getSuccessor() const
CatchPadInst * getCatchPad() const
Convenience accessors.
void setSuccessor(BasicBlock *NewSucc)
static bool classof(const Value *V)
static CatchReturnInst * Create(Value *CatchPad, BasicBlock *BB, InsertPosition InsertBefore=nullptr)
unsigned getNumSuccessors() const
friend class Instruction
Iterator for Instructions in a `BasicBlock.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide fast operand accessors.
void setCatchPad(CatchPadInst *CatchPad)
LLVM_ABI CatchReturnInst * cloneImpl() const
Value * getCatchSwitchParentPad() const
Get the parentPad of this catchret's catchpad's catchswitch.
void setUnwindDest(BasicBlock *UnwindDest)
static bool classof(const Instruction *I)
BasicBlock *(*)(Value *) DerefFnTy
const BasicBlock *(*)(const Value *) ConstDerefFnTy
unsigned getNumSuccessors() const
const_handler_iterator handler_begin() const
Returns an iterator that points to the first handler in the CatchSwitchInst.
mapped_iterator< const_op_iterator, ConstDerefFnTy > const_handler_iterator
LLVM_ABI CatchSwitchInst * cloneImpl() const
mapped_iterator< op_iterator, DerefFnTy > handler_iterator
unsigned getNumHandlers() const
return the number of 'handlers' in this catchswitch instruction, except the default handler
iterator_range< handler_iterator > handler_range
void setSuccessor(unsigned Idx, BasicBlock *NewSucc)
Value * getParentPad() const
iterator_range< const_handler_iterator > const_handler_range
iterator_range< succ_iterator > successors()
friend class Instruction
Iterator for Instructions in a `BasicBlock.
void setParentPad(Value *ParentPad)
bool unwindsToCaller() const
static bool classof(const Value *V)
iterator_range< const_succ_iterator > successors() const
handler_iterator handler_end()
Returns a read-only iterator that points one past the last handler in the CatchSwitchInst.
BasicBlock * getUnwindDest() const
BasicBlock * getSuccessor(unsigned Idx) const
const_handler_iterator handler_end() const
Returns an iterator that points one past the last handler in the CatchSwitchInst.
bool hasUnwindDest() const
handler_iterator handler_begin()
Returns an iterator that points to the first handler in CatchSwitchInst.
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
handler_range handlers()
iteration adapter for range-for loops.
const_handler_range handlers() const
iteration adapter for range-for loops.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide fast operand accessors.
static bool classof(const Value *V)
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value * > Args={}, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static bool classof(const Instruction *I)
CleanupPadInst * getCleanupPad() const
Convenience accessor.
unsigned getNumSuccessors() const
BasicBlock * getUnwindDest() const
void setCleanupPad(CleanupPadInst *CleanupPad)
static bool classof(const Value *V)
void setUnwindDest(BasicBlock *NewDest)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, InsertPosition InsertBefore=nullptr)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
LLVM_ABI CleanupReturnInst * cloneImpl() const
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide fast operand accessors.
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Definition InstrTypes.h:986
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
Definition InstrTypes.h:768
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:676
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition InstrTypes.h:679
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
Definition InstrTypes.h:693
@ ICMP_SLT
signed less than
Definition InstrTypes.h:705
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:706
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:700
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:699
@ ICMP_SGT
signed greater than
Definition InstrTypes.h:703
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition InstrTypes.h:684
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition InstrTypes.h:687
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:701
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition InstrTypes.h:685
@ ICMP_NE
not equal
Definition InstrTypes.h:698
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:704
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition InstrTypes.h:692
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:702
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
Definition InstrTypes.h:678
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition InstrTypes.h:686
static auto ICmpPredicates()
Returns the sequence of all ICmp predicates.
Definition InstrTypes.h:722
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Definition InstrTypes.h:827
static auto FCmpPredicates()
Returns the sequence of all FCmp predicates.
Definition InstrTypes.h:715
Predicate getNonStrictPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
Definition InstrTypes.h:871
bool isFPPredicate() const
Definition InstrTypes.h:782
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
Definition InstrTypes.h:789
Predicate getPredicate() const
Return the predicate for this instruction.
Definition InstrTypes.h:765
static bool isIntPredicate(Predicate P)
Definition InstrTypes.h:776
LLVM_ABI CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred, Value *LHS, Value *RHS, const Twine &Name="", InsertPosition InsertBefore=nullptr, Instruction *FlagsSource=nullptr)
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
Conditional Branch instruction.
static CondBrInst * Create(Value *Cond, BasicBlock *IfTrue, BasicBlock *IfFalse, InsertPosition InsertBefore=nullptr)
void setSuccessor(unsigned idx, BasicBlock *NewSucc)
LLVM_ABI CondBrInst * cloneImpl() const
static bool classof(const Instruction *I)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
void setCondition(Value *V)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
unsigned getNumSuccessors() const
static bool classof(const Value *V)
Value * getCondition() const
BasicBlock * getSuccessor(unsigned i) const
iterator_range< succ_iterator > successors()
iterator_range< const_succ_iterator > successors() const
This is the shared class of boolean and integer constants.
Definition Constants.h:87
This is an important base class in LLVM.
Definition Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
This instruction extracts a single (scalar) element from a VectorType value.
const Value * getVectorOperand() const
LLVM_ABI ExtractElementInst * cloneImpl() const
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static bool classof(const Value *V)
static ExtractElementInst * Create(Value *Vec, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
const Value * getIndexOperand() const
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Instruction *I)
VectorType * getVectorOperandType() const
static LLVM_ABI bool isValidOperands(const Value *Vec, const Value *Idx)
Return true if an extractelement instruction can be formed with the specified operands.
ArrayRef< unsigned > getIndices() const
unsigned getNumIndices() const
static bool classof(const Value *V)
static bool classof(const Instruction *I)
LLVM_ABI ExtractValueInst * cloneImpl() const
const unsigned * idx_iterator
iterator_range< idx_iterator > indices() const
friend class Instruction
Iterator for Instructions in a `BasicBlock.
idx_iterator idx_end() const
static ExtractValueInst * Create(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
const Value * getAggregateOperand() const
static unsigned getAggregateOperandIndex()
idx_iterator idx_begin() const
bool isRelational() const
FCmpInst(Predicate Pred, Value *LHS, Value *RHS, const Twine &NameStr="", Instruction *FlagsSource=nullptr)
Constructor with no-insertion semantics.
bool isEquality() const
static bool classof(const Value *V)
bool isCommutative() const
static bool isCommutative(Predicate Pred)
static LLVM_ABI bool compare(const APFloat &LHS, const APFloat &RHS, FCmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
static bool isEquality(Predicate Pred)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
static auto predicates()
Returns the sequence of all FCmp predicates.
LLVM_ABI FCmpInst * cloneImpl() const
Clone an identical FCmpInst.
void swapOperands()
Exchange the two operands to this instruction in such a way that it does not modify the semantics of ...
FCmpInst(InsertPosition InsertBefore, Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr="")
Constructor with insertion semantics.
static bool classof(const Value *V)
LLVM_ABI FPExtInst * cloneImpl() const
Clone an identical FPExtInst.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
LLVM_ABI FPExtInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
static bool classof(const Value *V)
LLVM_ABI FPToSIInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
LLVM_ABI FPToSIInst * cloneImpl() const
Clone an identical FPToSIInst.
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V)
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
friend class Instruction
Iterator for Instructions in a `BasicBlock.
LLVM_ABI FPToUIInst * cloneImpl() const
Clone an identical FPToUIInst.
LLVM_ABI FPToUIInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
LLVM_ABI FPTruncInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
static bool classof(const Value *V)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
LLVM_ABI FPTruncInst * cloneImpl() const
Clone an identical FPTruncInst.
static bool classof(const Value *V)
LLVM_ABI FenceInst(LLVMContext &C, AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, InsertPosition InsertBefore=nullptr)
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this fence instruction.
void setSyncScopeID(SyncScope::ID SSID)
Sets the synchronization scope ID of this fence instruction.
LLVM_ABI FenceInst * cloneImpl() const
static bool classof(const Instruction *I)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this fence instruction.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this fence instruction.
static bool classof(const Value *V)
LLVM_ABI FreezeInst(Value *S, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
LLVM_ABI FreezeInst * cloneImpl() const
Clone an identical FreezeInst.
static bool classof(const Instruction *I)
friend class CatchPadInst
friend class Instruction
Iterator for Instructions in a `BasicBlock.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Class to represent function types.
Represents flags for the getelementptr instruction/expression.
static GEPNoWrapFlags inBounds()
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
LLVM_ABI bool isInBounds() const
Determine whether the GEP has the inbounds flag.
LLVM_ABI bool hasNoUnsignedSignedWrap() const
Determine whether the GEP has the nusw flag.
static LLVM_ABI Type * getTypeAtIndex(Type *Ty, Value *Idx)
Return the type of the element at the given index of an indexable type.
LLVM_ABI bool hasAllZeroIndices() const
Return true if all of the indices of this GEP are zeros.
static Type * getGEPReturnType(Value *Ptr, ArrayRef< Value * > IdxList)
Returns the pointer type returned by the GEP instruction, which may be a vector of pointers.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
void setResultElementType(Type *Ty)
LLVM_ABI bool hasNoUnsignedWrap() const
Determine whether the GEP has the nuw flag.
LLVM_ABI bool hasAllConstantIndices() const
Return true if all of the indices of this GEP are constant integers.
unsigned getAddressSpace() const
Returns the address space of this instruction's pointer type.
iterator_range< const_op_iterator > indices() const
Type * getResultElementType() const
static bool classof(const Instruction *I)
static bool classof(const Value *V)
iterator_range< op_iterator > indices()
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
LLVM_ABI void setIsInBounds(bool b=true)
Set or clear the inbounds flag on this GEP instruction.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
void setSourceElementType(Type *Ty)
static LLVM_ABI Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the result type of a getelementptr with the given source element type and indexes.
Type * getSourceElementType() const
static GetElementPtrInst * CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Create an "inbounds" getelementptr.
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, GEPNoWrapFlags NW, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static unsigned getPointerOperandIndex()
LLVM_ABI bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
Accumulate the constant address offset of this GEP if possible.
const_op_iterator idx_begin() const
LLVM_ABI GetElementPtrInst * cloneImpl() const
LLVM_ABI bool collectOffset(const DataLayout &DL, unsigned BitWidth, SmallMapVector< Value *, APInt, 4 > &VariableOffsets, APInt &ConstantOffset) const
LLVM_ABI void setNoWrapFlags(GEPNoWrapFlags NW)
Set nowrap flags for GEP instruction.
unsigned getNumIndices() const
LLVM_ABI GEPNoWrapFlags getNoWrapFlags() const
Get the nowrap flags for the GEP instruction.
const_op_iterator idx_end() const
const Value * getPointerOperand() const
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
bool hasSameSign() const
An icmp instruction, which can be marked as "samesign", indicating that the two operands have the sam...
static bool classof(const Value *V)
void setSameSign(bool B=true)
ICmpInst(InsertPosition InsertBefore, Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr="")
Constructor with insertion semantics.
static bool isCommutative(Predicate P)
static CmpPredicate getSwappedCmpPredicate(CmpPredicate Pred)
CmpPredicate getCmpPredicate() const
bool isCommutative() const
static bool isGE(Predicate P)
Return true if the predicate is SGE or UGE.
CmpPredicate getSwappedCmpPredicate() const
static bool isLT(Predicate P)
Return true if the predicate is SLT or ULT.
LLVM_ABI ICmpInst * cloneImpl() const
Clone an identical ICmpInst.
CmpPredicate getInverseCmpPredicate() const
Predicate getNonStrictCmpPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
static bool isGT(Predicate P)
Return true if the predicate is SGT or UGT.
static bool classof(const Instruction *I)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Predicate getFlippedSignednessPredicate() const
For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->EQ.
static CmpPredicate getNonStrictCmpPredicate(CmpPredicate Pred)
Predicate getSignedPredicate() const
For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
static CmpPredicate getInverseCmpPredicate(CmpPredicate Pred)
bool isEquality() const
Return true if this predicate is either EQ or NE.
static LLVM_ABI Predicate getFlippedSignednessPredicate(Predicate Pred)
For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->EQ.
static bool isEquality(Predicate P)
Return true if this predicate is either EQ or NE.
static bool isRelational(Predicate P)
Return true if the predicate is relational (not EQ or NE).
void swapOperands()
Exchange the two operands to this instruction in such a way that it does not modify the semantics of ...
static auto predicates()
Returns the sequence of all ICmp predicates.
ICmpInst(Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr="")
Constructor with no-insertion semantics.
bool isRelational() const
Return true if the predicate is relational (not EQ or NE).
Predicate getUnsignedPredicate() const
For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
static bool isLE(Predicate P)
Return true if the predicate is SLE or ULE.
Indirect Branch Instruction.
static IndirectBrInst * Create(Value *Address, unsigned NumDests, InsertPosition InsertBefore=nullptr)
BasicBlock * getDestination(unsigned i)
Return the specified destination.
static bool classof(const Value *V)
const Value * getAddress() const
iterator_range< succ_iterator > successors()
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Instruction *I)
BasicBlock * getSuccessor(unsigned i) const
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide fast operand accessors.
unsigned getNumDestinations() const
return the number of possible destinations in this indirectbr instruction.
iterator_range< const_succ_iterator > successors() const
const BasicBlock * getDestination(unsigned i) const
void setSuccessor(unsigned i, BasicBlock *NewSucc)
void setAddress(Value *V)
unsigned getNumSuccessors() const
LLVM_ABI IndirectBrInst * cloneImpl() const
This instruction inserts a single (scalar) element into a VectorType value.
LLVM_ABI InsertElementInst * cloneImpl() const
static bool classof(const Value *V)
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
VectorType * getType() const
Overload to return most specific vector type.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Instruction *I)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
This instruction inserts a struct field of array element value into an aggregate value.
Value * getInsertedValueOperand()
static bool classof(const Instruction *I)
static unsigned getAggregateOperandIndex()
const unsigned * idx_iterator
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Value *V)
unsigned getNumIndices() const
ArrayRef< unsigned > getIndices() const
iterator_range< idx_iterator > indices() const
static unsigned getInsertedValueOperandIndex()
LLVM_ABI InsertValueInst * cloneImpl() const
idx_iterator idx_end() const
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
const Value * getAggregateOperand() const
const Value * getInsertedValueOperand() const
idx_iterator idx_begin() const
BitfieldElement::Type getSubclassData() const
typename Bitfield::Element< unsigned, Offset, 6, Value::MaxAlignmentExponent > AlignmentBitfieldElementT
typename Bitfield::Element< AtomicOrdering, Offset, 3, AtomicOrdering::LAST > AtomicOrderingBitfieldElementT
typename Bitfield::Element< bool, Offset, 1 > BoolBitfieldElementT
LLVM_ABI bool isAtomic() const LLVM_READONLY
Return true if this instruction has an AtomicOrdering of unordered or higher.
LLVM_ABI iterator_range< const_succ_iterator > successors() const LLVM_READONLY
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Instruction(const Instruction &)=delete
LLVM_ABI void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
friend class BasicBlock
Various leaf nodes.
void setSubclassData(typename BitfieldElement::Type Value)
static bool classof(const Instruction *I)
LLVM_ABI IntToPtrInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
LLVM_ABI IntToPtrInst * cloneImpl() const
Clone an identical IntToPtrInst.
unsigned getAddressSpace() const
Returns the address space of this instruction's pointer type.
static bool classof(const Value *V)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Instruction *I)
BasicBlock * getUnwindDest() const
void setNormalDest(BasicBlock *B)
LLVM_ABI InvokeInst * cloneImpl() const
static bool classof(const Value *V)
static InvokeInst * Create(FunctionCallee Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
void setSuccessor(unsigned i, BasicBlock *NewSucc)
static InvokeInst * Create(FunctionCallee Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles={}, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
iterator_range< const_succ_iterator > successors() const
BasicBlock * getSuccessor(unsigned i) const
void setUnwindDest(BasicBlock *B)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
iterator_range< succ_iterator > successors()
BasicBlock * getNormalDest() const
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles={}, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
unsigned getNumSuccessors() const
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
The landingpad instruction holds all of the information necessary to generate correct exception handl...
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
LLVM_ABI LandingPadInst * cloneImpl() const
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide fast operand accessors.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
bool isFilter(unsigned Idx) const
Return 'true' if the clause and index Idx is a filter clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Value *V)
void setCleanup(bool V)
Indicate that this landingpad instruction is a cleanup.
void reserveClauses(unsigned Size)
Grow the size of the operand list to accommodate the new number of clauses.
static bool classof(const Instruction *I)
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
const Value * getPointerOperand() const
void setAlignment(Align Align)
Value * getPointerOperand()
bool isVolatile() const
Return true if this is a load from a volatile memory location.
static bool classof(const Instruction *I)
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this load instruction.
static bool classof(const Value *V)
void setSyncScopeID(SyncScope::ID SSID)
Sets the synchronization scope ID of this load instruction.
void setAtomic(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Sets the ordering constraint and the synchronization scope ID of this load instruction.
LLVM_ABI LoadInst * cloneImpl() const
friend class Instruction
Iterator for Instructions in a `BasicBlock.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
Type * getPointerOperandType() const
static unsigned getPointerOperandIndex()
bool isUnordered() const
void setVolatile(bool V)
Specify whether this is a volatile load or not.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this load instruction.
bool isSimple() const
LLVM_ABI LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, InsertPosition InsertBefore)
Align getAlign() const
Return the alignment of the access that is being performed.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition ArrayRef.h:298
BasicBlock * getIncomingBlock(Value::const_user_iterator I) const
Return incoming basic block corresponding to value use iterator.
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
bool isComplete() const
If the PHI node is complete which means all of its parent's predecessors have incoming value in this ...
iterator_range< const_block_iterator > blocks() const
op_range incoming_values()
static bool classof(const Value *V)
void allocHungoffUses(unsigned N)
const_block_iterator block_begin() const
void setIncomingValueForBlock(const BasicBlock *BB, Value *V)
Set every incoming value(s) for block BB to V.
BasicBlock ** block_iterator
void setIncomingBlock(unsigned i, BasicBlock *BB)
LLVM_ABI Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
BasicBlock *const * const_block_iterator
friend class Instruction
Iterator for Instructions in a `BasicBlock.
void setIncomingValue(unsigned i, Value *V)
static unsigned getOperandNumForIncomingValue(unsigned i)
void copyIncomingBlocks(iterator_range< const_block_iterator > BBRange, uint32_t ToIdx=0)
Copies the basic blocks from BBRange to the incoming basic block list of this PHINode,...
const_block_iterator block_end() const
Value * getIncomingValueForBlock(const BasicBlock *BB) const
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide fast operand accessors.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
static unsigned getIncomingValueNumForOperand(unsigned i)
const_op_range incoming_values() const
Value * removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true)
LLVM_ABI PHINode * cloneImpl() const
void replaceIncomingBlockWith(const BasicBlock *Old, BasicBlock *New)
Replace every incoming basic block Old to basic block New.
BasicBlock * getIncomingBlock(const Use &U) const
Return incoming basic block corresponding to an operand of the PHI.
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
Class to represent pointers.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
PtrToAddrInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
static unsigned getPointerOperandIndex()
Gets the operand index of the pointer operand.
static bool classof(const Instruction *I)
PtrToAddrInst * cloneImpl() const
Clone an identical PtrToAddrInst.
static bool classof(const Value *V)
const Value * getPointerOperand() const
Gets the pointer operand.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Value * getPointerOperand()
Gets the pointer operand.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Value * getPointerOperand()
Gets the pointer operand.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
static bool classof(const Value *V)
const Value * getPointerOperand() const
Gets the pointer operand.
static unsigned getPointerOperandIndex()
Gets the operand index of the pointer operand.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Instruction *I)
LLVM_ABI PtrToIntInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
LLVM_ABI PtrToIntInst * cloneImpl() const
Clone an identical PtrToIntInst.
Resume the propagation of an exception.
static ResumeInst * Create(Value *Exn, InsertPosition InsertBefore=nullptr)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide fast operand accessors.
Value * getValue() const
Convenience accessor.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Value *V)
unsigned getNumSuccessors() const
LLVM_ABI ResumeInst * cloneImpl() const
static bool classof(const Instruction *I)
Return a value (possibly void), from a function.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide fast operand accessors.
unsigned getNumSuccessors() const
static bool classof(const Value *V)
static bool classof(const Instruction *I)
static ReturnInst * Create(LLVMContext &C, BasicBlock *InsertAtEnd)
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, InsertPosition InsertBefore=nullptr)
iterator_range< succ_iterator > successors()
LLVM_ABI ReturnInst * cloneImpl() const
iterator_range< const_succ_iterator > successors() const
static bool classof(const Value *V)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
LLVM_ABI SExtInst * cloneImpl() const
Clone an identical SExtInst.
LLVM_ABI SExtInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
LLVM_ABI SIToFPInst * cloneImpl() const
Clone an identical SIToFPInst.
LLVM_ABI SIToFPInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Value *V)
This class represents the LLVM 'select' instruction.
void setFalseValue(Value *V)
const Value * getFalseValue() const
void setTrueValue(Value *V)
OtherOps getOpcode() const
Value * getCondition()
Value * getTrueValue()
void swapValues()
Swap the true and false values of the select instruction.
Value * getFalseValue()
const Value * getCondition() const
LLVM_ABI SelectInst * cloneImpl() const
friend class Instruction
Iterator for Instructions in a `BasicBlock.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static LLVM_ABI const char * areInvalidOperands(Value *Cond, Value *True, Value *False)
Return a string if the specified operands are invalid for a select operation, otherwise return null.
static bool classof(const Value *V)
void setCondition(Value *V)
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", InsertPosition InsertBefore=nullptr, const Instruction *MDFrom=nullptr)
const Value * getTrueValue() const
static bool classof(const Instruction *I)
This instruction constructs a fixed permutation of two input vectors.
static bool classof(const Value *V)
static bool isInterleaveMask(ArrayRef< int > Mask, unsigned Factor, unsigned NumInputElts)
Constant * getShuffleMaskForBitcode() const
Return the mask for this instruction, for use in bitcode.
bool isSingleSource() const
Return true if this shuffle chooses elements from exactly one source vector without changing the leng...
static LLVM_ABI bool isZeroEltSplatMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses all elements with the same value as the first element of exa...
bool changesLength() const
Return true if this shuffle returns a vector with a different number of elements than its source vect...
bool isExtractSubvectorMask(int &Index) const
Return true if this shuffle mask is an extract subvector mask.
ArrayRef< int > getShuffleMask() const
static LLVM_ABI bool isSpliceMask(ArrayRef< int > Mask, int NumSrcElts, int &Index)
Return true if this shuffle mask is a splice mask, concatenating the two inputs together and then ext...
static bool isInsertSubvectorMask(const Constant *Mask, int NumSrcElts, int &NumSubElts, int &Index)
static bool isSingleSourceMask(const Constant *Mask, int NumSrcElts)
int getMaskValue(unsigned Elt) const
Return the shuffle mask value of this instruction for the given element index.
LLVM_ABI ShuffleVectorInst(Value *V1, Value *Mask, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
void getShuffleMask(SmallVectorImpl< int > &Result) const
Return the mask for this instruction as a vector of integers.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static bool isDeInterleaveMaskOfFactor(ArrayRef< int > Mask, unsigned Factor)
static LLVM_ABI bool isSelectMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from its source vectors without lane crossings.
VectorType * getType() const
Overload to return most specific vector type.
bool isInsertSubvectorMask(int &NumSubElts, int &Index) const
Return true if this shuffle mask is an insert subvector mask.
bool increasesLength() const
Return true if this shuffle returns a vector with a greater number of elements than its source vector...
bool isZeroEltSplat() const
Return true if all elements of this shuffle are the same value as the first element of exactly one so...
static bool isExtractSubvectorMask(const Constant *Mask, int NumSrcElts, int &Index)
static LLVM_ABI bool isSingleSourceMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from exactly one source vector.
static LLVM_ABI void getShuffleMask(const Constant *Mask, SmallVectorImpl< int > &Result)
Convert the input shuffle mask operand to a vector of integers.
bool isSelect() const
Return true if this shuffle chooses elements from its source vectors without lane crossings and all o...
static LLVM_ABI bool isDeInterleaveMaskOfFactor(ArrayRef< int > Mask, unsigned Factor, unsigned &Index)
Check if the mask is a DE-interleave mask of the given factor Factor like: <Index,...
LLVM_ABI ShuffleVectorInst * cloneImpl() const
static LLVM_ABI bool isIdentityMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from exactly one source vector without lane crossin...
static bool isSpliceMask(const Constant *Mask, int NumSrcElts, int &Index)
static LLVM_ABI bool isExtractSubvectorMask(ArrayRef< int > Mask, int NumSrcElts, int &Index)
Return true if this shuffle mask is an extract subvector mask.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
bool isTranspose() const
Return true if this shuffle transposes the elements of its inputs without changing the length of the ...
static void commuteShuffleMask(MutableArrayRef< int > Mask, unsigned InVecNumElts)
Change values in a shuffle permute mask assuming the two vector operands of length InVecNumElts have ...
static LLVM_ABI bool isTransposeMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask is a transpose mask.
bool isSplice(int &Index) const
Return true if this shuffle splices two inputs without changing the length of the vectors.
static bool isReverseMask(const Constant *Mask, int NumSrcElts)
static LLVM_ABI bool isInsertSubvectorMask(ArrayRef< int > Mask, int NumSrcElts, int &NumSubElts, int &Index)
Return true if this shuffle mask is an insert subvector mask.
static bool isSelectMask(const Constant *Mask, int NumSrcElts)
static bool classof(const Instruction *I)
static bool isZeroEltSplatMask(const Constant *Mask, int NumSrcElts)
bool isIdentity() const
Return true if this shuffle chooses elements from exactly one source vector without lane crossings an...
static bool isReplicationMask(const Constant *Mask, int &ReplicationFactor, int &VF)
static LLVM_ABI bool isReplicationMask(ArrayRef< int > Mask, int &ReplicationFactor, int &VF)
Return true if this shuffle mask replicates each of the VF elements in a vector ReplicationFactor tim...
static bool isIdentityMask(const Constant *Mask, int NumSrcElts)
static bool isTransposeMask(const Constant *Mask, int NumSrcElts)
static LLVM_ABI bool isInterleaveMask(ArrayRef< int > Mask, unsigned Factor, unsigned NumInputElts, SmallVectorImpl< unsigned > &StartIndexes)
Return true if the mask interleaves one or more input vectors together.
bool isReverse() const
Return true if this shuffle swaps the order of elements from exactly one source vector.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
static bool classof(const Instruction *I)
AtomicOrdering getOrdering() const
Returns the ordering constraint of this store instruction.
const Value * getPointerOperand() const
Align getAlign() const
Type * getPointerOperandType() const
void setVolatile(bool V)
Specify whether this is a volatile store or not.
void setAlignment(Align Align)
bool isSimple() const
const Value * getValueOperand() const
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this store instruction.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Value * getValueOperand()
static bool classof(const Value *V)
bool isUnordered() const
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
void setSyncScopeID(SyncScope::ID SSID)
Sets the synchronization scope ID of this store instruction.
LLVM_ABI StoreInst * cloneImpl() const
LLVM_ABI StoreInst(Value *Val, Value *Ptr, InsertPosition InsertBefore)
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
static unsigned getPointerOperandIndex()
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this store instruction.
bool isVolatile() const
Return true if this is a store to a volatile memory location.
Value * getPointerOperand()
void setAtomic(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Sets the ordering constraint and the synchronization scope ID of this store instruction.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
LLVM_ABI void setSuccessorWeight(unsigned idx, CaseWeightOpt W)
LLVM_ABI Instruction::InstListType::iterator eraseFromParent()
Delegate the call to the underlying SwitchInst::eraseFromParent() and mark this object to not touch t...
LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest, CaseWeightOpt W)
Delegate the call to the underlying SwitchInst::addCase() and set the specified branch weight for the...
SwitchInstProfUpdateWrapper(SwitchInst &SI)
LLVM_ABI CaseWeightOpt getSuccessorWeight(unsigned idx)
LLVM_ABI void replaceDefaultDest(SwitchInst::CaseIt I)
Replace the default destination by given case.
std::optional< uint32_t > CaseWeightOpt
LLVM_ABI SwitchInst::CaseIt removeCase(SwitchInst::CaseIt I)
Delegate the call to the underlying SwitchInst::removeCase() and remove correspondent branch weight.
A handle to a particular switch case.
unsigned getCaseIndex() const
Returns number of current case.
unsigned getSuccessorIndex() const
Returns successor index for current case successor.
BasicBlockT * getCaseSuccessor() const
Resolves successor for current case.
CaseHandleImpl(SwitchInstT *SI, ptrdiff_t Index)
bool operator==(const CaseHandleImpl &RHS) const
ConstantIntT * getCaseValue() const
Resolves case value for current case.
CaseHandle(SwitchInst *SI, ptrdiff_t Index)
void setValue(ConstantInt *V) const
Sets the new value for current case.
void setSuccessor(BasicBlock *S) const
Sets the new successor for current case.
const CaseHandleT & operator*() const
CaseIteratorImpl()=default
Default constructed iterator is in an invalid state until assigned to a case for a particular switch.
CaseIteratorImpl & operator-=(ptrdiff_t N)
bool operator==(const CaseIteratorImpl &RHS) const
CaseIteratorImpl & operator+=(ptrdiff_t N)
ptrdiff_t operator-(const CaseIteratorImpl &RHS) const
bool operator<(const CaseIteratorImpl &RHS) const
CaseIteratorImpl(SwitchInstT *SI, unsigned CaseNum)
Initializes case iterator for given SwitchInst and for given case number.
static CaseIteratorImpl fromSuccessorIndex(SwitchInstT *SI, unsigned SuccessorIndex)
Initializes case iterator for given SwitchInst and for given successor index.
Multiway switch.
BasicBlock * getDefaultDest() const
void allocHungoffUses(unsigned N)
CaseIteratorImpl< ConstCaseHandle > ConstCaseIt
CaseIt case_end()
Returns a read/write iterator that points one past the last in the SwitchInst.
LLVM_ABI SwitchInst * cloneImpl() const
BasicBlock * getSuccessor(unsigned idx) const
ConstCaseIt findCaseValue(const ConstantInt *C) const
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide fast operand accessors.
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, InsertPosition InsertBefore=nullptr)
void setCondition(Value *V)
bool defaultDestUnreachable() const
Returns true if the default branch must result in immediate undefined behavior, false otherwise.
ConstCaseIt case_begin() const
Returns a read-only iterator that points to the first case in the SwitchInst.
iterator_range< ConstCaseIt > cases() const
Constant iteration adapter for range-for loops.
static const unsigned DefaultPseudoIndex
LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest)
Add an entry to the switch instruction.
iterator_range< succ_iterator > successors()
CaseIteratorImpl< CaseHandle > CaseIt
ConstantInt * findCaseDest(BasicBlock *BB)
Finds the unique case value for a given successor.
void setSuccessor(unsigned idx, BasicBlock *NewSucc)
CaseHandleImpl< const SwitchInst, const ConstantInt, const BasicBlock > ConstCaseHandle
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Value *V)
unsigned getNumSuccessors() const
CaseIt case_default()
Returns an iterator that points to the default case.
void setDefaultDest(BasicBlock *DefaultCase)
ConstantInt *const * case_values() const
unsigned getNumCases() const
Return the number of 'cases' in this switch instruction, excluding the default case.
CaseIt findCaseValue(const ConstantInt *C)
Search all of the case values for the specified constant.
Value * getCondition() const
iterator_range< const_succ_iterator > successors() const
ConstCaseIt case_default() const
CaseIt case_begin()
Returns a read/write iterator that points to the first case in the SwitchInst.
static bool classof(const Instruction *I)
iterator_range< CaseIt > cases()
Iteration adapter for range-for loops.
ConstantInt ** case_values()
ConstCaseIt case_end() const
Returns a read-only iterator that points one past the last in the SwitchInst.
LLVM_ABI CaseIt removeCase(CaseIt I)
This method removes the specified case and its successor from the switch instruction.
void setHasNoSignedWrap(bool B)
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
LLVM_ABI TruncInst * cloneImpl() const
Clone an identical TruncInst.
void setHasNoUnsignedWrap(bool B)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
unsigned getNoWrapKind() const
Returns the no-wrap kind of the operation.
bool hasNoSignedWrap() const
Test whether this operation is known to never undergo signed overflow, aka the nsw property.
static bool classof(const Value *V)
LLVM_ABI TruncInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
bool hasNoUnsignedWrap() const
Test whether this operation is known to never undergo unsigned overflow, aka the nuw property.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static bool classof(const Value *V)
LLVM_ABI UIToFPInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
LLVM_ABI UIToFPInst * cloneImpl() const
Clone an identical UIToFPInst.
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
UnaryInstruction(Type *Ty, unsigned iType, Value *V, InsertPosition InsertBefore=nullptr)
Definition InstrTypes.h:62
Unconditional Branch instruction.
void setSuccessor(unsigned idx, BasicBlock *NewSucc)
iterator_range< succ_iterator > successors()
static bool classof(const Value *V)
static UncondBrInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
static bool classof(const Instruction *I)
void setSuccessor(BasicBlock *NewSucc)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
BasicBlock * getSuccessor(unsigned i=0) const
iterator_range< const_succ_iterator > successors() const
LLVM_ABI UncondBrInst * cloneImpl() const
unsigned getNumSuccessors() const
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
This function has undefined behavior.
LLVM_ABI UnreachableInst(LLVMContext &C, InsertPosition InsertBefore=nullptr)
unsigned getNumSuccessors() const
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Value *V)
static bool classof(const Instruction *I)
LLVM_ABI UnreachableInst * cloneImpl() const
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
iterator_range< const_op_iterator > const_op_range
Definition User.h:257
Use * op_iterator
Definition User.h:254
const Use * getOperandList() const
Definition User.h:200
op_range operands()
Definition User.h:267
op_iterator op_begin()
Definition User.h:259
LLVM_ABI void allocHungoffUses(unsigned N, bool WithExtraValues=false)
Allocate the array of Uses, followed by a pointer (with bottom bit set) to the User.
Definition User.cpp:54
const Use & getOperandUse(unsigned i) const
Definition User.h:220
void setOperand(unsigned i, Value *Val)
Definition User.h:212
const Use * const_op_iterator
Definition User.h:255
void setNumHungOffUseOperands(unsigned NumOps)
Subclasses with hung off uses need to manage the operand count themselves.
Definition User.h:240
iterator_range< op_iterator > op_range
Definition User.h:256
Value * getOperand(unsigned i) const
Definition User.h:207
unsigned getNumOperands() const
Definition User.h:229
op_iterator op_end()
Definition User.h:261
static bool classof(const Instruction *I)
Value * getPointerOperand()
VAArgInst(Value *List, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
const Value * getPointerOperand() const
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Value *V)
static unsigned getPointerOperandIndex()
LLVM_ABI VAArgInst * cloneImpl() const
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
user_iterator_impl< const User > const_user_iterator
Definition Value.h:393
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
Definition Value.h:85
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
Definition Value.cpp:397
Base class of all SIMD vector types.
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static bool classof(const Instruction *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
LLVM_ABI ZExtInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static bool classof(const Value *V)
LLVM_ABI ZExtInst * cloneImpl() const
Clone an identical ZExtInst.
An efficient, type-erasing, non-owning reference to a callable.
typename base_list_type::iterator iterator
Definition ilist.h:121
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition iterator.h:80
A range adaptor for a pair of iterators.
CallInst * Call
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ System
Synchronized with respect to all concurrently executing threads.
Definition LLVMContext.h:58
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Offset
Definition DWP.cpp:532
Type * checkGEPType(Type *Ty)
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1739
unsigned getLoadStoreAddressSpace(const Value *I)
A helper function that returns the address space of the pointer operand of load or store instruction.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
auto successors(const MachineBasicBlock *BB)
const Value * getLoadStorePointerOperand(const Value *V)
A helper function that returns the pointer operand of a load or store instruction.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto cast_or_null(const Y &Val)
Definition Casting.h:714
void setAtomicSyncScopeID(Instruction *I, SyncScope::ID SSID)
A helper function that sets an atomic operation's sync scope.
Align getLoadStoreAlignment(const Value *I)
A helper function that returns the alignment of load or store instruction.
const Value * getPointerOperand(const Value *V)
A helper function that returns the pointer operand of a load, store or GEP instruction.
LLVM_ABI void setBranchWeights(Instruction &I, ArrayRef< uint32_t > Weights, bool IsExpected, bool ElideAllZero=false)
Create a new branch_weights metadata node and add or overwrite a prof metadata reference to instructi...
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
std::optional< SyncScope::ID > getAtomicSyncScopeID(const Instruction *I)
A helper function that returns an atomic operation's sync scope; returns std::nullopt if it is not an...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
constexpr int PoisonMaskElem
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
Instruction::succ_iterator succ_iterator
Definition CFG.h:138
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
Definition STLExtras.h:1885
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1772
auto predecessors(const MachineBasicBlock *BB)
Instruction::const_succ_iterator const_succ_iterator
Definition CFG.h:139
Type * getLoadStoreType(const Value *I)
A helper function that returns the type of a load or store instruction.
void setLoadStoreAlignment(Value *I, Align NewAlign)
A helper function that set the alignment of load or store instruction.
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition Alignment.h:197
@ Default
The result values are uniform if and only if all operands are uniform.
Definition Uniformity.h:20
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Summary of memprof metadata on allocations.
Describes an element of a Bitfield.
Definition Bitfields.h:176
static constexpr bool areContiguous()
Definition Bitfields.h:233
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
HungoffOperandTraits - determine the allocation regime of the Use array when it is not a prefix to th...
Compile-time customization of User operands.
Definition User.h:42
A MapVector that performs no allocations if smaller than a certain size.
Definition MapVector.h:276
Information about how a User object was allocated, to be passed into the User constructor.
Definition User.h:79
const unsigned NumOps
Definition User.h:81
Indicates this User has operands "hung off" in another allocation.
Definition User.h:57
Indicates this User has operands co-allocated.
Definition User.h:60
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...