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