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