LLVM 24.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 /// Get the size of the allocated type. (This is the allocation size
122 /// ignoring the array size.)
124
125 // Get whether the allocated type is a scalable type.
126 bool isScalable() const { return AllocatedType->isScalableTy(); }
127
128 /// Return the type that is being allocated by the instruction.
129 Type *getAllocatedType() const { return AllocatedType; }
130 /// for use only in special circumstances that need to generically
131 /// transform a whole instruction (eg: IR linking and vectorization).
132 void setAllocatedType(Type *Ty) { AllocatedType = Ty; }
133
134 /// Return the alignment of the memory that is being allocated by the
135 /// instruction.
136 Align getAlign() const {
137 return Align(1ULL << getSubclassData<AlignmentField>());
138 }
139
141 setSubclassData<AlignmentField>(Log2(Align));
142 }
143
144 /// Return true if this alloca is in the entry block of the function and is a
145 /// constant size. If so, the code generator will fold it into the
146 /// prolog/epilog code, so it is basically free.
147 LLVM_ABI bool isStaticAlloca() const;
148
149 /// Return true if this alloca is used as an inalloca argument to a call. Such
150 /// allocas are never considered static even if they are in the entry block.
154
155 /// Specify whether this alloca is used to represent the arguments to a call.
156 void setUsedWithInAlloca(bool V) {
157 setSubclassData<UsedWithInAllocaField>(V);
158 }
159
160 /// Return true if this alloca is used as a swifterror argument to a call.
162 /// Specify whether this alloca is used to represent a swifterror.
163 void setSwiftError(bool V) { setSubclassData<SwiftErrorField>(V); }
164
165 // Methods for support type inquiry through isa, cast, and dyn_cast:
166 static bool classof(const Instruction *I) {
167 return (I->getOpcode() == Instruction::Alloca);
168 }
169 static bool classof(const Value *V) {
171 }
172
173private:
174 // Shadow Instruction::setInstructionSubclassData with a private forwarding
175 // method so that subclasses cannot accidentally use it.
176 template <typename Bitfield>
177 void setSubclassData(typename Bitfield::Type Value) {
179 }
180};
181
182//===----------------------------------------------------------------------===//
183// LoadInst Class
184//===----------------------------------------------------------------------===//
185
186/// A structure representing the properties of a load or store instruction.
194
195/// An instruction for reading from memory. This uses the SubclassData field in
196/// Value to store whether or not the load is volatile.
198 using VolatileField = BoolBitfieldElementT<0>;
201 using ElementWiseField = BoolBitfieldElementT<OrderingField::NextBit>;
202 static_assert(Bitfield::areContiguous<VolatileField, AlignmentField,
203 OrderingField, ElementWiseField>(),
204 "Bitfields must be contiguous");
205
206 void AssertOK();
207
208protected:
209 // Note: Instruction needs to be a friend here to call cloneImpl.
210 friend class Instruction;
211
212 LLVM_ABI LoadInst *cloneImpl() const;
213
214public:
215 LLVM_ABI LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr,
216 InsertPosition InsertBefore);
217 LLVM_ABI LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
218 InsertPosition InsertBefore);
219 LLVM_ABI LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
220 Align Align, InsertPosition InsertBefore = nullptr);
221 LLVM_ABI LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
224 InsertPosition InsertBefore = nullptr);
225 LLVM_ABI LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr,
226 const LoadStoreInstProperties &Props,
227 InsertPosition InsertBefore = nullptr);
228
229 /// Return true if this is a load from a volatile memory location.
231
232 /// Specify whether this is a volatile load or not.
233 void setVolatile(bool V) { setSubclassData<VolatileField>(V); }
234
235 /// Return true if this is an elementwise atomic load.
237
238 /// Specify whether this is an elementwise atomic load or not.
239 void setElementwise(bool V) { setSubclassData<ElementWiseField>(V); }
240
241 /// Return the alignment of the access that is being performed.
242 Align getAlign() const {
243 return Align(1ULL << (getSubclassData<AlignmentField>()));
244 }
245
247 setSubclassData<AlignmentField>(Log2(Align));
248 }
249
250 /// Returns the ordering constraint of this load instruction.
254 /// Sets the ordering constraint of this load instruction. May not be Release
255 /// or AcquireRelease.
257 setSubclassData<OrderingField>(Ordering);
258 }
259
260 /// Returns the synchronization scope ID of this load instruction.
262 return SSID;
263 }
264
265 /// Sets the synchronization scope ID of this load instruction.
267 this->SSID = SSID;
268 }
269
270 /// Sets the ordering constraint and the synchronization scope ID of this load
271 /// instruction.
274 setOrdering(Ordering);
275 setSyncScopeID(SSID);
276 }
277
278 /// Returns the properties of this load instruction.
283
284 /// Sets the properties of this load instruction.
286 setVolatile(Props.IsVolatile);
287 setAlignment(Props.Alignment);
288 setOrdering(Props.Ordering);
289 setSyncScopeID(Props.SSID);
291 }
292
293 bool isSimple() const { return !isAtomic() && !isVolatile(); }
294
295 bool isUnordered() const {
298 !isVolatile();
299 }
300
302 const Value *getPointerOperand() const { return getOperand(0); }
303 static unsigned getPointerOperandIndex() { return 0U; }
305
306 /// Returns the address space of the pointer operand.
307 unsigned getPointerAddressSpace() const {
309 }
310
311 // Methods for support type inquiry through isa, cast, and dyn_cast:
312 static bool classof(const Instruction *I) {
313 return I->getOpcode() == Instruction::Load;
314 }
315 static bool classof(const Value *V) {
317 }
318
319private:
320 // Shadow Instruction::setInstructionSubclassData with a private forwarding
321 // method so that subclasses cannot accidentally use it.
322 template <typename Bitfield>
323 void setSubclassData(typename Bitfield::Type Value) {
325 }
326
327 /// The synchronization scope ID of this load instruction. Not quite enough
328 /// room in SubClassData for everything, so synchronization scope ID gets its
329 /// own field.
330 SyncScope::ID SSID;
331};
332
333//===----------------------------------------------------------------------===//
334// StoreInst Class
335//===----------------------------------------------------------------------===//
336
337/// An instruction for storing to memory.
338class StoreInst : public Instruction {
339 using VolatileField = BoolBitfieldElementT<0>;
342 using ElementWiseField = BoolBitfieldElementT<OrderingField::NextBit>;
343 static_assert(Bitfield::areContiguous<VolatileField, AlignmentField,
344 OrderingField, ElementWiseField>(),
345 "Bitfields must be contiguous");
346
347 void AssertOK();
348
349 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
350
351protected:
352 // Note: Instruction needs to be a friend here to call cloneImpl.
353 friend class Instruction;
354
356
357public:
358 LLVM_ABI StoreInst(Value *Val, Value *Ptr, InsertPosition InsertBefore);
359 LLVM_ABI StoreInst(Value *Val, Value *Ptr, bool isVolatile,
360 InsertPosition InsertBefore);
362 InsertPosition InsertBefore = nullptr);
364 AtomicOrdering Order,
366 InsertPosition InsertBefore = nullptr);
367 LLVM_ABI StoreInst(Value *Val, Value *Ptr,
368 const LoadStoreInstProperties &Props,
369 InsertPosition InsertBefore = nullptr);
370
371 // allocate space for exactly two operands
372 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
373 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
374
375 /// Return true if this is a store to a volatile memory location.
377
378 /// Specify whether this is a volatile store or not.
379 void setVolatile(bool V) { setSubclassData<VolatileField>(V); }
380
381 /// Return true if this is an elementwise atomic store.
383
384 /// Specify whether this is an elementwise atomic store or not.
385 void setElementwise(bool V) { setSubclassData<ElementWiseField>(V); }
386
387 /// Transparently provide more efficient getOperand methods.
389
390 Align getAlign() const {
391 return Align(1ULL << (getSubclassData<AlignmentField>()));
392 }
393
395 setSubclassData<AlignmentField>(Log2(Align));
396 }
397
398 /// Returns the ordering constraint of this store instruction.
402
403 /// Sets the ordering constraint of this store instruction. May not be
404 /// Acquire or AcquireRelease.
406 setSubclassData<OrderingField>(Ordering);
407 }
408
409 /// Returns the synchronization scope ID of this store instruction.
411 return SSID;
412 }
413
414 /// Sets the synchronization scope ID of this store instruction.
416 this->SSID = SSID;
417 }
418
419 /// Sets the ordering constraint and the synchronization scope ID of this
420 /// store instruction.
423 setOrdering(Ordering);
424 setSyncScopeID(SSID);
425 }
426
427 /// Returns the properties of this store instruction.
432
433 /// Sets the properties of this store instruction.
435 setVolatile(Props.IsVolatile);
436 setAlignment(Props.Alignment);
437 setOrdering(Props.Ordering);
438 setSyncScopeID(Props.SSID);
440 }
441
442 bool isSimple() const { return !isAtomic() && !isVolatile(); }
443
444 bool isUnordered() const {
447 !isVolatile();
448 }
449
451 const Value *getValueOperand() const { return getOperand(0); }
452
454 const Value *getPointerOperand() const { return getOperand(1); }
455 static unsigned getPointerOperandIndex() { return 1U; }
457
458 /// Returns the address space of the pointer operand.
459 unsigned getPointerAddressSpace() const {
461 }
462
463 // Methods for support type inquiry through isa, cast, and dyn_cast:
464 static bool classof(const Instruction *I) {
465 return I->getOpcode() == Instruction::Store;
466 }
467 static bool classof(const Value *V) {
469 }
470
471private:
472 // Shadow Instruction::setInstructionSubclassData with a private forwarding
473 // method so that subclasses cannot accidentally use it.
474 template <typename Bitfield>
475 void setSubclassData(typename Bitfield::Type Value) {
477 }
478
479 /// The synchronization scope ID of this store instruction. Not quite enough
480 /// room in SubClassData for everything, so synchronization scope ID gets its
481 /// own field.
482 SyncScope::ID SSID;
483};
484
485template <>
486struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
487};
488
490
491//===----------------------------------------------------------------------===//
492// FenceInst Class
493//===----------------------------------------------------------------------===//
494
495/// An instruction for ordering other memory operations.
496class FenceInst : public Instruction {
497 using OrderingField = AtomicOrderingBitfieldElementT<0>;
498
499 constexpr static IntrusiveOperandsAllocMarker AllocMarker{0};
500
501 void Init(AtomicOrdering Ordering, SyncScope::ID SSID);
502
503protected:
504 // Note: Instruction needs to be a friend here to call cloneImpl.
505 friend class Instruction;
506
508
509public:
510 // Ordering may only be Acquire, Release, AcquireRelease, or
511 // SequentiallyConsistent.
514 InsertPosition InsertBefore = nullptr);
515
516 // allocate space for exactly zero operands
517 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
518 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
519
520 /// Returns the ordering constraint of this fence instruction.
524
525 /// Sets the ordering constraint of this fence instruction. May only be
526 /// Acquire, Release, AcquireRelease, or SequentiallyConsistent.
528 setSubclassData<OrderingField>(Ordering);
529 }
530
531 /// Returns the synchronization scope ID of this fence instruction.
533 return SSID;
534 }
535
536 /// Sets the synchronization scope ID of this fence instruction.
538 this->SSID = SSID;
539 }
540
541 // Methods for support type inquiry through isa, cast, and dyn_cast:
542 static bool classof(const Instruction *I) {
543 return I->getOpcode() == Instruction::Fence;
544 }
545 static bool classof(const Value *V) {
547 }
548
549private:
550 // Shadow Instruction::setInstructionSubclassData with a private forwarding
551 // method so that subclasses cannot accidentally use it.
552 template <typename Bitfield>
553 void setSubclassData(typename Bitfield::Type Value) {
555 }
556
557 /// The synchronization scope ID of this fence instruction. Not quite enough
558 /// room in SubClassData for everything, so synchronization scope ID gets its
559 /// own field.
560 SyncScope::ID SSID;
561};
562
563//===----------------------------------------------------------------------===//
564// AtomicCmpXchgInst Class
565//===----------------------------------------------------------------------===//
566
567/// An instruction that atomically checks whether a
568/// specified value is in a memory location, and, if it is, stores a new value
569/// there. The value returned by this instruction is a pair containing the
570/// original value as first element, and an i1 indicating success (true) or
571/// failure (false) as second element.
572///
574 void Init(Value *Ptr, Value *Cmp, Value *NewVal, Align Align,
575 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
576 SyncScope::ID SSID);
577
578 template <unsigned Offset>
579 using AtomicOrderingBitfieldElement =
582
583 constexpr static IntrusiveOperandsAllocMarker AllocMarker{3};
584
585protected:
586 // Note: Instruction needs to be a friend here to call cloneImpl.
587 friend class Instruction;
588
590
591public:
592 LLVM_ABI AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
593 Align Alignment, AtomicOrdering SuccessOrdering,
594 AtomicOrdering FailureOrdering, SyncScope::ID SSID,
595 InsertPosition InsertBefore = nullptr);
596
597 // allocate space for exactly three operands
598 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
599 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
600
609 static_assert(
612 "Bitfields must be contiguous");
613
614 /// Return the alignment of the memory that is being allocated by the
615 /// instruction.
616 Align getAlign() const {
617 return Align(1ULL << getSubclassData<AlignmentField>());
618 }
619
621 setSubclassData<AlignmentField>(Log2(Align));
622 }
623
624 /// Return true if this is a cmpxchg from a volatile memory
625 /// location.
626 ///
628
629 /// Specify whether this is a volatile cmpxchg.
630 ///
631 void setVolatile(bool V) { setSubclassData<VolatileField>(V); }
632
633 /// Return true if this cmpxchg may spuriously fail.
634 bool isWeak() const { return getSubclassData<WeakField>(); }
635
636 void setWeak(bool IsWeak) { setSubclassData<WeakField>(IsWeak); }
637
638 /// Transparently provide more efficient getOperand methods.
640
642 return Ordering != AtomicOrdering::NotAtomic &&
643 Ordering != AtomicOrdering::Unordered;
644 }
645
647 return Ordering != AtomicOrdering::NotAtomic &&
648 Ordering != AtomicOrdering::Unordered &&
649 Ordering != AtomicOrdering::AcquireRelease &&
650 Ordering != AtomicOrdering::Release;
651 }
652
653 /// Returns the success ordering constraint of this cmpxchg instruction.
657
658 /// Sets the success ordering constraint of this cmpxchg instruction.
660 assert(isValidSuccessOrdering(Ordering) &&
661 "invalid CmpXchg success ordering");
662 setSubclassData<SuccessOrderingField>(Ordering);
663 }
664
665 /// Returns the failure ordering constraint of this cmpxchg instruction.
669
670 /// Sets the failure ordering constraint of this cmpxchg instruction.
672 assert(isValidFailureOrdering(Ordering) &&
673 "invalid CmpXchg failure ordering");
674 setSubclassData<FailureOrderingField>(Ordering);
675 }
676
677 /// Returns a single ordering which is at least as strong as both the
678 /// success and failure orderings for this cmpxchg.
690
691 /// Returns the synchronization scope ID of this cmpxchg instruction.
693 return SSID;
694 }
695
696 /// Sets the synchronization scope ID of this cmpxchg instruction.
698 this->SSID = SSID;
699 }
700
702 const Value *getPointerOperand() const { return getOperand(0); }
703 static unsigned getPointerOperandIndex() { return 0U; }
704
706 const Value *getCompareOperand() const { return getOperand(1); }
707
709 const Value *getNewValOperand() const { return getOperand(2); }
710
711 /// Returns the address space of the pointer operand.
712 unsigned getPointerAddressSpace() const {
714 }
715
716 /// Returns the strongest permitted ordering on failure, given the
717 /// desired ordering on success.
718 ///
719 /// If the comparison in a cmpxchg operation fails, there is no atomic store
720 /// so release semantics cannot be provided. So this function drops explicit
721 /// Release requests from the AtomicOrdering. A SequentiallyConsistent
722 /// operation would remain SequentiallyConsistent.
723 static AtomicOrdering
725 switch (SuccessOrdering) {
726 default:
727 llvm_unreachable("invalid cmpxchg success ordering");
736 }
737 }
738
739 // Methods for support type inquiry through isa, cast, and dyn_cast:
740 static bool classof(const Instruction *I) {
741 return I->getOpcode() == Instruction::AtomicCmpXchg;
742 }
743 static bool classof(const Value *V) {
745 }
746
747private:
748 // Shadow Instruction::setInstructionSubclassData with a private forwarding
749 // method so that subclasses cannot accidentally use it.
750 template <typename Bitfield>
751 void setSubclassData(typename Bitfield::Type Value) {
753 }
754
755 /// The synchronization scope ID of this cmpxchg instruction. Not quite
756 /// enough room in SubClassData for everything, so synchronization scope ID
757 /// gets its own field.
758 SyncScope::ID SSID;
759};
760
761template <>
763 public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
764};
765
767
768//===----------------------------------------------------------------------===//
769// AtomicRMWInst Class
770//===----------------------------------------------------------------------===//
771
772/// an instruction that atomically reads a memory location,
773/// combines it with another value, and then stores the result back. Returns
774/// the old value.
775///
777protected:
778 // Note: Instruction needs to be a friend here to call cloneImpl.
779 friend class Instruction;
780
782
783public:
784 /// This enumeration lists the possible modifications atomicrmw can make. In
785 /// the descriptions, 'p' is the pointer to the instruction's memory location,
786 /// 'old' is the initial value of *p, and 'v' is the other value passed to the
787 /// instruction. These instructions always return 'old'.
788 enum BinOp : unsigned {
789 /// *p = v
791 /// *p = old + v
793 /// *p = old - v
795 /// *p = old & v
797 /// *p = ~(old & v)
799 /// *p = old | v
801 /// *p = old ^ v
803 /// *p = old >signed v ? old : v
805 /// *p = old <signed v ? old : v
807 /// *p = old >unsigned v ? old : v
809 /// *p = old <unsigned v ? old : v
811
812 /// *p = old + v
814
815 /// *p = old - v
817
818 /// *p = maxnum(old, v)
819 /// \p maxnum matches the behavior of \p llvm.maxnum.*.
821
822 /// *p = minnum(old, v)
823 /// \p minnum matches the behavior of \p llvm.minnum.*.
825
826 /// *p = maximum(old, v)
827 /// \p maximum matches the behavior of \p llvm.maximum.*.
829
830 /// *p = minimum(old, v)
831 /// \p minimum matches the behavior of \p llvm.minimum.*.
833
834 /// *p = maximumnum(old, v)
835 /// \p maximumnum matches the behavior of \p llvm.maximumnum.*.
837
838 /// *p = minimumnum(old, v)
839 /// \p minimumnum matches the behavior of \p llvm.minimumnum.*.
841
842 /// Increment one up to a maximum value.
843 /// *p = (old u>= v) ? 0 : (old + 1)
845
846 /// Decrement one until a minimum value or zero.
847 /// *p = ((old == 0) || (old u> v)) ? v : (old - 1)
849
850 /// Subtract only if no unsigned overflow.
851 /// *p = (old u>= v) ? old - v : old
853
854 /// *p = usub.sat(old, v)
855 /// \p usub.sat matches the behavior of \p llvm.usub.sat.*.
857
861 };
862
863private:
864 template <unsigned Offset>
865 using AtomicOrderingBitfieldElement =
868
869 template <unsigned Offset>
870 using BinOpBitfieldElement =
872
873 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
874
875public:
876 LLVM_ABI AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
877 Align Alignment, AtomicOrdering Ordering,
878 SyncScope::ID SSID, bool Elementwise = false,
879 InsertPosition InsertBefore = nullptr);
880
881 // allocate space for exactly two operands
882 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
883 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
884
888 using OperationField = BinOpBitfieldElement<AtomicOrderingField::NextBit>;
894 "Bitfields must be contiguous");
895
897
898 LLVM_ABI static StringRef getOperationName(BinOp Op);
899
900 static bool isFPOperation(BinOp Op) {
901 switch (Op) {
910 return true;
911 default:
912 return false;
913 }
914 }
915
917 setSubclassData<OperationField>(Operation);
918 }
919
920 /// Return the alignment of the memory that is being allocated by the
921 /// instruction.
922 Align getAlign() const {
923 return Align(1ULL << getSubclassData<AlignmentField>());
924 }
925
927 setSubclassData<AlignmentField>(Log2(Align));
928 }
929
930 /// Return true if this is a RMW on a volatile memory location.
931 ///
933
934 /// Specify whether this is a volatile RMW or not.
935 ///
936 void setVolatile(bool V) { setSubclassData<VolatileField>(V); }
937
938 /// Return true if this RMW has elementwise vector semantics.
940
941 /// Specify whether this RMW has elementwise vector semantics.
942 void setElementwise(bool V) { setSubclassData<ElementwiseField>(V); }
943
944 /// Transparently provide more efficient getOperand methods.
946
947 /// Returns the ordering constraint of this rmw instruction.
951
952 /// Sets the ordering constraint of this rmw instruction.
954 assert(Ordering != AtomicOrdering::NotAtomic &&
955 "atomicrmw instructions can only be atomic.");
956 assert(Ordering != AtomicOrdering::Unordered &&
957 "atomicrmw instructions cannot be unordered.");
958 setSubclassData<AtomicOrderingField>(Ordering);
959 }
960
961 /// Returns the synchronization scope ID of this rmw instruction.
963 return SSID;
964 }
965
966 /// Sets the synchronization scope ID of this rmw instruction.
968 this->SSID = SSID;
969 }
970
972 const Value *getPointerOperand() const { return getOperand(0); }
973 static unsigned getPointerOperandIndex() { return 0U; }
974
976 const Value *getValOperand() const { return getOperand(1); }
977
978 /// Returns the address space of the pointer operand.
979 unsigned getPointerAddressSpace() const {
981 }
982
984 return isFPOperation(getOperation());
985 }
986
987 // Methods for support type inquiry through isa, cast, and dyn_cast:
988 static bool classof(const Instruction *I) {
989 return I->getOpcode() == Instruction::AtomicRMW;
990 }
991 static bool classof(const Value *V) {
993 }
994
995private:
996 void Init(BinOp Operation, Value *Ptr, Value *Val, Align Align,
997 AtomicOrdering Ordering, SyncScope::ID SSID, bool Elementwise);
998
999 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1000 // method so that subclasses cannot accidentally use it.
1001 template <typename Bitfield>
1002 void setSubclassData(typename Bitfield::Type Value) {
1004 }
1005
1006 /// The synchronization scope ID of this rmw instruction. Not quite enough
1007 /// room in SubClassData for everything, so synchronization scope ID gets its
1008 /// own field.
1009 SyncScope::ID SSID;
1010};
1011
1012template <>
1014 : public FixedNumOperandTraits<AtomicRMWInst,2> {
1015};
1016
1018
1019//===----------------------------------------------------------------------===//
1020// GetElementPtrInst Class
1021//===----------------------------------------------------------------------===//
1022
1023// checkGEPType - Simple wrapper function to give a better assertion failure
1024// message on bad indexes for a gep instruction.
1025//
1027 assert(Ty && "Invalid GetElementPtrInst indices for type!");
1028 return Ty;
1029}
1030
1031/// an instruction for type-safe pointer arithmetic to
1032/// access elements of arrays and structs
1033///
1034class GetElementPtrInst : public Instruction {
1035 Type *SourceElementType;
1036 Type *ResultElementType;
1037
1038 GetElementPtrInst(const GetElementPtrInst &GEPI, AllocInfo AllocInfo);
1039
1040 /// Constructors - Create a getelementptr instruction with a base pointer an
1041 /// list of indices. The first and second ctor can optionally insert before an
1042 /// existing instruction, the third appends the new instruction to the
1043 /// specified BasicBlock.
1044 inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
1046 const Twine &NameStr, InsertPosition InsertBefore);
1047
1048 LLVM_ABI void init(Value *Ptr, ArrayRef<Value *> IdxList,
1049 const Twine &NameStr);
1050
1051protected:
1052 // Note: Instruction needs to be a friend here to call cloneImpl.
1053 friend class Instruction;
1054
1055 LLVM_ABI GetElementPtrInst *cloneImpl() const;
1056
1057public:
1058 static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
1059 ArrayRef<Value *> IdxList,
1060 const Twine &NameStr = "",
1061 InsertPosition InsertBefore = nullptr) {
1062 unsigned Values = 1 + unsigned(IdxList.size());
1063 assert(PointeeType && "Must specify element type");
1065 return new (AllocMarker) GetElementPtrInst(
1066 PointeeType, Ptr, IdxList, AllocMarker, NameStr, InsertBefore);
1067 }
1068
1069 static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
1071 const Twine &NameStr = "",
1072 InsertPosition InsertBefore = nullptr) {
1073 GetElementPtrInst *GEP =
1074 Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore);
1075 GEP->setNoWrapFlags(NW);
1076 return GEP;
1077 }
1078
1079 /// Create an "inbounds" getelementptr. See the documentation for the
1080 /// "inbounds" flag in LangRef.html for details.
1081 static GetElementPtrInst *
1082 CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef<Value *> IdxList,
1083 const Twine &NameStr = "",
1084 InsertPosition InsertBefore = nullptr) {
1085 return Create(PointeeType, Ptr, IdxList, GEPNoWrapFlags::inBounds(),
1086 NameStr, InsertBefore);
1087 }
1088
1089 /// Transparently provide more efficient getOperand methods.
1091
1092 Type *getSourceElementType() const { return SourceElementType; }
1093
1094 void setSourceElementType(Type *Ty) { SourceElementType = Ty; }
1095 void setResultElementType(Type *Ty) { ResultElementType = Ty; }
1096
1098 return ResultElementType;
1099 }
1100
1101 /// Returns the address space of this instruction's pointer type.
1102 unsigned getAddressSpace() const {
1103 // Note that this is always the same as the pointer operand's address space
1104 // and that is cheaper to compute, so cheat here.
1105 return getPointerAddressSpace();
1106 }
1107
1108 /// Returns the result type of a getelementptr with the given source
1109 /// element type and indexes.
1110 ///
1111 /// Null is returned if the indices are invalid for the specified
1112 /// source element type.
1113 LLVM_ABI static Type *getIndexedType(Type *Ty, ArrayRef<Value *> IdxList);
1115 LLVM_ABI static Type *getIndexedType(Type *Ty, ArrayRef<uint64_t> IdxList);
1116
1117 /// Return the type of the element at the given index of an indexable
1118 /// type. This is equivalent to "getIndexedType(Agg, {Zero, Idx})".
1119 ///
1120 /// Returns null if the type can't be indexed, or the given index is not
1121 /// legal for the given type.
1122 LLVM_ABI static Type *getTypeAtIndex(Type *Ty, Value *Idx);
1123 LLVM_ABI static Type *getTypeAtIndex(Type *Ty, uint64_t Idx);
1124
1125 inline op_iterator idx_begin() { return op_begin()+1; }
1126 inline const_op_iterator idx_begin() const { return op_begin()+1; }
1127 inline op_iterator idx_end() { return op_end(); }
1128 inline const_op_iterator idx_end() const { return op_end(); }
1129
1133
1135 return make_range(idx_begin(), idx_end());
1136 }
1137
1139 return getOperand(0);
1140 }
1141 const Value *getPointerOperand() const {
1142 return getOperand(0);
1143 }
1144 static unsigned getPointerOperandIndex() {
1145 return 0U; // get index for modifying correct operand.
1146 }
1147
1148 /// Method to return the pointer operand as a
1149 /// PointerType.
1151 return getPointerOperand()->getType();
1152 }
1153
1154 /// Returns the address space of the pointer operand.
1155 unsigned getPointerAddressSpace() const {
1157 }
1158
1159 /// Returns the pointer type returned by the GEP
1160 /// instruction, which may be a vector of pointers.
1162 // Vector GEP
1163 Type *Ty = Ptr->getType();
1164 if (Ty->isVectorTy())
1165 return Ty;
1166
1167 for (Value *Index : IdxList)
1168 if (auto *IndexVTy = dyn_cast<VectorType>(Index->getType())) {
1169 ElementCount EltCount = IndexVTy->getElementCount();
1170 return VectorType::get(Ty, EltCount);
1171 }
1172 // Scalar GEP
1173 return Ty;
1174 }
1175
1176 unsigned getNumIndices() const { // Note: always non-negative
1177 return getNumOperands() - 1;
1178 }
1179
1180 bool hasIndices() const {
1181 return getNumOperands() > 1;
1182 }
1183
1184 /// Return true if all of the indices of this GEP are
1185 /// zeros. If so, the result pointer and the first operand have the same
1186 /// value, just potentially different types.
1187 LLVM_ABI bool hasAllZeroIndices() const;
1188
1189 /// Return true if all of the indices of this GEP are
1190 /// constant integers. If so, the result pointer and the first operand have
1191 /// a constant offset between them.
1192 LLVM_ABI bool hasAllConstantIndices() const;
1193
1194 /// Set nowrap flags for GEP instruction.
1196
1197 /// Set or clear the inbounds flag on this GEP instruction.
1198 /// See LangRef.html for the meaning of inbounds on a getelementptr.
1199 /// TODO: Remove this method in favor of setNoWrapFlags().
1200 LLVM_ABI void setIsInBounds(bool b = true);
1201
1202 /// Get the nowrap flags for the GEP instruction.
1204
1205 /// Determine whether the GEP has the inbounds flag.
1206 LLVM_ABI bool isInBounds() const;
1207
1208 /// Determine whether the GEP has the nusw flag.
1209 LLVM_ABI bool hasNoUnsignedSignedWrap() const;
1210
1211 /// Determine whether the GEP has the nuw flag.
1212 LLVM_ABI bool hasNoUnsignedWrap() const;
1213
1214 /// Accumulate the constant address offset of this GEP if possible.
1215 ///
1216 /// This routine accepts an APInt into which it will accumulate the constant
1217 /// offset of this GEP if the GEP is in fact constant. If the GEP is not
1218 /// all-constant, it returns false and the value of the offset APInt is
1219 /// undefined (it is *not* preserved!). The APInt passed into this routine
1220 /// must be at least as wide as the IntPtr type for the address space of
1221 /// the base GEP pointer.
1223 APInt &Offset) const;
1224 LLVM_ABI bool
1225 collectOffset(const DataLayout &DL, unsigned BitWidth,
1226 SmallMapVector<Value *, APInt, 4> &VariableOffsets,
1227 APInt &ConstantOffset) const;
1228 // Methods for support type inquiry through isa, cast, and dyn_cast:
1229 static bool classof(const Instruction *I) {
1230 return (I->getOpcode() == Instruction::GetElementPtr);
1231 }
1232 static bool classof(const Value *V) {
1234 }
1235};
1236
1237template <>
1239 : public VariadicOperandTraits<GetElementPtrInst> {};
1240
1241GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
1242 ArrayRef<Value *> IdxList,
1243 AllocInfo AllocInfo, const Twine &NameStr,
1244 InsertPosition InsertBefore)
1245 : Instruction(getGEPReturnType(Ptr, IdxList), GetElementPtr, AllocInfo,
1246 InsertBefore),
1247 SourceElementType(PointeeType),
1248 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1249 init(Ptr, IdxList, NameStr);
1250}
1251
1252DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
1253
1254//===----------------------------------------------------------------------===//
1255// ICmpInst Class
1256//===----------------------------------------------------------------------===//
1257
1258/// This instruction compares its operands according to the predicate given
1259/// to the constructor. It only operates on integers or pointers. The operands
1260/// must be identical types.
1261/// Represent an integer comparison operator.
1262class ICmpInst: public CmpInst {
1263 void AssertOK() {
1265 "Invalid ICmp predicate value");
1266 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1267 "Both operands to ICmp instruction are not of the same type!");
1268 // Check that the operands are the right type
1269 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
1270 getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
1271 "Invalid operand types for ICmp instruction");
1272 }
1273
1274 enum { SameSign = (1 << 0) };
1275
1276protected:
1277 // Note: Instruction needs to be a friend here to call cloneImpl.
1278 friend class Instruction;
1279
1280 /// Clone an identical ICmpInst
1281 LLVM_ABI ICmpInst *cloneImpl() const;
1282
1283public:
1284 /// Constructor with insertion semantics.
1285 ICmpInst(InsertPosition InsertBefore, ///< Where to insert
1286 Predicate pred, ///< The predicate to use for the comparison
1287 Value *LHS, ///< The left-hand-side of the expression
1288 Value *RHS, ///< The right-hand-side of the expression
1289 const Twine &NameStr = "" ///< Name of the instruction
1290 )
1291 : CmpInst(makeCmpResultType(LHS->getType()), Instruction::ICmp, pred, LHS,
1292 RHS, NameStr, InsertBefore) {
1293#ifndef NDEBUG
1294 AssertOK();
1295#endif
1296 }
1297
1298 /// Constructor with no-insertion semantics
1300 Predicate pred, ///< The predicate to use for the comparison
1301 Value *LHS, ///< The left-hand-side of the expression
1302 Value *RHS, ///< The right-hand-side of the expression
1303 const Twine &NameStr = "" ///< Name of the instruction
1305 Instruction::ICmp, pred, LHS, RHS, NameStr) {
1306#ifndef NDEBUG
1307 AssertOK();
1308#endif
1309 }
1310
1311 /// @returns the predicate along with samesign information.
1313 return {getPredicate(), hasSameSign()};
1314 }
1315
1316 /// @returns the inverse predicate along with samesign information: static
1317 /// variant.
1319 return {getInversePredicate(Pred), Pred.hasSameSign()};
1320 }
1321
1322 /// @returns the inverse predicate along with samesign information.
1326
1327 /// @returns the swapped predicate along with samesign information: static
1328 /// variant.
1330 return {getSwappedPredicate(Pred), Pred.hasSameSign()};
1331 }
1332
1333 /// @returns the swapped predicate along with samesign information.
1337
1338 /// @returns the non-strict predicate along with samesign information: static
1339 /// variant.
1341 return {getNonStrictPredicate(Pred), Pred.hasSameSign()};
1342 }
1343
1344 /// For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
1345 /// @returns the non-strict predicate along with samesign information.
1349
1350 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
1351 /// @returns the predicate that would be the result if the operand were
1352 /// regarded as signed.
1353 /// Return the signed version of the predicate.
1357
1358 /// Return the signed version of the predicate: static variant.
1359 LLVM_ABI static Predicate getSignedPredicate(Predicate Pred);
1360
1361 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
1362 /// @returns the predicate that would be the result if the operand were
1363 /// regarded as unsigned.
1364 /// Return the unsigned version of the predicate.
1368
1369 /// Return the unsigned version of the predicate: static variant.
1370 LLVM_ABI static Predicate getUnsignedPredicate(Predicate Pred);
1371
1372 /// For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->EQ
1373 /// @returns the unsigned version of the signed predicate pred or
1374 /// the signed version of the signed predicate pred.
1375 /// Static variant.
1376 LLVM_ABI static Predicate getFlippedSignednessPredicate(Predicate Pred);
1377
1378 /// For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->EQ
1379 /// @returns the unsigned version of the signed predicate pred or
1380 /// the signed version of the signed predicate pred.
1384
1385 /// Determine if Pred1 implies Pred2 is true, false, or if nothing can be
1386 /// inferred about the implication, when two compares have matching operands.
1387 LLVM_ABI static std::optional<bool>
1388 isImpliedByMatchingCmp(CmpPredicate Pred1, CmpPredicate Pred2);
1389
1390 void setSameSign(bool B = true) {
1391 SubclassOptionalData = (SubclassOptionalData & ~SameSign) | (B * SameSign);
1392 }
1393
1394 /// An icmp instruction, which can be marked as "samesign", indicating that
1395 /// the two operands have the same sign. This means that we can convert
1396 /// "slt" to "ult" and vice versa, which enables more optimizations.
1397 bool hasSameSign() const { return SubclassOptionalData & SameSign; }
1398
1399 /// Return true if this predicate is either EQ or NE. This also
1400 /// tests for commutativity.
1401 static bool isEquality(Predicate P) {
1402 return P == ICMP_EQ || P == ICMP_NE;
1403 }
1404
1405 /// Return true if this predicate is either EQ or NE. This also
1406 /// tests for commutativity.
1407 bool isEquality() const {
1408 return isEquality(getPredicate());
1409 }
1410
1411 /// @returns true if the predicate is commutative
1412 /// Determine if this relation is commutative.
1413 static bool isCommutative(Predicate P) { return isEquality(P); }
1414
1415 /// @returns true if the predicate of this ICmpInst is commutative
1416 /// Determine if this relation is commutative.
1417 bool isCommutative() const { return isCommutative(getPredicate()); }
1418
1419 /// Return true if the predicate is relational (not EQ or NE).
1420 ///
1421 bool isRelational() const {
1422 return !isEquality();
1423 }
1424
1425 /// Return true if the predicate is relational (not EQ or NE).
1426 ///
1427 static bool isRelational(Predicate P) {
1428 return !isEquality(P);
1429 }
1430
1431 /// Return true if the predicate is SGT or UGT.
1432 ///
1433 static bool isGT(Predicate P) {
1434 return P == ICMP_SGT || P == ICMP_UGT;
1435 }
1436
1437 /// Return true if the predicate is SLT or ULT.
1438 ///
1439 static bool isLT(Predicate P) {
1440 return P == ICMP_SLT || P == ICMP_ULT;
1441 }
1442
1443 /// Return true if the predicate is SGE or UGE.
1444 ///
1445 static bool isGE(Predicate P) {
1446 return P == ICMP_SGE || P == ICMP_UGE;
1447 }
1448
1449 /// Return true if the predicate is SLE or ULE.
1450 ///
1451 static bool isLE(Predicate P) {
1452 return P == ICMP_SLE || P == ICMP_ULE;
1453 }
1454
1455 /// Returns the sequence of all ICmp predicates.
1456 ///
1457 static auto predicates() { return ICmpPredicates(); }
1458
1459 /// Exchange the two operands to this instruction in such a way that it does
1460 /// not modify the semantics of the instruction. The predicate value may be
1461 /// changed to retain the same result if the predicate is order dependent
1462 /// (e.g. ult).
1463 /// Swap operands and adjust predicate.
1466 Op<0>().swap(Op<1>());
1467 }
1468
1469 /// Return result of `LHS Pred RHS` comparison.
1470 LLVM_ABI static bool compare(const APInt &LHS, const APInt &RHS,
1471 ICmpInst::Predicate Pred);
1472
1473 /// Return result of `LHS Pred RHS`, if it can be determined from the
1474 /// KnownBits. Otherwise return nullopt.
1475 LLVM_ABI static std::optional<bool>
1476 compare(const KnownBits &LHS, const KnownBits &RHS, ICmpInst::Predicate Pred);
1477
1478 // Methods for support type inquiry through isa, cast, and dyn_cast:
1479 static bool classof(const Instruction *I) {
1480 return I->getOpcode() == Instruction::ICmp;
1481 }
1482 static bool classof(const Value *V) {
1484 }
1485};
1486
1487//===----------------------------------------------------------------------===//
1488// FCmpInst Class
1489//===----------------------------------------------------------------------===//
1490
1491/// This instruction compares its operands according to the predicate given
1492/// to the constructor. It only operates on floating point values or packed
1493/// vectors of floating point values. The operands must be identical types.
1494/// Represents a floating point comparison operator.
1495class FCmpInst : public CmpInst, public FastMathFlagsStorage {
1496 void AssertOK() {
1497 assert(isFPPredicate() && "Invalid FCmp predicate value");
1498 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1499 "Both operands to FCmp instruction are not of the same type!");
1500 // Check that the operands are the right type
1501 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1502 "Invalid operand types for FCmp instruction");
1503 }
1504
1505protected:
1506 // Note: Instruction needs to be a friend here to call cloneImpl.
1507 friend class Instruction;
1508
1509 /// Clone an identical FCmpInst
1510 LLVM_ABI FCmpInst *cloneImpl() const;
1511
1512public:
1513 /// Constructor with insertion semantics.
1514 FCmpInst(InsertPosition InsertBefore, ///< Where to insert
1515 Predicate pred, ///< The predicate to use for the comparison
1516 Value *LHS, ///< The left-hand-side of the expression
1517 Value *RHS, ///< The right-hand-side of the expression
1518 const Twine &NameStr = "" ///< Name of the instruction
1519 )
1520 : CmpInst(makeCmpResultType(LHS->getType()), Instruction::FCmp, pred, LHS,
1521 RHS, NameStr, InsertBefore) {
1522 AssertOK();
1523 }
1524
1525 /// Constructor with no-insertion semantics
1526 FCmpInst(Predicate Pred, ///< The predicate to use for the comparison
1527 Value *LHS, ///< The left-hand-side of the expression
1528 Value *RHS, ///< The right-hand-side of the expression
1529 const Twine &NameStr = "", ///< Name of the instruction
1530 Instruction *FlagsSource = nullptr)
1531 : CmpInst(makeCmpResultType(LHS->getType()), Instruction::FCmp, Pred, LHS,
1532 RHS, NameStr) {
1533 if (FlagsSource)
1534 copyIRFlags(FlagsSource);
1535 AssertOK();
1536 }
1537
1538 /// @returns true if the predicate is EQ or NE.
1539 /// Determine if this is an equality predicate.
1540 static bool isEquality(Predicate Pred) {
1541 return Pred == FCMP_OEQ || Pred == FCMP_ONE || Pred == FCMP_UEQ ||
1542 Pred == FCMP_UNE;
1543 }
1544
1545 /// @returns true if the predicate of this instruction is EQ or NE.
1546 /// Determine if this is an equality predicate.
1547 bool isEquality() const { return isEquality(getPredicate()); }
1548
1549 /// @returns true if the predicate is commutative.
1550 /// Determine if this is a commutative predicate.
1551 static bool isCommutative(Predicate Pred) {
1552 return isEquality(Pred) || Pred == FCMP_FALSE || Pred == FCMP_TRUE ||
1553 Pred == FCMP_ORD || Pred == FCMP_UNO;
1554 }
1555
1556 /// @returns true if the predicate of this instruction is commutative.
1557 /// Determine if this is a commutative predicate.
1558 bool isCommutative() const { return isCommutative(getPredicate()); }
1559
1560 /// @returns true if the predicate is relational (not EQ or NE).
1561 /// Determine if this a relational predicate.
1562 bool isRelational() const { return !isEquality(); }
1563
1564 /// Exchange the two operands to this instruction in such a way that it does
1565 /// not modify the semantics of the instruction. The predicate value may be
1566 /// changed to retain the same result if the predicate is order dependent
1567 /// (e.g. ult).
1568 /// Swap operands and adjust predicate.
1571 Op<0>().swap(Op<1>());
1572 }
1573
1574 /// Returns the sequence of all FCmp predicates.
1575 ///
1576 static auto predicates() { return FCmpPredicates(); }
1577
1578 /// Return result of `LHS Pred RHS` comparison.
1579 LLVM_ABI static bool compare(const APFloat &LHS, const APFloat &RHS,
1580 FCmpInst::Predicate Pred);
1581
1582 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1583 static bool classof(const Instruction *I) {
1584 return I->getOpcode() == Instruction::FCmp;
1585 }
1586 static bool classof(const Value *V) {
1588 }
1589};
1590
1591//===----------------------------------------------------------------------===//
1592/// This class represents a function call, abstracting a target
1593/// machine's calling convention. This class uses low bit of the SubClassData
1594/// field to indicate whether or not this is a tail call. The rest of the bits
1595/// hold the calling convention of the call.
1596///
1597class CallInst : public CallBase, public FastMathFlagsStorage {
1598 CallInst(const CallInst &CI, AllocInfo AllocInfo);
1599
1600 /// Construct a CallInst from a range of arguments
1601 inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1602 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1603 AllocInfo AllocInfo, InsertPosition InsertBefore);
1604
1605 inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1606 const Twine &NameStr, AllocInfo AllocInfo,
1607 InsertPosition InsertBefore)
1608 : CallInst(Ty, Func, Args, {}, NameStr, AllocInfo, InsertBefore) {}
1609
1610 LLVM_ABI explicit CallInst(FunctionType *Ty, Value *F, const Twine &NameStr,
1611 AllocInfo AllocInfo, InsertPosition InsertBefore);
1612
1613 LLVM_ABI void init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
1614 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
1615 void init(FunctionType *FTy, Value *Func, const Twine &NameStr);
1616
1617 /// Compute the number of operands to allocate.
1618 static unsigned ComputeNumOperands(unsigned NumArgs,
1619 unsigned NumBundleInputs = 0) {
1620 // We need one operand for the called function, plus the input operand
1621 // counts provided.
1622 return 1 + NumArgs + NumBundleInputs;
1623 }
1624
1625protected:
1626 // Note: Instruction needs to be a friend here to call cloneImpl.
1627 friend class Instruction;
1628
1629 LLVM_ABI CallInst *cloneImpl() const;
1630
1631public:
1632 static CallInst *Create(FunctionType *Ty, Value *F, const Twine &NameStr = "",
1633 InsertPosition InsertBefore = nullptr) {
1634 IntrusiveOperandsAllocMarker AllocMarker{ComputeNumOperands(0)};
1635 return new (AllocMarker)
1636 CallInst(Ty, F, NameStr, AllocMarker, InsertBefore);
1637 }
1638
1639 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1640 const Twine &NameStr,
1641 InsertPosition InsertBefore = nullptr) {
1642 IntrusiveOperandsAllocMarker AllocMarker{ComputeNumOperands(Args.size())};
1643 return new (AllocMarker)
1644 CallInst(Ty, Func, Args, {}, NameStr, AllocMarker, InsertBefore);
1645 }
1646
1647 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1648 ArrayRef<OperandBundleDef> Bundles = {},
1649 const Twine &NameStr = "",
1650 InsertPosition InsertBefore = nullptr) {
1651 IntrusiveOperandsAndDescriptorAllocMarker AllocMarker{
1652 ComputeNumOperands(unsigned(Args.size()), CountBundleInputs(Bundles)),
1653 unsigned(Bundles.size() * sizeof(BundleOpInfo))};
1654
1655 return new (AllocMarker)
1656 CallInst(Ty, Func, Args, Bundles, NameStr, AllocMarker, InsertBefore);
1657 }
1658
1659 static CallInst *Create(FunctionCallee Func, const Twine &NameStr = "",
1660 InsertPosition InsertBefore = nullptr) {
1661 return Create(Func.getFunctionType(), Func.getCallee(), NameStr,
1662 InsertBefore);
1663 }
1664
1665 static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
1666 ArrayRef<OperandBundleDef> Bundles = {},
1667 const Twine &NameStr = "",
1668 InsertPosition InsertBefore = nullptr) {
1669 return Create(Func.getFunctionType(), Func.getCallee(), Args, Bundles,
1670 NameStr, InsertBefore);
1671 }
1672
1673 static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
1674 const Twine &NameStr,
1675 InsertPosition InsertBefore = nullptr) {
1676 return Create(Func.getFunctionType(), Func.getCallee(), Args, NameStr,
1677 InsertBefore);
1678 }
1679
1680 /// Create a clone of \p CI with a different set of operand bundles and
1681 /// insert it before \p InsertBefore.
1682 ///
1683 /// The returned call instruction is identical \p CI in every way except that
1684 /// the operand bundles for the new instruction are set to the operand bundles
1685 /// in \p Bundles.
1686 LLVM_ABI static CallInst *Create(CallInst *CI,
1688 InsertPosition InsertPt = nullptr);
1689
1690 // Note that 'musttail' implies 'tail'.
1698
1700 static_assert(
1702 "Bitfields must be contiguous");
1703
1707
1708 bool isTailCall() const {
1710 return Kind == TCK_Tail || Kind == TCK_MustTail;
1711 }
1712
1713 bool isMustTailCall() const { return getTailCallKind() == TCK_MustTail; }
1714
1715 bool isNoTailCall() const { return getTailCallKind() == TCK_NoTail; }
1716
1718 setSubclassData<TailCallKindField>(TCK);
1719 }
1720
1721 void setTailCall(bool IsTc = true) {
1723 }
1724
1725 /// Return true if the call can return twice
1726 bool canReturnTwice() const { return hasFnAttr(Attribute::ReturnsTwice); }
1727 void setCanReturnTwice() { addFnAttr(Attribute::ReturnsTwice); }
1728
1729 /// Return true if the call is for a noreturn trap intrinsic.
1731 switch (getIntrinsicID()) {
1732 case Intrinsic::trap:
1733 case Intrinsic::ubsantrap:
1734 return !hasFnAttr("trap-func-name");
1735 default:
1736 return false;
1737 }
1738 }
1739
1740 // Methods for support type inquiry through isa, cast, and dyn_cast:
1741 static bool classof(const Instruction *I) {
1742 return I->getOpcode() == Instruction::Call;
1743 }
1744 static bool classof(const Value *V) {
1746 }
1747
1748 /// Updates profile metadata by scaling it by \p S / \p T.
1750
1751private:
1752 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1753 // method so that subclasses cannot accidentally use it.
1754 template <typename Bitfield>
1755 void setSubclassData(typename Bitfield::Type Value) {
1757 }
1758};
1759
1760CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1761 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1762 AllocInfo AllocInfo, InsertPosition InsertBefore)
1763 : CallBase(Ty->getReturnType(), Instruction::Call, AllocInfo,
1764 InsertBefore) {
1766 unsigned(Args.size() + CountBundleInputs(Bundles) + 1));
1767 init(Ty, Func, Args, Bundles, NameStr);
1768}
1769
1770//===----------------------------------------------------------------------===//
1771// SelectInst Class
1772//===----------------------------------------------------------------------===//
1773
1774/// This class represents the LLVM 'select' instruction.
1775///
1776class SelectInst : public Instruction, public FastMathFlagsStorage {
1777 constexpr static IntrusiveOperandsAllocMarker AllocMarker{3};
1778
1779 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1780 InsertPosition InsertBefore)
1781 : Instruction(S1->getType(), Instruction::Select, AllocMarker,
1782 InsertBefore) {
1783 init(C, S1, S2);
1784 setName(NameStr);
1785 }
1786
1787 void init(Value *C, Value *S1, Value *S2) {
1788 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1789 Op<0>() = C;
1790 Op<1>() = S1;
1791 Op<2>() = S2;
1792 }
1793
1794protected:
1795 // Note: Instruction needs to be a friend here to call cloneImpl.
1796 friend class Instruction;
1797
1798 LLVM_ABI SelectInst *cloneImpl() const;
1799
1800public:
1801 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1802 const Twine &NameStr = "",
1803 InsertPosition InsertBefore = nullptr,
1804 const Instruction *MDFrom = nullptr) {
1805 SelectInst *Sel =
1806 new (AllocMarker) SelectInst(C, S1, S2, NameStr, InsertBefore);
1807 if (MDFrom)
1808 Sel->copyMetadata(*MDFrom);
1809 return Sel;
1810 }
1811
1812 const Value *getCondition() const { return Op<0>(); }
1813 const Value *getTrueValue() const { return Op<1>(); }
1814 const Value *getFalseValue() const { return Op<2>(); }
1815 Value *getCondition() { return Op<0>(); }
1816 Value *getTrueValue() { return Op<1>(); }
1817 Value *getFalseValue() { return Op<2>(); }
1818
1819 void setCondition(Value *V) { Op<0>() = V; }
1820 void setTrueValue(Value *V) { Op<1>() = V; }
1821 void setFalseValue(Value *V) { Op<2>() = V; }
1822
1823 /// Swap the true and false values of the select instruction.
1824 /// This doesn't swap prof metadata.
1825 void swapValues() { Op<1>().swap(Op<2>()); }
1826
1827 /// Return a string if the specified operands are invalid
1828 /// for a select operation, otherwise return null.
1829 LLVM_ABI static const char *areInvalidOperands(Value *Cond, Value *True,
1830 Value *False);
1831
1832 /// Transparently provide more efficient getOperand methods.
1834
1836 return static_cast<OtherOps>(Instruction::getOpcode());
1837 }
1838
1839 // Methods for support type inquiry through isa, cast, and dyn_cast:
1840 static bool classof(const Instruction *I) {
1841 return I->getOpcode() == Instruction::Select;
1842 }
1843 static bool classof(const Value *V) {
1845 }
1846};
1847
1848template <>
1849struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1850};
1851
1853
1854//===----------------------------------------------------------------------===//
1855// VAArgInst Class
1856//===----------------------------------------------------------------------===//
1857
1858/// This class represents the va_arg llvm instruction, which returns
1859/// an argument of the specified type given a va_list and increments that list
1860///
1862protected:
1863 // Note: Instruction needs to be a friend here to call cloneImpl.
1864 friend class Instruction;
1865
1866 LLVM_ABI VAArgInst *cloneImpl() const;
1867
1868public:
1869 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1870 InsertPosition InsertBefore = nullptr)
1871 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1872 setName(NameStr);
1873 }
1874
1876 const Value *getPointerOperand() const { return getOperand(0); }
1877 static unsigned getPointerOperandIndex() { return 0U; }
1878
1879 // Methods for support type inquiry through isa, cast, and dyn_cast:
1880 static bool classof(const Instruction *I) {
1881 return I->getOpcode() == VAArg;
1882 }
1883 static bool classof(const Value *V) {
1885 }
1886};
1887
1888//===----------------------------------------------------------------------===//
1889// ExtractElementInst Class
1890//===----------------------------------------------------------------------===//
1891
1892/// This instruction extracts a single (scalar)
1893/// element from a VectorType value
1894///
1895class ExtractElementInst : public Instruction {
1896 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
1897
1898 LLVM_ABI ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1899 InsertPosition InsertBefore = nullptr);
1900
1901protected:
1902 // Note: Instruction needs to be a friend here to call cloneImpl.
1903 friend class Instruction;
1904
1905 LLVM_ABI ExtractElementInst *cloneImpl() const;
1906
1907public:
1908 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1909 const Twine &NameStr = "",
1910 InsertPosition InsertBefore = nullptr) {
1911 return new (AllocMarker)
1912 ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1913 }
1914
1915 /// Return true if an extractelement instruction can be
1916 /// formed with the specified operands.
1917 LLVM_ABI static bool isValidOperands(const Value *Vec, const Value *Idx);
1918
1920 Value *getIndexOperand() { return Op<1>(); }
1921 const Value *getVectorOperand() const { return Op<0>(); }
1922 const Value *getIndexOperand() const { return Op<1>(); }
1923
1927
1928 /// Transparently provide more efficient getOperand methods.
1930
1931 // Methods for support type inquiry through isa, cast, and dyn_cast:
1932 static bool classof(const Instruction *I) {
1933 return I->getOpcode() == Instruction::ExtractElement;
1934 }
1935 static bool classof(const Value *V) {
1937 }
1938};
1939
1940template <>
1942 public FixedNumOperandTraits<ExtractElementInst, 2> {
1943};
1944
1946
1947//===----------------------------------------------------------------------===//
1948// InsertElementInst Class
1949//===----------------------------------------------------------------------===//
1950
1951/// This instruction inserts a single (scalar)
1952/// element into a VectorType value
1953///
1954class InsertElementInst : public Instruction {
1955 constexpr static IntrusiveOperandsAllocMarker AllocMarker{3};
1956
1957 LLVM_ABI InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1958 const Twine &NameStr = "",
1959 InsertPosition InsertBefore = nullptr);
1960
1961protected:
1962 // Note: Instruction needs to be a friend here to call cloneImpl.
1963 friend class Instruction;
1964
1965 LLVM_ABI InsertElementInst *cloneImpl() const;
1966
1967public:
1968 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1969 const Twine &NameStr = "",
1970 InsertPosition InsertBefore = nullptr) {
1971 return new (AllocMarker)
1972 InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1973 }
1974
1975 /// Return true if an insertelement instruction can be
1976 /// formed with the specified operands.
1977 LLVM_ABI static bool isValidOperands(const Value *Vec, const Value *NewElt,
1978 const Value *Idx);
1979
1980 /// Overload to return most specific vector type.
1981 ///
1984 }
1985
1986 /// Transparently provide more efficient getOperand methods.
1988
1989 // Methods for support type inquiry through isa, cast, and dyn_cast:
1990 static bool classof(const Instruction *I) {
1991 return I->getOpcode() == Instruction::InsertElement;
1992 }
1993 static bool classof(const Value *V) {
1995 }
1996};
1997
1998template <>
2000 public FixedNumOperandTraits<InsertElementInst, 3> {
2001};
2002
2004
2005//===----------------------------------------------------------------------===//
2006// ShuffleVectorInst Class
2007//===----------------------------------------------------------------------===//
2008
2009constexpr int PoisonMaskElem = -1;
2010
2011/// This instruction constructs a fixed permutation of two
2012/// input vectors.
2013///
2014/// For each element of the result vector, the shuffle mask selects an element
2015/// from one of the input vectors to copy to the result. Non-negative elements
2016/// in the mask represent an index into the concatenated pair of input vectors.
2017/// PoisonMaskElem (-1) specifies that the result element is poison.
2018///
2019/// For scalable vectors, all the elements of the mask must be 0 or -1. This
2020/// requirement may be relaxed in the future.
2022 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
2023
2024 SmallVector<int, 4> ShuffleMask;
2025 Constant *ShuffleMaskForBitcode;
2026
2027protected:
2028 // Note: Instruction needs to be a friend here to call cloneImpl.
2029 friend class Instruction;
2030
2032
2033public:
2034 LLVM_ABI ShuffleVectorInst(Value *V1, Value *Mask, const Twine &NameStr = "",
2035 InsertPosition InsertBefore = nullptr);
2037 const Twine &NameStr = "",
2038 InsertPosition InsertBefore = nullptr);
2040 const Twine &NameStr = "",
2041 InsertPosition InsertBefore = nullptr);
2043 const Twine &NameStr = "",
2044 InsertPosition InsertBefore = nullptr);
2045
2046 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
2047 void operator delete(void *Ptr) {
2048 return User::operator delete(Ptr, AllocMarker);
2049 }
2050
2051 /// Swap the operands and adjust the mask to preserve the semantics
2052 /// of the instruction.
2053 LLVM_ABI void commute();
2054
2055 /// Return true if a shufflevector instruction can be
2056 /// formed with the specified operands.
2057 LLVM_ABI static bool isValidOperands(const Value *V1, const Value *V2,
2058 const Value *Mask);
2059 LLVM_ABI static bool isValidOperands(const Value *V1, const Value *V2,
2060 ArrayRef<int> Mask);
2061
2062 /// Overload to return most specific vector type.
2063 ///
2066 }
2067
2068 /// Transparently provide more efficient getOperand methods.
2070
2071 /// Return the shuffle mask value of this instruction for the given element
2072 /// index. Return PoisonMaskElem if the element is undef.
2073 int getMaskValue(unsigned Elt) const { return ShuffleMask[Elt]; }
2074
2075 /// Convert the input shuffle mask operand to a vector of integers. Undefined
2076 /// elements of the mask are returned as PoisonMaskElem.
2077 LLVM_ABI static void getShuffleMask(const Constant *Mask,
2078 SmallVectorImpl<int> &Result);
2079
2080 /// Return the mask for this instruction as a vector of integers. Undefined
2081 /// elements of the mask are returned as PoisonMaskElem.
2083 Result.assign(ShuffleMask.begin(), ShuffleMask.end());
2084 }
2085
2086 /// Return the mask for this instruction, for use in bitcode.
2087 ///
2088 /// TODO: This is temporary until we decide a new bitcode encoding for
2089 /// shufflevector.
2090 Constant *getShuffleMaskForBitcode() const { return ShuffleMaskForBitcode; }
2091
2092 LLVM_ABI static Constant *convertShuffleMaskForBitcode(ArrayRef<int> Mask,
2093 Type *ResultTy);
2094
2095 LLVM_ABI void setShuffleMask(ArrayRef<int> Mask);
2096
2097 ArrayRef<int> getShuffleMask() const { return ShuffleMask; }
2098
2099 /// Return true if this shuffle returns a vector with a different number of
2100 /// elements than its source vectors.
2101 /// Examples: shufflevector <4 x n> A, <4 x n> B, <1,2,3>
2102 /// shufflevector <4 x n> A, <4 x n> B, <1,2,3,4,5>
2103 bool changesLength() const {
2104 unsigned NumSourceElts = cast<VectorType>(Op<0>()->getType())
2105 ->getElementCount()
2106 .getKnownMinValue();
2107 unsigned NumMaskElts = ShuffleMask.size();
2108 return NumSourceElts != NumMaskElts;
2109 }
2110
2111 /// Return true if this shuffle returns a vector with a greater number of
2112 /// elements than its source vectors.
2113 /// Example: shufflevector <2 x n> A, <2 x n> B, <1,2,3>
2114 bool increasesLength() const {
2115 unsigned NumSourceElts = cast<VectorType>(Op<0>()->getType())
2116 ->getElementCount()
2117 .getKnownMinValue();
2118 unsigned NumMaskElts = ShuffleMask.size();
2119 return NumSourceElts < NumMaskElts;
2120 }
2121
2122 /// Return true if this shuffle mask chooses elements from exactly one source
2123 /// vector.
2124 /// Example: <7,5,undef,7>
2125 /// This assumes that vector operands (of length \p NumSrcElts) are the same
2126 /// length as the mask.
2127 LLVM_ABI static bool isSingleSourceMask(ArrayRef<int> Mask, int NumSrcElts);
2128 static bool isSingleSourceMask(const Constant *Mask, int NumSrcElts) {
2129 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2130 SmallVector<int, 16> MaskAsInts;
2131 getShuffleMask(Mask, MaskAsInts);
2132 return isSingleSourceMask(MaskAsInts, NumSrcElts);
2133 }
2134
2135 /// Return true if this shuffle chooses elements from exactly one source
2136 /// vector without changing the length of that vector.
2137 /// Example: shufflevector <4 x n> A, <4 x n> B, <3,0,undef,3>
2138 /// TODO: Optionally allow length-changing shuffles.
2139 bool isSingleSource() const {
2140 return !changesLength() &&
2141 isSingleSourceMask(ShuffleMask, ShuffleMask.size());
2142 }
2143
2144 /// Return true if this shuffle mask chooses elements from exactly one source
2145 /// vector without lane crossings. A shuffle using this mask is not
2146 /// necessarily a no-op because it may change the number of elements from its
2147 /// input vectors or it may provide demanded bits knowledge via undef lanes.
2148 /// Example: <undef,undef,2,3>
2149 LLVM_ABI static bool isIdentityMask(ArrayRef<int> Mask, int NumSrcElts);
2150 static bool isIdentityMask(const Constant *Mask, int NumSrcElts) {
2151 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2152
2153 // Not possible to express a shuffle mask for a scalable vector for this
2154 // case.
2155 if (isa<ScalableVectorType>(Mask->getType()))
2156 return false;
2157
2158 SmallVector<int, 16> MaskAsInts;
2159 getShuffleMask(Mask, MaskAsInts);
2160 return isIdentityMask(MaskAsInts, NumSrcElts);
2161 }
2162
2163 /// Return true if this shuffle chooses elements from exactly one source
2164 /// vector without lane crossings and does not change the number of elements
2165 /// from its input vectors.
2166 /// Example: shufflevector <4 x n> A, <4 x n> B, <4,undef,6,undef>
2167 bool isIdentity() const {
2168 // Not possible to express a shuffle mask for a scalable vector for this
2169 // case.
2171 return false;
2172
2173 return !changesLength() && isIdentityMask(ShuffleMask, ShuffleMask.size());
2174 }
2175
2176 /// Return true if this shuffle lengthens exactly one source vector with
2177 /// undefs in the high elements.
2178 LLVM_ABI bool isIdentityWithPadding() const;
2179
2180 /// Return true if this shuffle extracts the first N elements of exactly one
2181 /// source vector.
2182 LLVM_ABI bool isIdentityWithExtract() const;
2183
2184 /// Return true if this shuffle concatenates its 2 source vectors. This
2185 /// returns false if either input is undefined. In that case, the shuffle is
2186 /// is better classified as an identity with padding operation.
2187 LLVM_ABI bool isConcat() const;
2188
2189 /// Return true if this shuffle mask chooses elements from its source vectors
2190 /// without lane crossings. A shuffle using this mask would be
2191 /// equivalent to a vector select with a constant condition operand.
2192 /// Example: <4,1,6,undef>
2193 /// This returns false if the mask does not choose from both input vectors.
2194 /// In that case, the shuffle is better classified as an identity shuffle.
2195 /// This assumes that vector operands are the same length as the mask
2196 /// (a length-changing shuffle can never be equivalent to a vector select).
2197 LLVM_ABI static bool isSelectMask(ArrayRef<int> Mask, int NumSrcElts);
2198 static bool isSelectMask(const Constant *Mask, int NumSrcElts) {
2199 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2200 SmallVector<int, 16> MaskAsInts;
2201 getShuffleMask(Mask, MaskAsInts);
2202 return isSelectMask(MaskAsInts, NumSrcElts);
2203 }
2204
2205 /// Return true if this shuffle chooses elements from its source vectors
2206 /// without lane crossings and all operands have the same number of elements.
2207 /// In other words, this shuffle is equivalent to a vector select with a
2208 /// constant condition operand.
2209 /// Example: shufflevector <4 x n> A, <4 x n> B, <undef,1,6,3>
2210 /// This returns false if the mask does not choose from both input vectors.
2211 /// In that case, the shuffle is better classified as an identity shuffle.
2212 /// TODO: Optionally allow length-changing shuffles.
2213 bool isSelect() const {
2214 return !changesLength() && isSelectMask(ShuffleMask, ShuffleMask.size());
2215 }
2216
2217 /// Return true if this shuffle mask swaps the order of elements from exactly
2218 /// one source vector.
2219 /// Example: <7,6,undef,4>
2220 /// This assumes that vector operands (of length \p NumSrcElts) are the same
2221 /// length as the mask.
2222 LLVM_ABI static bool isReverseMask(ArrayRef<int> Mask, int NumSrcElts);
2223 static bool isReverseMask(const Constant *Mask, int NumSrcElts) {
2224 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2225 SmallVector<int, 16> MaskAsInts;
2226 getShuffleMask(Mask, MaskAsInts);
2227 return isReverseMask(MaskAsInts, NumSrcElts);
2228 }
2229
2230 /// Return true if this shuffle swaps the order of elements from exactly
2231 /// one source vector.
2232 /// Example: shufflevector <4 x n> A, <4 x n> B, <3,undef,1,undef>
2233 /// TODO: Optionally allow length-changing shuffles.
2234 bool isReverse() const {
2235 return !changesLength() && isReverseMask(ShuffleMask, ShuffleMask.size());
2236 }
2237
2238 /// Return true if this shuffle mask chooses all elements with the same value
2239 /// as the first element of exactly one source vector.
2240 /// Example: <4,undef,undef,4>
2241 /// This assumes that vector operands (of length \p NumSrcElts) are the same
2242 /// length as the mask.
2243 LLVM_ABI static bool isZeroEltSplatMask(ArrayRef<int> Mask, int NumSrcElts);
2244 static bool isZeroEltSplatMask(const Constant *Mask, int NumSrcElts) {
2245 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2246 SmallVector<int, 16> MaskAsInts;
2247 getShuffleMask(Mask, MaskAsInts);
2248 return isZeroEltSplatMask(MaskAsInts, NumSrcElts);
2249 }
2250
2251 /// Return true if all elements of this shuffle are the same value as the
2252 /// first element of exactly one source vector without changing the length
2253 /// of that vector.
2254 /// Example: shufflevector <4 x n> A, <4 x n> B, <undef,0,undef,0>
2255 /// TODO: Optionally allow length-changing shuffles.
2256 /// TODO: Optionally allow splats from other elements.
2257 bool isZeroEltSplat() const {
2258 return !changesLength() &&
2259 isZeroEltSplatMask(ShuffleMask, ShuffleMask.size());
2260 }
2261
2262 /// Return true if this shuffle mask is a transpose mask.
2263 /// Transpose vector masks transpose a 2xn matrix. They read corresponding
2264 /// even- or odd-numbered vector elements from two n-dimensional source
2265 /// vectors and write each result into consecutive elements of an
2266 /// n-dimensional destination vector. Two shuffles are necessary to complete
2267 /// the transpose, one for the even elements and another for the odd elements.
2268 /// This description closely follows how the TRN1 and TRN2 AArch64
2269 /// instructions operate.
2270 ///
2271 /// For example, a simple 2x2 matrix can be transposed with:
2272 ///
2273 /// ; Original matrix
2274 /// m0 = < a, b >
2275 /// m1 = < c, d >
2276 ///
2277 /// ; Transposed matrix
2278 /// t0 = < a, c > = shufflevector m0, m1, < 0, 2 >
2279 /// t1 = < b, d > = shufflevector m0, m1, < 1, 3 >
2280 ///
2281 /// For matrices having greater than n columns, the resulting nx2 transposed
2282 /// matrix is stored in two result vectors such that one vector contains
2283 /// interleaved elements from all the even-numbered rows and the other vector
2284 /// contains interleaved elements from all the odd-numbered rows. For example,
2285 /// a 2x4 matrix can be transposed with:
2286 ///
2287 /// ; Original matrix
2288 /// m0 = < a, b, c, d >
2289 /// m1 = < e, f, g, h >
2290 ///
2291 /// ; Transposed matrix
2292 /// t0 = < a, e, c, g > = shufflevector m0, m1 < 0, 4, 2, 6 >
2293 /// t1 = < b, f, d, h > = shufflevector m0, m1 < 1, 5, 3, 7 >
2294 LLVM_ABI static bool isTransposeMask(ArrayRef<int> Mask, int NumSrcElts);
2295 static bool isTransposeMask(const Constant *Mask, int NumSrcElts) {
2296 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2297 SmallVector<int, 16> MaskAsInts;
2298 getShuffleMask(Mask, MaskAsInts);
2299 return isTransposeMask(MaskAsInts, NumSrcElts);
2300 }
2301
2302 /// Return true if this shuffle transposes the elements of its inputs without
2303 /// changing the length of the vectors. This operation may also be known as a
2304 /// merge or interleave. See the description for isTransposeMask() for the
2305 /// exact specification.
2306 /// Example: shufflevector <4 x n> A, <4 x n> B, <0,4,2,6>
2307 bool isTranspose() const {
2308 return !changesLength() && isTransposeMask(ShuffleMask, ShuffleMask.size());
2309 }
2310
2311 /// Return true if this shuffle mask is a splice mask, concatenating the two
2312 /// inputs together and then extracts an original width vector starting from
2313 /// the splice index.
2314 /// Example: shufflevector <4 x n> A, <4 x n> B, <1,2,3,4>
2315 /// This assumes that vector operands (of length \p NumSrcElts) are the same
2316 /// length as the mask.
2317 LLVM_ABI static bool isSpliceMask(ArrayRef<int> Mask, int NumSrcElts,
2318 int &Index);
2319 static bool isSpliceMask(const Constant *Mask, int NumSrcElts, int &Index) {
2320 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2321 SmallVector<int, 16> MaskAsInts;
2322 getShuffleMask(Mask, MaskAsInts);
2323 return isSpliceMask(MaskAsInts, NumSrcElts, Index);
2324 }
2325
2326 /// Return true if this shuffle splices two inputs without changing the length
2327 /// of the vectors. This operation concatenates the two inputs together and
2328 /// then extracts an original width vector starting from the splice index.
2329 /// Example: shufflevector <4 x n> A, <4 x n> B, <1,2,3,4>
2330 bool isSplice(int &Index) const {
2331 return !changesLength() &&
2332 isSpliceMask(ShuffleMask, ShuffleMask.size(), Index);
2333 }
2334
2335 /// Return true if this shuffle mask is an extract subvector mask.
2336 /// A valid extract subvector mask returns a smaller vector from a single
2337 /// source operand. The base extraction index is returned as well.
2338 LLVM_ABI static bool isExtractSubvectorMask(ArrayRef<int> Mask,
2339 int NumSrcElts, int &Index);
2340 static bool isExtractSubvectorMask(const Constant *Mask, int NumSrcElts,
2341 int &Index) {
2342 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2343 // Not possible to express a shuffle mask for a scalable vector for this
2344 // case.
2345 if (isa<ScalableVectorType>(Mask->getType()))
2346 return false;
2347 SmallVector<int, 16> MaskAsInts;
2348 getShuffleMask(Mask, MaskAsInts);
2349 return isExtractSubvectorMask(MaskAsInts, NumSrcElts, Index);
2350 }
2351
2352 /// Return true if this shuffle mask is an extract subvector mask.
2353 bool isExtractSubvectorMask(int &Index) const {
2354 // Not possible to express a shuffle mask for a scalable vector for this
2355 // case.
2357 return false;
2358
2359 int NumSrcElts =
2360 cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
2361 return isExtractSubvectorMask(ShuffleMask, NumSrcElts, Index);
2362 }
2363
2364 /// Return true if this shuffle mask is an insert subvector mask.
2365 /// A valid insert subvector mask inserts the lowest elements of a second
2366 /// source operand into an in-place first source operand.
2367 /// Both the sub vector width and the insertion index is returned.
2368 LLVM_ABI static bool isInsertSubvectorMask(ArrayRef<int> Mask, int NumSrcElts,
2369 int &NumSubElts, int &Index);
2370 static bool isInsertSubvectorMask(const Constant *Mask, int NumSrcElts,
2371 int &NumSubElts, int &Index) {
2372 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2373 // Not possible to express a shuffle mask for a scalable vector for this
2374 // case.
2375 if (isa<ScalableVectorType>(Mask->getType()))
2376 return false;
2377 SmallVector<int, 16> MaskAsInts;
2378 getShuffleMask(Mask, MaskAsInts);
2379 return isInsertSubvectorMask(MaskAsInts, NumSrcElts, NumSubElts, Index);
2380 }
2381
2382 /// Return true if this shuffle mask is an insert subvector mask.
2383 bool isInsertSubvectorMask(int &NumSubElts, int &Index) const {
2384 // Not possible to express a shuffle mask for a scalable vector for this
2385 // case.
2387 return false;
2388
2389 int NumSrcElts =
2390 cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
2391 return isInsertSubvectorMask(ShuffleMask, NumSrcElts, NumSubElts, Index);
2392 }
2393
2394 /// Return true if this shuffle mask replicates each of the \p VF elements
2395 /// in a vector \p ReplicationFactor times.
2396 /// For example, the mask for \p ReplicationFactor=3 and \p VF=4 is:
2397 /// <0,0,0,1,1,1,2,2,2,3,3,3>
2398 LLVM_ABI static bool isReplicationMask(ArrayRef<int> Mask,
2399 int &ReplicationFactor, int &VF);
2400 static bool isReplicationMask(const Constant *Mask, int &ReplicationFactor,
2401 int &VF) {
2402 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2403 // Not possible to express a shuffle mask for a scalable vector for this
2404 // case.
2405 if (isa<ScalableVectorType>(Mask->getType()))
2406 return false;
2407 SmallVector<int, 16> MaskAsInts;
2408 getShuffleMask(Mask, MaskAsInts);
2409 return isReplicationMask(MaskAsInts, ReplicationFactor, VF);
2410 }
2411
2412 /// Return true if this shuffle mask is a replication mask.
2413 LLVM_ABI bool isReplicationMask(int &ReplicationFactor, int &VF) const;
2414
2415 /// Return true if this shuffle mask represents "clustered" mask of size VF,
2416 /// i.e. each index between [0..VF) is used exactly once in each submask of
2417 /// size VF.
2418 /// For example, the mask for \p VF=4 is:
2419 /// 0, 1, 2, 3, 3, 2, 0, 1 - "clustered", because each submask of size 4
2420 /// (0,1,2,3 and 3,2,0,1) uses indices [0..VF) exactly one time.
2421 /// 0, 1, 2, 3, 3, 3, 1, 0 - not "clustered", because
2422 /// element 3 is used twice in the second submask
2423 /// (3,3,1,0) and index 2 is not used at all.
2424 LLVM_ABI static bool isOneUseSingleSourceMask(ArrayRef<int> Mask, int VF);
2425
2426 /// Return true if this shuffle mask is a one-use-single-source("clustered")
2427 /// mask.
2428 LLVM_ABI bool isOneUseSingleSourceMask(int VF) const;
2429
2430 /// Change values in a shuffle permute mask assuming the two vector operands
2431 /// of length InVecNumElts have swapped position.
2433 unsigned InVecNumElts) {
2434 for (int &Idx : Mask) {
2435 if (Idx == -1)
2436 continue;
2437 Idx = Idx < (int)InVecNumElts ? Idx + InVecNumElts : Idx - InVecNumElts;
2438 assert(Idx >= 0 && Idx < (int)InVecNumElts * 2 &&
2439 "shufflevector mask index out of range");
2440 }
2441 }
2442
2443 /// Return if this shuffle interleaves its two input vectors together.
2444 LLVM_ABI bool isInterleave(unsigned Factor);
2445
2446 /// Return true if the mask interleaves one or more input vectors together.
2447 ///
2448 /// I.e. <0, LaneLen, ... , LaneLen*(Factor - 1), 1, LaneLen + 1, ...>
2449 /// E.g. For a Factor of 2 (LaneLen=4):
2450 /// <0, 4, 1, 5, 2, 6, 3, 7>
2451 /// E.g. For a Factor of 3 (LaneLen=4):
2452 /// <4, 0, 9, 5, 1, 10, 6, 2, 11, 7, 3, 12>
2453 /// E.g. For a Factor of 4 (LaneLen=2):
2454 /// <0, 2, 6, 4, 1, 3, 7, 5>
2455 ///
2456 /// NumInputElts is the total number of elements in the input vectors.
2457 ///
2458 /// StartIndexes are the first indexes of each vector being interleaved,
2459 /// substituting any indexes that were undef
2460 /// E.g. <4, -1, 2, 5, 1, 3> (Factor=3): StartIndexes=<4, 0, 2>
2461 ///
2462 /// Note that this does not check if the input vectors are consecutive:
2463 /// It will return true for masks such as
2464 /// <0, 4, 6, 1, 5, 7> (Factor=3, LaneLen=2)
2465 LLVM_ABI static bool
2466 isInterleaveMask(ArrayRef<int> Mask, unsigned Factor, unsigned NumInputElts,
2467 SmallVectorImpl<unsigned> &StartIndexes);
2468 static bool isInterleaveMask(ArrayRef<int> Mask, unsigned Factor,
2469 unsigned NumInputElts) {
2470 SmallVector<unsigned, 8> StartIndexes;
2471 return isInterleaveMask(Mask, Factor, NumInputElts, StartIndexes);
2472 }
2473
2474 /// Check if the mask is a DE-interleave mask of the given factor
2475 /// \p Factor like:
2476 /// <Index, Index+Factor, ..., Index+(NumElts-1)*Factor>
2477 LLVM_ABI static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask,
2478 unsigned Factor,
2479 unsigned &Index);
2480 static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask, unsigned Factor) {
2481 unsigned Unused;
2482 return isDeInterleaveMaskOfFactor(Mask, Factor, Unused);
2483 }
2484
2485 /// Checks if the shuffle is a bit rotation of the first operand across
2486 /// multiple subelements, e.g:
2487 ///
2488 /// shuffle <8 x i8> %a, <8 x i8> poison, <8 x i32> <1, 0, 3, 2, 5, 4, 7, 6>
2489 ///
2490 /// could be expressed as
2491 ///
2492 /// rotl <4 x i16> %a, 8
2493 ///
2494 /// If it can be expressed as a rotation, returns the number of subelements to
2495 /// group by in NumSubElts and the number of bits to rotate left in RotateAmt.
2496 LLVM_ABI static bool isBitRotateMask(ArrayRef<int> Mask,
2497 unsigned EltSizeInBits,
2498 unsigned MinSubElts, unsigned MaxSubElts,
2499 unsigned &NumSubElts,
2500 unsigned &RotateAmt);
2501
2502 // Methods for support type inquiry through isa, cast, and dyn_cast:
2503 static bool classof(const Instruction *I) {
2504 return I->getOpcode() == Instruction::ShuffleVector;
2505 }
2506 static bool classof(const Value *V) {
2508 }
2509};
2510
2511template <>
2513 : public FixedNumOperandTraits<ShuffleVectorInst, 2> {};
2514
2516
2517//===----------------------------------------------------------------------===//
2518// ExtractValueInst Class
2519//===----------------------------------------------------------------------===//
2520
2521/// This instruction extracts a struct member or array
2522/// element value from an aggregate value.
2523///
2524class ExtractValueInst : public UnaryInstruction {
2526
2527 ExtractValueInst(const ExtractValueInst &EVI);
2528
2529 /// Constructors - Create a extractvalue instruction with a base aggregate
2530 /// value and a list of indices. The first and second ctor can optionally
2531 /// insert before an existing instruction, the third appends the new
2532 /// instruction to the specified BasicBlock.
2533 inline ExtractValueInst(Value *Agg, ArrayRef<unsigned> Idxs,
2534 const Twine &NameStr, InsertPosition InsertBefore);
2535
2536 LLVM_ABI void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
2537
2538protected:
2539 // Note: Instruction needs to be a friend here to call cloneImpl.
2540 friend class Instruction;
2541
2542 LLVM_ABI ExtractValueInst *cloneImpl() const;
2543
2544public:
2545 static ExtractValueInst *Create(Value *Agg, ArrayRef<unsigned> Idxs,
2546 const Twine &NameStr = "",
2547 InsertPosition InsertBefore = nullptr) {
2548 return new
2549 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
2550 }
2551
2552 /// Returns the type of the element that would be extracted
2553 /// with an extractvalue instruction with the specified parameters.
2554 ///
2555 /// Null is returned if the indices are invalid for the specified type.
2556 LLVM_ABI static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
2557
2558 using idx_iterator = const unsigned*;
2559
2560 inline idx_iterator idx_begin() const { return Indices.begin(); }
2561 inline idx_iterator idx_end() const { return Indices.end(); }
2563 return make_range(idx_begin(), idx_end());
2564 }
2565
2567 return getOperand(0);
2568 }
2570 return getOperand(0);
2571 }
2572 static unsigned getAggregateOperandIndex() {
2573 return 0U; // get index for modifying correct operand
2574 }
2575
2577 return Indices;
2578 }
2579
2580 unsigned getNumIndices() const {
2581 return (unsigned)Indices.size();
2582 }
2583
2584 bool hasIndices() const {
2585 return true;
2586 }
2587
2588 // Methods for support type inquiry through isa, cast, and dyn_cast:
2589 static bool classof(const Instruction *I) {
2590 return I->getOpcode() == Instruction::ExtractValue;
2591 }
2592 static bool classof(const Value *V) {
2594 }
2595};
2596
2597ExtractValueInst::ExtractValueInst(Value *Agg, ArrayRef<unsigned> Idxs,
2598 const Twine &NameStr,
2599 InsertPosition InsertBefore)
2600 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
2601 ExtractValue, Agg, InsertBefore) {
2602 init(Idxs, NameStr);
2603}
2604
2605//===----------------------------------------------------------------------===//
2606// InsertValueInst Class
2607//===----------------------------------------------------------------------===//
2608
2609/// This instruction inserts a struct field of array element
2610/// value into an aggregate value.
2611///
2612class InsertValueInst : public Instruction {
2613 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
2614
2616
2617 InsertValueInst(const InsertValueInst &IVI);
2618
2619 /// Constructors - Create a insertvalue instruction with a base aggregate
2620 /// value, a value to insert, and a list of indices. The first and second ctor
2621 /// can optionally insert before an existing instruction, the third appends
2622 /// the new instruction to the specified BasicBlock.
2623 inline InsertValueInst(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
2624 const Twine &NameStr, InsertPosition InsertBefore);
2625
2626 /// Constructors - These three constructors are convenience methods because
2627 /// one and two index insertvalue instructions are so common.
2628 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
2629 const Twine &NameStr = "",
2630 InsertPosition InsertBefore = nullptr);
2631
2632 LLVM_ABI void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
2633 const Twine &NameStr);
2634
2635protected:
2636 // Note: Instruction needs to be a friend here to call cloneImpl.
2637 friend class Instruction;
2638
2639 LLVM_ABI InsertValueInst *cloneImpl() const;
2640
2641public:
2642 // allocate space for exactly two operands
2643 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
2644 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
2645
2646 static InsertValueInst *Create(Value *Agg, Value *Val,
2647 ArrayRef<unsigned> Idxs,
2648 const Twine &NameStr = "",
2649 InsertPosition InsertBefore = nullptr) {
2650 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
2651 }
2652
2653 /// Transparently provide more efficient getOperand methods.
2655
2656 using idx_iterator = const unsigned*;
2657
2658 inline idx_iterator idx_begin() const { return Indices.begin(); }
2659 inline idx_iterator idx_end() const { return Indices.end(); }
2661 return make_range(idx_begin(), idx_end());
2662 }
2663
2665 return getOperand(0);
2666 }
2668 return getOperand(0);
2669 }
2670 static unsigned getAggregateOperandIndex() {
2671 return 0U; // get index for modifying correct operand
2672 }
2673
2675 return getOperand(1);
2676 }
2678 return getOperand(1);
2679 }
2681 return 1U; // get index for modifying correct operand
2682 }
2683
2685 return Indices;
2686 }
2687
2688 unsigned getNumIndices() const {
2689 return (unsigned)Indices.size();
2690 }
2691
2692 bool hasIndices() const {
2693 return true;
2694 }
2695
2696 // Methods for support type inquiry through isa, cast, and dyn_cast:
2697 static bool classof(const Instruction *I) {
2698 return I->getOpcode() == Instruction::InsertValue;
2699 }
2700 static bool classof(const Value *V) {
2702 }
2703};
2704
2705template <>
2707 public FixedNumOperandTraits<InsertValueInst, 2> {
2708};
2709
2710InsertValueInst::InsertValueInst(Value *Agg, Value *Val,
2711 ArrayRef<unsigned> Idxs, const Twine &NameStr,
2712 InsertPosition InsertBefore)
2713 : Instruction(Agg->getType(), InsertValue, AllocMarker, InsertBefore) {
2714 init(Agg, Val, Idxs, NameStr);
2715}
2716
2717DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
2718
2719//===----------------------------------------------------------------------===//
2720// PHINode Class
2721//===----------------------------------------------------------------------===//
2722
2723// PHINode - The PHINode class is used to represent the magical mystical PHI
2724// node, that can not exist in nature, but can be synthesized in a computer
2725// scientist's overactive imagination.
2726//
2727class PHINode : public Instruction, public FastMathFlagsStorage {
2728 constexpr static HungOffOperandsAllocMarker AllocMarker{};
2729
2730 /// The number of operands actually allocated. NumOperands is
2731 /// the number actually in use.
2732 unsigned ReservedSpace;
2733
2734 PHINode(const PHINode &PN);
2735
2736 explicit PHINode(Type *Ty, unsigned NumReservedValues,
2737 const Twine &NameStr = "",
2738 InsertPosition InsertBefore = nullptr)
2739 : Instruction(Ty, Instruction::PHI, AllocMarker, InsertBefore),
2740 ReservedSpace(NumReservedValues) {
2741 setName(NameStr);
2742 allocHungoffUses(ReservedSpace);
2743 }
2744
2745protected:
2746 // Note: Instruction needs to be a friend here to call cloneImpl.
2747 friend class Instruction;
2748
2749 LLVM_ABI PHINode *cloneImpl() const;
2750
2751 // allocHungoffUses - this is more complicated than the generic
2752 // User::allocHungoffUses, because we have to allocate Uses for the incoming
2753 // values and pointers to the incoming blocks, all in one allocation.
2754 void allocHungoffUses(unsigned N) {
2755 User::allocHungoffUses(N, /*WithExtraValues=*/true);
2756 }
2757
2758public:
2759 /// Constructors - NumReservedValues is a hint for the number of incoming
2760 /// edges that this phi node will have (use 0 if you really have no idea).
2761 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2762 const Twine &NameStr = "",
2763 InsertPosition InsertBefore = nullptr) {
2764 return new (AllocMarker)
2765 PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2766 }
2767
2768 /// Provide fast operand accessors
2770
2771 // Block iterator interface. This provides access to the list of incoming
2772 // basic blocks, which parallels the list of incoming values.
2773 // Please note that we are not providing non-const iterators for blocks to
2774 // force all updates go through an interface function.
2775
2778
2780 return reinterpret_cast<const_block_iterator>(op_begin() + ReservedSpace);
2781 }
2782
2784 return block_begin() + getNumOperands();
2785 }
2786
2790
2792
2794
2795 /// Return the number of incoming edges
2796 ///
2797 unsigned getNumIncomingValues() const { return getNumOperands(); }
2798
2799 /// Return incoming value number x
2800 ///
2801 Value *getIncomingValue(unsigned i) const {
2802 return getOperand(i);
2803 }
2804 void setIncomingValue(unsigned i, Value *V) {
2805 assert(V && "PHI node got a null value!");
2806 assert(getType() == V->getType() &&
2807 "All operands to PHI node must be the same type as the PHI node!");
2808 setOperand(i, V);
2809 }
2810
2811 static unsigned getOperandNumForIncomingValue(unsigned i) {
2812 return i;
2813 }
2814
2815 static unsigned getIncomingValueNumForOperand(unsigned i) {
2816 return i;
2817 }
2818
2819 /// Return incoming basic block number @p i.
2820 ///
2821 BasicBlock *getIncomingBlock(unsigned i) const {
2822 return block_begin()[i];
2823 }
2824
2825 /// Return incoming basic block corresponding
2826 /// to an operand of the PHI.
2827 ///
2829 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2830 return getIncomingBlock(unsigned(&U - op_begin()));
2831 }
2832
2833 /// Return incoming basic block corresponding
2834 /// to value use iterator.
2835 ///
2839
2840 void setIncomingBlock(unsigned i, BasicBlock *BB) {
2841 const_cast<block_iterator>(block_begin())[i] = BB;
2842 }
2843
2844 /// Copies the basic blocks from \p BBRange to the incoming basic block list
2845 /// of this PHINode, starting at \p ToIdx.
2847 uint32_t ToIdx = 0) {
2848 copy(BBRange, const_cast<block_iterator>(block_begin()) + ToIdx);
2849 }
2850
2851 /// Replace every incoming basic block \p Old to basic block \p New.
2853 assert(New && Old && "PHI node got a null basic block!");
2854 for (unsigned Op = 0, NumOps = getNumOperands(); Op != NumOps; ++Op)
2855 if (getIncomingBlock(Op) == Old)
2856 setIncomingBlock(Op, New);
2857 }
2858
2859 /// Add an incoming value to the end of the PHI list
2860 ///
2862 if (getNumOperands() == ReservedSpace)
2863 growOperands(); // Get more space!
2864 // Initialize some new operands.
2868 }
2869
2870 /// Remove an incoming value. This is useful if a
2871 /// predecessor basic block is deleted. The value removed is returned.
2872 ///
2873 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2874 /// is true), the PHI node is destroyed and any uses of it are replaced with
2875 /// dummy values. The only time there should be zero incoming values to a PHI
2876 /// node is when the block is dead, so this strategy is sound.
2877 LLVM_ABI Value *removeIncomingValue(unsigned Idx,
2878 bool DeletePHIIfEmpty = true);
2879
2880 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2881 int Idx = getBasicBlockIndex(BB);
2882 assert(Idx >= 0 && "Invalid basic block argument to remove!");
2883 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2884 }
2885
2886 /// Remove all incoming values for which the predicate returns true.
2887 /// The predicate accepts the incoming value index.
2888 LLVM_ABI void removeIncomingValueIf(function_ref<bool(unsigned)> Predicate,
2889 bool DeletePHIIfEmpty = true);
2890
2891 /// Return the first index of the specified basic
2892 /// block in the value list for this PHI. Returns -1 if no instance.
2893 ///
2894 int getBasicBlockIndex(const BasicBlock *BB) const {
2895 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2896 if (block_begin()[i] == BB)
2897 return i;
2898 return -1;
2899 }
2900
2902 int Idx = getBasicBlockIndex(BB);
2903 assert(Idx >= 0 && "Invalid basic block argument!");
2904 return getIncomingValue(Idx);
2905 }
2906
2907 /// Set every incoming value(s) for block \p BB to \p V.
2909 assert(BB && "PHI node got a null basic block!");
2910 bool Found = false;
2911 for (unsigned Op = 0, NumOps = getNumOperands(); Op != NumOps; ++Op)
2912 if (getIncomingBlock(Op) == BB) {
2913 Found = true;
2914 setIncomingValue(Op, V);
2915 }
2916 (void)Found;
2917 assert(Found && "Invalid basic block argument to set!");
2918 }
2919
2920 /// If the specified PHI node always merges together the
2921 /// same value, return the value, otherwise return null.
2922 LLVM_ABI Value *hasConstantValue() const;
2923
2924 /// Whether the specified PHI node always merges
2925 /// together the same value, assuming undefs are equal to a unique
2926 /// non-undef value.
2927 LLVM_ABI bool hasConstantOrUndefValue() const;
2928
2929 /// If the PHI node is complete which means all of its parent's predecessors
2930 /// have incoming value in this PHI, return true, otherwise return false.
2931 bool isComplete() const {
2933 [this](const BasicBlock *Pred) {
2934 return getBasicBlockIndex(Pred) >= 0;
2935 });
2936 }
2937
2938 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2939 static bool classof(const Instruction *I) {
2940 return I->getOpcode() == Instruction::PHI;
2941 }
2942 static bool classof(const Value *V) {
2944 }
2945
2946private:
2947 LLVM_ABI void growOperands();
2948};
2949
2950template <> struct OperandTraits<PHINode> : public HungoffOperandTraits {};
2951
2953
2954//===----------------------------------------------------------------------===//
2955// LandingPadInst Class
2956//===----------------------------------------------------------------------===//
2957
2958//===---------------------------------------------------------------------------
2959/// The landingpad instruction holds all of the information
2960/// necessary to generate correct exception handling. The landingpad instruction
2961/// cannot be moved from the top of a landing pad block, which itself is
2962/// accessible only from the 'unwind' edge of an invoke. This uses the
2963/// SubclassData field in Value to store whether or not the landingpad is a
2964/// cleanup.
2965///
2966class LandingPadInst : public Instruction {
2967 using CleanupField = BoolBitfieldElementT<0>;
2968
2969 constexpr static HungOffOperandsAllocMarker AllocMarker{};
2970
2971 /// The number of operands actually allocated. NumOperands is
2972 /// the number actually in use.
2973 unsigned ReservedSpace;
2974
2975 LandingPadInst(const LandingPadInst &LP);
2976
2977public:
2979
2980private:
2981 explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
2982 const Twine &NameStr, InsertPosition InsertBefore);
2983
2984 // Allocate space for exactly zero operands.
2985 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
2986
2987 LLVM_ABI void growOperands(unsigned Size);
2988 void init(unsigned NumReservedValues, const Twine &NameStr);
2989
2990protected:
2991 // Note: Instruction needs to be a friend here to call cloneImpl.
2992 friend class Instruction;
2993
2994 LLVM_ABI LandingPadInst *cloneImpl() const;
2995
2996public:
2997 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
2998
2999 /// Constructors - NumReservedClauses is a hint for the number of incoming
3000 /// clauses that this landingpad will have (use 0 if you really have no idea).
3001 LLVM_ABI static LandingPadInst *Create(Type *RetTy,
3002 unsigned NumReservedClauses,
3003 const Twine &NameStr = "",
3004 InsertPosition InsertBefore = nullptr);
3005
3006 /// Provide fast operand accessors
3008
3009 /// Return 'true' if this landingpad instruction is a
3010 /// cleanup. I.e., it should be run when unwinding even if its landing pad
3011 /// doesn't catch the exception.
3012 bool isCleanup() const { return getSubclassData<CleanupField>(); }
3013
3014 /// Indicate that this landingpad instruction is a cleanup.
3016
3017 /// Add a catch or filter clause to the landing pad.
3018 LLVM_ABI void addClause(Constant *ClauseVal);
3019
3020 /// Get the value of the clause at index Idx. Use isCatch/isFilter to
3021 /// determine what type of clause this is.
3022 Constant *getClause(unsigned Idx) const {
3023 return cast<Constant>(getOperandList()[Idx]);
3024 }
3025
3026 /// Return 'true' if the clause and index Idx is a catch clause.
3027 bool isCatch(unsigned Idx) const {
3028 return !isa<ArrayType>(getOperandList()[Idx]->getType());
3029 }
3030
3031 /// Return 'true' if the clause and index Idx is a filter clause.
3032 bool isFilter(unsigned Idx) const {
3033 return isa<ArrayType>(getOperandList()[Idx]->getType());
3034 }
3035
3036 /// Get the number of clauses for this landing pad.
3037 unsigned getNumClauses() const { return getNumOperands(); }
3038
3039 /// Grow the size of the operand list to accommodate the new
3040 /// number of clauses.
3041 void reserveClauses(unsigned Size) { growOperands(Size); }
3042
3043 // Methods for support type inquiry through isa, cast, and dyn_cast:
3044 static bool classof(const Instruction *I) {
3045 return I->getOpcode() == Instruction::LandingPad;
3046 }
3047 static bool classof(const Value *V) {
3049 }
3050};
3051
3052template <>
3054
3056
3057//===----------------------------------------------------------------------===//
3058// ReturnInst Class
3059//===----------------------------------------------------------------------===//
3060
3061//===---------------------------------------------------------------------------
3062/// Return a value (possibly void), from a function. Execution
3063/// does not continue in this function any longer.
3064///
3065class ReturnInst : public Instruction {
3066 ReturnInst(const ReturnInst &RI, AllocInfo AllocInfo);
3067
3068private:
3069 // ReturnInst constructors:
3070 // ReturnInst() - 'ret void' instruction
3071 // ReturnInst( null) - 'ret void' instruction
3072 // ReturnInst(Value* X) - 'ret X' instruction
3073 // ReturnInst(null, Iterator It) - 'ret void' instruction, insert before I
3074 // ReturnInst(Value* X, Iterator It) - 'ret X' instruction, insert before I
3075 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
3076 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
3077 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
3078 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
3079 //
3080 // NOTE: If the Value* passed is of type void then the constructor behaves as
3081 // if it was passed NULL.
3082 LLVM_ABI explicit ReturnInst(LLVMContext &C, Value *retVal,
3084 InsertPosition InsertBefore);
3085
3086protected:
3087 // Note: Instruction needs to be a friend here to call cloneImpl.
3088 friend class Instruction;
3089
3090 LLVM_ABI ReturnInst *cloneImpl() const;
3091
3092public:
3093 static ReturnInst *Create(LLVMContext &C, Value *retVal = nullptr,
3094 InsertPosition InsertBefore = nullptr) {
3095 IntrusiveOperandsAllocMarker AllocMarker{retVal ? 1U : 0U};
3096 return new (AllocMarker) ReturnInst(C, retVal, AllocMarker, InsertBefore);
3097 }
3098
3099 static ReturnInst *Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
3100 IntrusiveOperandsAllocMarker AllocMarker{0};
3101 return new (AllocMarker) ReturnInst(C, nullptr, AllocMarker, InsertAtEnd);
3102 }
3103
3104 /// Provide fast operand accessors
3106
3107 /// Convenience accessor. Returns null if there is no return value.
3109 return getNumOperands() != 0 ? getOperand(0) : nullptr;
3110 }
3111
3118
3119 unsigned getNumSuccessors() const { return 0; }
3120
3121 // Methods for support type inquiry through isa, cast, and dyn_cast:
3122 static bool classof(const Instruction *I) {
3123 return (I->getOpcode() == Instruction::Ret);
3124 }
3125 static bool classof(const Value *V) {
3127 }
3128
3129private:
3130 BasicBlock *getSuccessor(unsigned idx) const {
3131 llvm_unreachable("ReturnInst has no successors!");
3132 }
3133
3134 void setSuccessor(unsigned idx, BasicBlock *B) {
3135 llvm_unreachable("ReturnInst has no successors!");
3136 }
3137};
3138
3139template <>
3140struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {};
3141
3143
3144//===----------------------------------------------------------------------===//
3145// UncondBrInst Class
3146//===----------------------------------------------------------------------===//
3147
3148//===---------------------------------------------------------------------------
3149/// Unconditional Branch instruction.
3150///
3151class UncondBrInst : public Instruction {
3152 constexpr static IntrusiveOperandsAllocMarker AllocMarker{1};
3153
3154 UncondBrInst(const UncondBrInst &BI);
3155 LLVM_ABI explicit UncondBrInst(BasicBlock *Target,
3156 InsertPosition InsertBefore);
3157
3158protected:
3159 // Note: Instruction needs to be a friend here to call cloneImpl.
3160 friend class Instruction;
3161
3162 LLVM_ABI UncondBrInst *cloneImpl() const;
3163
3164public:
3165 static UncondBrInst *Create(BasicBlock *Target,
3166 InsertPosition InsertBefore = nullptr) {
3167 return new (AllocMarker) UncondBrInst(Target, InsertBefore);
3168 }
3169
3170 /// Transparently provide more efficient getOperand methods.
3172
3173 unsigned getNumSuccessors() const { return 1; }
3174
3175 BasicBlock *getSuccessor(unsigned i = 0) const {
3176 assert(i == 0 && "Successor # out of range for Branch!");
3178 }
3179
3180 void setSuccessor(BasicBlock *NewSucc) { Op<-1>() = NewSucc; }
3181 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3182 assert(idx == 0 && "Successor # out of range for Branch!");
3183 Op<-1>() = NewSucc;
3184 }
3185
3189
3194
3195 // Methods for support type inquiry through isa, cast, and dyn_cast:
3196 static bool classof(const Instruction *I) {
3197 return (I->getOpcode() == Instruction::UncondBr);
3198 }
3199 static bool classof(const Value *V) {
3201 }
3202};
3203
3204template <>
3206 : public FixedNumOperandTraits<UncondBrInst, 1> {};
3207
3209
3210//===----------------------------------------------------------------------===//
3211// CondBrInst Class
3212//===----------------------------------------------------------------------===//
3213
3214//===---------------------------------------------------------------------------
3215/// Conditional Branch instruction.
3216///
3217class CondBrInst : public Instruction {
3218 constexpr static IntrusiveOperandsAllocMarker AllocMarker{3};
3219
3220 CondBrInst(const CondBrInst &BI);
3221 LLVM_ABI CondBrInst(Value *Cond, BasicBlock *IfTrue, BasicBlock *IfFalse,
3222 InsertPosition InsertBefore);
3223
3224 void AssertOK();
3225
3226protected:
3227 // Note: Instruction needs to be a friend here to call cloneImpl.
3228 friend class Instruction;
3229
3230 LLVM_ABI CondBrInst *cloneImpl() const;
3231
3232public:
3233 static CondBrInst *Create(Value *Cond, BasicBlock *IfTrue,
3234 BasicBlock *IfFalse,
3235 InsertPosition InsertBefore = nullptr) {
3236 return new (AllocMarker) CondBrInst(Cond, IfTrue, IfFalse, InsertBefore);
3237 }
3238
3239 /// Transparently provide more efficient getOperand methods.
3241
3242 Value *getCondition() const { return Op<-3>(); }
3243 void setCondition(Value *V) { Op<-3>() = V; }
3244
3245 unsigned getNumSuccessors() const { return 2; }
3246
3247 BasicBlock *getSuccessor(unsigned i) const {
3248 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
3249 return cast_or_null<BasicBlock>((&Op<-2>() + i)->get());
3250 }
3251
3252 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3253 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
3254 *(&Op<-2>() + idx) = NewSucc;
3255 }
3256
3257 /// Swap the successors of this branch instruction.
3258 ///
3259 /// Swaps the successors of the branch instruction. This also swaps any
3260 /// branch weight metadata associated with the instruction so that it
3261 /// continues to map correctly to each operand.
3262 LLVM_ABI void swapSuccessors();
3263
3268
3273
3274 // Methods for support type inquiry through isa, cast, and dyn_cast:
3275 static bool classof(const Instruction *I) {
3276 return (I->getOpcode() == Instruction::CondBr);
3277 }
3278 static bool classof(const Value *V) {
3280 }
3281};
3282
3283template <>
3284struct OperandTraits<CondBrInst> : public FixedNumOperandTraits<CondBrInst, 3> {
3285};
3286
3288
3289//===----------------------------------------------------------------------===//
3290// SwitchInst Class
3291//===----------------------------------------------------------------------===//
3292
3293//===---------------------------------------------------------------------------
3294/// Multiway switch
3295///
3296class SwitchInst : public Instruction {
3297 constexpr static HungOffOperandsAllocMarker AllocMarker{};
3298
3299 unsigned ReservedSpace;
3300
3301 // Operand[0] = Value to switch on
3302 // Operand[1] = Default basic block destination
3303 // Operand[n] = BasicBlock to go to on match
3304 // Values are stored after the Uses similar to PHINode's basic blocks.
3305 SwitchInst(const SwitchInst &SI);
3306
3307 /// Create a new switch instruction, specifying a value to switch on and a
3308 /// default destination. The number of additional cases can be specified here
3309 /// to make memory allocation more efficient. This constructor can also
3310 /// auto-insert before another instruction.
3311 LLVM_ABI SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
3312 InsertPosition InsertBefore);
3313
3314 // allocate space for exactly zero operands
3315 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
3316
3317 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
3318 void growOperands();
3319
3320protected:
3321 // Note: Instruction needs to be a friend here to call cloneImpl.
3322 friend class Instruction;
3323
3324 LLVM_ABI SwitchInst *cloneImpl() const;
3325
3326 void allocHungoffUses(unsigned N) {
3327 User::allocHungoffUses(N, /*WithExtraValues=*/true);
3328 }
3329
3330 ConstantInt *const *case_values() const {
3331 return reinterpret_cast<ConstantInt *const *>(op_begin() + ReservedSpace);
3332 }
3334 return reinterpret_cast<ConstantInt **>(op_begin() + ReservedSpace);
3335 }
3336
3337public:
3338 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
3339
3340 // -2
3341 static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
3342
3343 template <typename CaseHandleT> class CaseIteratorImpl;
3344
3345 /// A handle to a particular switch case. It exposes a convenient interface
3346 /// to both the case value and the successor block.
3347 ///
3348 /// We define this as a template and instantiate it to form both a const and
3349 /// non-const handle.
3350 template <typename SwitchInstT, typename ConstantIntT, typename BasicBlockT>
3352 // Directly befriend both const and non-const iterators.
3353 friend class SwitchInst::CaseIteratorImpl<
3354 CaseHandleImpl<SwitchInstT, ConstantIntT, BasicBlockT>>;
3355
3356 protected:
3357 // Expose the switch type we're parameterized with to the iterator.
3358 using SwitchInstType = SwitchInstT;
3359
3360 SwitchInstT *SI;
3362
3363 CaseHandleImpl() = default;
3365
3366 public:
3367 /// Resolves case value for current case.
3368 ConstantIntT *getCaseValue() const {
3369 assert((unsigned)Index < SI->getNumCases() &&
3370 "Index out the number of cases.");
3371 return SI->case_values()[Index];
3372 }
3373
3374 /// Resolves successor for current case.
3375 BasicBlockT *getCaseSuccessor() const {
3376 assert(((unsigned)Index < SI->getNumCases() ||
3377 (unsigned)Index == DefaultPseudoIndex) &&
3378 "Index out the number of cases.");
3379 return SI->getSuccessor(getSuccessorIndex());
3380 }
3381
3382 /// Returns number of current case.
3383 unsigned getCaseIndex() const { return Index; }
3384
3385 /// Returns successor index for current case successor.
3386 unsigned getSuccessorIndex() const {
3387 assert(((unsigned)Index == DefaultPseudoIndex ||
3388 (unsigned)Index < SI->getNumCases()) &&
3389 "Index out the number of cases.");
3390 return (unsigned)Index != DefaultPseudoIndex ? Index + 1 : 0;
3391 }
3392
3393 bool operator==(const CaseHandleImpl &RHS) const {
3394 assert(SI == RHS.SI && "Incompatible operators.");
3395 return Index == RHS.Index;
3396 }
3397 };
3398
3401
3403 : public CaseHandleImpl<SwitchInst, ConstantInt, BasicBlock> {
3405
3406 public:
3408
3409 /// Sets the new value for current case.
3410 void setValue(ConstantInt *V) const {
3411 assert((unsigned)Index < SI->getNumCases() &&
3412 "Index out the number of cases.");
3413 SI->case_values()[Index] = V;
3414 }
3415
3416 /// Sets the new successor for current case.
3417 void setSuccessor(BasicBlock *S) const {
3418 SI->setSuccessor(getSuccessorIndex(), S);
3419 }
3420 };
3421
3422 template <typename CaseHandleT>
3424 : public iterator_facade_base<CaseIteratorImpl<CaseHandleT>,
3425 std::random_access_iterator_tag,
3426 const CaseHandleT> {
3427 using SwitchInstT = typename CaseHandleT::SwitchInstType;
3428
3429 CaseHandleT Case;
3430
3431 public:
3432 /// Default constructed iterator is in an invalid state until assigned to
3433 /// a case for a particular switch.
3434 CaseIteratorImpl() = default;
3435
3436 /// Initializes case iterator for given SwitchInst and for given
3437 /// case number.
3438 CaseIteratorImpl(SwitchInstT *SI, unsigned CaseNum) : Case(SI, CaseNum) {}
3439
3440 /// Initializes case iterator for given SwitchInst and for given
3441 /// successor index.
3443 unsigned SuccessorIndex) {
3444 assert(SuccessorIndex < SI->getNumSuccessors() &&
3445 "Successor index # out of range!");
3446 return SuccessorIndex != 0 ? CaseIteratorImpl(SI, SuccessorIndex - 1)
3448 }
3449
3450 /// Support converting to the const variant. This will be a no-op for const
3451 /// variant.
3453 return CaseIteratorImpl<ConstCaseHandle>(Case.SI, Case.Index);
3454 }
3455
3457 // Check index correctness after addition.
3458 // Note: Index == getNumCases() means end().
3459 assert(Case.Index + N >= 0 &&
3460 (unsigned)(Case.Index + N) <= Case.SI->getNumCases() &&
3461 "Case.Index out the number of cases.");
3462 Case.Index += N;
3463 return *this;
3464 }
3466 // Check index correctness after subtraction.
3467 // Note: Case.Index == getNumCases() means end().
3468 assert(Case.Index - N >= 0 &&
3469 (unsigned)(Case.Index - N) <= Case.SI->getNumCases() &&
3470 "Case.Index out the number of cases.");
3471 Case.Index -= N;
3472 return *this;
3473 }
3475 assert(Case.SI == RHS.Case.SI && "Incompatible operators.");
3476 return Case.Index - RHS.Case.Index;
3477 }
3478 bool operator==(const CaseIteratorImpl &RHS) const {
3479 return Case == RHS.Case;
3480 }
3481 bool operator<(const CaseIteratorImpl &RHS) const {
3482 assert(Case.SI == RHS.Case.SI && "Incompatible operators.");
3483 return Case.Index < RHS.Case.Index;
3484 }
3485 const CaseHandleT &operator*() const { return Case; }
3486 };
3487
3490
3491 static SwitchInst *Create(Value *Value, BasicBlock *Default,
3492 unsigned NumCases,
3493 InsertPosition InsertBefore = nullptr) {
3494 return new SwitchInst(Value, Default, NumCases, InsertBefore);
3495 }
3496
3497 /// Provide fast operand accessors
3499
3500 // Accessor Methods for Switch stmt
3501 Value *getCondition() const { return getOperand(0); }
3502 void setCondition(Value *V) { setOperand(0, V); }
3503
3505 return cast<BasicBlock>(getOperand(1));
3506 }
3507
3508 /// Returns true if the default branch must result in immediate undefined
3509 /// behavior, false otherwise.
3511 return isa<UnreachableInst>(getDefaultDest()->getFirstNonPHIOrDbg());
3512 }
3513
3514 void setDefaultDest(BasicBlock *DefaultCase) {
3515 setOperand(1, reinterpret_cast<Value*>(DefaultCase));
3516 }
3517
3518 /// Return the number of 'cases' in this switch instruction, excluding the
3519 /// default case.
3520 unsigned getNumCases() const { return getNumOperands() - 2; }
3521
3522 /// Returns a read/write iterator that points to the first case in the
3523 /// SwitchInst.
3525 return CaseIt(this, 0);
3526 }
3527
3528 /// Returns a read-only iterator that points to the first case in the
3529 /// SwitchInst.
3531 return ConstCaseIt(this, 0);
3532 }
3533
3534 /// Returns a read/write iterator that points one past the last in the
3535 /// SwitchInst.
3537 return CaseIt(this, getNumCases());
3538 }
3539
3540 /// Returns a read-only iterator that points one past the last in the
3541 /// SwitchInst.
3543 return ConstCaseIt(this, getNumCases());
3544 }
3545
3546 /// Iteration adapter for range-for loops.
3550
3551 /// Constant iteration adapter for range-for loops.
3555
3556 /// Returns an iterator that points to the default case.
3557 /// Note: this iterator allows to resolve successor only. Attempt
3558 /// to resolve case value causes an assertion.
3559 /// Also note, that increment and decrement also causes an assertion and
3560 /// makes iterator invalid.
3562 return CaseIt(this, DefaultPseudoIndex);
3563 }
3565 return ConstCaseIt(this, DefaultPseudoIndex);
3566 }
3567
3568 /// Search all of the case values for the specified constant. If it is
3569 /// explicitly handled, return the case iterator of it, otherwise return
3570 /// default case iterator to indicate that it is handled by the default
3571 /// handler.
3573 return CaseIt(
3574 this,
3575 const_cast<const SwitchInst *>(this)->findCaseValue(C)->getCaseIndex());
3576 }
3578 ConstCaseIt I = llvm::find_if(cases(), [C](const ConstCaseHandle &Case) {
3579 return Case.getCaseValue() == C;
3580 });
3581 if (I != case_end())
3582 return I;
3583
3584 return case_default();
3585 }
3586
3587 /// Finds the unique case value for a given successor. Returns null if the
3588 /// successor is not found, not unique, or is the default case.
3590 if (BB == getDefaultDest())
3591 return nullptr;
3592
3593 ConstantInt *CI = nullptr;
3594 for (auto Case : cases()) {
3595 if (Case.getCaseSuccessor() != BB)
3596 continue;
3597
3598 if (CI)
3599 return nullptr; // Multiple cases lead to BB.
3600
3601 CI = Case.getCaseValue();
3602 }
3603
3604 return CI;
3605 }
3606
3607 /// Add an entry to the switch instruction.
3608 /// Note:
3609 /// This action invalidates case_end(). Old case_end() iterator will
3610 /// point to the added case.
3611 LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest);
3612
3613 /// This method removes the specified case and its successor from the switch
3614 /// instruction. Note that this operation may reorder the remaining cases at
3615 /// index idx and above.
3616 /// Note:
3617 /// This action invalidates iterators for all cases following the one removed,
3618 /// including the case_end() iterator. It returns an iterator for the next
3619 /// case.
3620 LLVM_ABI CaseIt removeCase(CaseIt I);
3621
3623 return make_range(std::next(op_begin()), op_end());
3624 }
3626 return make_range(std::next(op_begin()), op_end());
3627 }
3628
3629 unsigned getNumSuccessors() const { return getNumOperands() - 1; }
3630 BasicBlock *getSuccessor(unsigned idx) const {
3631 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
3632 return cast<BasicBlock>(getOperand(idx + 1));
3633 }
3634 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3635 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
3636 setOperand(idx + 1, NewSucc);
3637 }
3638
3639 // Methods for support type inquiry through isa, cast, and dyn_cast:
3640 static bool classof(const Instruction *I) {
3641 return I->getOpcode() == Instruction::Switch;
3642 }
3643 static bool classof(const Value *V) {
3645 }
3646};
3647
3648/// A wrapper class to simplify modification of SwitchInst cases along with
3649/// their prof branch_weights metadata.
3651 SwitchInst &SI;
3652 std::optional<SmallVector<uint32_t, 8>> Weights;
3653 bool Changed = false;
3654
3655protected:
3656 LLVM_ABI void init();
3657
3658public:
3659 using CaseWeightOpt = std::optional<uint32_t>;
3660 SwitchInst *operator->() { return &SI; }
3661 SwitchInst &operator*() { return SI; }
3662 operator SwitchInst *() { return &SI; }
3663
3665
3667 if (Changed && Weights.has_value()) {
3668 if (Weights->size() >= 2) {
3669 setBranchWeights(SI, Weights.value(), /*IsExpected=*/false);
3670 return;
3671 }
3672 // In some cases while simplifying switch instructions, we end up with
3673 // degenerate switch instructions (e.g., only contains the default case).
3674 // We drop profile metadata in such cases rather than updating given it
3675 // does not convey anything.
3676 SI.setMetadata(LLVMContext::MD_prof, nullptr);
3677 }
3678 }
3679
3680 /// Delegate the call to the underlying SwitchInst::removeCase() and remove
3681 /// correspondent branch weight.
3683
3684 /// Replace the default destination by given case. Delegate the call to
3685 /// the underlying SwitchInst::setDefaultDest and remove correspondent branch
3686 /// weight.
3688
3689 /// Delegate the call to the underlying SwitchInst::addCase() and set the
3690 /// specified branch weight for the added case.
3691 LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest, CaseWeightOpt W);
3692
3693 /// Delegate the call to the underlying SwitchInst::eraseFromParent() and mark
3694 /// this object to not touch the underlying SwitchInst in destructor.
3696
3697 LLVM_ABI void setSuccessorWeight(unsigned idx, CaseWeightOpt W);
3699
3701 unsigned idx);
3702};
3703
3704template <> struct OperandTraits<SwitchInst> : public HungoffOperandTraits {};
3705
3707
3708//===----------------------------------------------------------------------===//
3709// IndirectBrInst Class
3710//===----------------------------------------------------------------------===//
3711
3712//===---------------------------------------------------------------------------
3713/// Indirect Branch Instruction.
3714///
3715class IndirectBrInst : public Instruction {
3716 constexpr static HungOffOperandsAllocMarker AllocMarker{};
3717
3718 unsigned ReservedSpace;
3719
3720 // Operand[0] = Address to jump to
3721 // Operand[n+1] = n-th destination
3722 IndirectBrInst(const IndirectBrInst &IBI);
3723
3724 /// Create a new indirectbr instruction, specifying an
3725 /// Address to jump to. The number of expected destinations can be specified
3726 /// here to make memory allocation more efficient. This constructor can also
3727 /// autoinsert before another instruction.
3728 LLVM_ABI IndirectBrInst(Value *Address, unsigned NumDests,
3729 InsertPosition InsertBefore);
3730
3731 // allocate space for exactly zero operands
3732 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
3733
3734 void init(Value *Address, unsigned NumDests);
3735 void growOperands();
3736
3737protected:
3738 // Note: Instruction needs to be a friend here to call cloneImpl.
3739 friend class Instruction;
3740
3741 LLVM_ABI IndirectBrInst *cloneImpl() const;
3742
3743public:
3744 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
3745
3746 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
3747 InsertPosition InsertBefore = nullptr) {
3748 return new IndirectBrInst(Address, NumDests, InsertBefore);
3749 }
3750
3751 /// Provide fast operand accessors.
3753
3754 // Accessor Methods for IndirectBrInst instruction.
3755 Value *getAddress() { return getOperand(0); }
3756 const Value *getAddress() const { return getOperand(0); }
3757 void setAddress(Value *V) { setOperand(0, V); }
3758
3759 /// return the number of possible destinations in this
3760 /// indirectbr instruction.
3761 unsigned getNumDestinations() const { return getNumOperands()-1; }
3762
3763 /// Return the specified destination.
3764 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
3765 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
3766
3767 /// Add a destination.
3768 ///
3769 LLVM_ABI void addDestination(BasicBlock *Dest);
3770
3771 /// This method removes the specified successor from the
3772 /// indirectbr instruction.
3773 LLVM_ABI void removeDestination(unsigned i);
3774
3775 unsigned getNumSuccessors() const { return getNumOperands()-1; }
3776 BasicBlock *getSuccessor(unsigned i) const {
3777 return cast<BasicBlock>(getOperand(i+1));
3778 }
3779 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
3780 setOperand(i + 1, NewSucc);
3781 }
3782
3787
3792
3793 // Methods for support type inquiry through isa, cast, and dyn_cast:
3794 static bool classof(const Instruction *I) {
3795 return I->getOpcode() == Instruction::IndirectBr;
3796 }
3797 static bool classof(const Value *V) {
3799 }
3800};
3801
3802template <>
3804
3806
3807//===----------------------------------------------------------------------===//
3808// InvokeInst Class
3809//===----------------------------------------------------------------------===//
3810
3811/// Invoke instruction. The SubclassData field is used to hold the
3812/// calling convention of the call.
3813///
3814class InvokeInst : public CallBase {
3815 /// The number of operands for this call beyond the called function,
3816 /// arguments, and operand bundles.
3817 static constexpr int NumExtraOperands = 2;
3818
3819 /// The index from the end of the operand array to the normal destination.
3820 static constexpr int NormalDestOpEndIdx = -3;
3821
3822 /// The index from the end of the operand array to the unwind destination.
3823 static constexpr int UnwindDestOpEndIdx = -2;
3824
3825 InvokeInst(const InvokeInst &BI, AllocInfo AllocInfo);
3826
3827 /// Construct an InvokeInst given a range of arguments.
3828 ///
3829 /// Construct an InvokeInst from a range of arguments
3830 inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3831 BasicBlock *IfException, ArrayRef<Value *> Args,
3833 const Twine &NameStr, InsertPosition InsertBefore);
3834
3835 LLVM_ABI void init(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3836 BasicBlock *IfException, ArrayRef<Value *> Args,
3837 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
3838
3839 /// Compute the number of operands to allocate.
3840 static unsigned ComputeNumOperands(unsigned NumArgs,
3841 size_t NumBundleInputs = 0) {
3842 // We need one operand for the called function, plus our extra operands and
3843 // the input operand counts provided.
3844 return 1 + NumExtraOperands + NumArgs + unsigned(NumBundleInputs);
3845 }
3846
3847protected:
3848 // Note: Instruction needs to be a friend here to call cloneImpl.
3849 friend class Instruction;
3850
3851 LLVM_ABI InvokeInst *cloneImpl() const;
3852
3853public:
3854 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3855 BasicBlock *IfException, ArrayRef<Value *> Args,
3856 const Twine &NameStr,
3857 InsertPosition InsertBefore = nullptr) {
3858 IntrusiveOperandsAllocMarker AllocMarker{
3859 ComputeNumOperands(unsigned(Args.size()))};
3860 return new (AllocMarker) InvokeInst(Ty, Func, IfNormal, IfException, Args,
3861 {}, AllocMarker, NameStr, InsertBefore);
3862 }
3863
3864 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3865 BasicBlock *IfException, ArrayRef<Value *> Args,
3866 ArrayRef<OperandBundleDef> Bundles = {},
3867 const Twine &NameStr = "",
3868 InsertPosition InsertBefore = nullptr) {
3869 IntrusiveOperandsAndDescriptorAllocMarker AllocMarker{
3870 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles)),
3871 unsigned(Bundles.size() * sizeof(BundleOpInfo))};
3872
3873 return new (AllocMarker)
3874 InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, AllocMarker,
3875 NameStr, InsertBefore);
3876 }
3877
3878 static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
3879 BasicBlock *IfException, ArrayRef<Value *> Args,
3880 const Twine &NameStr,
3881 InsertPosition InsertBefore = nullptr) {
3882 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3883 IfException, Args, {}, NameStr, InsertBefore);
3884 }
3885
3886 static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
3887 BasicBlock *IfException, ArrayRef<Value *> Args,
3888 ArrayRef<OperandBundleDef> Bundles = {},
3889 const Twine &NameStr = "",
3890 InsertPosition InsertBefore = nullptr) {
3891 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3892 IfException, Args, Bundles, NameStr, InsertBefore);
3893 }
3894
3895 /// Create a clone of \p II with a different set of operand bundles and
3896 /// insert it before \p InsertBefore.
3897 ///
3898 /// The returned invoke instruction is identical to \p II in every way except
3899 /// that the operand bundles for the new instruction are set to the operand
3900 /// bundles in \p Bundles.
3901 LLVM_ABI static InvokeInst *Create(InvokeInst *II,
3903 InsertPosition InsertPt = nullptr);
3904
3905 // get*Dest - Return the destination basic blocks...
3913 Op<NormalDestOpEndIdx>() = reinterpret_cast<Value *>(B);
3914 }
3916 Op<UnwindDestOpEndIdx>() = reinterpret_cast<Value *>(B);
3917 }
3918
3919 /// Get the landingpad instruction from the landing pad
3920 /// block (the unwind destination).
3921 LLVM_ABI LandingPadInst *getLandingPadInst() const;
3922
3923 BasicBlock *getSuccessor(unsigned i) const {
3924 assert(i < 2 && "Successor # out of range for invoke!");
3925 return i == 0 ? getNormalDest() : getUnwindDest();
3926 }
3927
3928 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
3929 assert(i < 2 && "Successor # out of range for invoke!");
3930 if (i == 0)
3931 setNormalDest(NewSucc);
3932 else
3933 setUnwindDest(NewSucc);
3934 }
3935
3936 unsigned getNumSuccessors() const { return 2; }
3937
3946
3947 /// Updates profile metadata by scaling it by \p S / \p T.
3948 LLVM_ABI void updateProfWeight(uint64_t S, uint64_t T);
3949
3950 // Methods for support type inquiry through isa, cast, and dyn_cast:
3951 static bool classof(const Instruction *I) {
3952 return (I->getOpcode() == Instruction::Invoke);
3953 }
3954 static bool classof(const Value *V) {
3956 }
3957
3958private:
3959 // Shadow Instruction::setInstructionSubclassData with a private forwarding
3960 // method so that subclasses cannot accidentally use it.
3961 template <typename Bitfield>
3962 void setSubclassData(typename Bitfield::Type Value) {
3964 }
3965};
3966
3967InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3968 BasicBlock *IfException, ArrayRef<Value *> Args,
3970 const Twine &NameStr, InsertPosition InsertBefore)
3971 : CallBase(Ty->getReturnType(), Instruction::Invoke, AllocInfo,
3972 InsertBefore) {
3973 init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
3974}
3975
3976//===----------------------------------------------------------------------===//
3977// CallBrInst Class
3978//===----------------------------------------------------------------------===//
3979
3980/// CallBr instruction, tracking function calls that may not return control but
3981/// instead transfer it to a third location. The SubclassData field is used to
3982/// hold the calling convention of the call.
3983///
3984class CallBrInst : public CallBase {
3985
3986 unsigned NumIndirectDests;
3987
3988 CallBrInst(const CallBrInst &BI, AllocInfo AllocInfo);
3989
3990 /// Construct a CallBrInst given a range of arguments.
3991 ///
3992 /// Construct a CallBrInst from a range of arguments
3993 inline CallBrInst(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
3994 ArrayRef<BasicBlock *> IndirectDests,
3996 AllocInfo AllocInfo, const Twine &NameStr,
3997 InsertPosition InsertBefore);
3998
3999 LLVM_ABI void init(FunctionType *FTy, Value *Func, BasicBlock *DefaultDest,
4000 ArrayRef<BasicBlock *> IndirectDests,
4002 const Twine &NameStr);
4003
4004 /// Compute the number of operands to allocate.
4005 static unsigned ComputeNumOperands(int NumArgs, int NumIndirectDests,
4006 int NumBundleInputs = 0) {
4007 // We need one operand for the called function, plus our extra operands and
4008 // the input operand counts provided.
4009 return unsigned(2 + NumIndirectDests + NumArgs + NumBundleInputs);
4010 }
4011
4012protected:
4013 // Note: Instruction needs to be a friend here to call cloneImpl.
4014 friend class Instruction;
4015
4016 LLVM_ABI CallBrInst *cloneImpl() const;
4017
4018public:
4019 static CallBrInst *Create(FunctionType *Ty, Value *Func,
4020 BasicBlock *DefaultDest,
4021 ArrayRef<BasicBlock *> IndirectDests,
4022 ArrayRef<Value *> Args, const Twine &NameStr,
4023 InsertPosition InsertBefore = nullptr) {
4024 IntrusiveOperandsAllocMarker AllocMarker{
4025 ComputeNumOperands(Args.size(), IndirectDests.size())};
4026 return new (AllocMarker)
4027 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, {}, AllocMarker,
4028 NameStr, InsertBefore);
4029 }
4030
4031 static CallBrInst *
4032 Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
4033 ArrayRef<BasicBlock *> IndirectDests, ArrayRef<Value *> Args,
4034 ArrayRef<OperandBundleDef> Bundles = {}, const Twine &NameStr = "",
4035 InsertPosition InsertBefore = nullptr) {
4036 IntrusiveOperandsAndDescriptorAllocMarker AllocMarker{
4037 ComputeNumOperands(Args.size(), IndirectDests.size(),
4038 CountBundleInputs(Bundles)),
4039 unsigned(Bundles.size() * sizeof(BundleOpInfo))};
4040
4041 return new (AllocMarker)
4042 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, Bundles,
4043 AllocMarker, NameStr, InsertBefore);
4044 }
4045
4046 static CallBrInst *Create(FunctionCallee Func, BasicBlock *DefaultDest,
4047 ArrayRef<BasicBlock *> IndirectDests,
4048 ArrayRef<Value *> Args, const Twine &NameStr,
4049 InsertPosition InsertBefore = nullptr) {
4050 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4051 IndirectDests, Args, NameStr, InsertBefore);
4052 }
4053
4054 static CallBrInst *Create(FunctionCallee Func, BasicBlock *DefaultDest,
4055 ArrayRef<BasicBlock *> IndirectDests,
4056 ArrayRef<Value *> Args,
4057 ArrayRef<OperandBundleDef> Bundles = {},
4058 const Twine &NameStr = "",
4059 InsertPosition InsertBefore = nullptr) {
4060 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4061 IndirectDests, Args, Bundles, NameStr, InsertBefore);
4062 }
4063
4064 /// Create a clone of \p CBI with a different set of operand bundles and
4065 /// insert it before \p InsertBefore.
4066 ///
4067 /// The returned callbr instruction is identical to \p CBI in every way
4068 /// except that the operand bundles for the new instruction are set to the
4069 /// operand bundles in \p Bundles.
4070 LLVM_ABI static CallBrInst *Create(CallBrInst *CBI,
4072 InsertPosition InsertBefore = nullptr);
4073
4074 /// Return the number of callbr indirect dest labels.
4075 ///
4076 unsigned getNumIndirectDests() const { return NumIndirectDests; }
4077
4078 /// getIndirectDestLabel - Return the i-th indirect dest label.
4079 ///
4080 Value *getIndirectDestLabel(unsigned i) const {
4081 assert(i < getNumIndirectDests() && "Out of bounds!");
4082 return getOperand(i + arg_size() + getNumTotalBundleOperands() + 1);
4083 }
4084
4085 Value *getIndirectDestLabelUse(unsigned i) const {
4086 assert(i < getNumIndirectDests() && "Out of bounds!");
4087 return getOperandUse(i + arg_size() + getNumTotalBundleOperands() + 1);
4088 }
4089
4090 // Return the destination basic blocks...
4092 return cast<BasicBlock>(*(&Op<-1>() - getNumIndirectDests() - 1));
4093 }
4094 BasicBlock *getIndirectDest(unsigned i) const {
4096 }
4098 SmallVector<BasicBlock *, 16> IndirectDests;
4099 for (unsigned i = 0, e = getNumIndirectDests(); i < e; ++i)
4100 IndirectDests.push_back(getIndirectDest(i));
4101 return IndirectDests;
4102 }
4104 *(&Op<-1>() - getNumIndirectDests() - 1) = reinterpret_cast<Value *>(B);
4105 }
4106 void setIndirectDest(unsigned i, BasicBlock *B) {
4107 *(&Op<-1>() - getNumIndirectDests() + i) = reinterpret_cast<Value *>(B);
4108 }
4109
4110 BasicBlock *getSuccessor(unsigned i) const {
4111 assert(i < getNumSuccessors() + 1 &&
4112 "Successor # out of range for callbr!");
4113 return i == 0 ? getDefaultDest() : getIndirectDest(i - 1);
4114 }
4115
4116 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
4117 assert(i < getNumIndirectDests() + 1 &&
4118 "Successor # out of range for callbr!");
4119 return i == 0 ? setDefaultDest(NewSucc) : setIndirectDest(i - 1, NewSucc);
4120 }
4121
4122 unsigned getNumSuccessors() const { return getNumIndirectDests() + 1; }
4123
4132
4133 // Methods for support type inquiry through isa, cast, and dyn_cast:
4134 static bool classof(const Instruction *I) {
4135 return (I->getOpcode() == Instruction::CallBr);
4136 }
4137 static bool classof(const Value *V) {
4139 }
4140
4141private:
4142 // Shadow Instruction::setInstructionSubclassData with a private forwarding
4143 // method so that subclasses cannot accidentally use it.
4144 template <typename Bitfield>
4145 void setSubclassData(typename Bitfield::Type Value) {
4147 }
4148};
4149
4150CallBrInst::CallBrInst(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
4151 ArrayRef<BasicBlock *> IndirectDests,
4152 ArrayRef<Value *> Args,
4154 const Twine &NameStr, InsertPosition InsertBefore)
4155 : CallBase(Ty->getReturnType(), Instruction::CallBr, AllocInfo,
4156 InsertBefore) {
4157 init(Ty, Func, DefaultDest, IndirectDests, Args, Bundles, NameStr);
4158}
4159
4160//===----------------------------------------------------------------------===//
4161// ResumeInst Class
4162//===----------------------------------------------------------------------===//
4163
4164//===---------------------------------------------------------------------------
4165/// Resume the propagation of an exception.
4166///
4167class ResumeInst : public Instruction {
4168 constexpr static IntrusiveOperandsAllocMarker AllocMarker{1};
4169
4170 ResumeInst(const ResumeInst &RI);
4171
4172 LLVM_ABI explicit ResumeInst(Value *Exn,
4173 InsertPosition InsertBefore = nullptr);
4174
4175protected:
4176 // Note: Instruction needs to be a friend here to call cloneImpl.
4177 friend class Instruction;
4178
4179 LLVM_ABI ResumeInst *cloneImpl() const;
4180
4181public:
4182 static ResumeInst *Create(Value *Exn, InsertPosition InsertBefore = nullptr) {
4183 return new (AllocMarker) ResumeInst(Exn, InsertBefore);
4184 }
4185
4186 /// Provide fast operand accessors
4188
4189 /// Convenience accessor.
4190 Value *getValue() const { return Op<0>(); }
4191
4192 unsigned getNumSuccessors() const { return 0; }
4193
4194 // Methods for support type inquiry through isa, cast, and dyn_cast:
4195 static bool classof(const Instruction *I) {
4196 return I->getOpcode() == Instruction::Resume;
4197 }
4198 static bool classof(const Value *V) {
4200 }
4201
4202private:
4203 BasicBlock *getSuccessor(unsigned idx) const {
4204 llvm_unreachable("ResumeInst has no successors!");
4205 }
4206
4207 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
4208 llvm_unreachable("ResumeInst has no successors!");
4209 }
4210
4211 iterator_range<succ_iterator> successors() {
4212 return {succ_iterator(op_end()), succ_iterator(op_end())};
4213 }
4214 iterator_range<const_succ_iterator> successors() const {
4216 }
4217};
4218
4219template <>
4221 public FixedNumOperandTraits<ResumeInst, 1> {
4222};
4223
4225
4226//===----------------------------------------------------------------------===//
4227// CatchSwitchInst Class
4228//===----------------------------------------------------------------------===//
4229class CatchSwitchInst : public Instruction {
4230 using UnwindDestField = BoolBitfieldElementT<0>;
4231
4232 constexpr static HungOffOperandsAllocMarker AllocMarker{};
4233
4234 /// The number of operands actually allocated. NumOperands is
4235 /// the number actually in use.
4236 unsigned ReservedSpace;
4237
4238 // Operand[0] = Outer scope
4239 // Operand[1] = Unwind block destination
4240 // Operand[n] = BasicBlock to go to on match
4241 CatchSwitchInst(const CatchSwitchInst &CSI);
4242
4243 /// Create a new switch instruction, specifying a
4244 /// default destination. The number of additional handlers can be specified
4245 /// here to make memory allocation more efficient.
4246 /// This constructor can also autoinsert before another instruction.
4247 LLVM_ABI CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
4248 unsigned NumHandlers, const Twine &NameStr,
4249 InsertPosition InsertBefore);
4250
4251 // allocate space for exactly zero operands
4252 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
4253
4254 void init(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumReserved);
4255 void growOperands(unsigned Size);
4256
4257protected:
4258 // Note: Instruction needs to be a friend here to call cloneImpl.
4259 friend class Instruction;
4260
4261 LLVM_ABI CatchSwitchInst *cloneImpl() const;
4262
4263public:
4264 void operator delete(void *Ptr) {
4265 return User::operator delete(Ptr, AllocMarker);
4266 }
4267
4268 static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest,
4269 unsigned NumHandlers,
4270 const Twine &NameStr = "",
4271 InsertPosition InsertBefore = nullptr) {
4272 return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
4273 InsertBefore);
4274 }
4275
4276 /// Provide fast operand accessors
4278
4279 // Accessor Methods for CatchSwitch stmt
4280 Value *getParentPad() const { return getOperand(0); }
4281 void setParentPad(Value *ParentPad) { setOperand(0, ParentPad); }
4282
4283 // Accessor Methods for CatchSwitch stmt
4285 bool unwindsToCaller() const { return !hasUnwindDest(); }
4287 if (hasUnwindDest())
4288 return cast<BasicBlock>(getOperand(1));
4289 return nullptr;
4290 }
4291 void setUnwindDest(BasicBlock *UnwindDest) {
4292 assert(UnwindDest);
4294 setOperand(1, UnwindDest);
4295 }
4296
4297 /// return the number of 'handlers' in this catchswitch
4298 /// instruction, except the default handler
4299 unsigned getNumHandlers() const {
4300 if (hasUnwindDest())
4301 return getNumOperands() - 2;
4302 return getNumOperands() - 1;
4303 }
4304
4305private:
4306 static BasicBlock *handler_helper(Value *V) { return cast<BasicBlock>(V); }
4307 static const BasicBlock *handler_helper(const Value *V) {
4308 return cast<BasicBlock>(V);
4309 }
4310
4311public:
4312 using DerefFnTy = BasicBlock *(*)(Value *);
4315 using ConstDerefFnTy = const BasicBlock *(*)(const Value *);
4319
4320 /// Returns an iterator that points to the first handler in CatchSwitchInst.
4322 op_iterator It = op_begin() + 1;
4323 if (hasUnwindDest())
4324 ++It;
4325 return handler_iterator(It, DerefFnTy(handler_helper));
4326 }
4327
4328 /// Returns an iterator that points to the first handler in the
4329 /// CatchSwitchInst.
4331 const_op_iterator It = op_begin() + 1;
4332 if (hasUnwindDest())
4333 ++It;
4334 return const_handler_iterator(It, ConstDerefFnTy(handler_helper));
4335 }
4336
4337 /// Returns a read-only iterator that points one past the last
4338 /// handler in the CatchSwitchInst.
4340 return handler_iterator(op_end(), DerefFnTy(handler_helper));
4341 }
4342
4343 /// Returns an iterator that points one past the last handler in the
4344 /// CatchSwitchInst.
4346 return const_handler_iterator(op_end(), ConstDerefFnTy(handler_helper));
4347 }
4348
4349 /// iteration adapter for range-for loops.
4353
4354 /// iteration adapter for range-for loops.
4358
4359 /// Add an entry to the switch instruction...
4360 /// Note:
4361 /// This action invalidates handler_end(). Old handler_end() iterator will
4362 /// point to the added handler.
4363 LLVM_ABI void addHandler(BasicBlock *Dest);
4364
4365 LLVM_ABI void removeHandler(handler_iterator HI);
4366
4367 unsigned getNumSuccessors() const { return getNumOperands() - 1; }
4368 BasicBlock *getSuccessor(unsigned Idx) const {
4369 assert(Idx < getNumSuccessors() &&
4370 "Successor # out of range for catchswitch!");
4371 return cast<BasicBlock>(getOperand(Idx + 1));
4372 }
4373 void setSuccessor(unsigned Idx, BasicBlock *NewSucc) {
4374 assert(Idx < getNumSuccessors() &&
4375 "Successor # out of range for catchswitch!");
4376 setOperand(Idx + 1, NewSucc);
4377 }
4378
4386
4387 // Methods for support type inquiry through isa, cast, and dyn_cast:
4388 static bool classof(const Instruction *I) {
4389 return I->getOpcode() == Instruction::CatchSwitch;
4390 }
4391 static bool classof(const Value *V) {
4393 }
4394};
4395
4396template <>
4398
4400
4401//===----------------------------------------------------------------------===//
4402// CleanupPadInst Class
4403//===----------------------------------------------------------------------===//
4404class CleanupPadInst : public FuncletPadInst {
4405private:
4406 explicit CleanupPadInst(Value *ParentPad, ArrayRef<Value *> Args,
4407 AllocInfo AllocInfo, const Twine &NameStr,
4408 InsertPosition InsertBefore)
4409 : FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, AllocInfo,
4410 NameStr, InsertBefore) {}
4411
4412public:
4413 static CleanupPadInst *Create(Value *ParentPad, ArrayRef<Value *> Args = {},
4414 const Twine &NameStr = "",
4415 InsertPosition InsertBefore = nullptr) {
4416 IntrusiveOperandsAllocMarker AllocMarker{unsigned(1 + Args.size())};
4417 return new (AllocMarker)
4418 CleanupPadInst(ParentPad, Args, AllocMarker, NameStr, InsertBefore);
4419 }
4420
4421 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4422 static bool classof(const Instruction *I) {
4423 return I->getOpcode() == Instruction::CleanupPad;
4424 }
4425 static bool classof(const Value *V) {
4427 }
4428};
4429
4430//===----------------------------------------------------------------------===//
4431// CatchPadInst Class
4432//===----------------------------------------------------------------------===//
4433class CatchPadInst : public FuncletPadInst {
4434private:
4435 explicit CatchPadInst(Value *CatchSwitch, ArrayRef<Value *> Args,
4436 AllocInfo AllocInfo, const Twine &NameStr,
4437 InsertPosition InsertBefore)
4438 : FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, AllocInfo,
4439 NameStr, InsertBefore) {}
4440
4441public:
4442 static CatchPadInst *Create(Value *CatchSwitch, ArrayRef<Value *> Args,
4443 const Twine &NameStr = "",
4444 InsertPosition InsertBefore = nullptr) {
4445 IntrusiveOperandsAllocMarker AllocMarker{unsigned(1 + Args.size())};
4446 return new (AllocMarker)
4447 CatchPadInst(CatchSwitch, Args, AllocMarker, NameStr, InsertBefore);
4448 }
4449
4450 /// Convenience accessors
4454 void setCatchSwitch(Value *CatchSwitch) {
4455 assert(CatchSwitch);
4456 Op<-1>() = CatchSwitch;
4457 }
4458
4459 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4460 static bool classof(const Instruction *I) {
4461 return I->getOpcode() == Instruction::CatchPad;
4462 }
4463 static bool classof(const Value *V) {
4465 }
4466};
4467
4468//===----------------------------------------------------------------------===//
4469// CatchReturnInst Class
4470//===----------------------------------------------------------------------===//
4471
4472class CatchReturnInst : public Instruction {
4473 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
4474
4475 CatchReturnInst(const CatchReturnInst &RI);
4476 LLVM_ABI CatchReturnInst(Value *CatchPad, BasicBlock *BB,
4477 InsertPosition InsertBefore);
4478
4479 void init(Value *CatchPad, BasicBlock *BB);
4480
4481protected:
4482 // Note: Instruction needs to be a friend here to call cloneImpl.
4483 friend class Instruction;
4484
4485 LLVM_ABI CatchReturnInst *cloneImpl() const;
4486
4487public:
4488 static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB,
4489 InsertPosition InsertBefore = nullptr) {
4490 assert(CatchPad);
4491 assert(BB);
4492 return new (AllocMarker) CatchReturnInst(CatchPad, BB, InsertBefore);
4493 }
4494
4495 /// Provide fast operand accessors
4497
4498 /// Convenience accessors.
4500 void setCatchPad(CatchPadInst *CatchPad) {
4501 assert(CatchPad);
4502 Op<0>() = CatchPad;
4503 }
4504
4506 void setSuccessor(BasicBlock *NewSucc) {
4507 assert(NewSucc);
4508 Op<1>() = NewSucc;
4509 }
4510 unsigned getNumSuccessors() const { return 1; }
4511
4512 /// Get the parentPad of this catchret's catchpad's catchswitch.
4513 /// The successor block is implicitly a member of this funclet.
4517
4518 // Methods for support type inquiry through isa, cast, and dyn_cast:
4519 static bool classof(const Instruction *I) {
4520 return (I->getOpcode() == Instruction::CatchRet);
4521 }
4522 static bool classof(const Value *V) {
4524 }
4525
4526private:
4527 BasicBlock *getSuccessor(unsigned Idx) const {
4528 assert(Idx < getNumSuccessors() && "Successor # out of range for catchret!");
4529 return getSuccessor();
4530 }
4531
4532 void setSuccessor(unsigned Idx, BasicBlock *B) {
4533 assert(Idx < getNumSuccessors() && "Successor # out of range for catchret!");
4534 setSuccessor(B);
4535 }
4536
4537 iterator_range<succ_iterator> successors() {
4538 return {succ_iterator(std::next(op_begin())), succ_iterator(op_end())};
4539 }
4540 iterator_range<const_succ_iterator> successors() const {
4541 return {const_succ_iterator(std::next(op_begin())),
4543 }
4544};
4545
4546template <>
4548 : public FixedNumOperandTraits<CatchReturnInst, 2> {};
4549
4551
4552//===----------------------------------------------------------------------===//
4553// CleanupReturnInst Class
4554//===----------------------------------------------------------------------===//
4555
4556class CleanupReturnInst : public Instruction {
4557 using UnwindDestField = BoolBitfieldElementT<0>;
4558
4559private:
4560 CleanupReturnInst(const CleanupReturnInst &RI, AllocInfo AllocInfo);
4561 LLVM_ABI CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB,
4563 InsertPosition InsertBefore = nullptr);
4564
4565 void init(Value *CleanupPad, BasicBlock *UnwindBB);
4566
4567protected:
4568 // Note: Instruction needs to be a friend here to call cloneImpl.
4569 friend class Instruction;
4570
4571 LLVM_ABI CleanupReturnInst *cloneImpl() const;
4572
4573public:
4574 static CleanupReturnInst *Create(Value *CleanupPad,
4575 BasicBlock *UnwindBB = nullptr,
4576 InsertPosition InsertBefore = nullptr) {
4577 assert(CleanupPad);
4578 unsigned Values = 1;
4579 if (UnwindBB)
4580 ++Values;
4582 return new (AllocMarker)
4583 CleanupReturnInst(CleanupPad, UnwindBB, AllocMarker, InsertBefore);
4584 }
4585
4586 /// Provide fast operand accessors
4588
4590 bool unwindsToCaller() const { return !hasUnwindDest(); }
4591
4592 /// Convenience accessor.
4594 return cast<CleanupPadInst>(Op<0>());
4595 }
4596 void setCleanupPad(CleanupPadInst *CleanupPad) {
4597 assert(CleanupPad);
4598 Op<0>() = CleanupPad;
4599 }
4600
4601 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
4602
4604 return hasUnwindDest() ? cast<BasicBlock>(Op<1>()) : nullptr;
4605 }
4606 void setUnwindDest(BasicBlock *NewDest) {
4607 assert(NewDest);
4609 Op<1>() = NewDest;
4610 }
4611
4612 // Methods for support type inquiry through isa, cast, and dyn_cast:
4613 static bool classof(const Instruction *I) {
4614 return (I->getOpcode() == Instruction::CleanupRet);
4615 }
4616 static bool classof(const Value *V) {
4618 }
4619
4620private:
4621 BasicBlock *getSuccessor(unsigned Idx) const {
4622 assert(Idx == 0);
4623 return getUnwindDest();
4624 }
4625
4626 void setSuccessor(unsigned Idx, BasicBlock *B) {
4627 assert(Idx == 0);
4628 setUnwindDest(B);
4629 }
4630
4632 return {succ_iterator(std::next(op_begin())), succ_iterator(op_end())};
4633 }
4635 return {const_succ_iterator(std::next(op_begin())),
4636 const_succ_iterator(op_end())};
4637 }
4638
4639 // Shadow Instruction::setInstructionSubclassData with a private forwarding
4640 // method so that subclasses cannot accidentally use it.
4641 template <typename Bitfield>
4642 void setSubclassData(typename Bitfield::Type Value) {
4644 }
4645};
4646
4647template <>
4649 : public VariadicOperandTraits<CleanupReturnInst> {};
4650
4652
4653//===----------------------------------------------------------------------===//
4654// UnreachableInst Class
4655//===----------------------------------------------------------------------===//
4656
4657//===---------------------------------------------------------------------------
4658/// This function has undefined behavior. In particular, the
4659/// presence of this instruction indicates some higher level knowledge that the
4660/// end of the block cannot be reached.
4661///
4663 constexpr static IntrusiveOperandsAllocMarker AllocMarker{0};
4664
4665protected:
4666 // Note: Instruction needs to be a friend here to call cloneImpl.
4667 friend class Instruction;
4668
4670
4671public:
4673 InsertPosition InsertBefore = nullptr);
4674
4675 // allocate space for exactly zero operands
4676 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
4677 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
4678
4679 unsigned getNumSuccessors() const { return 0; }
4680
4681 // Methods for support type inquiry through isa, cast, and dyn_cast:
4682 static bool classof(const Instruction *I) {
4683 return I->getOpcode() == Instruction::Unreachable;
4684 }
4685 static bool classof(const Value *V) {
4687 }
4688
4689 // Whether to do target lowering in SelectionDAG.
4690 LLVM_ABI bool shouldLowerToTrap(bool TrapUnreachable,
4691 bool NoTrapAfterNoreturn) const;
4692
4693private:
4694 BasicBlock *getSuccessor(unsigned idx) const {
4695 llvm_unreachable("UnreachableInst has no successors!");
4696 }
4697
4698 void setSuccessor(unsigned idx, BasicBlock *B) {
4699 llvm_unreachable("UnreachableInst has no successors!");
4700 }
4701
4703 return {succ_iterator(op_end()), succ_iterator(op_end())};
4704 }
4706 return {const_succ_iterator(op_end()), const_succ_iterator(op_end())};
4707 }
4708};
4709
4710//===----------------------------------------------------------------------===//
4711// TruncInst Class
4712//===----------------------------------------------------------------------===//
4713
4714/// This class represents a truncation of integer types.
4715class TruncInst : public CastInst {
4716protected:
4717 // Note: Instruction needs to be a friend here to call cloneImpl.
4718 friend class Instruction;
4719
4720 /// Clone an identical TruncInst
4721 LLVM_ABI TruncInst *cloneImpl() const;
4722
4723public:
4724 enum { AnyWrap = 0, NoUnsignedWrap = (1 << 0), NoSignedWrap = (1 << 1) };
4725
4726 /// Constructor with insert-before-instruction semantics
4727 LLVM_ABI
4728 TruncInst(Value *S, ///< The value to be truncated
4729 Type *Ty, ///< The (smaller) type to truncate to
4730 const Twine &NameStr = "", ///< A name for the new instruction
4731 InsertPosition InsertBefore =
4732 nullptr ///< Where to insert the new instruction
4733 );
4734
4735 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4736 static bool classof(const Instruction *I) {
4737 return I->getOpcode() == Trunc;
4738 }
4739 static bool classof(const Value *V) {
4741 }
4742
4751
4752 /// Test whether this operation is known to never
4753 /// undergo unsigned overflow, aka the nuw property.
4754 bool hasNoUnsignedWrap() const {
4756 }
4757
4758 /// Test whether this operation is known to never
4759 /// undergo signed overflow, aka the nsw property.
4760 bool hasNoSignedWrap() const {
4761 return (SubclassOptionalData & NoSignedWrap) != 0;
4762 }
4763
4764 /// Returns the no-wrap kind of the operation.
4765 unsigned getNoWrapKind() const {
4766 unsigned NoWrapKind = 0;
4767 if (hasNoUnsignedWrap())
4768 NoWrapKind |= NoUnsignedWrap;
4769
4770 if (hasNoSignedWrap())
4771 NoWrapKind |= NoSignedWrap;
4772
4773 return NoWrapKind;
4774 }
4775};
4776
4777//===----------------------------------------------------------------------===//
4778// ZExtInst Class
4779//===----------------------------------------------------------------------===//
4780
4781/// This class represents zero extension of integer types.
4782class ZExtInst : public CastInst {
4783protected:
4784 // Note: Instruction needs to be a friend here to call cloneImpl.
4785 friend class Instruction;
4786
4787 /// Clone an identical ZExtInst
4788 LLVM_ABI ZExtInst *cloneImpl() const;
4789
4790public:
4791 /// Constructor with insert-before-instruction semantics
4792 LLVM_ABI
4793 ZExtInst(Value *S, ///< The value to be zero extended
4794 Type *Ty, ///< The type to zero extend to
4795 const Twine &NameStr = "", ///< A name for the new instruction
4796 InsertPosition InsertBefore =
4797 nullptr ///< Where to insert the new instruction
4798 );
4799
4800 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4801 static bool classof(const Instruction *I) {
4802 return I->getOpcode() == ZExt;
4803 }
4804 static bool classof(const Value *V) {
4806 }
4807};
4808
4809//===----------------------------------------------------------------------===//
4810// SExtInst Class
4811//===----------------------------------------------------------------------===//
4812
4813/// This class represents a sign extension of integer types.
4814class SExtInst : public CastInst {
4815protected:
4816 // Note: Instruction needs to be a friend here to call cloneImpl.
4817 friend class Instruction;
4818
4819 /// Clone an identical SExtInst
4820 LLVM_ABI SExtInst *cloneImpl() const;
4821
4822public:
4823 /// Constructor with insert-before-instruction semantics
4824 LLVM_ABI
4825 SExtInst(Value *S, ///< The value to be sign extended
4826 Type *Ty, ///< The type to sign extend to
4827 const Twine &NameStr = "", ///< A name for the new instruction
4828 InsertPosition InsertBefore =
4829 nullptr ///< Where to insert the new instruction
4830 );
4831
4832 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4833 static bool classof(const Instruction *I) {
4834 return I->getOpcode() == SExt;
4835 }
4836 static bool classof(const Value *V) {
4838 }
4839};
4840
4841//===----------------------------------------------------------------------===//
4842// FPTruncInst Class
4843//===----------------------------------------------------------------------===//
4844
4845/// This class represents a truncation of floating point types.
4847protected:
4848 // Note: Instruction needs to be a friend here to call cloneImpl.
4849 friend class Instruction;
4850
4851 /// Clone an identical FPTruncInst
4853
4854public: /// Constructor with insert-before-instruction semantics
4855 LLVM_ABI
4856 FPTruncInst(Value *S, ///< The value to be truncated
4857 Type *Ty, ///< The type to truncate to
4858 const Twine &NameStr = "", ///< A name for the new instruction
4859 InsertPosition InsertBefore =
4860 nullptr ///< Where to insert the new instruction
4861 );
4862
4863 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4864 static bool classof(const Instruction *I) {
4865 return I->getOpcode() == FPTrunc;
4866 }
4867 static bool classof(const Value *V) {
4869 }
4870};
4871
4872//===----------------------------------------------------------------------===//
4873// FPExtInst Class
4874//===----------------------------------------------------------------------===//
4875
4876/// This class represents an extension of floating point types.
4878protected:
4879 // Note: Instruction needs to be a friend here to call cloneImpl.
4880 friend class Instruction;
4881
4882 /// Clone an identical FPExtInst
4883 LLVM_ABI FPExtInst *cloneImpl() const;
4884
4885public:
4886 /// Constructor with insert-before-instruction semantics
4887 LLVM_ABI
4888 FPExtInst(Value *S, ///< The value to be extended
4889 Type *Ty, ///< The type to extend to
4890 const Twine &NameStr = "", ///< A name for the new instruction
4891 InsertPosition InsertBefore =
4892 nullptr ///< Where to insert the new instruction
4893 );
4894
4895 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4896 static bool classof(const Instruction *I) {
4897 return I->getOpcode() == FPExt;
4898 }
4899 static bool classof(const Value *V) {
4901 }
4902};
4903
4904//===----------------------------------------------------------------------===//
4905// UIToFPInst Class
4906//===----------------------------------------------------------------------===//
4907
4908/// This class represents a cast unsigned integer to floating point.
4910protected:
4911 // Note: Instruction needs to be a friend here to call cloneImpl.
4912 friend class Instruction;
4913
4914 /// Clone an identical UIToFPInst
4915 LLVM_ABI UIToFPInst *cloneImpl() const;
4916
4917public:
4918 /// Constructor with insert-before-instruction semantics
4919 LLVM_ABI
4920 UIToFPInst(Value *S, ///< The value to be converted
4921 Type *Ty, ///< The type to convert to
4922 const Twine &NameStr = "", ///< A name for the new instruction
4923 InsertPosition InsertBefore =
4924 nullptr ///< Where to insert the new instruction
4925 );
4926
4927 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4928 static bool classof(const Instruction *I) {
4929 return I->getOpcode() == UIToFP;
4930 }
4931 static bool classof(const Value *V) {
4933 }
4934};
4935
4936//===----------------------------------------------------------------------===//
4937// SIToFPInst Class
4938//===----------------------------------------------------------------------===//
4939
4940/// This class represents a cast from signed integer to floating point.
4942protected:
4943 // Note: Instruction needs to be a friend here to call cloneImpl.
4944 friend class Instruction;
4945
4946 /// Clone an identical SIToFPInst
4947 LLVM_ABI SIToFPInst *cloneImpl() const;
4948
4949public:
4950 /// Constructor with insert-before-instruction semantics
4951 LLVM_ABI
4952 SIToFPInst(Value *S, ///< The value to be converted
4953 Type *Ty, ///< The type to convert to
4954 const Twine &NameStr = "", ///< A name for the new instruction
4955 InsertPosition InsertBefore =
4956 nullptr ///< Where to insert the new instruction
4957 );
4958
4959 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4960 static bool classof(const Instruction *I) {
4961 return I->getOpcode() == SIToFP;
4962 }
4963 static bool classof(const Value *V) {
4965 }
4966};
4967
4968//===----------------------------------------------------------------------===//
4969// FPToUIInst Class
4970//===----------------------------------------------------------------------===//
4971
4972/// This class represents a cast from floating point to unsigned integer
4973class FPToUIInst : public CastInst {
4974protected:
4975 // Note: Instruction needs to be a friend here to call cloneImpl.
4976 friend class Instruction;
4977
4978 /// Clone an identical FPToUIInst
4979 LLVM_ABI FPToUIInst *cloneImpl() const;
4980
4981public:
4982 /// Constructor with insert-before-instruction semantics
4983 LLVM_ABI
4984 FPToUIInst(Value *S, ///< The value to be converted
4985 Type *Ty, ///< The type to convert to
4986 const Twine &NameStr = "", ///< A name for the new instruction
4987 InsertPosition InsertBefore =
4988 nullptr ///< Where to insert the new instruction
4989 );
4990
4991 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4992 static bool classof(const Instruction *I) {
4993 return I->getOpcode() == FPToUI;
4994 }
4995 static bool classof(const Value *V) {
4997 }
4998};
4999
5000//===----------------------------------------------------------------------===//
5001// FPToSIInst Class
5002//===----------------------------------------------------------------------===//
5003
5004/// This class represents a cast from floating point to signed integer.
5005class FPToSIInst : public CastInst {
5006protected:
5007 // Note: Instruction needs to be a friend here to call cloneImpl.
5008 friend class Instruction;
5009
5010 /// Clone an identical FPToSIInst
5011 LLVM_ABI FPToSIInst *cloneImpl() const;
5012
5013public:
5014 /// Constructor with insert-before-instruction semantics
5015 LLVM_ABI
5016 FPToSIInst(Value *S, ///< The value to be converted
5017 Type *Ty, ///< The type to convert to
5018 const Twine &NameStr = "", ///< A name for the new instruction
5019 InsertPosition InsertBefore =
5020 nullptr ///< Where to insert the new instruction
5021 );
5022
5023 /// Methods for support type inquiry through isa, cast, and dyn_cast:
5024 static bool classof(const Instruction *I) {
5025 return I->getOpcode() == FPToSI;
5026 }
5027 static bool classof(const Value *V) {
5029 }
5030};
5031
5032//===----------------------------------------------------------------------===//
5033// IntToPtrInst Class
5034//===----------------------------------------------------------------------===//
5035
5036/// This class represents a cast from an integer to a pointer.
5037class IntToPtrInst : public CastInst {
5038public:
5039 // Note: Instruction needs to be a friend here to call cloneImpl.
5040 friend class Instruction;
5041
5042 /// Constructor with insert-before-instruction semantics
5043 LLVM_ABI
5044 IntToPtrInst(Value *S, ///< The value to be converted
5045 Type *Ty, ///< The type to convert to
5046 const Twine &NameStr = "", ///< A name for the new instruction
5047 InsertPosition InsertBefore =
5048 nullptr ///< Where to insert the new instruction
5049 );
5050
5051 /// Clone an identical IntToPtrInst.
5053
5054 /// Returns the address space of this instruction's pointer type.
5055 unsigned getAddressSpace() const {
5056 return getType()->getPointerAddressSpace();
5057 }
5058
5059 // Methods for support type inquiry through isa, cast, and dyn_cast:
5060 static bool classof(const Instruction *I) {
5061 return I->getOpcode() == IntToPtr;
5062 }
5063 static bool classof(const Value *V) {
5065 }
5066};
5067
5068//===----------------------------------------------------------------------===//
5069// PtrToIntInst Class
5070//===----------------------------------------------------------------------===//
5071
5072/// This class represents a cast from a pointer to an integer.
5073class PtrToIntInst : public CastInst {
5074protected:
5075 // Note: Instruction needs to be a friend here to call cloneImpl.
5076 friend class Instruction;
5077
5078 /// Clone an identical PtrToIntInst.
5080
5081public:
5082 /// Constructor with insert-before-instruction semantics
5083 LLVM_ABI
5084 PtrToIntInst(Value *S, ///< The value to be converted
5085 Type *Ty, ///< The type to convert to
5086 const Twine &NameStr = "", ///< A name for the new instruction
5087 InsertPosition InsertBefore =
5088 nullptr ///< Where to insert the new instruction
5089 );
5090
5091 /// Gets the pointer operand.
5093 /// Gets the pointer operand.
5094 const Value *getPointerOperand() const { return getOperand(0); }
5095 /// Gets the operand index of the pointer operand.
5096 static unsigned getPointerOperandIndex() { return 0U; }
5097
5098 /// Returns the address space of the pointer operand.
5099 unsigned getPointerAddressSpace() const {
5101 }
5102
5103 // Methods for support type inquiry through isa, cast, and dyn_cast:
5104 static bool classof(const Instruction *I) {
5105 return I->getOpcode() == PtrToInt;
5106 }
5107 static bool classof(const Value *V) {
5109 }
5110};
5111
5112/// This class represents a cast from a pointer to an address (non-capturing
5113/// ptrtoint).
5114class PtrToAddrInst : public CastInst {
5115protected:
5116 // Note: Instruction needs to be a friend here to call cloneImpl.
5117 friend class Instruction;
5118
5119 /// Clone an identical PtrToAddrInst.
5121
5122public:
5123 /// Constructor with insert-before-instruction semantics
5124 LLVM_ABI
5125 PtrToAddrInst(Value *S, ///< The value to be converted
5126 Type *Ty, ///< The type to convert to
5127 const Twine &NameStr = "", ///< A name for the new instruction
5128 InsertPosition InsertBefore =
5129 nullptr ///< Where to insert the new instruction
5130 );
5131
5132 /// Gets the pointer operand.
5134 /// Gets the pointer operand.
5135 const Value *getPointerOperand() const { return getOperand(0); }
5136 /// Gets the operand index of the pointer operand.
5137 static unsigned getPointerOperandIndex() { return 0U; }
5138
5139 /// Returns the address space of the pointer operand.
5140 unsigned getPointerAddressSpace() const {
5142 }
5143
5144 // Methods for support type inquiry through isa, cast, and dyn_cast:
5145 static bool classof(const Instruction *I) {
5146 return I->getOpcode() == PtrToAddr;
5147 }
5148 static bool classof(const Value *V) {
5150 }
5151};
5152
5153//===----------------------------------------------------------------------===//
5154// BitCastInst Class
5155//===----------------------------------------------------------------------===//
5156
5157/// This class represents a no-op cast from one type to another.
5158class BitCastInst : public CastInst {
5159protected:
5160 // Note: Instruction needs to be a friend here to call cloneImpl.
5161 friend class Instruction;
5162
5163 /// Clone an identical BitCastInst.
5165
5166public:
5167 /// Constructor with insert-before-instruction semantics
5168 LLVM_ABI
5169 BitCastInst(Value *S, ///< The value to be casted
5170 Type *Ty, ///< The type to casted to
5171 const Twine &NameStr = "", ///< A name for the new instruction
5172 InsertPosition InsertBefore =
5173 nullptr ///< Where to insert the new instruction
5174 );
5175
5176 // Methods for support type inquiry through isa, cast, and dyn_cast:
5177 static bool classof(const Instruction *I) {
5178 return I->getOpcode() == BitCast;
5179 }
5180 static bool classof(const Value *V) {
5182 }
5183};
5184
5185//===----------------------------------------------------------------------===//
5186// AddrSpaceCastInst Class
5187//===----------------------------------------------------------------------===//
5188
5189/// This class represents a conversion between pointers from one address space
5190/// to another.
5192protected:
5193 // Note: Instruction needs to be a friend here to call cloneImpl.
5194 friend class Instruction;
5195
5196 /// Clone an identical AddrSpaceCastInst.
5198
5199public:
5200 /// Constructor with insert-before-instruction semantics
5202 Value *S, ///< The value to be casted
5203 Type *Ty, ///< The type to casted to
5204 const Twine &NameStr = "", ///< A name for the new instruction
5205 InsertPosition InsertBefore =
5206 nullptr ///< Where to insert the new instruction
5207 );
5208
5209 // Methods for support type inquiry through isa, cast, and dyn_cast:
5210 static bool classof(const Instruction *I) {
5211 return I->getOpcode() == AddrSpaceCast;
5212 }
5213 static bool classof(const Value *V) {
5215 }
5216
5217 /// Gets the pointer operand.
5219 return getOperand(0);
5220 }
5221
5222 /// Gets the pointer operand.
5223 const Value *getPointerOperand() const {
5224 return getOperand(0);
5225 }
5226
5227 /// Gets the operand index of the pointer operand.
5228 static unsigned getPointerOperandIndex() {
5229 return 0U;
5230 }
5231
5232 /// Returns the address space of the pointer operand.
5233 unsigned getSrcAddressSpace() const {
5235 }
5236
5237 /// Returns the address space of the result.
5238 unsigned getDestAddressSpace() const {
5239 return getType()->getPointerAddressSpace();
5240 }
5241};
5242
5243//===----------------------------------------------------------------------===//
5244// Helper functions
5245//===----------------------------------------------------------------------===//
5246
5247/// A helper function that returns the pointer operand of a load or store
5248/// instruction. Returns nullptr if not load or store.
5249inline const Value *getLoadStorePointerOperand(const Value *V) {
5250 if (auto *Load = dyn_cast<LoadInst>(V))
5251 return Load->getPointerOperand();
5252 if (auto *Store = dyn_cast<StoreInst>(V))
5253 return Store->getPointerOperand();
5254 return nullptr;
5255}
5257 return const_cast<Value *>(
5258 getLoadStorePointerOperand(static_cast<const Value *>(V)));
5259}
5260
5261/// A helper function that returns the pointer operand of a load, store
5262/// or GEP instruction. Returns nullptr if not load, store, or GEP.
5263inline const Value *getPointerOperand(const Value *V) {
5264 if (auto *Ptr = getLoadStorePointerOperand(V))
5265 return Ptr;
5266 if (auto *Gep = dyn_cast<GetElementPtrInst>(V))
5267 return Gep->getPointerOperand();
5268 return nullptr;
5269}
5271 return const_cast<Value *>(getPointerOperand(static_cast<const Value *>(V)));
5272}
5273
5274/// A helper function that returns the alignment of load or store instruction.
5277 "Expected Load or Store instruction");
5278 if (auto *LI = dyn_cast<LoadInst>(I))
5279 return LI->getAlign();
5280 return cast<StoreInst>(I)->getAlign();
5281}
5282
5283/// A helper function that set the alignment of load or store instruction.
5284inline void setLoadStoreAlignment(Value *I, Align NewAlign) {
5286 "Expected Load or Store instruction");
5287 if (auto *LI = dyn_cast<LoadInst>(I))
5288 LI->setAlignment(NewAlign);
5289 else
5290 cast<StoreInst>(I)->setAlignment(NewAlign);
5291}
5292
5293/// A helper function that returns the address space of the pointer operand of
5294/// load or store instruction.
5295inline unsigned getLoadStoreAddressSpace(const Value *I) {
5297 "Expected Load or Store instruction");
5298 if (auto *LI = dyn_cast<LoadInst>(I))
5299 return LI->getPointerAddressSpace();
5300 return cast<StoreInst>(I)->getPointerAddressSpace();
5301}
5302
5303/// A helper function that returns the type of a load or store instruction.
5304inline Type *getLoadStoreType(const Value *I) {
5306 "Expected Load or Store instruction");
5307 if (auto *LI = dyn_cast<LoadInst>(I))
5308 return LI->getType();
5309 return cast<StoreInst>(I)->getValueOperand()->getType();
5310}
5311
5312/// A helper function that returns an atomic operation's sync scope; returns
5313/// std::nullopt if it is not an atomic operation.
5314inline std::optional<SyncScope::ID> getAtomicSyncScopeID(const Instruction *I) {
5315 if (!I->isAtomic())
5316 return std::nullopt;
5317 if (auto *AI = dyn_cast<LoadInst>(I))
5318 return AI->getSyncScopeID();
5319 if (auto *AI = dyn_cast<StoreInst>(I))
5320 return AI->getSyncScopeID();
5321 if (auto *AI = dyn_cast<FenceInst>(I))
5322 return AI->getSyncScopeID();
5323 if (auto *AI = dyn_cast<AtomicCmpXchgInst>(I))
5324 return AI->getSyncScopeID();
5325 if (auto *AI = dyn_cast<AtomicRMWInst>(I))
5326 return AI->getSyncScopeID();
5327 llvm_unreachable("unhandled atomic operation");
5328}
5329
5330/// A helper function that sets an atomic operation's sync scope.
5332 assert(I->isAtomic());
5333 if (auto *AI = dyn_cast<LoadInst>(I))
5334 AI->setSyncScopeID(SSID);
5335 else if (auto *AI = dyn_cast<StoreInst>(I))
5336 AI->setSyncScopeID(SSID);
5337 else if (auto *AI = dyn_cast<FenceInst>(I))
5338 AI->setSyncScopeID(SSID);
5339 else if (auto *AI = dyn_cast<AtomicCmpXchgInst>(I))
5340 AI->setSyncScopeID(SSID);
5341 else if (auto *AI = dyn_cast<AtomicRMWInst>(I))
5342 AI->setSyncScopeID(SSID);
5343 else
5344 llvm_unreachable("unhandled atomic operation");
5345}
5346
5347//===----------------------------------------------------------------------===//
5348// FreezeInst Class
5349//===----------------------------------------------------------------------===//
5350
5351/// This class represents a freeze function that returns random concrete
5352/// value if an operand is either a poison value or an undef value
5354protected:
5355 // Note: Instruction needs to be a friend here to call cloneImpl.
5356 friend class Instruction;
5357
5358 /// Clone an identical FreezeInst
5359 LLVM_ABI FreezeInst *cloneImpl() const;
5360
5361public:
5362 LLVM_ABI explicit FreezeInst(Value *S, const Twine &NameStr = "",
5363 InsertPosition InsertBefore = nullptr);
5364
5365 // Methods for support type inquiry through isa, cast, and dyn_cast:
5366 static inline bool classof(const Instruction *I) {
5367 return I->getOpcode() == Freeze;
5368 }
5369 static inline bool classof(const Value *V) {
5371 }
5372};
5373
5374} // end namespace llvm
5375
5376#endif // LLVM_IR_INSTRUCTIONS_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
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< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:215
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)
LLVM_ABI TypeSize getAllocationBaseSize(const DataLayout &DL) const
Get the size of the allocated type.
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()
bool isScalable() const
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)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
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,...
bool isElementwise() const
Return true if this RMW has elementwise vector semantics.
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.
LLVM_ABI AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, Align Alignment, AtomicOrdering Ordering, SyncScope::ID SSID, bool Elementwise=false, InsertPosition InsertBefore=nullptr)
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
BoolBitfieldElementT< AlignmentField::NextBit > ElementwiseField
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this rmw instruction.
void setAlignment(Align Align)
void setElementwise(bool V)
Specify whether this RMW has elementwise vector semantics.
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.
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:515
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.
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
Definition InstrTypes.h:831
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition InstrTypes.h:743
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
Definition InstrTypes.h:757
@ ICMP_SLT
signed less than
Definition InstrTypes.h:769
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:770
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:764
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:763
@ ICMP_SGT
signed greater than
Definition InstrTypes.h:767
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition InstrTypes.h:748
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition InstrTypes.h:751
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:765
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition InstrTypes.h:749
@ ICMP_NE
not equal
Definition InstrTypes.h:762
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:768
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition InstrTypes.h:756
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:766
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
Definition InstrTypes.h:742
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition InstrTypes.h:750
static auto ICmpPredicates()
Returns the sequence of all ICmp predicates.
Definition InstrTypes.h:786
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Definition InstrTypes.h:890
static auto FCmpPredicates()
Returns the sequence of all FCmp predicates.
Definition InstrTypes.h:779
Predicate getNonStrictPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
Definition InstrTypes.h:934
LLVM_ABI CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred, Value *LHS, Value *RHS, const Twine &Name="", InsertPosition InsertBefore=nullptr)
bool isFPPredicate() const
Definition InstrTypes.h:845
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
Definition InstrTypes.h:852
Predicate getPredicate() const
Return the predicate for this instruction.
Definition InstrTypes.h:828
static bool isIntPredicate(Predicate P)
Definition InstrTypes.h:839
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.
Provide fast-math flags storage, instructions that support fast-math flags should inherit from this c...
Definition InstrTypes.h:56
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
LLVM_ABI void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
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.
LLVM_ABI void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
friend class Value
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)
void setElementwise(bool V)
Specify whether this is an elementwise atomic load or not.
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
void setProperties(const LoadStoreInstProperties &Props)
Sets the properties of this load instruction.
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.
LoadStoreInstProperties getProperties() const
Returns the properties of this load instruction.
bool isElementwise() const
Return true if this is an elementwise atomic load.
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.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
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.
LLVM_ABI 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)
LLVM_ABI 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.
bool isElementwise() const
Return true if this is an elementwise atomic store.
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.
LoadStoreInstProperties getProperties() const
Returns the properties of this store instruction.
void setSyncScopeID(SyncScope::ID SSID)
Sets the synchronization scope ID of this store instruction.
LLVM_ABI StoreInst * cloneImpl() const
void setProperties(const LoadStoreInstProperties &Props)
Sets the properties of this store instruction.
void setElementwise(bool V)
Specify whether this is an elementwise atomic store or not.
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.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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.
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
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.
Target - Wrapper for Target specific information.
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:71
Unconditional Branch instruction.
void setSuccessor(unsigned idx, BasicBlock *NewSucc)
iterator_range< succ_iterator > successors()
static bool classof(const Value *V)
static bool classof(const Instruction *I)
void setSuccessor(BasicBlock *NewSucc)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
static UncondBrInst * Create(BasicBlock *Target, InsertPosition InsertBefore=nullptr)
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:255
user_iterator_impl< const User > const_user_iterator
Definition Value.h:392
unsigned char SubclassOptionalData
Hold arbitary subclass data.
Definition Value.h:85
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
Definition Value.cpp:394
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.
@ System
Synchronized with respect to all concurrently executing threads.
Definition LLVMContext.h:58
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:578
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.
RelativeUniformCounterPtr Values
Definition InstrProf.h:91
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.
@ Load
The value being inserted comes from a load (InsertElement only).
@ Store
The extracted value is stored (ExtractElement only).
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:126
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:127
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 value is 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...
A structure representing the properties of a load or store instruction.
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:342
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...