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