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