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