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