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 {
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, nullptr, FlagsSource) {
1467 AssertOK();
1468 }
1469
1470 /// @returns true if the predicate is EQ or NE.
1471 /// Determine if this is an equality predicate.
1472 static bool isEquality(Predicate Pred) {
1473 return Pred == FCMP_OEQ || Pred == FCMP_ONE || Pred == FCMP_UEQ ||
1474 Pred == FCMP_UNE;
1475 }
1476
1477 /// @returns true if the predicate of this instruction is EQ or NE.
1478 /// Determine if this is an equality predicate.
1479 bool isEquality() const { return isEquality(getPredicate()); }
1480
1481 /// @returns true if the predicate is commutative.
1482 /// Determine if this is a commutative predicate.
1483 static bool isCommutative(Predicate Pred) {
1484 return isEquality(Pred) || Pred == FCMP_FALSE || Pred == FCMP_TRUE ||
1485 Pred == FCMP_ORD || Pred == FCMP_UNO;
1486 }
1487
1488 /// @returns true if the predicate of this instruction is commutative.
1489 /// Determine if this is a commutative predicate.
1490 bool isCommutative() const { return isCommutative(getPredicate()); }
1491
1492 /// @returns true if the predicate is relational (not EQ or NE).
1493 /// Determine if this a relational predicate.
1494 bool isRelational() const { return !isEquality(); }
1495
1496 /// Exchange the two operands to this instruction in such a way that it does
1497 /// not modify the semantics of the instruction. The predicate value may be
1498 /// changed to retain the same result if the predicate is order dependent
1499 /// (e.g. ult).
1500 /// Swap operands and adjust predicate.
1503 Op<0>().swap(Op<1>());
1504 }
1505
1506 /// Returns the sequence of all FCmp predicates.
1507 ///
1508 static auto predicates() { return FCmpPredicates(); }
1509
1510 /// Return result of `LHS Pred RHS` comparison.
1511 LLVM_ABI static bool compare(const APFloat &LHS, const APFloat &RHS,
1512 FCmpInst::Predicate Pred);
1513
1514 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1515 static bool classof(const Instruction *I) {
1516 return I->getOpcode() == Instruction::FCmp;
1517 }
1518 static bool classof(const Value *V) {
1520 }
1521};
1522
1523//===----------------------------------------------------------------------===//
1524/// This class represents a function call, abstracting a target
1525/// machine's calling convention. This class uses low bit of the SubClassData
1526/// field to indicate whether or not this is a tail call. The rest of the bits
1527/// hold the calling convention of the call.
1528///
1529class CallInst : public CallBase {
1530 CallInst(const CallInst &CI, AllocInfo AllocInfo);
1531
1532 /// Construct a CallInst from a range of arguments
1533 inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1534 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1535 AllocInfo AllocInfo, InsertPosition InsertBefore);
1536
1537 inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1538 const Twine &NameStr, AllocInfo AllocInfo,
1539 InsertPosition InsertBefore)
1540 : CallInst(Ty, Func, Args, {}, NameStr, AllocInfo, InsertBefore) {}
1541
1542 LLVM_ABI explicit CallInst(FunctionType *Ty, Value *F, const Twine &NameStr,
1543 AllocInfo AllocInfo, InsertPosition InsertBefore);
1544
1545 LLVM_ABI void init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
1546 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
1547 void init(FunctionType *FTy, Value *Func, const Twine &NameStr);
1548
1549 /// Compute the number of operands to allocate.
1550 static unsigned ComputeNumOperands(unsigned NumArgs,
1551 unsigned NumBundleInputs = 0) {
1552 // We need one operand for the called function, plus the input operand
1553 // counts provided.
1554 return 1 + NumArgs + NumBundleInputs;
1555 }
1556
1557protected:
1558 // Note: Instruction needs to be a friend here to call cloneImpl.
1559 friend class Instruction;
1560
1561 LLVM_ABI CallInst *cloneImpl() const;
1562
1563public:
1564 static CallInst *Create(FunctionType *Ty, Value *F, const Twine &NameStr = "",
1565 InsertPosition InsertBefore = nullptr) {
1566 IntrusiveOperandsAllocMarker AllocMarker{ComputeNumOperands(0)};
1567 return new (AllocMarker)
1568 CallInst(Ty, F, NameStr, AllocMarker, InsertBefore);
1569 }
1570
1571 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1572 const Twine &NameStr,
1573 InsertPosition InsertBefore = nullptr) {
1574 IntrusiveOperandsAllocMarker AllocMarker{ComputeNumOperands(Args.size())};
1575 return new (AllocMarker)
1576 CallInst(Ty, Func, Args, {}, NameStr, AllocMarker, InsertBefore);
1577 }
1578
1579 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1580 ArrayRef<OperandBundleDef> Bundles = {},
1581 const Twine &NameStr = "",
1582 InsertPosition InsertBefore = nullptr) {
1583 IntrusiveOperandsAndDescriptorAllocMarker AllocMarker{
1584 ComputeNumOperands(unsigned(Args.size()), CountBundleInputs(Bundles)),
1585 unsigned(Bundles.size() * sizeof(BundleOpInfo))};
1586
1587 return new (AllocMarker)
1588 CallInst(Ty, Func, Args, Bundles, NameStr, AllocMarker, InsertBefore);
1589 }
1590
1591 static CallInst *Create(FunctionCallee Func, const Twine &NameStr = "",
1592 InsertPosition InsertBefore = nullptr) {
1593 return Create(Func.getFunctionType(), Func.getCallee(), NameStr,
1594 InsertBefore);
1595 }
1596
1597 static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
1598 ArrayRef<OperandBundleDef> Bundles = {},
1599 const Twine &NameStr = "",
1600 InsertPosition InsertBefore = nullptr) {
1601 return Create(Func.getFunctionType(), Func.getCallee(), Args, Bundles,
1602 NameStr, InsertBefore);
1603 }
1604
1605 static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
1606 const Twine &NameStr,
1607 InsertPosition InsertBefore = nullptr) {
1608 return Create(Func.getFunctionType(), Func.getCallee(), Args, NameStr,
1609 InsertBefore);
1610 }
1611
1612 /// Create a clone of \p CI with a different set of operand bundles and
1613 /// insert it before \p InsertBefore.
1614 ///
1615 /// The returned call instruction is identical \p CI in every way except that
1616 /// the operand bundles for the new instruction are set to the operand bundles
1617 /// in \p Bundles.
1618 LLVM_ABI static CallInst *Create(CallInst *CI,
1620 InsertPosition InsertPt = nullptr);
1621
1622 // Note that 'musttail' implies 'tail'.
1630
1632 static_assert(
1634 "Bitfields must be contiguous");
1635
1639
1640 bool isTailCall() const {
1642 return Kind == TCK_Tail || Kind == TCK_MustTail;
1643 }
1644
1645 bool isMustTailCall() const { return getTailCallKind() == TCK_MustTail; }
1646
1647 bool isNoTailCall() const { return getTailCallKind() == TCK_NoTail; }
1648
1650 setSubclassData<TailCallKindField>(TCK);
1651 }
1652
1653 void setTailCall(bool IsTc = true) {
1655 }
1656
1657 /// Return true if the call can return twice
1658 bool canReturnTwice() const { return hasFnAttr(Attribute::ReturnsTwice); }
1659 void setCanReturnTwice() { addFnAttr(Attribute::ReturnsTwice); }
1660
1661 /// Return true if the call is for a noreturn trap intrinsic.
1663 switch (getIntrinsicID()) {
1664 case Intrinsic::trap:
1665 case Intrinsic::ubsantrap:
1666 return !hasFnAttr("trap-func-name");
1667 default:
1668 return false;
1669 }
1670 }
1671
1672 // Methods for support type inquiry through isa, cast, and dyn_cast:
1673 static bool classof(const Instruction *I) {
1674 return I->getOpcode() == Instruction::Call;
1675 }
1676 static bool classof(const Value *V) {
1678 }
1679
1680 /// Updates profile metadata by scaling it by \p S / \p T.
1682
1683private:
1684 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1685 // method so that subclasses cannot accidentally use it.
1686 template <typename Bitfield>
1687 void setSubclassData(typename Bitfield::Type Value) {
1689 }
1690};
1691
1692CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1693 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1694 AllocInfo AllocInfo, InsertPosition InsertBefore)
1695 : CallBase(Ty->getReturnType(), Instruction::Call, AllocInfo,
1696 InsertBefore) {
1698 unsigned(Args.size() + CountBundleInputs(Bundles) + 1));
1699 init(Ty, Func, Args, Bundles, NameStr);
1700}
1701
1702//===----------------------------------------------------------------------===//
1703// SelectInst Class
1704//===----------------------------------------------------------------------===//
1705
1706/// This class represents the LLVM 'select' instruction.
1707///
1708class SelectInst : public Instruction {
1709 constexpr static IntrusiveOperandsAllocMarker AllocMarker{3};
1710
1711 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1712 InsertPosition InsertBefore)
1713 : Instruction(S1->getType(), Instruction::Select, AllocMarker,
1714 InsertBefore) {
1715 init(C, S1, S2);
1716 setName(NameStr);
1717 }
1718
1719 void init(Value *C, Value *S1, Value *S2) {
1720 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1721 Op<0>() = C;
1722 Op<1>() = S1;
1723 Op<2>() = S2;
1724 }
1725
1726protected:
1727 // Note: Instruction needs to be a friend here to call cloneImpl.
1728 friend class Instruction;
1729
1730 LLVM_ABI SelectInst *cloneImpl() const;
1731
1732public:
1733 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1734 const Twine &NameStr = "",
1735 InsertPosition InsertBefore = nullptr,
1736 const Instruction *MDFrom = nullptr) {
1737 SelectInst *Sel =
1738 new (AllocMarker) SelectInst(C, S1, S2, NameStr, InsertBefore);
1739 if (MDFrom)
1740 Sel->copyMetadata(*MDFrom);
1741 return Sel;
1742 }
1743
1744 const Value *getCondition() const { return Op<0>(); }
1745 const Value *getTrueValue() const { return Op<1>(); }
1746 const Value *getFalseValue() const { return Op<2>(); }
1747 Value *getCondition() { return Op<0>(); }
1748 Value *getTrueValue() { return Op<1>(); }
1749 Value *getFalseValue() { return Op<2>(); }
1750
1751 void setCondition(Value *V) { Op<0>() = V; }
1752 void setTrueValue(Value *V) { Op<1>() = V; }
1753 void setFalseValue(Value *V) { Op<2>() = V; }
1754
1755 /// Swap the true and false values of the select instruction.
1756 /// This doesn't swap prof metadata.
1757 void swapValues() { Op<1>().swap(Op<2>()); }
1758
1759 /// Return a string if the specified operands are invalid
1760 /// for a select operation, otherwise return null.
1761 LLVM_ABI static const char *areInvalidOperands(Value *Cond, Value *True,
1762 Value *False);
1763
1764 /// Transparently provide more efficient getOperand methods.
1766
1768 return static_cast<OtherOps>(Instruction::getOpcode());
1769 }
1770
1771 // Methods for support type inquiry through isa, cast, and dyn_cast:
1772 static bool classof(const Instruction *I) {
1773 return I->getOpcode() == Instruction::Select;
1774 }
1775 static bool classof(const Value *V) {
1777 }
1778};
1779
1780template <>
1781struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1782};
1783
1785
1786//===----------------------------------------------------------------------===//
1787// VAArgInst Class
1788//===----------------------------------------------------------------------===//
1789
1790/// This class represents the va_arg llvm instruction, which returns
1791/// an argument of the specified type given a va_list and increments that list
1792///
1794protected:
1795 // Note: Instruction needs to be a friend here to call cloneImpl.
1796 friend class Instruction;
1797
1798 LLVM_ABI VAArgInst *cloneImpl() const;
1799
1800public:
1801 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1802 InsertPosition InsertBefore = nullptr)
1803 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1804 setName(NameStr);
1805 }
1806
1808 const Value *getPointerOperand() const { return getOperand(0); }
1809 static unsigned getPointerOperandIndex() { return 0U; }
1810
1811 // Methods for support type inquiry through isa, cast, and dyn_cast:
1812 static bool classof(const Instruction *I) {
1813 return I->getOpcode() == VAArg;
1814 }
1815 static bool classof(const Value *V) {
1817 }
1818};
1819
1820//===----------------------------------------------------------------------===//
1821// ExtractElementInst Class
1822//===----------------------------------------------------------------------===//
1823
1824/// This instruction extracts a single (scalar)
1825/// element from a VectorType value
1826///
1827class ExtractElementInst : public Instruction {
1828 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
1829
1830 LLVM_ABI ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1831 InsertPosition InsertBefore = nullptr);
1832
1833protected:
1834 // Note: Instruction needs to be a friend here to call cloneImpl.
1835 friend class Instruction;
1836
1837 LLVM_ABI ExtractElementInst *cloneImpl() const;
1838
1839public:
1840 static ExtractElementInst *Create(Value *Vec, Value *Idx,
1841 const Twine &NameStr = "",
1842 InsertPosition InsertBefore = nullptr) {
1843 return new (AllocMarker)
1844 ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1845 }
1846
1847 /// Return true if an extractelement instruction can be
1848 /// formed with the specified operands.
1849 LLVM_ABI static bool isValidOperands(const Value *Vec, const Value *Idx);
1850
1852 Value *getIndexOperand() { return Op<1>(); }
1853 const Value *getVectorOperand() const { return Op<0>(); }
1854 const Value *getIndexOperand() const { return Op<1>(); }
1855
1859
1860 /// Transparently provide more efficient getOperand methods.
1862
1863 // Methods for support type inquiry through isa, cast, and dyn_cast:
1864 static bool classof(const Instruction *I) {
1865 return I->getOpcode() == Instruction::ExtractElement;
1866 }
1867 static bool classof(const Value *V) {
1869 }
1870};
1871
1872template <>
1874 public FixedNumOperandTraits<ExtractElementInst, 2> {
1875};
1876
1878
1879//===----------------------------------------------------------------------===//
1880// InsertElementInst Class
1881//===----------------------------------------------------------------------===//
1882
1883/// This instruction inserts a single (scalar)
1884/// element into a VectorType value
1885///
1886class InsertElementInst : public Instruction {
1887 constexpr static IntrusiveOperandsAllocMarker AllocMarker{3};
1888
1889 LLVM_ABI InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1890 const Twine &NameStr = "",
1891 InsertPosition InsertBefore = nullptr);
1892
1893protected:
1894 // Note: Instruction needs to be a friend here to call cloneImpl.
1895 friend class Instruction;
1896
1897 LLVM_ABI InsertElementInst *cloneImpl() const;
1898
1899public:
1900 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1901 const Twine &NameStr = "",
1902 InsertPosition InsertBefore = nullptr) {
1903 return new (AllocMarker)
1904 InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1905 }
1906
1907 /// Return true if an insertelement instruction can be
1908 /// formed with the specified operands.
1909 LLVM_ABI static bool isValidOperands(const Value *Vec, const Value *NewElt,
1910 const Value *Idx);
1911
1912 /// Overload to return most specific vector type.
1913 ///
1916 }
1917
1918 /// Transparently provide more efficient getOperand methods.
1920
1921 // Methods for support type inquiry through isa, cast, and dyn_cast:
1922 static bool classof(const Instruction *I) {
1923 return I->getOpcode() == Instruction::InsertElement;
1924 }
1925 static bool classof(const Value *V) {
1927 }
1928};
1929
1930template <>
1932 public FixedNumOperandTraits<InsertElementInst, 3> {
1933};
1934
1936
1937//===----------------------------------------------------------------------===//
1938// ShuffleVectorInst Class
1939//===----------------------------------------------------------------------===//
1940
1941constexpr int PoisonMaskElem = -1;
1942
1943/// This instruction constructs a fixed permutation of two
1944/// input vectors.
1945///
1946/// For each element of the result vector, the shuffle mask selects an element
1947/// from one of the input vectors to copy to the result. Non-negative elements
1948/// in the mask represent an index into the concatenated pair of input vectors.
1949/// PoisonMaskElem (-1) specifies that the result element is poison.
1950///
1951/// For scalable vectors, all the elements of the mask must be 0 or -1. This
1952/// requirement may be relaxed in the future.
1954 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
1955
1956 SmallVector<int, 4> ShuffleMask;
1957 Constant *ShuffleMaskForBitcode;
1958
1959protected:
1960 // Note: Instruction needs to be a friend here to call cloneImpl.
1961 friend class Instruction;
1962
1964
1965public:
1966 LLVM_ABI ShuffleVectorInst(Value *V1, Value *Mask, const Twine &NameStr = "",
1967 InsertPosition InsertBefore = nullptr);
1969 const Twine &NameStr = "",
1970 InsertPosition InsertBefore = nullptr);
1971 LLVM_ABI ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1972 const Twine &NameStr = "",
1973 InsertPosition InsertBefore = nullptr);
1975 const Twine &NameStr = "",
1976 InsertPosition InsertBefore = nullptr);
1977
1978 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
1979 void operator delete(void *Ptr) {
1980 return User::operator delete(Ptr, AllocMarker);
1981 }
1982
1983 /// Swap the operands and adjust the mask to preserve the semantics
1984 /// of the instruction.
1985 LLVM_ABI void commute();
1986
1987 /// Return true if a shufflevector instruction can be
1988 /// formed with the specified operands.
1989 LLVM_ABI static bool isValidOperands(const Value *V1, const Value *V2,
1990 const Value *Mask);
1991 LLVM_ABI static bool isValidOperands(const Value *V1, const Value *V2,
1992 ArrayRef<int> Mask);
1993
1994 /// Overload to return most specific vector type.
1995 ///
1998 }
1999
2000 /// Transparently provide more efficient getOperand methods.
2002
2003 /// Return the shuffle mask value of this instruction for the given element
2004 /// index. Return PoisonMaskElem if the element is undef.
2005 int getMaskValue(unsigned Elt) const { return ShuffleMask[Elt]; }
2006
2007 /// Convert the input shuffle mask operand to a vector of integers. Undefined
2008 /// elements of the mask are returned as PoisonMaskElem.
2009 LLVM_ABI static void getShuffleMask(const Constant *Mask,
2010 SmallVectorImpl<int> &Result);
2011
2012 /// Return the mask for this instruction as a vector of integers. Undefined
2013 /// elements of the mask are returned as PoisonMaskElem.
2015 Result.assign(ShuffleMask.begin(), ShuffleMask.end());
2016 }
2017
2018 /// Return the mask for this instruction, for use in bitcode.
2019 ///
2020 /// TODO: This is temporary until we decide a new bitcode encoding for
2021 /// shufflevector.
2022 Constant *getShuffleMaskForBitcode() const { return ShuffleMaskForBitcode; }
2023
2024 LLVM_ABI static Constant *convertShuffleMaskForBitcode(ArrayRef<int> Mask,
2025 Type *ResultTy);
2026
2027 LLVM_ABI void setShuffleMask(ArrayRef<int> Mask);
2028
2029 ArrayRef<int> getShuffleMask() const { return ShuffleMask; }
2030
2031 /// Return true if this shuffle returns a vector with a different number of
2032 /// elements than its source vectors.
2033 /// Examples: shufflevector <4 x n> A, <4 x n> B, <1,2,3>
2034 /// shufflevector <4 x n> A, <4 x n> B, <1,2,3,4,5>
2035 bool changesLength() const {
2036 unsigned NumSourceElts = cast<VectorType>(Op<0>()->getType())
2037 ->getElementCount()
2038 .getKnownMinValue();
2039 unsigned NumMaskElts = ShuffleMask.size();
2040 return NumSourceElts != NumMaskElts;
2041 }
2042
2043 /// Return true if this shuffle returns a vector with a greater number of
2044 /// elements than its source vectors.
2045 /// Example: shufflevector <2 x n> A, <2 x n> B, <1,2,3>
2046 bool increasesLength() const {
2047 unsigned NumSourceElts = cast<VectorType>(Op<0>()->getType())
2048 ->getElementCount()
2049 .getKnownMinValue();
2050 unsigned NumMaskElts = ShuffleMask.size();
2051 return NumSourceElts < NumMaskElts;
2052 }
2053
2054 /// Return true if this shuffle mask chooses elements from exactly one source
2055 /// vector.
2056 /// Example: <7,5,undef,7>
2057 /// This assumes that vector operands (of length \p NumSrcElts) are the same
2058 /// length as the mask.
2059 LLVM_ABI static bool isSingleSourceMask(ArrayRef<int> Mask, int NumSrcElts);
2060 static bool isSingleSourceMask(const Constant *Mask, int NumSrcElts) {
2061 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2062 SmallVector<int, 16> MaskAsInts;
2063 getShuffleMask(Mask, MaskAsInts);
2064 return isSingleSourceMask(MaskAsInts, NumSrcElts);
2065 }
2066
2067 /// Return true if this shuffle chooses elements from exactly one source
2068 /// vector without changing the length of that vector.
2069 /// Example: shufflevector <4 x n> A, <4 x n> B, <3,0,undef,3>
2070 /// TODO: Optionally allow length-changing shuffles.
2071 bool isSingleSource() const {
2072 return !changesLength() &&
2073 isSingleSourceMask(ShuffleMask, ShuffleMask.size());
2074 }
2075
2076 /// Return true if this shuffle mask chooses elements from exactly one source
2077 /// vector without lane crossings. A shuffle using this mask is not
2078 /// necessarily a no-op because it may change the number of elements from its
2079 /// input vectors or it may provide demanded bits knowledge via undef lanes.
2080 /// Example: <undef,undef,2,3>
2081 LLVM_ABI static bool isIdentityMask(ArrayRef<int> Mask, int NumSrcElts);
2082 static bool isIdentityMask(const Constant *Mask, int NumSrcElts) {
2083 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2084
2085 // Not possible to express a shuffle mask for a scalable vector for this
2086 // case.
2087 if (isa<ScalableVectorType>(Mask->getType()))
2088 return false;
2089
2090 SmallVector<int, 16> MaskAsInts;
2091 getShuffleMask(Mask, MaskAsInts);
2092 return isIdentityMask(MaskAsInts, NumSrcElts);
2093 }
2094
2095 /// Return true if this shuffle chooses elements from exactly one source
2096 /// vector without lane crossings and does not change the number of elements
2097 /// from its input vectors.
2098 /// Example: shufflevector <4 x n> A, <4 x n> B, <4,undef,6,undef>
2099 bool isIdentity() const {
2100 // Not possible to express a shuffle mask for a scalable vector for this
2101 // case.
2103 return false;
2104
2105 return !changesLength() && isIdentityMask(ShuffleMask, ShuffleMask.size());
2106 }
2107
2108 /// Return true if this shuffle lengthens exactly one source vector with
2109 /// undefs in the high elements.
2110 LLVM_ABI bool isIdentityWithPadding() const;
2111
2112 /// Return true if this shuffle extracts the first N elements of exactly one
2113 /// source vector.
2114 LLVM_ABI bool isIdentityWithExtract() const;
2115
2116 /// Return true if this shuffle concatenates its 2 source vectors. This
2117 /// returns false if either input is undefined. In that case, the shuffle is
2118 /// is better classified as an identity with padding operation.
2119 LLVM_ABI bool isConcat() const;
2120
2121 /// Return true if this shuffle mask chooses elements from its source vectors
2122 /// without lane crossings. A shuffle using this mask would be
2123 /// equivalent to a vector select with a constant condition operand.
2124 /// Example: <4,1,6,undef>
2125 /// This returns false if the mask does not choose from both input vectors.
2126 /// In that case, the shuffle is better classified as an identity shuffle.
2127 /// This assumes that vector operands are the same length as the mask
2128 /// (a length-changing shuffle can never be equivalent to a vector select).
2129 LLVM_ABI static bool isSelectMask(ArrayRef<int> Mask, int NumSrcElts);
2130 static bool isSelectMask(const Constant *Mask, int NumSrcElts) {
2131 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2132 SmallVector<int, 16> MaskAsInts;
2133 getShuffleMask(Mask, MaskAsInts);
2134 return isSelectMask(MaskAsInts, NumSrcElts);
2135 }
2136
2137 /// Return true if this shuffle chooses elements from its source vectors
2138 /// without lane crossings and all operands have the same number of elements.
2139 /// In other words, this shuffle is equivalent to a vector select with a
2140 /// constant condition operand.
2141 /// Example: shufflevector <4 x n> A, <4 x n> B, <undef,1,6,3>
2142 /// This returns false if the mask does not choose from both input vectors.
2143 /// In that case, the shuffle is better classified as an identity shuffle.
2144 /// TODO: Optionally allow length-changing shuffles.
2145 bool isSelect() const {
2146 return !changesLength() && isSelectMask(ShuffleMask, ShuffleMask.size());
2147 }
2148
2149 /// Return true if this shuffle mask swaps the order of elements from exactly
2150 /// one source vector.
2151 /// Example: <7,6,undef,4>
2152 /// This assumes that vector operands (of length \p NumSrcElts) are the same
2153 /// length as the mask.
2154 LLVM_ABI static bool isReverseMask(ArrayRef<int> Mask, int NumSrcElts);
2155 static bool isReverseMask(const Constant *Mask, int NumSrcElts) {
2156 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2157 SmallVector<int, 16> MaskAsInts;
2158 getShuffleMask(Mask, MaskAsInts);
2159 return isReverseMask(MaskAsInts, NumSrcElts);
2160 }
2161
2162 /// Return true if this shuffle swaps the order of elements from exactly
2163 /// one source vector.
2164 /// Example: shufflevector <4 x n> A, <4 x n> B, <3,undef,1,undef>
2165 /// TODO: Optionally allow length-changing shuffles.
2166 bool isReverse() const {
2167 return !changesLength() && isReverseMask(ShuffleMask, ShuffleMask.size());
2168 }
2169
2170 /// Return true if this shuffle mask chooses all elements with the same value
2171 /// as the first element of exactly one source vector.
2172 /// Example: <4,undef,undef,4>
2173 /// This assumes that vector operands (of length \p NumSrcElts) are the same
2174 /// length as the mask.
2175 LLVM_ABI static bool isZeroEltSplatMask(ArrayRef<int> Mask, int NumSrcElts);
2176 static bool isZeroEltSplatMask(const Constant *Mask, int NumSrcElts) {
2177 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2178 SmallVector<int, 16> MaskAsInts;
2179 getShuffleMask(Mask, MaskAsInts);
2180 return isZeroEltSplatMask(MaskAsInts, NumSrcElts);
2181 }
2182
2183 /// Return true if all elements of this shuffle are the same value as the
2184 /// first element of exactly one source vector without changing the length
2185 /// of that vector.
2186 /// Example: shufflevector <4 x n> A, <4 x n> B, <undef,0,undef,0>
2187 /// TODO: Optionally allow length-changing shuffles.
2188 /// TODO: Optionally allow splats from other elements.
2189 bool isZeroEltSplat() const {
2190 return !changesLength() &&
2191 isZeroEltSplatMask(ShuffleMask, ShuffleMask.size());
2192 }
2193
2194 /// Return true if this shuffle mask is a transpose mask.
2195 /// Transpose vector masks transpose a 2xn matrix. They read corresponding
2196 /// even- or odd-numbered vector elements from two n-dimensional source
2197 /// vectors and write each result into consecutive elements of an
2198 /// n-dimensional destination vector. Two shuffles are necessary to complete
2199 /// the transpose, one for the even elements and another for the odd elements.
2200 /// This description closely follows how the TRN1 and TRN2 AArch64
2201 /// instructions operate.
2202 ///
2203 /// For example, a simple 2x2 matrix can be transposed with:
2204 ///
2205 /// ; Original matrix
2206 /// m0 = < a, b >
2207 /// m1 = < c, d >
2208 ///
2209 /// ; Transposed matrix
2210 /// t0 = < a, c > = shufflevector m0, m1, < 0, 2 >
2211 /// t1 = < b, d > = shufflevector m0, m1, < 1, 3 >
2212 ///
2213 /// For matrices having greater than n columns, the resulting nx2 transposed
2214 /// matrix is stored in two result vectors such that one vector contains
2215 /// interleaved elements from all the even-numbered rows and the other vector
2216 /// contains interleaved elements from all the odd-numbered rows. For example,
2217 /// a 2x4 matrix can be transposed with:
2218 ///
2219 /// ; Original matrix
2220 /// m0 = < a, b, c, d >
2221 /// m1 = < e, f, g, h >
2222 ///
2223 /// ; Transposed matrix
2224 /// t0 = < a, e, c, g > = shufflevector m0, m1 < 0, 4, 2, 6 >
2225 /// t1 = < b, f, d, h > = shufflevector m0, m1 < 1, 5, 3, 7 >
2226 LLVM_ABI static bool isTransposeMask(ArrayRef<int> Mask, int NumSrcElts);
2227 static bool isTransposeMask(const Constant *Mask, int NumSrcElts) {
2228 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2229 SmallVector<int, 16> MaskAsInts;
2230 getShuffleMask(Mask, MaskAsInts);
2231 return isTransposeMask(MaskAsInts, NumSrcElts);
2232 }
2233
2234 /// Return true if this shuffle transposes the elements of its inputs without
2235 /// changing the length of the vectors. This operation may also be known as a
2236 /// merge or interleave. See the description for isTransposeMask() for the
2237 /// exact specification.
2238 /// Example: shufflevector <4 x n> A, <4 x n> B, <0,4,2,6>
2239 bool isTranspose() const {
2240 return !changesLength() && isTransposeMask(ShuffleMask, ShuffleMask.size());
2241 }
2242
2243 /// Return true if this shuffle mask is a splice mask, concatenating the two
2244 /// inputs together and then extracts an original width vector starting from
2245 /// the splice index.
2246 /// Example: shufflevector <4 x n> A, <4 x n> B, <1,2,3,4>
2247 /// This assumes that vector operands (of length \p NumSrcElts) are the same
2248 /// length as the mask.
2249 LLVM_ABI static bool isSpliceMask(ArrayRef<int> Mask, int NumSrcElts,
2250 int &Index);
2251 static bool isSpliceMask(const Constant *Mask, int NumSrcElts, int &Index) {
2252 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2253 SmallVector<int, 16> MaskAsInts;
2254 getShuffleMask(Mask, MaskAsInts);
2255 return isSpliceMask(MaskAsInts, NumSrcElts, Index);
2256 }
2257
2258 /// Return true if this shuffle splices two inputs without changing the length
2259 /// of the vectors. This operation concatenates the two inputs together and
2260 /// then extracts an original width vector starting from the splice index.
2261 /// Example: shufflevector <4 x n> A, <4 x n> B, <1,2,3,4>
2262 bool isSplice(int &Index) const {
2263 return !changesLength() &&
2264 isSpliceMask(ShuffleMask, ShuffleMask.size(), Index);
2265 }
2266
2267 /// Return true if this shuffle mask is an extract subvector mask.
2268 /// A valid extract subvector mask returns a smaller vector from a single
2269 /// source operand. The base extraction index is returned as well.
2270 LLVM_ABI static bool isExtractSubvectorMask(ArrayRef<int> Mask,
2271 int NumSrcElts, int &Index);
2272 static bool isExtractSubvectorMask(const Constant *Mask, int NumSrcElts,
2273 int &Index) {
2274 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2275 // Not possible to express a shuffle mask for a scalable vector for this
2276 // case.
2277 if (isa<ScalableVectorType>(Mask->getType()))
2278 return false;
2279 SmallVector<int, 16> MaskAsInts;
2280 getShuffleMask(Mask, MaskAsInts);
2281 return isExtractSubvectorMask(MaskAsInts, NumSrcElts, Index);
2282 }
2283
2284 /// Return true if this shuffle mask is an extract subvector mask.
2285 bool isExtractSubvectorMask(int &Index) const {
2286 // Not possible to express a shuffle mask for a scalable vector for this
2287 // case.
2289 return false;
2290
2291 int NumSrcElts =
2292 cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
2293 return isExtractSubvectorMask(ShuffleMask, NumSrcElts, Index);
2294 }
2295
2296 /// Return true if this shuffle mask is an insert subvector mask.
2297 /// A valid insert subvector mask inserts the lowest elements of a second
2298 /// source operand into an in-place first source operand.
2299 /// Both the sub vector width and the insertion index is returned.
2300 LLVM_ABI static bool isInsertSubvectorMask(ArrayRef<int> Mask, int NumSrcElts,
2301 int &NumSubElts, int &Index);
2302 static bool isInsertSubvectorMask(const Constant *Mask, int NumSrcElts,
2303 int &NumSubElts, int &Index) {
2304 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2305 // Not possible to express a shuffle mask for a scalable vector for this
2306 // case.
2307 if (isa<ScalableVectorType>(Mask->getType()))
2308 return false;
2309 SmallVector<int, 16> MaskAsInts;
2310 getShuffleMask(Mask, MaskAsInts);
2311 return isInsertSubvectorMask(MaskAsInts, NumSrcElts, NumSubElts, Index);
2312 }
2313
2314 /// Return true if this shuffle mask is an insert subvector mask.
2315 bool isInsertSubvectorMask(int &NumSubElts, int &Index) const {
2316 // Not possible to express a shuffle mask for a scalable vector for this
2317 // case.
2319 return false;
2320
2321 int NumSrcElts =
2322 cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
2323 return isInsertSubvectorMask(ShuffleMask, NumSrcElts, NumSubElts, Index);
2324 }
2325
2326 /// Return true if this shuffle mask replicates each of the \p VF elements
2327 /// in a vector \p ReplicationFactor times.
2328 /// For example, the mask for \p ReplicationFactor=3 and \p VF=4 is:
2329 /// <0,0,0,1,1,1,2,2,2,3,3,3>
2330 LLVM_ABI static bool isReplicationMask(ArrayRef<int> Mask,
2331 int &ReplicationFactor, int &VF);
2332 static bool isReplicationMask(const Constant *Mask, int &ReplicationFactor,
2333 int &VF) {
2334 assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
2335 // Not possible to express a shuffle mask for a scalable vector for this
2336 // case.
2337 if (isa<ScalableVectorType>(Mask->getType()))
2338 return false;
2339 SmallVector<int, 16> MaskAsInts;
2340 getShuffleMask(Mask, MaskAsInts);
2341 return isReplicationMask(MaskAsInts, ReplicationFactor, VF);
2342 }
2343
2344 /// Return true if this shuffle mask is a replication mask.
2345 LLVM_ABI bool isReplicationMask(int &ReplicationFactor, int &VF) const;
2346
2347 /// Return true if this shuffle mask represents "clustered" mask of size VF,
2348 /// i.e. each index between [0..VF) is used exactly once in each submask of
2349 /// size VF.
2350 /// For example, the mask for \p VF=4 is:
2351 /// 0, 1, 2, 3, 3, 2, 0, 1 - "clustered", because each submask of size 4
2352 /// (0,1,2,3 and 3,2,0,1) uses indices [0..VF) exactly one time.
2353 /// 0, 1, 2, 3, 3, 3, 1, 0 - not "clustered", because
2354 /// element 3 is used twice in the second submask
2355 /// (3,3,1,0) and index 2 is not used at all.
2356 LLVM_ABI static bool isOneUseSingleSourceMask(ArrayRef<int> Mask, int VF);
2357
2358 /// Return true if this shuffle mask is a one-use-single-source("clustered")
2359 /// mask.
2360 LLVM_ABI bool isOneUseSingleSourceMask(int VF) const;
2361
2362 /// Change values in a shuffle permute mask assuming the two vector operands
2363 /// of length InVecNumElts have swapped position.
2365 unsigned InVecNumElts) {
2366 for (int &Idx : Mask) {
2367 if (Idx == -1)
2368 continue;
2369 Idx = Idx < (int)InVecNumElts ? Idx + InVecNumElts : Idx - InVecNumElts;
2370 assert(Idx >= 0 && Idx < (int)InVecNumElts * 2 &&
2371 "shufflevector mask index out of range");
2372 }
2373 }
2374
2375 /// Return if this shuffle interleaves its two input vectors together.
2376 LLVM_ABI bool isInterleave(unsigned Factor);
2377
2378 /// Return true if the mask interleaves one or more input vectors together.
2379 ///
2380 /// I.e. <0, LaneLen, ... , LaneLen*(Factor - 1), 1, LaneLen + 1, ...>
2381 /// E.g. For a Factor of 2 (LaneLen=4):
2382 /// <0, 4, 1, 5, 2, 6, 3, 7>
2383 /// E.g. For a Factor of 3 (LaneLen=4):
2384 /// <4, 0, 9, 5, 1, 10, 6, 2, 11, 7, 3, 12>
2385 /// E.g. For a Factor of 4 (LaneLen=2):
2386 /// <0, 2, 6, 4, 1, 3, 7, 5>
2387 ///
2388 /// NumInputElts is the total number of elements in the input vectors.
2389 ///
2390 /// StartIndexes are the first indexes of each vector being interleaved,
2391 /// substituting any indexes that were undef
2392 /// E.g. <4, -1, 2, 5, 1, 3> (Factor=3): StartIndexes=<4, 0, 2>
2393 ///
2394 /// Note that this does not check if the input vectors are consecutive:
2395 /// It will return true for masks such as
2396 /// <0, 4, 6, 1, 5, 7> (Factor=3, LaneLen=2)
2397 LLVM_ABI static bool
2398 isInterleaveMask(ArrayRef<int> Mask, unsigned Factor, unsigned NumInputElts,
2399 SmallVectorImpl<unsigned> &StartIndexes);
2400 static bool isInterleaveMask(ArrayRef<int> Mask, unsigned Factor,
2401 unsigned NumInputElts) {
2402 SmallVector<unsigned, 8> StartIndexes;
2403 return isInterleaveMask(Mask, Factor, NumInputElts, StartIndexes);
2404 }
2405
2406 /// Check if the mask is a DE-interleave mask of the given factor
2407 /// \p Factor like:
2408 /// <Index, Index+Factor, ..., Index+(NumElts-1)*Factor>
2409 LLVM_ABI static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask,
2410 unsigned Factor,
2411 unsigned &Index);
2412 static bool isDeInterleaveMaskOfFactor(ArrayRef<int> Mask, unsigned Factor) {
2413 unsigned Unused;
2414 return isDeInterleaveMaskOfFactor(Mask, Factor, Unused);
2415 }
2416
2417 /// Checks if the shuffle is a bit rotation of the first operand across
2418 /// multiple subelements, e.g:
2419 ///
2420 /// shuffle <8 x i8> %a, <8 x i8> poison, <8 x i32> <1, 0, 3, 2, 5, 4, 7, 6>
2421 ///
2422 /// could be expressed as
2423 ///
2424 /// rotl <4 x i16> %a, 8
2425 ///
2426 /// If it can be expressed as a rotation, returns the number of subelements to
2427 /// group by in NumSubElts and the number of bits to rotate left in RotateAmt.
2428 LLVM_ABI static bool isBitRotateMask(ArrayRef<int> Mask,
2429 unsigned EltSizeInBits,
2430 unsigned MinSubElts, unsigned MaxSubElts,
2431 unsigned &NumSubElts,
2432 unsigned &RotateAmt);
2433
2434 // Methods for support type inquiry through isa, cast, and dyn_cast:
2435 static bool classof(const Instruction *I) {
2436 return I->getOpcode() == Instruction::ShuffleVector;
2437 }
2438 static bool classof(const Value *V) {
2440 }
2441};
2442
2443template <>
2445 : public FixedNumOperandTraits<ShuffleVectorInst, 2> {};
2446
2448
2449//===----------------------------------------------------------------------===//
2450// ExtractValueInst Class
2451//===----------------------------------------------------------------------===//
2452
2453/// This instruction extracts a struct member or array
2454/// element value from an aggregate value.
2455///
2456class ExtractValueInst : public UnaryInstruction {
2458
2459 ExtractValueInst(const ExtractValueInst &EVI);
2460
2461 /// Constructors - Create a extractvalue instruction with a base aggregate
2462 /// value and a list of indices. The first and second ctor can optionally
2463 /// insert before an existing instruction, the third appends the new
2464 /// instruction to the specified BasicBlock.
2465 inline ExtractValueInst(Value *Agg, ArrayRef<unsigned> Idxs,
2466 const Twine &NameStr, InsertPosition InsertBefore);
2467
2468 LLVM_ABI void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
2469
2470protected:
2471 // Note: Instruction needs to be a friend here to call cloneImpl.
2472 friend class Instruction;
2473
2474 LLVM_ABI ExtractValueInst *cloneImpl() const;
2475
2476public:
2477 static ExtractValueInst *Create(Value *Agg, ArrayRef<unsigned> Idxs,
2478 const Twine &NameStr = "",
2479 InsertPosition InsertBefore = nullptr) {
2480 return new
2481 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
2482 }
2483
2484 /// Returns the type of the element that would be extracted
2485 /// with an extractvalue instruction with the specified parameters.
2486 ///
2487 /// Null is returned if the indices are invalid for the specified type.
2488 LLVM_ABI static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
2489
2490 using idx_iterator = const unsigned*;
2491
2492 inline idx_iterator idx_begin() const { return Indices.begin(); }
2493 inline idx_iterator idx_end() const { return Indices.end(); }
2495 return make_range(idx_begin(), idx_end());
2496 }
2497
2499 return getOperand(0);
2500 }
2502 return getOperand(0);
2503 }
2504 static unsigned getAggregateOperandIndex() {
2505 return 0U; // get index for modifying correct operand
2506 }
2507
2509 return Indices;
2510 }
2511
2512 unsigned getNumIndices() const {
2513 return (unsigned)Indices.size();
2514 }
2515
2516 bool hasIndices() const {
2517 return true;
2518 }
2519
2520 // Methods for support type inquiry through isa, cast, and dyn_cast:
2521 static bool classof(const Instruction *I) {
2522 return I->getOpcode() == Instruction::ExtractValue;
2523 }
2524 static bool classof(const Value *V) {
2526 }
2527};
2528
2529ExtractValueInst::ExtractValueInst(Value *Agg, ArrayRef<unsigned> Idxs,
2530 const Twine &NameStr,
2531 InsertPosition InsertBefore)
2532 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
2533 ExtractValue, Agg, InsertBefore) {
2534 init(Idxs, NameStr);
2535}
2536
2537//===----------------------------------------------------------------------===//
2538// InsertValueInst Class
2539//===----------------------------------------------------------------------===//
2540
2541/// This instruction inserts a struct field of array element
2542/// value into an aggregate value.
2543///
2544class InsertValueInst : public Instruction {
2545 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
2546
2548
2549 InsertValueInst(const InsertValueInst &IVI);
2550
2551 /// Constructors - Create a insertvalue instruction with a base aggregate
2552 /// value, a value to insert, and a list of indices. The first and second ctor
2553 /// can optionally insert before an existing instruction, the third appends
2554 /// the new instruction to the specified BasicBlock.
2555 inline InsertValueInst(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
2556 const Twine &NameStr, InsertPosition InsertBefore);
2557
2558 /// Constructors - These three constructors are convenience methods because
2559 /// one and two index insertvalue instructions are so common.
2560 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
2561 const Twine &NameStr = "",
2562 InsertPosition InsertBefore = nullptr);
2563
2564 LLVM_ABI void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
2565 const Twine &NameStr);
2566
2567protected:
2568 // Note: Instruction needs to be a friend here to call cloneImpl.
2569 friend class Instruction;
2570
2571 LLVM_ABI InsertValueInst *cloneImpl() const;
2572
2573public:
2574 // allocate space for exactly two operands
2575 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
2576 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
2577
2578 static InsertValueInst *Create(Value *Agg, Value *Val,
2579 ArrayRef<unsigned> Idxs,
2580 const Twine &NameStr = "",
2581 InsertPosition InsertBefore = nullptr) {
2582 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
2583 }
2584
2585 /// Transparently provide more efficient getOperand methods.
2587
2588 using idx_iterator = const unsigned*;
2589
2590 inline idx_iterator idx_begin() const { return Indices.begin(); }
2591 inline idx_iterator idx_end() const { return Indices.end(); }
2593 return make_range(idx_begin(), idx_end());
2594 }
2595
2597 return getOperand(0);
2598 }
2600 return getOperand(0);
2601 }
2602 static unsigned getAggregateOperandIndex() {
2603 return 0U; // get index for modifying correct operand
2604 }
2605
2607 return getOperand(1);
2608 }
2610 return getOperand(1);
2611 }
2613 return 1U; // get index for modifying correct operand
2614 }
2615
2617 return Indices;
2618 }
2619
2620 unsigned getNumIndices() const {
2621 return (unsigned)Indices.size();
2622 }
2623
2624 bool hasIndices() const {
2625 return true;
2626 }
2627
2628 // Methods for support type inquiry through isa, cast, and dyn_cast:
2629 static bool classof(const Instruction *I) {
2630 return I->getOpcode() == Instruction::InsertValue;
2631 }
2632 static bool classof(const Value *V) {
2634 }
2635};
2636
2637template <>
2639 public FixedNumOperandTraits<InsertValueInst, 2> {
2640};
2641
2642InsertValueInst::InsertValueInst(Value *Agg, Value *Val,
2643 ArrayRef<unsigned> Idxs, const Twine &NameStr,
2644 InsertPosition InsertBefore)
2645 : Instruction(Agg->getType(), InsertValue, AllocMarker, InsertBefore) {
2646 init(Agg, Val, Idxs, NameStr);
2647}
2648
2649DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
2650
2651//===----------------------------------------------------------------------===//
2652// PHINode Class
2653//===----------------------------------------------------------------------===//
2654
2655// PHINode - The PHINode class is used to represent the magical mystical PHI
2656// node, that can not exist in nature, but can be synthesized in a computer
2657// scientist's overactive imagination.
2658//
2659class PHINode : public Instruction {
2660 constexpr static HungOffOperandsAllocMarker AllocMarker{};
2661
2662 /// The number of operands actually allocated. NumOperands is
2663 /// the number actually in use.
2664 unsigned ReservedSpace;
2665
2666 PHINode(const PHINode &PN);
2667
2668 explicit PHINode(Type *Ty, unsigned NumReservedValues,
2669 const Twine &NameStr = "",
2670 InsertPosition InsertBefore = nullptr)
2671 : Instruction(Ty, Instruction::PHI, AllocMarker, InsertBefore),
2672 ReservedSpace(NumReservedValues) {
2673 setName(NameStr);
2674 allocHungoffUses(ReservedSpace);
2675 }
2676
2677protected:
2678 // Note: Instruction needs to be a friend here to call cloneImpl.
2679 friend class Instruction;
2680
2681 LLVM_ABI PHINode *cloneImpl() const;
2682
2683 // allocHungoffUses - this is more complicated than the generic
2684 // User::allocHungoffUses, because we have to allocate Uses for the incoming
2685 // values and pointers to the incoming blocks, all in one allocation.
2686 void allocHungoffUses(unsigned N) {
2687 User::allocHungoffUses(N, /*WithExtraValues=*/true);
2688 }
2689
2690public:
2691 /// Constructors - NumReservedValues is a hint for the number of incoming
2692 /// edges that this phi node will have (use 0 if you really have no idea).
2693 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2694 const Twine &NameStr = "",
2695 InsertPosition InsertBefore = nullptr) {
2696 return new (AllocMarker)
2697 PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2698 }
2699
2700 /// Provide fast operand accessors
2702
2703 // Block iterator interface. This provides access to the list of incoming
2704 // basic blocks, which parallels the list of incoming values.
2705 // Please note that we are not providing non-const iterators for blocks to
2706 // force all updates go through an interface function.
2707
2710
2712 return reinterpret_cast<const_block_iterator>(op_begin() + ReservedSpace);
2713 }
2714
2716 return block_begin() + getNumOperands();
2717 }
2718
2722
2724
2726
2727 /// Return the number of incoming edges
2728 ///
2729 unsigned getNumIncomingValues() const { return getNumOperands(); }
2730
2731 /// Return incoming value number x
2732 ///
2733 Value *getIncomingValue(unsigned i) const {
2734 return getOperand(i);
2735 }
2736 void setIncomingValue(unsigned i, Value *V) {
2737 assert(V && "PHI node got a null value!");
2738 assert(getType() == V->getType() &&
2739 "All operands to PHI node must be the same type as the PHI node!");
2740 setOperand(i, V);
2741 }
2742
2743 static unsigned getOperandNumForIncomingValue(unsigned i) {
2744 return i;
2745 }
2746
2747 static unsigned getIncomingValueNumForOperand(unsigned i) {
2748 return i;
2749 }
2750
2751 /// Return incoming basic block number @p i.
2752 ///
2753 BasicBlock *getIncomingBlock(unsigned i) const {
2754 return block_begin()[i];
2755 }
2756
2757 /// Return incoming basic block corresponding
2758 /// to an operand of the PHI.
2759 ///
2761 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2762 return getIncomingBlock(unsigned(&U - op_begin()));
2763 }
2764
2765 /// Return incoming basic block corresponding
2766 /// to value use iterator.
2767 ///
2771
2772 void setIncomingBlock(unsigned i, BasicBlock *BB) {
2773 const_cast<block_iterator>(block_begin())[i] = BB;
2774 }
2775
2776 /// Copies the basic blocks from \p BBRange to the incoming basic block list
2777 /// of this PHINode, starting at \p ToIdx.
2779 uint32_t ToIdx = 0) {
2780 copy(BBRange, const_cast<block_iterator>(block_begin()) + ToIdx);
2781 }
2782
2783 /// Replace every incoming basic block \p Old to basic block \p New.
2785 assert(New && Old && "PHI node got a null basic block!");
2786 for (unsigned Op = 0, NumOps = getNumOperands(); Op != NumOps; ++Op)
2787 if (getIncomingBlock(Op) == Old)
2788 setIncomingBlock(Op, New);
2789 }
2790
2791 /// Add an incoming value to the end of the PHI list
2792 ///
2794 if (getNumOperands() == ReservedSpace)
2795 growOperands(); // Get more space!
2796 // Initialize some new operands.
2800 }
2801
2802 /// Remove an incoming value. This is useful if a
2803 /// predecessor basic block is deleted. The value removed is returned.
2804 ///
2805 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2806 /// is true), the PHI node is destroyed and any uses of it are replaced with
2807 /// dummy values. The only time there should be zero incoming values to a PHI
2808 /// node is when the block is dead, so this strategy is sound.
2809 LLVM_ABI Value *removeIncomingValue(unsigned Idx,
2810 bool DeletePHIIfEmpty = true);
2811
2812 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2813 int Idx = getBasicBlockIndex(BB);
2814 assert(Idx >= 0 && "Invalid basic block argument to remove!");
2815 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2816 }
2817
2818 /// Remove all incoming values for which the predicate returns true.
2819 /// The predicate accepts the incoming value index.
2820 LLVM_ABI void removeIncomingValueIf(function_ref<bool(unsigned)> Predicate,
2821 bool DeletePHIIfEmpty = true);
2822
2823 /// Return the first index of the specified basic
2824 /// block in the value list for this PHI. Returns -1 if no instance.
2825 ///
2826 int getBasicBlockIndex(const BasicBlock *BB) const {
2827 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2828 if (block_begin()[i] == BB)
2829 return i;
2830 return -1;
2831 }
2832
2834 int Idx = getBasicBlockIndex(BB);
2835 assert(Idx >= 0 && "Invalid basic block argument!");
2836 return getIncomingValue(Idx);
2837 }
2838
2839 /// Set every incoming value(s) for block \p BB to \p V.
2841 assert(BB && "PHI node got a null basic block!");
2842 bool Found = false;
2843 for (unsigned Op = 0, NumOps = getNumOperands(); Op != NumOps; ++Op)
2844 if (getIncomingBlock(Op) == BB) {
2845 Found = true;
2846 setIncomingValue(Op, V);
2847 }
2848 (void)Found;
2849 assert(Found && "Invalid basic block argument to set!");
2850 }
2851
2852 /// If the specified PHI node always merges together the
2853 /// same value, return the value, otherwise return null.
2854 LLVM_ABI Value *hasConstantValue() const;
2855
2856 /// Whether the specified PHI node always merges
2857 /// together the same value, assuming undefs are equal to a unique
2858 /// non-undef value.
2859 LLVM_ABI bool hasConstantOrUndefValue() const;
2860
2861 /// If the PHI node is complete which means all of its parent's predecessors
2862 /// have incoming value in this PHI, return true, otherwise return false.
2863 bool isComplete() const {
2865 [this](const BasicBlock *Pred) {
2866 return getBasicBlockIndex(Pred) >= 0;
2867 });
2868 }
2869
2870 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2871 static bool classof(const Instruction *I) {
2872 return I->getOpcode() == Instruction::PHI;
2873 }
2874 static bool classof(const Value *V) {
2876 }
2877
2878private:
2879 LLVM_ABI void growOperands();
2880};
2881
2882template <> struct OperandTraits<PHINode> : public HungoffOperandTraits {};
2883
2885
2886//===----------------------------------------------------------------------===//
2887// LandingPadInst Class
2888//===----------------------------------------------------------------------===//
2889
2890//===---------------------------------------------------------------------------
2891/// The landingpad instruction holds all of the information
2892/// necessary to generate correct exception handling. The landingpad instruction
2893/// cannot be moved from the top of a landing pad block, which itself is
2894/// accessible only from the 'unwind' edge of an invoke. This uses the
2895/// SubclassData field in Value to store whether or not the landingpad is a
2896/// cleanup.
2897///
2898class LandingPadInst : public Instruction {
2899 using CleanupField = BoolBitfieldElementT<0>;
2900
2901 constexpr static HungOffOperandsAllocMarker AllocMarker{};
2902
2903 /// The number of operands actually allocated. NumOperands is
2904 /// the number actually in use.
2905 unsigned ReservedSpace;
2906
2907 LandingPadInst(const LandingPadInst &LP);
2908
2909public:
2911
2912private:
2913 explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
2914 const Twine &NameStr, InsertPosition InsertBefore);
2915
2916 // Allocate space for exactly zero operands.
2917 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
2918
2919 LLVM_ABI void growOperands(unsigned Size);
2920 void init(unsigned NumReservedValues, const Twine &NameStr);
2921
2922protected:
2923 // Note: Instruction needs to be a friend here to call cloneImpl.
2924 friend class Instruction;
2925
2926 LLVM_ABI LandingPadInst *cloneImpl() const;
2927
2928public:
2929 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
2930
2931 /// Constructors - NumReservedClauses is a hint for the number of incoming
2932 /// clauses that this landingpad will have (use 0 if you really have no idea).
2933 LLVM_ABI static LandingPadInst *Create(Type *RetTy,
2934 unsigned NumReservedClauses,
2935 const Twine &NameStr = "",
2936 InsertPosition InsertBefore = nullptr);
2937
2938 /// Provide fast operand accessors
2940
2941 /// Return 'true' if this landingpad instruction is a
2942 /// cleanup. I.e., it should be run when unwinding even if its landing pad
2943 /// doesn't catch the exception.
2944 bool isCleanup() const { return getSubclassData<CleanupField>(); }
2945
2946 /// Indicate that this landingpad instruction is a cleanup.
2948
2949 /// Add a catch or filter clause to the landing pad.
2950 LLVM_ABI void addClause(Constant *ClauseVal);
2951
2952 /// Get the value of the clause at index Idx. Use isCatch/isFilter to
2953 /// determine what type of clause this is.
2954 Constant *getClause(unsigned Idx) const {
2955 return cast<Constant>(getOperandList()[Idx]);
2956 }
2957
2958 /// Return 'true' if the clause and index Idx is a catch clause.
2959 bool isCatch(unsigned Idx) const {
2960 return !isa<ArrayType>(getOperandList()[Idx]->getType());
2961 }
2962
2963 /// Return 'true' if the clause and index Idx is a filter clause.
2964 bool isFilter(unsigned Idx) const {
2965 return isa<ArrayType>(getOperandList()[Idx]->getType());
2966 }
2967
2968 /// Get the number of clauses for this landing pad.
2969 unsigned getNumClauses() const { return getNumOperands(); }
2970
2971 /// Grow the size of the operand list to accommodate the new
2972 /// number of clauses.
2973 void reserveClauses(unsigned Size) { growOperands(Size); }
2974
2975 // Methods for support type inquiry through isa, cast, and dyn_cast:
2976 static bool classof(const Instruction *I) {
2977 return I->getOpcode() == Instruction::LandingPad;
2978 }
2979 static bool classof(const Value *V) {
2981 }
2982};
2983
2984template <>
2986
2988
2989//===----------------------------------------------------------------------===//
2990// ReturnInst Class
2991//===----------------------------------------------------------------------===//
2992
2993//===---------------------------------------------------------------------------
2994/// Return a value (possibly void), from a function. Execution
2995/// does not continue in this function any longer.
2996///
2997class ReturnInst : public Instruction {
2998 ReturnInst(const ReturnInst &RI, AllocInfo AllocInfo);
2999
3000private:
3001 // ReturnInst constructors:
3002 // ReturnInst() - 'ret void' instruction
3003 // ReturnInst( null) - 'ret void' instruction
3004 // ReturnInst(Value* X) - 'ret X' instruction
3005 // ReturnInst(null, Iterator It) - 'ret void' instruction, insert before I
3006 // ReturnInst(Value* X, Iterator It) - 'ret X' instruction, insert before I
3007 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
3008 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
3009 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
3010 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
3011 //
3012 // NOTE: If the Value* passed is of type void then the constructor behaves as
3013 // if it was passed NULL.
3014 LLVM_ABI explicit ReturnInst(LLVMContext &C, Value *retVal,
3016 InsertPosition InsertBefore);
3017
3018protected:
3019 // Note: Instruction needs to be a friend here to call cloneImpl.
3020 friend class Instruction;
3021
3022 LLVM_ABI ReturnInst *cloneImpl() const;
3023
3024public:
3025 static ReturnInst *Create(LLVMContext &C, Value *retVal = nullptr,
3026 InsertPosition InsertBefore = nullptr) {
3027 IntrusiveOperandsAllocMarker AllocMarker{retVal ? 1U : 0U};
3028 return new (AllocMarker) ReturnInst(C, retVal, AllocMarker, InsertBefore);
3029 }
3030
3031 static ReturnInst *Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
3032 IntrusiveOperandsAllocMarker AllocMarker{0};
3033 return new (AllocMarker) ReturnInst(C, nullptr, AllocMarker, InsertAtEnd);
3034 }
3035
3036 /// Provide fast operand accessors
3038
3039 /// Convenience accessor. Returns null if there is no return value.
3041 return getNumOperands() != 0 ? getOperand(0) : nullptr;
3042 }
3043
3050
3051 unsigned getNumSuccessors() const { return 0; }
3052
3053 // Methods for support type inquiry through isa, cast, and dyn_cast:
3054 static bool classof(const Instruction *I) {
3055 return (I->getOpcode() == Instruction::Ret);
3056 }
3057 static bool classof(const Value *V) {
3059 }
3060
3061private:
3062 BasicBlock *getSuccessor(unsigned idx) const {
3063 llvm_unreachable("ReturnInst has no successors!");
3064 }
3065
3066 void setSuccessor(unsigned idx, BasicBlock *B) {
3067 llvm_unreachable("ReturnInst has no successors!");
3068 }
3069};
3070
3071template <>
3072struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {};
3073
3075
3076//===----------------------------------------------------------------------===//
3077// BranchInst Class
3078//===----------------------------------------------------------------------===//
3079
3080//===---------------------------------------------------------------------------
3081/// Conditional or Unconditional Branch instruction.
3082///
3083class LLVM_DEPRECATED("Use UncondBrInst/CondBrInst/Instruction instead", "")
3084 BranchInst : public Instruction {
3085protected:
3086 BranchInst(Type *Ty, unsigned Opcode, AllocInfo AllocInfo,
3087 InsertPosition InsertBefore = nullptr)
3088 : Instruction(Ty, Opcode, AllocInfo, InsertBefore) {}
3089
3090public:
3091 LLVM_DEPRECATED("Use UncondBrInst::Create instead", "UncondBrInst::Create")
3092 static BranchInst *Create(BasicBlock *IfTrue,
3093 InsertPosition InsertBefore = nullptr);
3094
3095 LLVM_DEPRECATED("Use CondBrInst::Create instead", "CondBrInst::Create")
3096 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
3097 Value *Cond, InsertPosition InsertBefore = nullptr);
3098
3099 /// Transparently provide more efficient getOperand methods.
3101
3102 // Defined out-of-line below to access CondBrInst.
3103 LLVM_DEPRECATED("Use isa<UncondBrInst> instead", "isa<UncondBrInst>")
3104 bool isUnconditional() const;
3105 LLVM_DEPRECATED("Use isa<CondBrInst> instead", "isa<CondBrInst>")
3106 bool isConditional() const;
3107
3108 LLVM_DEPRECATED("Cast to CondBrInst", "")
3109 Value *getCondition() const;
3110 LLVM_DEPRECATED("Cast to CondBrInst", "")
3111 void setCondition(Value *V);
3112
3113 /// Swap the successors of this branch instruction.
3114 ///
3115 /// Swaps the successors of the branch instruction. This also swaps any
3116 /// branch weight metadata associated with the instruction so that it
3117 /// continues to map correctly to each operand.
3118 LLVM_DEPRECATED("Cast to CondBrInst", "")
3119 void swapSuccessors();
3120
3121 // Methods for support type inquiry through isa, cast, and dyn_cast:
3122 static bool classof(const Instruction *I) {
3123 return (I->getOpcode() == Instruction::UncondBr ||
3124 I->getOpcode() == Instruction::CondBr);
3125 }
3126 static bool classof(const Value *V) {
3127 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3128 }
3129};
3130
3131// Suppress deprecation warnings from BranchInst.
3133
3134template <>
3135struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst> {};
3136
3138
3139//===----------------------------------------------------------------------===//
3140// UncondBrInst Class
3141//===----------------------------------------------------------------------===//
3142
3143//===---------------------------------------------------------------------------
3144/// Unconditional Branch instruction.
3145///
3146class UncondBrInst : public BranchInst {
3147 constexpr static IntrusiveOperandsAllocMarker AllocMarker{1};
3148
3149 UncondBrInst(const UncondBrInst &BI);
3150 LLVM_ABI explicit UncondBrInst(BasicBlock *Target,
3151 InsertPosition InsertBefore);
3152
3153protected:
3154 // Note: Instruction needs to be a friend here to call cloneImpl.
3155 friend class Instruction;
3156
3157 LLVM_ABI UncondBrInst *cloneImpl() const;
3158
3159public:
3160 static UncondBrInst *Create(BasicBlock *Target,
3161 InsertPosition InsertBefore = nullptr) {
3162 return new (AllocMarker) UncondBrInst(Target, InsertBefore);
3163 }
3164
3165 /// Transparently provide more efficient getOperand methods.
3167
3168private:
3169 // Hide methods.
3170 using BranchInst::getCondition;
3171 using BranchInst::isConditional;
3172 using BranchInst::isUnconditional;
3173 using BranchInst::setCondition;
3174 using BranchInst::swapSuccessors;
3175
3176public:
3177 unsigned getNumSuccessors() const { return 1; }
3178
3179 BasicBlock *getSuccessor(unsigned i = 0) const {
3180 assert(i == 0 && "Successor # out of range for Branch!");
3182 }
3183
3184 void setSuccessor(BasicBlock *NewSucc) { Op<-1>() = NewSucc; }
3185 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3186 assert(idx == 0 && "Successor # out of range for Branch!");
3187 Op<-1>() = NewSucc;
3188 }
3189
3191 return make_range(succ_iterator(op_begin()), succ_iterator(op_end()));
3192 }
3193
3198
3199 // Methods for support type inquiry through isa, cast, and dyn_cast:
3200 static bool classof(const Instruction *I) {
3201 return (I->getOpcode() == Instruction::UncondBr);
3202 }
3203 static bool classof(const Value *V) {
3205 }
3206};
3207
3208template <>
3210 : public FixedNumOperandTraits<UncondBrInst, 1> {};
3211
3213
3214//===----------------------------------------------------------------------===//
3215// CondBrInst Class
3216//===----------------------------------------------------------------------===//
3217
3218//===---------------------------------------------------------------------------
3219/// Conditional Branch instruction.
3220///
3221class CondBrInst : public BranchInst {
3222 constexpr static IntrusiveOperandsAllocMarker AllocMarker{3};
3223
3224 CondBrInst(const CondBrInst &BI);
3225 LLVM_ABI CondBrInst(Value *Cond, BasicBlock *IfTrue, BasicBlock *IfFalse,
3226 InsertPosition InsertBefore);
3227
3228 void AssertOK();
3229
3230protected:
3231 // Note: Instruction needs to be a friend here to call cloneImpl.
3232 friend class Instruction;
3233
3234 LLVM_ABI CondBrInst *cloneImpl() const;
3235
3236private:
3237 // Hide methods.
3238 using BranchInst::isConditional;
3239 using BranchInst::isUnconditional;
3240
3241public:
3242 static CondBrInst *Create(Value *Cond, BasicBlock *IfTrue,
3243 BasicBlock *IfFalse,
3244 InsertPosition InsertBefore = nullptr) {
3245 return new (AllocMarker) CondBrInst(Cond, IfTrue, IfFalse, InsertBefore);
3246 }
3247
3248 /// Transparently provide more efficient getOperand methods.
3250
3251 Value *getCondition() const { return Op<-3>(); }
3252 void setCondition(Value *V) { Op<-3>() = V; }
3253
3254 unsigned getNumSuccessors() const { return 2; }
3255
3256 BasicBlock *getSuccessor(unsigned i) const {
3257 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
3258 return cast_or_null<BasicBlock>((&Op<-2>() + i)->get());
3259 }
3260
3261 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3262 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
3263 *(&Op<-2>() + idx) = NewSucc;
3264 }
3265
3266 /// Swap the successors of this branch instruction.
3267 ///
3268 /// Swaps the successors of the branch instruction. This also swaps any
3269 /// branch weight metadata associated with the instruction so that it
3270 /// continues to map correctly to each operand.
3271 LLVM_ABI void swapSuccessors();
3272
3274 return make_range(succ_iterator(std::next(op_begin())),
3275 succ_iterator(op_end()));
3276 }
3277
3279 return make_range(const_succ_iterator(std::next(op_begin())),
3280 const_succ_iterator(op_end()));
3281 }
3282
3283 // Methods for support type inquiry through isa, cast, and dyn_cast:
3284 static bool classof(const Instruction *I) {
3285 return (I->getOpcode() == Instruction::CondBr);
3286 }
3287 static bool classof(const Value *V) {
3289 }
3290};
3291
3292template <>
3293struct OperandTraits<CondBrInst> : public FixedNumOperandTraits<CondBrInst, 3> {
3294};
3295
3297
3298//===----------------------------------------------------------------------===//
3299// BranchInst Out-Of-Line Functions
3300//===----------------------------------------------------------------------===//
3301
3302inline BranchInst *BranchInst::Create(BasicBlock *IfTrue,
3303 InsertPosition InsertBefore) {
3304 return UncondBrInst::Create(IfTrue, InsertBefore);
3305}
3306
3307inline BranchInst *BranchInst::Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
3308 Value *Cond,
3309 InsertPosition InsertBefore) {
3310 return CondBrInst::Create(Cond, IfTrue, IfFalse, InsertBefore);
3311}
3312
3313inline bool BranchInst::isConditional() const { return isa<CondBrInst>(this); }
3314inline bool BranchInst::isUnconditional() const {
3315 return isa<UncondBrInst>(this);
3316}
3317
3318inline Value *BranchInst::getCondition() const {
3319 return cast<CondBrInst>(this)->getCondition();
3320}
3321inline void BranchInst::setCondition(Value *V) {
3322 cast<CondBrInst>(this)->setCondition(V);
3323}
3324
3325inline void BranchInst::swapSuccessors() {
3326 cast<CondBrInst>(this)->swapSuccessors();
3327}
3328
3329// Suppress deprecation warnings from BranchInst.
3331
3332//===----------------------------------------------------------------------===//
3333// SwitchInst Class
3334//===----------------------------------------------------------------------===//
3335
3336//===---------------------------------------------------------------------------
3337/// Multiway switch
3338///
3339class SwitchInst : public Instruction {
3340 constexpr static HungOffOperandsAllocMarker AllocMarker{};
3341
3342 unsigned ReservedSpace;
3343
3344 // Operand[0] = Value to switch on
3345 // Operand[1] = Default basic block destination
3346 // Operand[n] = BasicBlock to go to on match
3347 // Values are stored after the Uses similar to PHINode's basic blocks.
3348 SwitchInst(const SwitchInst &SI);
3349
3350 /// Create a new switch instruction, specifying a value to switch on and a
3351 /// default destination. The number of additional cases can be specified here
3352 /// to make memory allocation more efficient. This constructor can also
3353 /// auto-insert before another instruction.
3354 LLVM_ABI SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
3355 InsertPosition InsertBefore);
3356
3357 // allocate space for exactly zero operands
3358 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
3359
3360 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
3361 void growOperands();
3362
3363protected:
3364 // Note: Instruction needs to be a friend here to call cloneImpl.
3365 friend class Instruction;
3366
3367 LLVM_ABI SwitchInst *cloneImpl() const;
3368
3369 void allocHungoffUses(unsigned N) {
3370 User::allocHungoffUses(N, /*WithExtraValues=*/true);
3371 }
3372
3373 ConstantInt *const *case_values() const {
3374 return reinterpret_cast<ConstantInt *const *>(op_begin() + ReservedSpace);
3375 }
3377 return reinterpret_cast<ConstantInt **>(op_begin() + ReservedSpace);
3378 }
3379
3380public:
3381 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
3382
3383 // -2
3384 static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
3385
3386 template <typename CaseHandleT> class CaseIteratorImpl;
3387
3388 /// A handle to a particular switch case. It exposes a convenient interface
3389 /// to both the case value and the successor block.
3390 ///
3391 /// We define this as a template and instantiate it to form both a const and
3392 /// non-const handle.
3393 template <typename SwitchInstT, typename ConstantIntT, typename BasicBlockT>
3395 // Directly befriend both const and non-const iterators.
3396 friend class SwitchInst::CaseIteratorImpl<
3397 CaseHandleImpl<SwitchInstT, ConstantIntT, BasicBlockT>>;
3398
3399 protected:
3400 // Expose the switch type we're parameterized with to the iterator.
3401 using SwitchInstType = SwitchInstT;
3402
3403 SwitchInstT *SI;
3405
3406 CaseHandleImpl() = default;
3408
3409 public:
3410 /// Resolves case value for current case.
3411 ConstantIntT *getCaseValue() const {
3412 assert((unsigned)Index < SI->getNumCases() &&
3413 "Index out the number of cases.");
3414 return SI->case_values()[Index];
3415 }
3416
3417 /// Resolves successor for current case.
3418 BasicBlockT *getCaseSuccessor() const {
3419 assert(((unsigned)Index < SI->getNumCases() ||
3420 (unsigned)Index == DefaultPseudoIndex) &&
3421 "Index out the number of cases.");
3422 return SI->getSuccessor(getSuccessorIndex());
3423 }
3424
3425 /// Returns number of current case.
3426 unsigned getCaseIndex() const { return Index; }
3427
3428 /// Returns successor index for current case successor.
3429 unsigned getSuccessorIndex() const {
3430 assert(((unsigned)Index == DefaultPseudoIndex ||
3431 (unsigned)Index < SI->getNumCases()) &&
3432 "Index out the number of cases.");
3433 return (unsigned)Index != DefaultPseudoIndex ? Index + 1 : 0;
3434 }
3435
3436 bool operator==(const CaseHandleImpl &RHS) const {
3437 assert(SI == RHS.SI && "Incompatible operators.");
3438 return Index == RHS.Index;
3439 }
3440 };
3441
3444
3446 : public CaseHandleImpl<SwitchInst, ConstantInt, BasicBlock> {
3448
3449 public:
3451
3452 /// Sets the new value for current case.
3453 void setValue(ConstantInt *V) const {
3454 assert((unsigned)Index < SI->getNumCases() &&
3455 "Index out the number of cases.");
3456 SI->case_values()[Index] = V;
3457 }
3458
3459 /// Sets the new successor for current case.
3460 void setSuccessor(BasicBlock *S) const {
3461 SI->setSuccessor(getSuccessorIndex(), S);
3462 }
3463 };
3464
3465 template <typename CaseHandleT>
3467 : public iterator_facade_base<CaseIteratorImpl<CaseHandleT>,
3468 std::random_access_iterator_tag,
3469 const CaseHandleT> {
3470 using SwitchInstT = typename CaseHandleT::SwitchInstType;
3471
3472 CaseHandleT Case;
3473
3474 public:
3475 /// Default constructed iterator is in an invalid state until assigned to
3476 /// a case for a particular switch.
3477 CaseIteratorImpl() = default;
3478
3479 /// Initializes case iterator for given SwitchInst and for given
3480 /// case number.
3481 CaseIteratorImpl(SwitchInstT *SI, unsigned CaseNum) : Case(SI, CaseNum) {}
3482
3483 /// Initializes case iterator for given SwitchInst and for given
3484 /// successor index.
3486 unsigned SuccessorIndex) {
3487 assert(SuccessorIndex < SI->getNumSuccessors() &&
3488 "Successor index # out of range!");
3489 return SuccessorIndex != 0 ? CaseIteratorImpl(SI, SuccessorIndex - 1)
3491 }
3492
3493 /// Support converting to the const variant. This will be a no-op for const
3494 /// variant.
3496 return CaseIteratorImpl<ConstCaseHandle>(Case.SI, Case.Index);
3497 }
3498
3500 // Check index correctness after addition.
3501 // Note: Index == getNumCases() means end().
3502 assert(Case.Index + N >= 0 &&
3503 (unsigned)(Case.Index + N) <= Case.SI->getNumCases() &&
3504 "Case.Index out the number of cases.");
3505 Case.Index += N;
3506 return *this;
3507 }
3509 // Check index correctness after subtraction.
3510 // Note: Case.Index == getNumCases() means end().
3511 assert(Case.Index - N >= 0 &&
3512 (unsigned)(Case.Index - N) <= Case.SI->getNumCases() &&
3513 "Case.Index out the number of cases.");
3514 Case.Index -= N;
3515 return *this;
3516 }
3518 assert(Case.SI == RHS.Case.SI && "Incompatible operators.");
3519 return Case.Index - RHS.Case.Index;
3520 }
3521 bool operator==(const CaseIteratorImpl &RHS) const {
3522 return Case == RHS.Case;
3523 }
3524 bool operator<(const CaseIteratorImpl &RHS) const {
3525 assert(Case.SI == RHS.Case.SI && "Incompatible operators.");
3526 return Case.Index < RHS.Case.Index;
3527 }
3528 const CaseHandleT &operator*() const { return Case; }
3529 };
3530
3533
3534 static SwitchInst *Create(Value *Value, BasicBlock *Default,
3535 unsigned NumCases,
3536 InsertPosition InsertBefore = nullptr) {
3537 return new SwitchInst(Value, Default, NumCases, InsertBefore);
3538 }
3539
3540 /// Provide fast operand accessors
3542
3543 // Accessor Methods for Switch stmt
3544 Value *getCondition() const { return getOperand(0); }
3545 void setCondition(Value *V) { setOperand(0, V); }
3546
3548 return cast<BasicBlock>(getOperand(1));
3549 }
3550
3551 /// Returns true if the default branch must result in immediate undefined
3552 /// behavior, false otherwise.
3554 return isa<UnreachableInst>(getDefaultDest()->getFirstNonPHIOrDbg());
3555 }
3556
3557 void setDefaultDest(BasicBlock *DefaultCase) {
3558 setOperand(1, reinterpret_cast<Value*>(DefaultCase));
3559 }
3560
3561 /// Return the number of 'cases' in this switch instruction, excluding the
3562 /// default case.
3563 unsigned getNumCases() const { return getNumOperands() - 2; }
3564
3565 /// Returns a read/write iterator that points to the first case in the
3566 /// SwitchInst.
3568 return CaseIt(this, 0);
3569 }
3570
3571 /// Returns a read-only iterator that points to the first case in the
3572 /// SwitchInst.
3574 return ConstCaseIt(this, 0);
3575 }
3576
3577 /// Returns a read/write iterator that points one past the last in the
3578 /// SwitchInst.
3580 return CaseIt(this, getNumCases());
3581 }
3582
3583 /// Returns a read-only iterator that points one past the last in the
3584 /// SwitchInst.
3586 return ConstCaseIt(this, getNumCases());
3587 }
3588
3589 /// Iteration adapter for range-for loops.
3593
3594 /// Constant iteration adapter for range-for loops.
3598
3599 /// Returns an iterator that points to the default case.
3600 /// Note: this iterator allows to resolve successor only. Attempt
3601 /// to resolve case value causes an assertion.
3602 /// Also note, that increment and decrement also causes an assertion and
3603 /// makes iterator invalid.
3605 return CaseIt(this, DefaultPseudoIndex);
3606 }
3608 return ConstCaseIt(this, DefaultPseudoIndex);
3609 }
3610
3611 /// Search all of the case values for the specified constant. If it is
3612 /// explicitly handled, return the case iterator of it, otherwise return
3613 /// default case iterator to indicate that it is handled by the default
3614 /// handler.
3616 return CaseIt(
3617 this,
3618 const_cast<const SwitchInst *>(this)->findCaseValue(C)->getCaseIndex());
3619 }
3621 ConstCaseIt I = llvm::find_if(cases(), [C](const ConstCaseHandle &Case) {
3622 return Case.getCaseValue() == C;
3623 });
3624 if (I != case_end())
3625 return I;
3626
3627 return case_default();
3628 }
3629
3630 /// Finds the unique case value for a given successor. Returns null if the
3631 /// successor is not found, not unique, or is the default case.
3633 if (BB == getDefaultDest())
3634 return nullptr;
3635
3636 ConstantInt *CI = nullptr;
3637 for (auto Case : cases()) {
3638 if (Case.getCaseSuccessor() != BB)
3639 continue;
3640
3641 if (CI)
3642 return nullptr; // Multiple cases lead to BB.
3643
3644 CI = Case.getCaseValue();
3645 }
3646
3647 return CI;
3648 }
3649
3650 /// Add an entry to the switch instruction.
3651 /// Note:
3652 /// This action invalidates case_end(). Old case_end() iterator will
3653 /// point to the added case.
3654 LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest);
3655
3656 /// This method removes the specified case and its successor from the switch
3657 /// instruction. Note that this operation may reorder the remaining cases at
3658 /// index idx and above.
3659 /// Note:
3660 /// This action invalidates iterators for all cases following the one removed,
3661 /// including the case_end() iterator. It returns an iterator for the next
3662 /// case.
3664
3666 return make_range(std::next(op_begin()), op_end());
3667 }
3669 return make_range(std::next(op_begin()), op_end());
3670 }
3671
3672 unsigned getNumSuccessors() const { return getNumOperands() - 1; }
3673 BasicBlock *getSuccessor(unsigned idx) const {
3674 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
3675 return cast<BasicBlock>(getOperand(idx + 1));
3676 }
3677 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3678 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
3679 setOperand(idx + 1, NewSucc);
3680 }
3681
3682 // Methods for support type inquiry through isa, cast, and dyn_cast:
3683 static bool classof(const Instruction *I) {
3684 return I->getOpcode() == Instruction::Switch;
3685 }
3686 static bool classof(const Value *V) {
3688 }
3689};
3690
3691/// A wrapper class to simplify modification of SwitchInst cases along with
3692/// their prof branch_weights metadata.
3694 SwitchInst &SI;
3695 std::optional<SmallVector<uint32_t, 8>> Weights;
3696 bool Changed = false;
3697
3698protected:
3699 LLVM_ABI void init();
3700
3701public:
3702 using CaseWeightOpt = std::optional<uint32_t>;
3703 SwitchInst *operator->() { return &SI; }
3704 SwitchInst &operator*() { return SI; }
3705 operator SwitchInst *() { return &SI; }
3706
3708
3710 if (Changed && Weights.has_value()) {
3711 if (Weights->size() >= 2) {
3712 setBranchWeights(SI, Weights.value(), /*IsExpected=*/false);
3713 return;
3714 }
3715 // In some cases while simplifying switch instructions, we end up with
3716 // degenerate switch instructions (e.g., only contains the default case).
3717 // We drop profile metadata in such cases rather than updating given it
3718 // does not convey anything.
3719 SI.setMetadata(LLVMContext::MD_prof, nullptr);
3720 }
3721 }
3722
3723 /// Delegate the call to the underlying SwitchInst::removeCase() and remove
3724 /// correspondent branch weight.
3726
3727 /// Replace the default destination by given case. Delegate the call to
3728 /// the underlying SwitchInst::setDefaultDest and remove correspondent branch
3729 /// weight.
3731
3732 /// Delegate the call to the underlying SwitchInst::addCase() and set the
3733 /// specified branch weight for the added case.
3734 LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest, CaseWeightOpt W);
3735
3736 /// Delegate the call to the underlying SwitchInst::eraseFromParent() and mark
3737 /// this object to not touch the underlying SwitchInst in destructor.
3739
3740 LLVM_ABI void setSuccessorWeight(unsigned idx, CaseWeightOpt W);
3742
3744 unsigned idx);
3745};
3746
3747template <> struct OperandTraits<SwitchInst> : public HungoffOperandTraits {};
3748
3750
3751//===----------------------------------------------------------------------===//
3752// IndirectBrInst Class
3753//===----------------------------------------------------------------------===//
3754
3755//===---------------------------------------------------------------------------
3756/// Indirect Branch Instruction.
3757///
3758class IndirectBrInst : public Instruction {
3759 constexpr static HungOffOperandsAllocMarker AllocMarker{};
3760
3761 unsigned ReservedSpace;
3762
3763 // Operand[0] = Address to jump to
3764 // Operand[n+1] = n-th destination
3765 IndirectBrInst(const IndirectBrInst &IBI);
3766
3767 /// Create a new indirectbr instruction, specifying an
3768 /// Address to jump to. The number of expected destinations can be specified
3769 /// here to make memory allocation more efficient. This constructor can also
3770 /// autoinsert before another instruction.
3771 LLVM_ABI IndirectBrInst(Value *Address, unsigned NumDests,
3772 InsertPosition InsertBefore);
3773
3774 // allocate space for exactly zero operands
3775 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
3776
3777 void init(Value *Address, unsigned NumDests);
3778 void growOperands();
3779
3780protected:
3781 // Note: Instruction needs to be a friend here to call cloneImpl.
3782 friend class Instruction;
3783
3784 LLVM_ABI IndirectBrInst *cloneImpl() const;
3785
3786public:
3787 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
3788
3789 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
3790 InsertPosition InsertBefore = nullptr) {
3791 return new IndirectBrInst(Address, NumDests, InsertBefore);
3792 }
3793
3794 /// Provide fast operand accessors.
3796
3797 // Accessor Methods for IndirectBrInst instruction.
3798 Value *getAddress() { return getOperand(0); }
3799 const Value *getAddress() const { return getOperand(0); }
3800 void setAddress(Value *V) { setOperand(0, V); }
3801
3802 /// return the number of possible destinations in this
3803 /// indirectbr instruction.
3804 unsigned getNumDestinations() const { return getNumOperands()-1; }
3805
3806 /// Return the specified destination.
3807 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
3808 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
3809
3810 /// Add a destination.
3811 ///
3812 LLVM_ABI void addDestination(BasicBlock *Dest);
3813
3814 /// This method removes the specified successor from the
3815 /// indirectbr instruction.
3816 LLVM_ABI void removeDestination(unsigned i);
3817
3818 unsigned getNumSuccessors() const { return getNumOperands()-1; }
3819 BasicBlock *getSuccessor(unsigned i) const {
3820 return cast<BasicBlock>(getOperand(i+1));
3821 }
3822 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
3823 setOperand(i + 1, NewSucc);
3824 }
3825
3830
3835
3836 // Methods for support type inquiry through isa, cast, and dyn_cast:
3837 static bool classof(const Instruction *I) {
3838 return I->getOpcode() == Instruction::IndirectBr;
3839 }
3840 static bool classof(const Value *V) {
3842 }
3843};
3844
3845template <>
3847
3849
3850//===----------------------------------------------------------------------===//
3851// InvokeInst Class
3852//===----------------------------------------------------------------------===//
3853
3854/// Invoke instruction. The SubclassData field is used to hold the
3855/// calling convention of the call.
3856///
3857class InvokeInst : public CallBase {
3858 /// The number of operands for this call beyond the called function,
3859 /// arguments, and operand bundles.
3860 static constexpr int NumExtraOperands = 2;
3861
3862 /// The index from the end of the operand array to the normal destination.
3863 static constexpr int NormalDestOpEndIdx = -3;
3864
3865 /// The index from the end of the operand array to the unwind destination.
3866 static constexpr int UnwindDestOpEndIdx = -2;
3867
3868 InvokeInst(const InvokeInst &BI, AllocInfo AllocInfo);
3869
3870 /// Construct an InvokeInst given a range of arguments.
3871 ///
3872 /// Construct an InvokeInst from a range of arguments
3873 inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3874 BasicBlock *IfException, ArrayRef<Value *> Args,
3876 const Twine &NameStr, InsertPosition InsertBefore);
3877
3878 LLVM_ABI void init(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3879 BasicBlock *IfException, ArrayRef<Value *> Args,
3880 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
3881
3882 /// Compute the number of operands to allocate.
3883 static unsigned ComputeNumOperands(unsigned NumArgs,
3884 size_t NumBundleInputs = 0) {
3885 // We need one operand for the called function, plus our extra operands and
3886 // the input operand counts provided.
3887 return 1 + NumExtraOperands + NumArgs + unsigned(NumBundleInputs);
3888 }
3889
3890protected:
3891 // Note: Instruction needs to be a friend here to call cloneImpl.
3892 friend class Instruction;
3893
3894 LLVM_ABI InvokeInst *cloneImpl() const;
3895
3896public:
3897 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3898 BasicBlock *IfException, ArrayRef<Value *> Args,
3899 const Twine &NameStr,
3900 InsertPosition InsertBefore = nullptr) {
3901 IntrusiveOperandsAllocMarker AllocMarker{
3902 ComputeNumOperands(unsigned(Args.size()))};
3903 return new (AllocMarker) InvokeInst(Ty, Func, IfNormal, IfException, Args,
3904 {}, AllocMarker, NameStr, InsertBefore);
3905 }
3906
3907 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3908 BasicBlock *IfException, ArrayRef<Value *> Args,
3909 ArrayRef<OperandBundleDef> Bundles = {},
3910 const Twine &NameStr = "",
3911 InsertPosition InsertBefore = nullptr) {
3912 IntrusiveOperandsAndDescriptorAllocMarker AllocMarker{
3913 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles)),
3914 unsigned(Bundles.size() * sizeof(BundleOpInfo))};
3915
3916 return new (AllocMarker)
3917 InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, AllocMarker,
3918 NameStr, InsertBefore);
3919 }
3920
3921 static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
3922 BasicBlock *IfException, ArrayRef<Value *> Args,
3923 const Twine &NameStr,
3924 InsertPosition InsertBefore = nullptr) {
3925 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3926 IfException, Args, {}, NameStr, InsertBefore);
3927 }
3928
3929 static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
3930 BasicBlock *IfException, ArrayRef<Value *> Args,
3931 ArrayRef<OperandBundleDef> Bundles = {},
3932 const Twine &NameStr = "",
3933 InsertPosition InsertBefore = nullptr) {
3934 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3935 IfException, Args, Bundles, NameStr, InsertBefore);
3936 }
3937
3938 /// Create a clone of \p II with a different set of operand bundles and
3939 /// insert it before \p InsertBefore.
3940 ///
3941 /// The returned invoke instruction is identical to \p II in every way except
3942 /// that the operand bundles for the new instruction are set to the operand
3943 /// bundles in \p Bundles.
3944 LLVM_ABI static InvokeInst *Create(InvokeInst *II,
3946 InsertPosition InsertPt = nullptr);
3947
3948 // get*Dest - Return the destination basic blocks...
3956 Op<NormalDestOpEndIdx>() = reinterpret_cast<Value *>(B);
3957 }
3959 Op<UnwindDestOpEndIdx>() = reinterpret_cast<Value *>(B);
3960 }
3961
3962 /// Get the landingpad instruction from the landing pad
3963 /// block (the unwind destination).
3964 LLVM_ABI LandingPadInst *getLandingPadInst() const;
3965
3966 BasicBlock *getSuccessor(unsigned i) const {
3967 assert(i < 2 && "Successor # out of range for invoke!");
3968 return i == 0 ? getNormalDest() : getUnwindDest();
3969 }
3970
3971 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
3972 assert(i < 2 && "Successor # out of range for invoke!");
3973 if (i == 0)
3974 setNormalDest(NewSucc);
3975 else
3976 setUnwindDest(NewSucc);
3977 }
3978
3979 unsigned getNumSuccessors() const { return 2; }
3980
3989
3990 /// Updates profile metadata by scaling it by \p S / \p T.
3991 LLVM_ABI void updateProfWeight(uint64_t S, uint64_t T);
3992
3993 // Methods for support type inquiry through isa, cast, and dyn_cast:
3994 static bool classof(const Instruction *I) {
3995 return (I->getOpcode() == Instruction::Invoke);
3996 }
3997 static bool classof(const Value *V) {
3999 }
4000
4001private:
4002 // Shadow Instruction::setInstructionSubclassData with a private forwarding
4003 // method so that subclasses cannot accidentally use it.
4004 template <typename Bitfield>
4005 void setSubclassData(typename Bitfield::Type Value) {
4007 }
4008};
4009
4010InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
4011 BasicBlock *IfException, ArrayRef<Value *> Args,
4013 const Twine &NameStr, InsertPosition InsertBefore)
4014 : CallBase(Ty->getReturnType(), Instruction::Invoke, AllocInfo,
4015 InsertBefore) {
4016 init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
4017}
4018
4019//===----------------------------------------------------------------------===//
4020// CallBrInst Class
4021//===----------------------------------------------------------------------===//
4022
4023/// CallBr instruction, tracking function calls that may not return control but
4024/// instead transfer it to a third location. The SubclassData field is used to
4025/// hold the calling convention of the call.
4026///
4027class CallBrInst : public CallBase {
4028
4029 unsigned NumIndirectDests;
4030
4031 CallBrInst(const CallBrInst &BI, AllocInfo AllocInfo);
4032
4033 /// Construct a CallBrInst given a range of arguments.
4034 ///
4035 /// Construct a CallBrInst from a range of arguments
4036 inline CallBrInst(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
4037 ArrayRef<BasicBlock *> IndirectDests,
4039 AllocInfo AllocInfo, const Twine &NameStr,
4040 InsertPosition InsertBefore);
4041
4042 LLVM_ABI void init(FunctionType *FTy, Value *Func, BasicBlock *DefaultDest,
4043 ArrayRef<BasicBlock *> IndirectDests,
4045 const Twine &NameStr);
4046
4047 /// Compute the number of operands to allocate.
4048 static unsigned ComputeNumOperands(int NumArgs, int NumIndirectDests,
4049 int NumBundleInputs = 0) {
4050 // We need one operand for the called function, plus our extra operands and
4051 // the input operand counts provided.
4052 return unsigned(2 + NumIndirectDests + NumArgs + NumBundleInputs);
4053 }
4054
4055protected:
4056 // Note: Instruction needs to be a friend here to call cloneImpl.
4057 friend class Instruction;
4058
4059 LLVM_ABI CallBrInst *cloneImpl() const;
4060
4061public:
4062 static CallBrInst *Create(FunctionType *Ty, Value *Func,
4063 BasicBlock *DefaultDest,
4064 ArrayRef<BasicBlock *> IndirectDests,
4065 ArrayRef<Value *> Args, const Twine &NameStr,
4066 InsertPosition InsertBefore = nullptr) {
4067 IntrusiveOperandsAllocMarker AllocMarker{
4068 ComputeNumOperands(Args.size(), IndirectDests.size())};
4069 return new (AllocMarker)
4070 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, {}, AllocMarker,
4071 NameStr, InsertBefore);
4072 }
4073
4074 static CallBrInst *
4075 Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
4076 ArrayRef<BasicBlock *> IndirectDests, ArrayRef<Value *> Args,
4077 ArrayRef<OperandBundleDef> Bundles = {}, const Twine &NameStr = "",
4078 InsertPosition InsertBefore = nullptr) {
4079 IntrusiveOperandsAndDescriptorAllocMarker AllocMarker{
4080 ComputeNumOperands(Args.size(), IndirectDests.size(),
4081 CountBundleInputs(Bundles)),
4082 unsigned(Bundles.size() * sizeof(BundleOpInfo))};
4083
4084 return new (AllocMarker)
4085 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, Bundles,
4086 AllocMarker, NameStr, InsertBefore);
4087 }
4088
4089 static CallBrInst *Create(FunctionCallee Func, BasicBlock *DefaultDest,
4090 ArrayRef<BasicBlock *> IndirectDests,
4091 ArrayRef<Value *> Args, const Twine &NameStr,
4092 InsertPosition InsertBefore = nullptr) {
4093 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4094 IndirectDests, Args, NameStr, InsertBefore);
4095 }
4096
4097 static CallBrInst *Create(FunctionCallee Func, BasicBlock *DefaultDest,
4098 ArrayRef<BasicBlock *> IndirectDests,
4099 ArrayRef<Value *> Args,
4100 ArrayRef<OperandBundleDef> Bundles = {},
4101 const Twine &NameStr = "",
4102 InsertPosition InsertBefore = nullptr) {
4103 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4104 IndirectDests, Args, Bundles, NameStr, InsertBefore);
4105 }
4106
4107 /// Create a clone of \p CBI with a different set of operand bundles and
4108 /// insert it before \p InsertBefore.
4109 ///
4110 /// The returned callbr instruction is identical to \p CBI in every way
4111 /// except that the operand bundles for the new instruction are set to the
4112 /// operand bundles in \p Bundles.
4113 LLVM_ABI static CallBrInst *Create(CallBrInst *CBI,
4115 InsertPosition InsertBefore = nullptr);
4116
4117 /// Return the number of callbr indirect dest labels.
4118 ///
4119 unsigned getNumIndirectDests() const { return NumIndirectDests; }
4120
4121 /// getIndirectDestLabel - Return the i-th indirect dest label.
4122 ///
4123 Value *getIndirectDestLabel(unsigned i) const {
4124 assert(i < getNumIndirectDests() && "Out of bounds!");
4125 return getOperand(i + arg_size() + getNumTotalBundleOperands() + 1);
4126 }
4127
4128 Value *getIndirectDestLabelUse(unsigned i) const {
4129 assert(i < getNumIndirectDests() && "Out of bounds!");
4130 return getOperandUse(i + arg_size() + getNumTotalBundleOperands() + 1);
4131 }
4132
4133 // Return the destination basic blocks...
4135 return cast<BasicBlock>(*(&Op<-1>() - getNumIndirectDests() - 1));
4136 }
4137 BasicBlock *getIndirectDest(unsigned i) const {
4139 }
4141 SmallVector<BasicBlock *, 16> IndirectDests;
4142 for (unsigned i = 0, e = getNumIndirectDests(); i < e; ++i)
4143 IndirectDests.push_back(getIndirectDest(i));
4144 return IndirectDests;
4145 }
4147 *(&Op<-1>() - getNumIndirectDests() - 1) = reinterpret_cast<Value *>(B);
4148 }
4149 void setIndirectDest(unsigned i, BasicBlock *B) {
4150 *(&Op<-1>() - getNumIndirectDests() + i) = reinterpret_cast<Value *>(B);
4151 }
4152
4153 BasicBlock *getSuccessor(unsigned i) const {
4154 assert(i < getNumSuccessors() + 1 &&
4155 "Successor # out of range for callbr!");
4156 return i == 0 ? getDefaultDest() : getIndirectDest(i - 1);
4157 }
4158
4159 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
4160 assert(i < getNumIndirectDests() + 1 &&
4161 "Successor # out of range for callbr!");
4162 return i == 0 ? setDefaultDest(NewSucc) : setIndirectDest(i - 1, NewSucc);
4163 }
4164
4165 unsigned getNumSuccessors() const { return getNumIndirectDests() + 1; }
4166
4175
4176 // Methods for support type inquiry through isa, cast, and dyn_cast:
4177 static bool classof(const Instruction *I) {
4178 return (I->getOpcode() == Instruction::CallBr);
4179 }
4180 static bool classof(const Value *V) {
4182 }
4183
4184private:
4185 // Shadow Instruction::setInstructionSubclassData with a private forwarding
4186 // method so that subclasses cannot accidentally use it.
4187 template <typename Bitfield>
4188 void setSubclassData(typename Bitfield::Type Value) {
4190 }
4191};
4192
4193CallBrInst::CallBrInst(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
4194 ArrayRef<BasicBlock *> IndirectDests,
4195 ArrayRef<Value *> Args,
4197 const Twine &NameStr, InsertPosition InsertBefore)
4198 : CallBase(Ty->getReturnType(), Instruction::CallBr, AllocInfo,
4199 InsertBefore) {
4200 init(Ty, Func, DefaultDest, IndirectDests, Args, Bundles, NameStr);
4201}
4202
4203//===----------------------------------------------------------------------===//
4204// ResumeInst Class
4205//===----------------------------------------------------------------------===//
4206
4207//===---------------------------------------------------------------------------
4208/// Resume the propagation of an exception.
4209///
4210class ResumeInst : public Instruction {
4211 constexpr static IntrusiveOperandsAllocMarker AllocMarker{1};
4212
4213 ResumeInst(const ResumeInst &RI);
4214
4215 LLVM_ABI explicit ResumeInst(Value *Exn,
4216 InsertPosition InsertBefore = nullptr);
4217
4218protected:
4219 // Note: Instruction needs to be a friend here to call cloneImpl.
4220 friend class Instruction;
4221
4222 LLVM_ABI ResumeInst *cloneImpl() const;
4223
4224public:
4225 static ResumeInst *Create(Value *Exn, InsertPosition InsertBefore = nullptr) {
4226 return new (AllocMarker) ResumeInst(Exn, InsertBefore);
4227 }
4228
4229 /// Provide fast operand accessors
4231
4232 /// Convenience accessor.
4233 Value *getValue() const { return Op<0>(); }
4234
4235 unsigned getNumSuccessors() const { return 0; }
4236
4237 // Methods for support type inquiry through isa, cast, and dyn_cast:
4238 static bool classof(const Instruction *I) {
4239 return I->getOpcode() == Instruction::Resume;
4240 }
4241 static bool classof(const Value *V) {
4243 }
4244
4245private:
4246 BasicBlock *getSuccessor(unsigned idx) const {
4247 llvm_unreachable("ResumeInst has no successors!");
4248 }
4249
4250 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
4251 llvm_unreachable("ResumeInst has no successors!");
4252 }
4253
4254 iterator_range<succ_iterator> successors() {
4255 return {succ_iterator(op_end()), succ_iterator(op_end())};
4256 }
4257 iterator_range<const_succ_iterator> successors() const {
4259 }
4260};
4261
4262template <>
4264 public FixedNumOperandTraits<ResumeInst, 1> {
4265};
4266
4268
4269//===----------------------------------------------------------------------===//
4270// CatchSwitchInst Class
4271//===----------------------------------------------------------------------===//
4272class CatchSwitchInst : public Instruction {
4273 using UnwindDestField = BoolBitfieldElementT<0>;
4274
4275 constexpr static HungOffOperandsAllocMarker AllocMarker{};
4276
4277 /// The number of operands actually allocated. NumOperands is
4278 /// the number actually in use.
4279 unsigned ReservedSpace;
4280
4281 // Operand[0] = Outer scope
4282 // Operand[1] = Unwind block destination
4283 // Operand[n] = BasicBlock to go to on match
4284 CatchSwitchInst(const CatchSwitchInst &CSI);
4285
4286 /// Create a new switch instruction, specifying a
4287 /// default destination. The number of additional handlers can be specified
4288 /// here to make memory allocation more efficient.
4289 /// This constructor can also autoinsert before another instruction.
4290 LLVM_ABI CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
4291 unsigned NumHandlers, const Twine &NameStr,
4292 InsertPosition InsertBefore);
4293
4294 // allocate space for exactly zero operands
4295 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
4296
4297 void init(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumReserved);
4298 void growOperands(unsigned Size);
4299
4300protected:
4301 // Note: Instruction needs to be a friend here to call cloneImpl.
4302 friend class Instruction;
4303
4304 LLVM_ABI CatchSwitchInst *cloneImpl() const;
4305
4306public:
4307 void operator delete(void *Ptr) {
4308 return User::operator delete(Ptr, AllocMarker);
4309 }
4310
4311 static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest,
4312 unsigned NumHandlers,
4313 const Twine &NameStr = "",
4314 InsertPosition InsertBefore = nullptr) {
4315 return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
4316 InsertBefore);
4317 }
4318
4319 /// Provide fast operand accessors
4321
4322 // Accessor Methods for CatchSwitch stmt
4323 Value *getParentPad() const { return getOperand(0); }
4324 void setParentPad(Value *ParentPad) { setOperand(0, ParentPad); }
4325
4326 // Accessor Methods for CatchSwitch stmt
4328 bool unwindsToCaller() const { return !hasUnwindDest(); }
4330 if (hasUnwindDest())
4331 return cast<BasicBlock>(getOperand(1));
4332 return nullptr;
4333 }
4334 void setUnwindDest(BasicBlock *UnwindDest) {
4335 assert(UnwindDest);
4337 setOperand(1, UnwindDest);
4338 }
4339
4340 /// return the number of 'handlers' in this catchswitch
4341 /// instruction, except the default handler
4342 unsigned getNumHandlers() const {
4343 if (hasUnwindDest())
4344 return getNumOperands() - 2;
4345 return getNumOperands() - 1;
4346 }
4347
4348private:
4349 static BasicBlock *handler_helper(Value *V) { return cast<BasicBlock>(V); }
4350 static const BasicBlock *handler_helper(const Value *V) {
4351 return cast<BasicBlock>(V);
4352 }
4353
4354public:
4355 using DerefFnTy = BasicBlock *(*)(Value *);
4358 using ConstDerefFnTy = const BasicBlock *(*)(const Value *);
4362
4363 /// Returns an iterator that points to the first handler in CatchSwitchInst.
4365 op_iterator It = op_begin() + 1;
4366 if (hasUnwindDest())
4367 ++It;
4368 return handler_iterator(It, DerefFnTy(handler_helper));
4369 }
4370
4371 /// Returns an iterator that points to the first handler in the
4372 /// CatchSwitchInst.
4374 const_op_iterator It = op_begin() + 1;
4375 if (hasUnwindDest())
4376 ++It;
4377 return const_handler_iterator(It, ConstDerefFnTy(handler_helper));
4378 }
4379
4380 /// Returns a read-only iterator that points one past the last
4381 /// handler in the CatchSwitchInst.
4383 return handler_iterator(op_end(), DerefFnTy(handler_helper));
4384 }
4385
4386 /// Returns an iterator that points one past the last handler in the
4387 /// CatchSwitchInst.
4389 return const_handler_iterator(op_end(), ConstDerefFnTy(handler_helper));
4390 }
4391
4392 /// iteration adapter for range-for loops.
4396
4397 /// iteration adapter for range-for loops.
4401
4402 /// Add an entry to the switch instruction...
4403 /// Note:
4404 /// This action invalidates handler_end(). Old handler_end() iterator will
4405 /// point to the added handler.
4406 LLVM_ABI void addHandler(BasicBlock *Dest);
4407
4408 LLVM_ABI void removeHandler(handler_iterator HI);
4409
4410 unsigned getNumSuccessors() const { return getNumOperands() - 1; }
4411 BasicBlock *getSuccessor(unsigned Idx) const {
4412 assert(Idx < getNumSuccessors() &&
4413 "Successor # out of range for catchswitch!");
4414 return cast<BasicBlock>(getOperand(Idx + 1));
4415 }
4416 void setSuccessor(unsigned Idx, BasicBlock *NewSucc) {
4417 assert(Idx < getNumSuccessors() &&
4418 "Successor # out of range for catchswitch!");
4419 setOperand(Idx + 1, NewSucc);
4420 }
4421
4429
4430 // Methods for support type inquiry through isa, cast, and dyn_cast:
4431 static bool classof(const Instruction *I) {
4432 return I->getOpcode() == Instruction::CatchSwitch;
4433 }
4434 static bool classof(const Value *V) {
4436 }
4437};
4438
4439template <>
4441
4443
4444//===----------------------------------------------------------------------===//
4445// CleanupPadInst Class
4446//===----------------------------------------------------------------------===//
4447class CleanupPadInst : public FuncletPadInst {
4448private:
4449 explicit CleanupPadInst(Value *ParentPad, ArrayRef<Value *> Args,
4450 AllocInfo AllocInfo, const Twine &NameStr,
4451 InsertPosition InsertBefore)
4452 : FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, AllocInfo,
4453 NameStr, InsertBefore) {}
4454
4455public:
4456 static CleanupPadInst *Create(Value *ParentPad, ArrayRef<Value *> Args = {},
4457 const Twine &NameStr = "",
4458 InsertPosition InsertBefore = nullptr) {
4459 IntrusiveOperandsAllocMarker AllocMarker{unsigned(1 + Args.size())};
4460 return new (AllocMarker)
4461 CleanupPadInst(ParentPad, Args, AllocMarker, NameStr, InsertBefore);
4462 }
4463
4464 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4465 static bool classof(const Instruction *I) {
4466 return I->getOpcode() == Instruction::CleanupPad;
4467 }
4468 static bool classof(const Value *V) {
4470 }
4471};
4472
4473//===----------------------------------------------------------------------===//
4474// CatchPadInst Class
4475//===----------------------------------------------------------------------===//
4476class CatchPadInst : public FuncletPadInst {
4477private:
4478 explicit CatchPadInst(Value *CatchSwitch, ArrayRef<Value *> Args,
4479 AllocInfo AllocInfo, const Twine &NameStr,
4480 InsertPosition InsertBefore)
4481 : FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, AllocInfo,
4482 NameStr, InsertBefore) {}
4483
4484public:
4485 static CatchPadInst *Create(Value *CatchSwitch, ArrayRef<Value *> Args,
4486 const Twine &NameStr = "",
4487 InsertPosition InsertBefore = nullptr) {
4488 IntrusiveOperandsAllocMarker AllocMarker{unsigned(1 + Args.size())};
4489 return new (AllocMarker)
4490 CatchPadInst(CatchSwitch, Args, AllocMarker, NameStr, InsertBefore);
4491 }
4492
4493 /// Convenience accessors
4497 void setCatchSwitch(Value *CatchSwitch) {
4498 assert(CatchSwitch);
4499 Op<-1>() = CatchSwitch;
4500 }
4501
4502 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4503 static bool classof(const Instruction *I) {
4504 return I->getOpcode() == Instruction::CatchPad;
4505 }
4506 static bool classof(const Value *V) {
4508 }
4509};
4510
4511//===----------------------------------------------------------------------===//
4512// CatchReturnInst Class
4513//===----------------------------------------------------------------------===//
4514
4515class CatchReturnInst : public Instruction {
4516 constexpr static IntrusiveOperandsAllocMarker AllocMarker{2};
4517
4518 CatchReturnInst(const CatchReturnInst &RI);
4519 LLVM_ABI CatchReturnInst(Value *CatchPad, BasicBlock *BB,
4520 InsertPosition InsertBefore);
4521
4522 void init(Value *CatchPad, BasicBlock *BB);
4523
4524protected:
4525 // Note: Instruction needs to be a friend here to call cloneImpl.
4526 friend class Instruction;
4527
4528 LLVM_ABI CatchReturnInst *cloneImpl() const;
4529
4530public:
4531 static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB,
4532 InsertPosition InsertBefore = nullptr) {
4533 assert(CatchPad);
4534 assert(BB);
4535 return new (AllocMarker) CatchReturnInst(CatchPad, BB, InsertBefore);
4536 }
4537
4538 /// Provide fast operand accessors
4540
4541 /// Convenience accessors.
4543 void setCatchPad(CatchPadInst *CatchPad) {
4544 assert(CatchPad);
4545 Op<0>() = CatchPad;
4546 }
4547
4549 void setSuccessor(BasicBlock *NewSucc) {
4550 assert(NewSucc);
4551 Op<1>() = NewSucc;
4552 }
4553 unsigned getNumSuccessors() const { return 1; }
4554
4555 /// Get the parentPad of this catchret's catchpad's catchswitch.
4556 /// The successor block is implicitly a member of this funclet.
4560
4561 // Methods for support type inquiry through isa, cast, and dyn_cast:
4562 static bool classof(const Instruction *I) {
4563 return (I->getOpcode() == Instruction::CatchRet);
4564 }
4565 static bool classof(const Value *V) {
4567 }
4568
4569private:
4570 BasicBlock *getSuccessor(unsigned Idx) const {
4571 assert(Idx < getNumSuccessors() && "Successor # out of range for catchret!");
4572 return getSuccessor();
4573 }
4574
4575 void setSuccessor(unsigned Idx, BasicBlock *B) {
4576 assert(Idx < getNumSuccessors() && "Successor # out of range for catchret!");
4577 setSuccessor(B);
4578 }
4579
4580 iterator_range<succ_iterator> successors() {
4581 return {succ_iterator(std::next(op_begin())), succ_iterator(op_end())};
4582 }
4583 iterator_range<const_succ_iterator> successors() const {
4584 return {const_succ_iterator(std::next(op_begin())),
4586 }
4587};
4588
4589template <>
4591 : public FixedNumOperandTraits<CatchReturnInst, 2> {};
4592
4594
4595//===----------------------------------------------------------------------===//
4596// CleanupReturnInst Class
4597//===----------------------------------------------------------------------===//
4598
4599class CleanupReturnInst : public Instruction {
4600 using UnwindDestField = BoolBitfieldElementT<0>;
4601
4602private:
4603 CleanupReturnInst(const CleanupReturnInst &RI, AllocInfo AllocInfo);
4604 LLVM_ABI CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB,
4606 InsertPosition InsertBefore = nullptr);
4607
4608 void init(Value *CleanupPad, BasicBlock *UnwindBB);
4609
4610protected:
4611 // Note: Instruction needs to be a friend here to call cloneImpl.
4612 friend class Instruction;
4613
4614 LLVM_ABI CleanupReturnInst *cloneImpl() const;
4615
4616public:
4617 static CleanupReturnInst *Create(Value *CleanupPad,
4618 BasicBlock *UnwindBB = nullptr,
4619 InsertPosition InsertBefore = nullptr) {
4620 assert(CleanupPad);
4621 unsigned Values = 1;
4622 if (UnwindBB)
4623 ++Values;
4624 IntrusiveOperandsAllocMarker AllocMarker{Values};
4625 return new (AllocMarker)
4626 CleanupReturnInst(CleanupPad, UnwindBB, AllocMarker, InsertBefore);
4627 }
4628
4629 /// Provide fast operand accessors
4631
4633 bool unwindsToCaller() const { return !hasUnwindDest(); }
4634
4635 /// Convenience accessor.
4637 return cast<CleanupPadInst>(Op<0>());
4638 }
4639 void setCleanupPad(CleanupPadInst *CleanupPad) {
4640 assert(CleanupPad);
4641 Op<0>() = CleanupPad;
4642 }
4643
4644 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
4645
4647 return hasUnwindDest() ? cast<BasicBlock>(Op<1>()) : nullptr;
4648 }
4649 void setUnwindDest(BasicBlock *NewDest) {
4650 assert(NewDest);
4652 Op<1>() = NewDest;
4653 }
4654
4655 // Methods for support type inquiry through isa, cast, and dyn_cast:
4656 static bool classof(const Instruction *I) {
4657 return (I->getOpcode() == Instruction::CleanupRet);
4658 }
4659 static bool classof(const Value *V) {
4661 }
4662
4663private:
4664 BasicBlock *getSuccessor(unsigned Idx) const {
4665 assert(Idx == 0);
4666 return getUnwindDest();
4667 }
4668
4669 void setSuccessor(unsigned Idx, BasicBlock *B) {
4670 assert(Idx == 0);
4671 setUnwindDest(B);
4672 }
4673
4675 return {succ_iterator(std::next(op_begin())), succ_iterator(op_end())};
4676 }
4678 return {const_succ_iterator(std::next(op_begin())),
4679 const_succ_iterator(op_end())};
4680 }
4681
4682 // Shadow Instruction::setInstructionSubclassData with a private forwarding
4683 // method so that subclasses cannot accidentally use it.
4684 template <typename Bitfield>
4685 void setSubclassData(typename Bitfield::Type Value) {
4687 }
4688};
4689
4690template <>
4692 : public VariadicOperandTraits<CleanupReturnInst> {};
4693
4695
4696//===----------------------------------------------------------------------===//
4697// UnreachableInst Class
4698//===----------------------------------------------------------------------===//
4699
4700//===---------------------------------------------------------------------------
4701/// This function has undefined behavior. In particular, the
4702/// presence of this instruction indicates some higher level knowledge that the
4703/// end of the block cannot be reached.
4704///
4706 constexpr static IntrusiveOperandsAllocMarker AllocMarker{0};
4707
4708protected:
4709 // Note: Instruction needs to be a friend here to call cloneImpl.
4710 friend class Instruction;
4711
4713
4714public:
4716 InsertPosition InsertBefore = nullptr);
4717
4718 // allocate space for exactly zero operands
4719 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
4720 void operator delete(void *Ptr) { User::operator delete(Ptr, AllocMarker); }
4721
4722 unsigned getNumSuccessors() const { return 0; }
4723
4724 // Methods for support type inquiry through isa, cast, and dyn_cast:
4725 static bool classof(const Instruction *I) {
4726 return I->getOpcode() == Instruction::Unreachable;
4727 }
4728 static bool classof(const Value *V) {
4730 }
4731
4732 // Whether to do target lowering in SelectionDAG.
4733 LLVM_ABI bool shouldLowerToTrap(bool TrapUnreachable,
4734 bool NoTrapAfterNoreturn) const;
4735
4736private:
4737 BasicBlock *getSuccessor(unsigned idx) const {
4738 llvm_unreachable("UnreachableInst has no successors!");
4739 }
4740
4741 void setSuccessor(unsigned idx, BasicBlock *B) {
4742 llvm_unreachable("UnreachableInst has no successors!");
4743 }
4744
4746 return {succ_iterator(op_end()), succ_iterator(op_end())};
4747 }
4749 return {const_succ_iterator(op_end()), const_succ_iterator(op_end())};
4750 }
4751};
4752
4753//===----------------------------------------------------------------------===//
4754// TruncInst Class
4755//===----------------------------------------------------------------------===//
4756
4757/// This class represents a truncation of integer types.
4758class TruncInst : public CastInst {
4759protected:
4760 // Note: Instruction needs to be a friend here to call cloneImpl.
4761 friend class Instruction;
4762
4763 /// Clone an identical TruncInst
4764 LLVM_ABI TruncInst *cloneImpl() const;
4765
4766public:
4767 enum { AnyWrap = 0, NoUnsignedWrap = (1 << 0), NoSignedWrap = (1 << 1) };
4768
4769 /// Constructor with insert-before-instruction semantics
4770 LLVM_ABI
4771 TruncInst(Value *S, ///< The value to be truncated
4772 Type *Ty, ///< The (smaller) type to truncate to
4773 const Twine &NameStr = "", ///< A name for the new instruction
4774 InsertPosition InsertBefore =
4775 nullptr ///< Where to insert the new instruction
4776 );
4777
4778 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4779 static bool classof(const Instruction *I) {
4780 return I->getOpcode() == Trunc;
4781 }
4782 static bool classof(const Value *V) {
4784 }
4785
4794
4795 /// Test whether this operation is known to never
4796 /// undergo unsigned overflow, aka the nuw property.
4797 bool hasNoUnsignedWrap() const {
4799 }
4800
4801 /// Test whether this operation is known to never
4802 /// undergo signed overflow, aka the nsw property.
4803 bool hasNoSignedWrap() const {
4804 return (SubclassOptionalData & NoSignedWrap) != 0;
4805 }
4806
4807 /// Returns the no-wrap kind of the operation.
4808 unsigned getNoWrapKind() const {
4809 unsigned NoWrapKind = 0;
4810 if (hasNoUnsignedWrap())
4811 NoWrapKind |= NoUnsignedWrap;
4812
4813 if (hasNoSignedWrap())
4814 NoWrapKind |= NoSignedWrap;
4815
4816 return NoWrapKind;
4817 }
4818};
4819
4820//===----------------------------------------------------------------------===//
4821// ZExtInst Class
4822//===----------------------------------------------------------------------===//
4823
4824/// This class represents zero extension of integer types.
4825class ZExtInst : public CastInst {
4826protected:
4827 // Note: Instruction needs to be a friend here to call cloneImpl.
4828 friend class Instruction;
4829
4830 /// Clone an identical ZExtInst
4831 LLVM_ABI ZExtInst *cloneImpl() const;
4832
4833public:
4834 /// Constructor with insert-before-instruction semantics
4835 LLVM_ABI
4836 ZExtInst(Value *S, ///< The value to be zero extended
4837 Type *Ty, ///< The type to zero extend to
4838 const Twine &NameStr = "", ///< A name for the new instruction
4839 InsertPosition InsertBefore =
4840 nullptr ///< Where to insert the new instruction
4841 );
4842
4843 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4844 static bool classof(const Instruction *I) {
4845 return I->getOpcode() == ZExt;
4846 }
4847 static bool classof(const Value *V) {
4849 }
4850};
4851
4852//===----------------------------------------------------------------------===//
4853// SExtInst Class
4854//===----------------------------------------------------------------------===//
4855
4856/// This class represents a sign extension of integer types.
4857class SExtInst : public CastInst {
4858protected:
4859 // Note: Instruction needs to be a friend here to call cloneImpl.
4860 friend class Instruction;
4861
4862 /// Clone an identical SExtInst
4863 LLVM_ABI SExtInst *cloneImpl() const;
4864
4865public:
4866 /// Constructor with insert-before-instruction semantics
4867 LLVM_ABI
4868 SExtInst(Value *S, ///< The value to be sign extended
4869 Type *Ty, ///< The type to sign extend to
4870 const Twine &NameStr = "", ///< A name for the new instruction
4871 InsertPosition InsertBefore =
4872 nullptr ///< Where to insert the new instruction
4873 );
4874
4875 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4876 static bool classof(const Instruction *I) {
4877 return I->getOpcode() == SExt;
4878 }
4879 static bool classof(const Value *V) {
4881 }
4882};
4883
4884//===----------------------------------------------------------------------===//
4885// FPTruncInst Class
4886//===----------------------------------------------------------------------===//
4887
4888/// This class represents a truncation of floating point types.
4889class FPTruncInst : public CastInst {
4890protected:
4891 // Note: Instruction needs to be a friend here to call cloneImpl.
4892 friend class Instruction;
4893
4894 /// Clone an identical FPTruncInst
4896
4897public: /// Constructor with insert-before-instruction semantics
4898 LLVM_ABI
4899 FPTruncInst(Value *S, ///< The value to be truncated
4900 Type *Ty, ///< The type to truncate to
4901 const Twine &NameStr = "", ///< A name for the new instruction
4902 InsertPosition InsertBefore =
4903 nullptr ///< Where to insert the new instruction
4904 );
4905
4906 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4907 static bool classof(const Instruction *I) {
4908 return I->getOpcode() == FPTrunc;
4909 }
4910 static bool classof(const Value *V) {
4912 }
4913};
4914
4915//===----------------------------------------------------------------------===//
4916// FPExtInst Class
4917//===----------------------------------------------------------------------===//
4918
4919/// This class represents an extension of floating point types.
4920class FPExtInst : public CastInst {
4921protected:
4922 // Note: Instruction needs to be a friend here to call cloneImpl.
4923 friend class Instruction;
4924
4925 /// Clone an identical FPExtInst
4926 LLVM_ABI FPExtInst *cloneImpl() const;
4927
4928public:
4929 /// Constructor with insert-before-instruction semantics
4930 LLVM_ABI
4931 FPExtInst(Value *S, ///< The value to be extended
4932 Type *Ty, ///< The type to extend to
4933 const Twine &NameStr = "", ///< A name for the new instruction
4934 InsertPosition InsertBefore =
4935 nullptr ///< Where to insert the new instruction
4936 );
4937
4938 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4939 static bool classof(const Instruction *I) {
4940 return I->getOpcode() == FPExt;
4941 }
4942 static bool classof(const Value *V) {
4944 }
4945};
4946
4947//===----------------------------------------------------------------------===//
4948// UIToFPInst Class
4949//===----------------------------------------------------------------------===//
4950
4951/// This class represents a cast unsigned integer to floating point.
4952class UIToFPInst : public CastInst {
4953protected:
4954 // Note: Instruction needs to be a friend here to call cloneImpl.
4955 friend class Instruction;
4956
4957 /// Clone an identical UIToFPInst
4958 LLVM_ABI UIToFPInst *cloneImpl() const;
4959
4960public:
4961 /// Constructor with insert-before-instruction semantics
4962 LLVM_ABI
4963 UIToFPInst(Value *S, ///< The value to be converted
4964 Type *Ty, ///< The type to convert to
4965 const Twine &NameStr = "", ///< A name for the new instruction
4966 InsertPosition InsertBefore =
4967 nullptr ///< Where to insert the new instruction
4968 );
4969
4970 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4971 static bool classof(const Instruction *I) {
4972 return I->getOpcode() == UIToFP;
4973 }
4974 static bool classof(const Value *V) {
4976 }
4977};
4978
4979//===----------------------------------------------------------------------===//
4980// SIToFPInst Class
4981//===----------------------------------------------------------------------===//
4982
4983/// This class represents a cast from signed integer to floating point.
4984class SIToFPInst : public CastInst {
4985protected:
4986 // Note: Instruction needs to be a friend here to call cloneImpl.
4987 friend class Instruction;
4988
4989 /// Clone an identical SIToFPInst
4990 LLVM_ABI SIToFPInst *cloneImpl() const;
4991
4992public:
4993 /// Constructor with insert-before-instruction semantics
4994 LLVM_ABI
4995 SIToFPInst(Value *S, ///< The value to be converted
4996 Type *Ty, ///< The type to convert to
4997 const Twine &NameStr = "", ///< A name for the new instruction
4998 InsertPosition InsertBefore =
4999 nullptr ///< Where to insert the new instruction
5000 );
5001
5002 /// Methods for support type inquiry through isa, cast, and dyn_cast:
5003 static bool classof(const Instruction *I) {
5004 return I->getOpcode() == SIToFP;
5005 }
5006 static bool classof(const Value *V) {
5008 }
5009};
5010
5011//===----------------------------------------------------------------------===//
5012// FPToUIInst Class
5013//===----------------------------------------------------------------------===//
5014
5015/// This class represents a cast from floating point to unsigned integer
5016class FPToUIInst : public CastInst {
5017protected:
5018 // Note: Instruction needs to be a friend here to call cloneImpl.
5019 friend class Instruction;
5020
5021 /// Clone an identical FPToUIInst
5022 LLVM_ABI FPToUIInst *cloneImpl() const;
5023
5024public:
5025 /// Constructor with insert-before-instruction semantics
5026 LLVM_ABI
5027 FPToUIInst(Value *S, ///< The value to be converted
5028 Type *Ty, ///< The type to convert to
5029 const Twine &NameStr = "", ///< A name for the new instruction
5030 InsertPosition InsertBefore =
5031 nullptr ///< Where to insert the new instruction
5032 );
5033
5034 /// Methods for support type inquiry through isa, cast, and dyn_cast:
5035 static bool classof(const Instruction *I) {
5036 return I->getOpcode() == FPToUI;
5037 }
5038 static bool classof(const Value *V) {
5040 }
5041};
5042
5043//===----------------------------------------------------------------------===//
5044// FPToSIInst Class
5045//===----------------------------------------------------------------------===//
5046
5047/// This class represents a cast from floating point to signed integer.
5048class FPToSIInst : public CastInst {
5049protected:
5050 // Note: Instruction needs to be a friend here to call cloneImpl.
5051 friend class Instruction;
5052
5053 /// Clone an identical FPToSIInst
5054 LLVM_ABI FPToSIInst *cloneImpl() const;
5055
5056public:
5057 /// Constructor with insert-before-instruction semantics
5058 LLVM_ABI
5059 FPToSIInst(Value *S, ///< The value to be converted
5060 Type *Ty, ///< The type to convert to
5061 const Twine &NameStr = "", ///< A name for the new instruction
5062 InsertPosition InsertBefore =
5063 nullptr ///< Where to insert the new instruction
5064 );
5065
5066 /// Methods for support type inquiry through isa, cast, and dyn_cast:
5067 static bool classof(const Instruction *I) {
5068 return I->getOpcode() == FPToSI;
5069 }
5070 static bool classof(const Value *V) {
5072 }
5073};
5074
5075//===----------------------------------------------------------------------===//
5076// IntToPtrInst Class
5077//===----------------------------------------------------------------------===//
5078
5079/// This class represents a cast from an integer to a pointer.
5080class IntToPtrInst : public CastInst {
5081public:
5082 // Note: Instruction needs to be a friend here to call cloneImpl.
5083 friend class Instruction;
5084
5085 /// Constructor with insert-before-instruction semantics
5086 LLVM_ABI
5087 IntToPtrInst(Value *S, ///< The value to be converted
5088 Type *Ty, ///< The type to convert to
5089 const Twine &NameStr = "", ///< A name for the new instruction
5090 InsertPosition InsertBefore =
5091 nullptr ///< Where to insert the new instruction
5092 );
5093
5094 /// Clone an identical IntToPtrInst.
5096
5097 /// Returns the address space of this instruction's pointer type.
5098 unsigned getAddressSpace() const {
5099 return getType()->getPointerAddressSpace();
5100 }
5101
5102 // Methods for support type inquiry through isa, cast, and dyn_cast:
5103 static bool classof(const Instruction *I) {
5104 return I->getOpcode() == IntToPtr;
5105 }
5106 static bool classof(const Value *V) {
5108 }
5109};
5110
5111//===----------------------------------------------------------------------===//
5112// PtrToIntInst Class
5113//===----------------------------------------------------------------------===//
5114
5115/// This class represents a cast from a pointer to an integer.
5116class PtrToIntInst : public CastInst {
5117protected:
5118 // Note: Instruction needs to be a friend here to call cloneImpl.
5119 friend class Instruction;
5120
5121 /// Clone an identical PtrToIntInst.
5123
5124public:
5125 /// Constructor with insert-before-instruction semantics
5126 LLVM_ABI
5127 PtrToIntInst(Value *S, ///< The value to be converted
5128 Type *Ty, ///< The type to convert to
5129 const Twine &NameStr = "", ///< A name for the new instruction
5130 InsertPosition InsertBefore =
5131 nullptr ///< Where to insert the new instruction
5132 );
5133
5134 /// Gets the pointer operand.
5136 /// Gets the pointer operand.
5137 const Value *getPointerOperand() const { return getOperand(0); }
5138 /// Gets the operand index of the pointer operand.
5139 static unsigned getPointerOperandIndex() { return 0U; }
5140
5141 /// Returns the address space of the pointer operand.
5142 unsigned getPointerAddressSpace() const {
5144 }
5145
5146 // Methods for support type inquiry through isa, cast, and dyn_cast:
5147 static bool classof(const Instruction *I) {
5148 return I->getOpcode() == PtrToInt;
5149 }
5150 static bool classof(const Value *V) {
5152 }
5153};
5154
5155/// This class represents a cast from a pointer to an address (non-capturing
5156/// ptrtoint).
5157class PtrToAddrInst : public CastInst {
5158protected:
5159 // Note: Instruction needs to be a friend here to call cloneImpl.
5160 friend class Instruction;
5161
5162 /// Clone an identical PtrToAddrInst.
5163 PtrToAddrInst *cloneImpl() const;
5164
5165public:
5166 /// Constructor with insert-before-instruction semantics
5167 PtrToAddrInst(Value *S, ///< The value to be converted
5168 Type *Ty, ///< The type to convert to
5169 const Twine &NameStr = "", ///< A name for the new instruction
5170 InsertPosition InsertBefore =
5171 nullptr ///< Where to insert the new instruction
5172 );
5173
5174 /// Gets the pointer operand.
5176 /// Gets the pointer operand.
5177 const Value *getPointerOperand() const { return getOperand(0); }
5178 /// Gets the operand index of the pointer operand.
5179 static unsigned getPointerOperandIndex() { return 0U; }
5180
5181 /// Returns the address space of the pointer operand.
5182 unsigned getPointerAddressSpace() const {
5184 }
5185
5186 // Methods for support type inquiry through isa, cast, and dyn_cast:
5187 static bool classof(const Instruction *I) {
5188 return I->getOpcode() == PtrToAddr;
5189 }
5190 static bool classof(const Value *V) {
5192 }
5193};
5194
5195//===----------------------------------------------------------------------===//
5196// BitCastInst Class
5197//===----------------------------------------------------------------------===//
5198
5199/// This class represents a no-op cast from one type to another.
5200class BitCastInst : public CastInst {
5201protected:
5202 // Note: Instruction needs to be a friend here to call cloneImpl.
5203 friend class Instruction;
5204
5205 /// Clone an identical BitCastInst.
5207
5208public:
5209 /// Constructor with insert-before-instruction semantics
5210 LLVM_ABI
5211 BitCastInst(Value *S, ///< The value to be casted
5212 Type *Ty, ///< The type to casted to
5213 const Twine &NameStr = "", ///< A name for the new instruction
5214 InsertPosition InsertBefore =
5215 nullptr ///< Where to insert the new instruction
5216 );
5217
5218 // Methods for support type inquiry through isa, cast, and dyn_cast:
5219 static bool classof(const Instruction *I) {
5220 return I->getOpcode() == BitCast;
5221 }
5222 static bool classof(const Value *V) {
5224 }
5225};
5226
5227//===----------------------------------------------------------------------===//
5228// AddrSpaceCastInst Class
5229//===----------------------------------------------------------------------===//
5230
5231/// This class represents a conversion between pointers from one address space
5232/// to another.
5234protected:
5235 // Note: Instruction needs to be a friend here to call cloneImpl.
5236 friend class Instruction;
5237
5238 /// Clone an identical AddrSpaceCastInst.
5240
5241public:
5242 /// Constructor with insert-before-instruction semantics
5244 Value *S, ///< The value to be casted
5245 Type *Ty, ///< The type to casted to
5246 const Twine &NameStr = "", ///< A name for the new instruction
5247 InsertPosition InsertBefore =
5248 nullptr ///< Where to insert the new instruction
5249 );
5250
5251 // Methods for support type inquiry through isa, cast, and dyn_cast:
5252 static bool classof(const Instruction *I) {
5253 return I->getOpcode() == AddrSpaceCast;
5254 }
5255 static bool classof(const Value *V) {
5257 }
5258
5259 /// Gets the pointer operand.
5261 return getOperand(0);
5262 }
5263
5264 /// Gets the pointer operand.
5265 const Value *getPointerOperand() const {
5266 return getOperand(0);
5267 }
5268
5269 /// Gets the operand index of the pointer operand.
5270 static unsigned getPointerOperandIndex() {
5271 return 0U;
5272 }
5273
5274 /// Returns the address space of the pointer operand.
5275 unsigned getSrcAddressSpace() const {
5277 }
5278
5279 /// Returns the address space of the result.
5280 unsigned getDestAddressSpace() const {
5281 return getType()->getPointerAddressSpace();
5282 }
5283};
5284
5285//===----------------------------------------------------------------------===//
5286// Helper functions
5287//===----------------------------------------------------------------------===//
5288
5289/// A helper function that returns the pointer operand of a load or store
5290/// instruction. Returns nullptr if not load or store.
5291inline const Value *getLoadStorePointerOperand(const Value *V) {
5292 if (auto *Load = dyn_cast<LoadInst>(V))
5293 return Load->getPointerOperand();
5294 if (auto *Store = dyn_cast<StoreInst>(V))
5295 return Store->getPointerOperand();
5296 return nullptr;
5297}
5299 return const_cast<Value *>(
5300 getLoadStorePointerOperand(static_cast<const Value *>(V)));
5301}
5302
5303/// A helper function that returns the pointer operand of a load, store
5304/// or GEP instruction. Returns nullptr if not load, store, or GEP.
5305inline const Value *getPointerOperand(const Value *V) {
5306 if (auto *Ptr = getLoadStorePointerOperand(V))
5307 return Ptr;
5308 if (auto *Gep = dyn_cast<GetElementPtrInst>(V))
5309 return Gep->getPointerOperand();
5310 return nullptr;
5311}
5313 return const_cast<Value *>(getPointerOperand(static_cast<const Value *>(V)));
5314}
5315
5316/// A helper function that returns the alignment of load or store instruction.
5319 "Expected Load or Store instruction");
5320 if (auto *LI = dyn_cast<LoadInst>(I))
5321 return LI->getAlign();
5322 return cast<StoreInst>(I)->getAlign();
5323}
5324
5325/// A helper function that set the alignment of load or store instruction.
5326inline void setLoadStoreAlignment(Value *I, Align NewAlign) {
5328 "Expected Load or Store instruction");
5329 if (auto *LI = dyn_cast<LoadInst>(I))
5330 LI->setAlignment(NewAlign);
5331 else
5332 cast<StoreInst>(I)->setAlignment(NewAlign);
5333}
5334
5335/// A helper function that returns the address space of the pointer operand of
5336/// load or store instruction.
5337inline unsigned getLoadStoreAddressSpace(const Value *I) {
5339 "Expected Load or Store instruction");
5340 if (auto *LI = dyn_cast<LoadInst>(I))
5341 return LI->getPointerAddressSpace();
5342 return cast<StoreInst>(I)->getPointerAddressSpace();
5343}
5344
5345/// A helper function that returns the type of a load or store instruction.
5346inline Type *getLoadStoreType(const Value *I) {
5348 "Expected Load or Store instruction");
5349 if (auto *LI = dyn_cast<LoadInst>(I))
5350 return LI->getType();
5351 return cast<StoreInst>(I)->getValueOperand()->getType();
5352}
5353
5354/// A helper function that returns an atomic operation's sync scope; returns
5355/// std::nullopt if it is not an atomic operation.
5356inline std::optional<SyncScope::ID> getAtomicSyncScopeID(const Instruction *I) {
5357 if (!I->isAtomic())
5358 return std::nullopt;
5359 if (auto *AI = dyn_cast<LoadInst>(I))
5360 return AI->getSyncScopeID();
5361 if (auto *AI = dyn_cast<StoreInst>(I))
5362 return AI->getSyncScopeID();
5363 if (auto *AI = dyn_cast<FenceInst>(I))
5364 return AI->getSyncScopeID();
5365 if (auto *AI = dyn_cast<AtomicCmpXchgInst>(I))
5366 return AI->getSyncScopeID();
5367 if (auto *AI = dyn_cast<AtomicRMWInst>(I))
5368 return AI->getSyncScopeID();
5369 llvm_unreachable("unhandled atomic operation");
5370}
5371
5372/// A helper function that sets an atomic operation's sync scope.
5374 assert(I->isAtomic());
5375 if (auto *AI = dyn_cast<LoadInst>(I))
5376 AI->setSyncScopeID(SSID);
5377 else if (auto *AI = dyn_cast<StoreInst>(I))
5378 AI->setSyncScopeID(SSID);
5379 else if (auto *AI = dyn_cast<FenceInst>(I))
5380 AI->setSyncScopeID(SSID);
5381 else if (auto *AI = dyn_cast<AtomicCmpXchgInst>(I))
5382 AI->setSyncScopeID(SSID);
5383 else if (auto *AI = dyn_cast<AtomicRMWInst>(I))
5384 AI->setSyncScopeID(SSID);
5385 else
5386 llvm_unreachable("unhandled atomic operation");
5387}
5388
5389//===----------------------------------------------------------------------===//
5390// FreezeInst Class
5391//===----------------------------------------------------------------------===//
5392
5393/// This class represents a freeze function that returns random concrete
5394/// value if an operand is either a poison value or an undef value
5396protected:
5397 // Note: Instruction needs to be a friend here to call cloneImpl.
5398 friend class Instruction;
5399
5400 /// Clone an identical FreezeInst
5401 LLVM_ABI FreezeInst *cloneImpl() const;
5402
5403public:
5404 LLVM_ABI explicit FreezeInst(Value *S, const Twine &NameStr = "",
5405 InsertPosition InsertBefore = nullptr);
5406
5407 // Methods for support type inquiry through isa, cast, and dyn_cast:
5408 static inline bool classof(const Instruction *I) {
5409 return I->getOpcode() == Freeze;
5410 }
5411 static inline bool classof(const Value *V) {
5413 }
5414};
5415
5416} // end namespace llvm
5417
5418#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:451
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.
Definition InstrTypes.h:986
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
Definition InstrTypes.h:768
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:676
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition InstrTypes.h:679
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
Definition InstrTypes.h:693
@ ICMP_SLT
signed less than
Definition InstrTypes.h:705
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:706
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:700
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:699
@ ICMP_SGT
signed greater than
Definition InstrTypes.h:703
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition InstrTypes.h:684
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition InstrTypes.h:687
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:701
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition InstrTypes.h:685
@ ICMP_NE
not equal
Definition InstrTypes.h:698
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:704
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition InstrTypes.h:692
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:702
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
Definition InstrTypes.h:678
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition InstrTypes.h:686
static auto ICmpPredicates()
Returns the sequence of all ICmp predicates.
Definition InstrTypes.h:722
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Definition InstrTypes.h:827
static auto FCmpPredicates()
Returns the sequence of all FCmp predicates.
Definition InstrTypes.h:715
Predicate getNonStrictPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
Definition InstrTypes.h:871
bool isFPPredicate() const
Definition InstrTypes.h:782
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
Definition InstrTypes.h:789
Predicate getPredicate() const
Return the predicate for this instruction.
Definition InstrTypes.h:765
static bool isIntPredicate(Predicate P)
Definition InstrTypes.h:776
LLVM_ABI CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred, Value *LHS, Value *RHS, const Twine &Name="", InsertPosition InsertBefore=nullptr, Instruction *FlagsSource=nullptr)
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.
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
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:62
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:557
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...