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