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