LLVM 24.0.0git
SelectionDAGNodes.h
Go to the documentation of this file.
1//===- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ----*- 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 declares the SDNode class and derived classes, which are used to
10// represent the nodes and operations present in a SelectionDAG. These nodes
11// and operations are machine code level operations, with some similarities to
12// the GCC RTL representation.
13//
14// Clients should include the SelectionDAG.h file instead of this file directly.
15//
16//===----------------------------------------------------------------------===//
17
18#ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
19#define LLVM_CODEGEN_SELECTIONDAGNODES_H
20
21#include "llvm/ADT/APFloat.h"
22#include "llvm/ADT/ArrayRef.h"
23#include "llvm/ADT/BitVector.h"
24#include "llvm/ADT/FoldingSet.h"
28#include "llvm/ADT/ilist_node.h"
29#include "llvm/ADT/iterator.h"
36#include "llvm/IR/Constants.h"
37#include "llvm/IR/DebugLoc.h"
38#include "llvm/IR/Instruction.h"
40#include "llvm/IR/Metadata.h"
41#include "llvm/IR/Operator.h"
48#include <algorithm>
49#include <cassert>
50#include <climits>
51#include <cstddef>
52#include <cstdint>
53#include <cstring>
54#include <iterator>
55#include <string>
56#include <tuple>
57#include <utility>
58
59namespace llvm {
60
61class APInt;
62class Constant;
63class GlobalValue;
66class MCSymbol;
67class raw_ostream;
68class SDNode;
69class SDValue;
70class SelectionDAG;
71class Type;
72class Value;
73
74LLVM_ABI void checkForCycles(const SDNode *N, const SelectionDAG *DAG = nullptr,
75 bool force = false);
76
77/// This represents a list of ValueType's that has been intern'd by
78/// a SelectionDAG. Instances of this simple value class are returned by
79/// SelectionDAG::getVTList(...).
80///
81struct SDVTList {
82 const EVT *VTs;
83 unsigned int NumVTs;
84};
85
86namespace ISD {
87
88 /// Node predicates
89
90/// If V is a BUILD_VECTOR or SPLAT_VECTOR value whose elements are all the
91/// same constant or undefined, return true and return the constant value in
92/// \p SplatValue.
94
95/// Return true if the specified value is a BUILD_VECTOR or SPLAT_VECTOR where
96/// all of the elements are ~0 or undef. If \p BuildVectorOnly is set to
97/// true, it only checks BUILD_VECTOR.
99 bool BuildVectorOnly = false);
100
101/// Return true if the specified value is a BUILD_VECTOR or SPLAT_VECTOR where
102/// all of the elements are 0 or undef. If \p BuildVectorOnly is set to true, it
103/// only checks BUILD_VECTOR.
105 bool BuildVectorOnly = false);
106
107/// Return true if the specified value is a BUILD_VECTOR where all of the
108/// elements are ~0 or undef.
110
111/// Return true if the specified value is a BUILD_VECTOR where all of the
112/// elements are 0 or undef.
114
115/// Return true if the specified value is a BUILD_VECTOR node of all
116/// ConstantSDNode or undef.
118
119/// Return true if the specified value is a BUILD_VECTOR node of all
120/// ConstantFPSDNode or undef.
122
123/// Returns true if the specified value is a vector where all elements can
124/// be truncated to the specified element size without a loss in meaning.
125LLVM_ABI bool isVectorShrinkable(SDValue V, unsigned NewEltSize, bool Signed);
126
127/// Return true if the value has at least one operand and all operands of the
128/// specified value are ISD::UNDEF.
130
131/// Return true if the specified value is FREEZE(UNDEF).
133
134} // end namespace ISD
135
136//===----------------------------------------------------------------------===//
137/// Unlike LLVM values, Selection DAG nodes may return multiple
138/// values as the result of a computation. Many nodes return multiple values,
139/// from loads (which define a token and a return value) to ADDC (which returns
140/// a result and a carry value), to calls (which may return an arbitrary number
141/// of values).
142///
143/// As such, each use of a SelectionDAG computation must indicate the node that
144/// computes it as well as which return value to use from that node. This pair
145/// of information is represented with the SDValue value type.
146///
147class SDValue {
148 friend struct DenseMapInfo<SDValue>;
149
150 SDNode *Node = nullptr; // The node defining the value we are using.
151 unsigned ResNo = 0; // Which return value of the node we are using.
152
153public:
154 SDValue() = default;
155 SDValue(SDNode *node, unsigned resno);
156
157 /// get the index which selects a specific result in the SDNode
158 unsigned getResNo() const { return ResNo; }
159
160 /// get the SDNode which holds the desired result
161 SDNode *getNode() const { return Node; }
162
163 /// set the SDNode
164 void setNode(SDNode *N) { Node = N; }
165
166 inline SDNode *operator->() const { return Node; }
167
168 bool operator==(const SDValue &O) const {
169 return Node == O.Node && ResNo == O.ResNo;
170 }
171 bool operator!=(const SDValue &O) const {
172 return !operator==(O);
173 }
174 bool operator<(const SDValue &O) const {
175 return std::tie(Node, ResNo) < std::tie(O.Node, O.ResNo);
176 }
177 explicit operator bool() const {
178 return Node != nullptr;
179 }
180
181 SDValue getValue(unsigned R) const {
182 return SDValue(Node, R);
183 }
184
185 /// Return true if the referenced return value is an operand of N.
186 LLVM_ABI bool isOperandOf(const SDNode *N) const;
187
188 /// Return the ValueType of the referenced return value.
189 inline EVT getValueType() const;
190
191 /// Return the simple ValueType of the referenced return value.
193 return getValueType().getSimpleVT();
194 }
195
196 /// Returns the size of the value in bits.
197 ///
198 /// If the value type is a scalable vector type, the scalable property will
199 /// be set and the runtime size will be a positive integer multiple of the
200 /// base size.
202 return getValueType().getSizeInBits();
203 }
204
208
209 // Forwarding methods - These forward to the corresponding methods in SDNode.
210 inline unsigned getOpcode() const;
211 inline unsigned getNumOperands() const;
212 inline const SDValue &getOperand(unsigned i) const;
213 inline uint64_t getConstantOperandVal(unsigned i) const;
214 inline const APInt &getConstantOperandAPInt(unsigned i) const;
215 inline ISD::CondCode getOperandCondCode(unsigned i) const;
216 inline bool isTargetOpcode() const;
217 inline bool isMachineOpcode() const;
218 inline bool isUndef() const;
219 inline bool isAnyAdd() const;
220 inline unsigned getMachineOpcode() const;
221 inline const DebugLoc &getDebugLoc() const;
222 inline void dump() const;
223 inline void dump(const SelectionDAG *G) const;
224 inline void dumpr() const;
225 inline void dumpr(const SelectionDAG *G) const;
226
227 /// Return true if this operand (which must be a chain) reaches the
228 /// specified operand without crossing any side-effecting instructions.
229 /// In practice, this looks through token factors and non-volatile loads.
230 /// In order to remain efficient, this only
231 /// looks a couple of nodes in, it does not do an exhaustive search.
233 unsigned Depth = 2) const;
234
235 /// Return true if there are no nodes using value ResNo of Node.
236 inline bool use_empty() const;
237
238 /// Return true if there is exactly one node using value ResNo of Node, in
239 /// exactly one operand.
240 inline bool hasOneUse() const;
241
242 /// Return true if there is exactly one node using value ResNo of Node, in
243 /// potentially multiple operands.
244 inline bool hasOneUser() const;
245};
246
247template <> struct DenseMapInfo<SDValue> {
248 static unsigned getHashValue(const SDValue &Val) {
250 Val.getResNo();
251 }
252
253 static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
254 return LHS == RHS;
255 }
256};
257
258/// Allow casting operators to work directly on
259/// SDValues as if they were SDNode*'s.
260template<> struct simplify_type<SDValue> {
262
264 return Val.getNode();
265 }
266};
267template<> struct simplify_type<const SDValue> {
268 using SimpleType = /*const*/ SDNode *;
269
271 return Val.getNode();
272 }
273};
274
275/// Represents a use of a SDNode. This class holds an SDValue,
276/// which records the SDNode being used and the result number, a
277/// pointer to the SDNode using the value, and Next and Prev pointers,
278/// which link together all the uses of an SDNode.
279///
280class SDUse {
281 /// Val - The value being used.
282 SDValue Val;
283 /// User - The user of this value.
284 SDNode *User = nullptr;
285 /// Prev, Next - Pointers to the uses list of the SDNode referred by
286 /// this operand.
287 SDUse **Prev = nullptr;
288 SDUse *Next = nullptr;
289
290public:
291 SDUse() = default;
292 SDUse(const SDUse &U) = delete;
293 SDUse &operator=(const SDUse &) = delete;
294
295 /// Normally SDUse will just implicitly convert to an SDValue that it holds.
296 operator const SDValue&() const { return Val; }
297
298 /// If implicit conversion to SDValue doesn't work, the get() method returns
299 /// the SDValue.
300 const SDValue &get() const { return Val; }
301
302 /// This returns the SDNode that contains this Use.
303 SDNode *getUser() { return User; }
304 const SDNode *getUser() const { return User; }
305
306 /// Get the next SDUse in the use list.
307 SDUse *getNext() const { return Next; }
308
309 /// Return the operand # of this use in its user.
310 inline unsigned getOperandNo() const;
311
312 /// Convenience function for get().getNode().
313 SDNode *getNode() const { return Val.getNode(); }
314 /// Convenience function for get().getResNo().
315 unsigned getResNo() const { return Val.getResNo(); }
316 /// Convenience function for get().getValueType().
317 EVT getValueType() const { return Val.getValueType(); }
318
319 /// Convenience function for get().operator==
320 bool operator==(const SDValue &V) const {
321 return Val == V;
322 }
323
324 /// Convenience function for get().operator!=
325 bool operator!=(const SDValue &V) const {
326 return Val != V;
327 }
328
329 /// Convenience function for get().operator<
330 bool operator<(const SDValue &V) const {
331 return Val < V;
332 }
333
334private:
335 friend class SelectionDAG;
336 friend class SDNode;
337 // TODO: unfriend HandleSDNode once we fix its operand handling.
338 friend class HandleSDNode;
339
340 void setUser(SDNode *p) { User = p; }
341
342 /// Remove this use from its existing use list, assign it the
343 /// given value, and add it to the new value's node's use list.
344 inline void set(const SDValue &V);
345 /// Like set, but only supports initializing a newly-allocated
346 /// SDUse with a non-null value.
347 inline void setInitial(const SDValue &V);
348 /// Like set, but only sets the Node portion of the value,
349 /// leaving the ResNo portion unmodified.
350 inline void setNode(SDNode *N);
351
352 void addToList(SDUse **List) {
353 Next = *List;
354 if (Next) Next->Prev = &Next;
355 Prev = List;
356 *List = this;
357 }
358
359 void removeFromList() {
360 *Prev = Next;
361 if (Next) Next->Prev = Prev;
362 }
363};
364
365/// simplify_type specializations - Allow casting operators to work directly on
366/// SDValues as if they were SDNode*'s.
367template<> struct simplify_type<SDUse> {
369
371 return Val.getNode();
372 }
373};
374
375/// These are IR-level optimization flags that may be propagated to SDNodes.
376/// TODO: This data structure should be shared by the IR optimizer and the
377/// the backend.
379private:
380 friend class SDNode;
381
382 unsigned Flags = 0;
383
384 template <unsigned Flag> void setFlag(bool B) {
385 Flags = (Flags & ~Flag) | (B ? Flag : 0);
386 }
387
388public:
389 enum : unsigned {
390 None = 0,
392 NoSignedWrap = 1 << 1,
394 Exact = 1 << 2,
395 Disjoint = 1 << 3,
396 NonNeg = 1 << 4,
397 NoNaNs = 1 << 5,
398 NoInfs = 1 << 6,
404
405 // We assume instructions do not raise floating-point exceptions by default,
406 // and only those marked explicitly may do so. We could choose to represent
407 // this via a positive "FPExcept" flags like on the MI level, but having a
408 // negative "NoFPExcept" flag here makes the flag intersection logic more
409 // straightforward.
410 NoFPExcept = 1 << 12,
411 // Instructions with attached 'unpredictable' metadata on IR level.
412 Unpredictable = 1 << 13,
413 // Compare instructions which may carry the samesign flag.
414 SameSign = 1 << 14,
415 // ISD::PTRADD operations that remain in bounds, i.e., the left operand is
416 // an address in a memory object in which the result of the operation also
417 // lies. WARNING: Since SDAG generally uses integers instead of pointer
418 // types, a PTRADD's pointer operand is effectively the result of an
419 // implicit inttoptr cast. Therefore, when an inbounds PTRADD uses a
420 // pointer P, transformations cannot assume that P has the provenance
421 // implied by its producer as, e.g, operations between producer and PTRADD
422 // that affect the provenance may have been optimized away.
423 InBounds = 1 << 15,
424
425 // Call does not require convergence guarantees.
426 NoConvergent = 1 << 16,
427
428 // ISD::ADDRSPACECAST where the source is known not to be the null value of
429 // the source address space, so the result is poison if the source is null.
430 NonNull = 1 << 17,
431
432 // NOTE: Please update LargestValue in LLVM_DECLARE_ENUM_AS_BITMASK below
433 // the class definition when adding new flags.
434
439 };
440
441 /// Default constructor turns off all optimization flags.
442 SDNodeFlags(unsigned Flags = SDNodeFlags::None) : Flags(Flags) {}
443
444 /// Propagate the fast-math-flags from an IR FPMathOperator.
454
455 // These are mutators for each flag.
456 void setNoUnsignedWrap(bool b) { setFlag<NoUnsignedWrap>(b); }
457 void setNoSignedWrap(bool b) { setFlag<NoSignedWrap>(b); }
458 void setExact(bool b) { setFlag<Exact>(b); }
459 void setDisjoint(bool b) { setFlag<Disjoint>(b); }
460 void setSameSign(bool b) { setFlag<SameSign>(b); }
461 void setNonNeg(bool b) { setFlag<NonNeg>(b); }
462 void setNoNaNs(bool b) { setFlag<NoNaNs>(b); }
463 void setNoInfs(bool b) { setFlag<NoInfs>(b); }
464 void setNoSignedZeros(bool b) { setFlag<NoSignedZeros>(b); }
465 void setAllowReciprocal(bool b) { setFlag<AllowReciprocal>(b); }
466 void setAllowContract(bool b) { setFlag<AllowContract>(b); }
467 void setApproximateFuncs(bool b) { setFlag<ApproximateFuncs>(b); }
468 void setAllowReassociation(bool b) { setFlag<AllowReassociation>(b); }
469 void setNoFPExcept(bool b) { setFlag<NoFPExcept>(b); }
470 void setUnpredictable(bool b) { setFlag<Unpredictable>(b); }
471 void setInBounds(bool b) { setFlag<InBounds>(b); }
472 void setNoConvergent(bool b) { setFlag<NoConvergent>(b); }
473 void setNonNull(bool b) { setFlag<NonNull>(b); }
474
475 // These are accessors for each flag.
476 bool hasNoUnsignedWrap() const { return Flags & NoUnsignedWrap; }
477 bool hasNoSignedWrap() const { return Flags & NoSignedWrap; }
478 bool hasExact() const { return Flags & Exact; }
479 bool hasDisjoint() const { return Flags & Disjoint; }
480 bool hasSameSign() const { return Flags & SameSign; }
481 bool hasNonNeg() const { return Flags & NonNeg; }
482 bool hasNoNaNs() const { return Flags & NoNaNs; }
483 bool hasNoInfs() const { return Flags & NoInfs; }
484 bool hasNoSignedZeros() const { return Flags & NoSignedZeros; }
485 bool hasAllowReciprocal() const { return Flags & AllowReciprocal; }
486 bool hasAllowContract() const { return Flags & AllowContract; }
487 bool hasApproximateFuncs() const { return Flags & ApproximateFuncs; }
488 bool hasAllowReassociation() const { return Flags & AllowReassociation; }
489 bool hasNoFPExcept() const { return Flags & NoFPExcept; }
490 bool hasUnpredictable() const { return Flags & Unpredictable; }
491 bool hasInBounds() const { return Flags & InBounds; }
492 bool hasNoConvergent() const { return Flags & NoConvergent; }
493 bool hasNonNull() const { return Flags & NonNull; }
494
495 bool operator==(const SDNodeFlags &Other) const {
496 return Flags == Other.Flags;
497 }
498 void operator&=(const SDNodeFlags &OtherFlags) { Flags &= OtherFlags.Flags; }
499 void operator|=(const SDNodeFlags &OtherFlags) { Flags |= OtherFlags.Flags; }
500};
501
503
505 LHS |= RHS;
506 return LHS;
507}
508
510 LHS &= RHS;
511 return LHS;
512}
513
514/// Represents one node in the SelectionDAG.
515///
516class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
517private:
518 /// The operation that this node performs.
519 int32_t NodeType;
520
521 SDNodeFlags Flags;
522
523protected:
524 // We define a set of mini-helper classes to help us interpret the bits in our
525 // SubclassData. These are designed to fit within a uint16_t so they pack
526 // with SDNodeFlags.
527
528#if defined(_AIX) && (!defined(__GNUC__) || defined(__clang__))
529// Except for GCC; by default, AIX compilers store bit-fields in 4-byte words
530// and give the `pack` pragma push semantics.
531#define BEGIN_TWO_BYTE_PACK() _Pragma("pack(2)")
532#define END_TWO_BYTE_PACK() _Pragma("pack(pop)")
533#else
534#define BEGIN_TWO_BYTE_PACK()
535#define END_TWO_BYTE_PACK()
536#endif
537
540 friend class SDNode;
541 friend class MemIntrinsicSDNode;
542 friend class MemSDNode;
543 friend class SelectionDAG;
544
545 uint16_t HasDebugValue : 1;
546 uint16_t IsMemIntrinsic : 1;
547 uint16_t IsDivergent : 1;
548 };
549 enum { NumSDNodeBits = 3 };
550
552 friend class ConstantSDNode;
553
555
556 uint16_t IsOpaque : 1;
557 };
558
560 friend class MemSDNode;
561 friend class MemIntrinsicSDNode;
562 friend class AtomicSDNode;
563
565
566 uint16_t IsVolatile : 1;
567 uint16_t IsNonTemporal : 1;
568 uint16_t IsDereferenceable : 1;
569 uint16_t IsInvariant : 1;
570 };
572
574 friend class LSBaseSDNode;
580
582
583 // This storage is shared between disparate class hierarchies to hold an
584 // enumeration specific to the class hierarchy in use.
585 // LSBaseSDNode => enum ISD::MemIndexedMode
586 // VPLoadStoreBaseSDNode => enum ISD::MemIndexedMode
587 // MaskedLoadStoreBaseSDNode => enum ISD::MemIndexedMode
588 // VPGatherScatterSDNode => enum ISD::MemIndexType
589 // MaskedGatherScatterSDNode => enum ISD::MemIndexType
590 // MaskedHistogramSDNode => enum ISD::MemIndexType
591 uint16_t AddressingMode : 3;
592 };
594
596 friend class LoadSDNode;
597 friend class AtomicSDNode;
598 friend class VPLoadSDNode;
600 friend class MaskedLoadSDNode;
601 friend class MaskedGatherSDNode;
602 friend class VPGatherSDNode;
604
606
607 uint16_t ExtTy : 2; // enum ISD::LoadExtType
608 uint16_t IsExpanding : 1;
609 };
610
612 friend class StoreSDNode;
613 friend class VPStoreSDNode;
615 friend class MaskedStoreSDNode;
617 friend class VPScatterSDNode;
618
620
621 uint16_t IsTruncating : 1;
622 uint16_t IsCompressing : 1;
623 };
624
625 union {
626 char RawSDNodeBits[sizeof(uint16_t)];
633 };
635#undef BEGIN_TWO_BYTE_PACK
636#undef END_TWO_BYTE_PACK
637
638 // RawSDNodeBits must cover the entirety of the union. This means that all of
639 // the union's members must have size <= RawSDNodeBits. We write the RHS as
640 // "2" instead of sizeof(RawSDNodeBits) because MSVC can't handle the latter.
641 static_assert(sizeof(SDNodeBitfields) <= 2, "field too wide");
642 static_assert(sizeof(ConstantSDNodeBitfields) <= 2, "field too wide");
643 static_assert(sizeof(MemSDNodeBitfields) <= 2, "field too wide");
644 static_assert(sizeof(LSBaseSDNodeBitfields) <= 2, "field too wide");
645 static_assert(sizeof(LoadSDNodeBitfields) <= 2, "field too wide");
646 static_assert(sizeof(StoreSDNodeBitfields) <= 2, "field too wide");
647
648public:
649 /// Unique and persistent id per SDNode in the DAG. Used for debug printing.
650 /// We do not place that under `#if LLVM_ENABLE_ABI_BREAKING_CHECKS`
651 /// intentionally because it adds unneeded complexity without noticeable
652 /// benefits (see discussion with @thakis in D120714). Currently, there are
653 /// two padding bytes after this field.
655
656private:
657 friend class SelectionDAG;
658 // TODO: unfriend HandleSDNode once we fix its operand handling.
659 friend class HandleSDNode;
660
661 /// Unique id per SDNode in the DAG.
662 int NodeId = -1;
663
664 /// The values that are used by this operation.
665 SDUse *OperandList = nullptr;
666
667 /// The types of the values this node defines. SDNode's may
668 /// define multiple values simultaneously.
669 const EVT *ValueList;
670
671 /// List of uses for this SDNode.
672 SDUse *UseList = nullptr;
673
674 /// The number of entries in the Operand/Value list.
675 unsigned short NumOperands = 0;
676 unsigned short NumValues;
677
678 // The ordering of the SDNodes. It roughly corresponds to the ordering of the
679 // original LLVM instructions.
680 // This is used for turning off scheduling, because we'll forgo
681 // the normal scheduling algorithms and output the instructions according to
682 // this ordering.
683 unsigned IROrder;
684
685 /// Source line information.
686 DebugLoc debugLoc;
687
688 /// Return a pointer to the specified value type.
689 LLVM_ABI static const EVT *getValueTypeList(MVT VT);
690
691 union {
692 /// Index in worklist of DAGCombiner, or negative if the node is not in the
693 /// worklist. -1 = not in worklist; -2 = not in worklist, but has already
694 /// been combined at least once.
696 /// Visited state in ScheduleDAGSDNodes::BuildSchedUnits.
698 };
699
700 uint32_t CFIType = 0;
701
702public:
703 //===--------------------------------------------------------------------===//
704 // Accessors
705 //
706
707 /// Return the SelectionDAG opcode value for this node. For
708 /// pre-isel nodes (those for which isMachineOpcode returns false), these
709 /// are the opcode values in the ISD and <target>ISD namespaces. For
710 /// post-isel opcodes, see getMachineOpcode.
711 unsigned getOpcode() const { return (unsigned)NodeType; }
712
713 /// Test if this node has a target-specific opcode (in the
714 /// <target>ISD namespace).
715 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
716
717 /// Returns true if the node type is UNDEF or POISON.
718 bool isUndef() const {
719 return NodeType == ISD::UNDEF || NodeType == ISD::POISON;
720 }
721
722 /// Returns true if the node type is ADD or PTRADD.
723 bool isAnyAdd() const {
724 return NodeType == ISD::ADD || NodeType == ISD::PTRADD;
725 }
726
727 /// Test if this node is a memory intrinsic (with valid pointer information).
728 bool isMemIntrinsic() const { return SDNodeBits.IsMemIntrinsic; }
729
730 /// Test if this node is a strict floating point pseudo-op.
732 switch (NodeType) {
733 default:
734 return false;
739#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
740 case ISD::STRICT_##DAGN:
741#include "llvm/IR/ConstrainedOps.def"
742 return true;
743 }
744 }
745
746 /// Test if this node is an assert operation.
747 bool isAssert() const {
748 switch (NodeType) {
749 default:
750 return false;
751 case ISD::AssertAlign:
753 case ISD::AssertSext:
754 case ISD::AssertZext:
755 return true;
756 }
757 }
758
759 /// Test if this node is a vector predication operation.
760 bool isVPOpcode() const { return ISD::isVPOpcode(getOpcode()); }
761
762 /// Test if this node has a post-isel opcode, directly
763 /// corresponding to a MachineInstr opcode.
764 bool isMachineOpcode() const { return NodeType < 0; }
765
766 /// As above, for an opcode not held by a node.
767 static bool isMachineOpcode(unsigned Opc) {
768 return static_cast<int32_t>(Opc) < 0;
769 }
770
771 /// This may only be called if isMachineOpcode returns
772 /// true. It returns the MachineInstr opcode value that the node's opcode
773 /// corresponds to.
774 unsigned getMachineOpcode() const {
775 assert(isMachineOpcode() && "Not a MachineInstr opcode!");
776 return ~NodeType;
777 }
778
779 bool getHasDebugValue() const { return SDNodeBits.HasDebugValue; }
780 void setHasDebugValue(bool b) { SDNodeBits.HasDebugValue = b; }
781
782 bool isDivergent() const { return SDNodeBits.IsDivergent; }
783
784 /// Return true if there are no uses of this node.
785 bool use_empty() const { return UseList == nullptr; }
786
787 /// Return true if there is exactly one use of this node.
788 bool hasOneUse() const { return hasSingleElement(uses()); }
789
790 /// Return the number of uses of this node. This method takes
791 /// time proportional to the number of uses.
792 size_t use_size() const { return std::distance(use_begin(), use_end()); }
793
794 /// Return the unique node id.
795 int getNodeId() const { return NodeId; }
796
797 /// Set unique node id.
798 void setNodeId(int Id) { NodeId = Id; }
799
800 /// Get worklist index for DAGCombiner
802
803 /// Set worklist index for DAGCombiner
805
806 /// Get visited state for ScheduleDAGSDNodes::BuildSchedUnits.
808
809 /// Set visited state for ScheduleDAGSDNodes::BuildSchedUnits.
810 void setSchedulerWorklistVisited(bool Visited) {
811 SchedulerWorklistVisited = Visited;
812 }
813
814 /// Return the node ordering.
815 unsigned getIROrder() const { return IROrder; }
816
817 /// Set the node ordering.
818 void setIROrder(unsigned Order) { IROrder = Order; }
819
820 /// Return the source location info.
821 const DebugLoc &getDebugLoc() const { return debugLoc; }
822
823 /// Set source location info. Try to avoid this, putting
824 /// it in the constructor is preferable.
825 void setDebugLoc(DebugLoc dl) { debugLoc = std::move(dl); }
826
827 /// This class provides iterator support for SDUse
828 /// operands that use a specific SDNode.
829 class use_iterator {
830 friend class SDNode;
831
832 SDUse *Op = nullptr;
833
834 explicit use_iterator(SDUse *op) : Op(op) {}
835
836 public:
837 using iterator_category = std::forward_iterator_tag;
839 using difference_type = std::ptrdiff_t;
842
843 use_iterator() = default;
844 use_iterator(const use_iterator &I) = default;
845 use_iterator &operator=(const use_iterator &) = default;
846
847 bool operator==(const use_iterator &x) const { return Op == x.Op; }
848 bool operator!=(const use_iterator &x) const {
849 return !operator==(x);
850 }
851
852 // Iterator traversal: forward iteration only.
853 use_iterator &operator++() { // Preincrement
854 assert(Op && "Cannot increment end iterator!");
855 Op = Op->getNext();
856 return *this;
857 }
858
859 use_iterator operator++(int) { // Postincrement
860 use_iterator tmp = *this; ++*this; return tmp;
861 }
862
863 /// Retrieve a pointer to the current user node.
864 SDUse &operator*() const {
865 assert(Op && "Cannot dereference end iterator!");
866 return *Op;
867 }
868
869 SDUse *operator->() const { return &operator*(); }
870 };
871
872 class user_iterator {
873 friend class SDNode;
874 use_iterator UI;
875
876 explicit user_iterator(SDUse *op) : UI(op) {};
877
878 public:
879 using iterator_category = std::forward_iterator_tag;
881 using difference_type = std::ptrdiff_t;
884
885 user_iterator() = default;
886
887 bool operator==(const user_iterator &x) const { return UI == x.UI; }
888 bool operator!=(const user_iterator &x) const { return !operator==(x); }
889
890 user_iterator &operator++() { // Preincrement
891 ++UI;
892 return *this;
893 }
894
895 user_iterator operator++(int) { // Postincrement
896 auto tmp = *this;
897 ++*this;
898 return tmp;
899 }
900
901 // Retrieve a pointer to the current User.
902 SDNode *operator*() const { return UI->getUser(); }
903
904 SDNode *operator->() const { return operator*(); }
905
906 SDUse &getUse() const { return *UI; }
907 };
908
909 /// Provide iteration support to walk over all uses of an SDNode.
911 return use_iterator(UseList);
912 }
913
914 static use_iterator use_end() { return use_iterator(nullptr); }
915
920 return make_range(use_begin(), use_end());
921 }
922
923 /// Provide iteration support to walk over all users of an SDNode.
924 user_iterator user_begin() const { return user_iterator(UseList); }
925
926 static user_iterator user_end() { return user_iterator(nullptr); }
927
932 return make_range(user_begin(), user_end());
933 }
934
935 /// Return true if there are exactly NUSES uses of the indicated value.
936 /// This method ignores uses of other values defined by this operation.
937 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const {
938 assert(Value < getNumValues() && "Bad value!");
939
940 // TODO: Only iterate over uses of a given value of the node
941 for (SDUse &U : uses()) {
942 if (U.getResNo() == Value) {
943 if (NUses == 0)
944 return false;
945 --NUses;
946 }
947 }
948
949 // Found exactly the right number of uses?
950 return NUses == 0;
951 }
952
953 /// Return true if there are any use of the indicated value.
954 /// This method ignores uses of other values defined by this operation.
955 LLVM_ABI bool hasAnyUseOfValue(unsigned Value) const;
956
957 /// Return true if this node is the only use of N.
958 LLVM_ABI bool isOnlyUserOf(const SDNode *N) const;
959
960 /// Return true if this node is an operand of N.
961 LLVM_ABI bool isOperandOf(const SDNode *N) const;
962
963 /// Return true if this node is a predecessor of N.
964 /// NOTE: Implemented on top of hasPredecessor and every bit as
965 /// expensive. Use carefully.
966 bool isPredecessorOf(const SDNode *N) const {
967 return N->hasPredecessor(this);
968 }
969
970 /// Return true if N is a predecessor of this node.
971 /// N is either an operand of this node, or can be reached by recursively
972 /// traversing up the operands.
973 /// NOTE: This is an expensive method. Use it carefully.
974 LLVM_ABI bool hasPredecessor(const SDNode *N) const;
975
976 /// Returns true if N is a predecessor of any node in Worklist. This
977 /// helper keeps Visited and Worklist sets externally to allow unions
978 /// searches to be performed in parallel, caching of results across
979 /// queries and incremental addition to Worklist. Stops early if N is
980 /// found but will resume. Remember to clear Visited and Worklists
981 /// if DAG changes. MaxSteps gives a maximum number of nodes to visit before
982 /// giving up. The TopologicalPrune flag signals that positive NodeIds are
983 /// topologically ordered (Operands have strictly smaller node id) and search
984 /// can be pruned leveraging this.
985 static bool hasPredecessorHelper(const SDNode *N,
988 unsigned int MaxSteps = 0,
989 bool TopologicalPrune = false) {
990 if (Visited.count(N))
991 return true;
992
993 SmallVector<const SDNode *, 8> DeferredNodes;
994 // Node Id's are assigned in three places: As a topological
995 // ordering (> 0), during legalization (results in values set to
996 // 0), new nodes (set to -1). If N has a topolgical id then we
997 // know that all nodes with ids smaller than it cannot be
998 // successors and we need not check them. Filter out all node
999 // that can't be matches. We add them to the worklist before exit
1000 // in case of multiple calls. Note that during selection the topological id
1001 // may be violated if a node's predecessor is selected before it. We mark
1002 // this at selection negating the id of unselected successors and
1003 // restricting topological pruning to positive ids.
1004
1005 int NId = N->getNodeId();
1006 // If we Invalidated the Id, reconstruct original NId.
1007 if (NId < -1)
1008 NId = -(NId + 1);
1009
1010 bool Found = false;
1011 while (!Worklist.empty()) {
1012 const SDNode *M = Worklist.pop_back_val();
1013 int MId = M->getNodeId();
1014 if (TopologicalPrune && M->getOpcode() != ISD::TokenFactor && (NId > 0) &&
1015 (MId > 0) && (MId < NId)) {
1016 DeferredNodes.push_back(M);
1017 continue;
1018 }
1019 for (const SDValue &OpV : M->op_values()) {
1020 SDNode *Op = OpV.getNode();
1021 if (Visited.insert(Op).second)
1022 Worklist.push_back(Op);
1023 if (Op == N)
1024 Found = true;
1025 }
1026 if (Found)
1027 break;
1028 if (MaxSteps != 0 && Visited.size() >= MaxSteps)
1029 break;
1030 }
1031 // Push deferred nodes back on worklist.
1032 Worklist.append(DeferredNodes.begin(), DeferredNodes.end());
1033 // If we bailed early, conservatively return found.
1034 if (MaxSteps != 0 && Visited.size() >= MaxSteps)
1035 return true;
1036 return Found;
1037 }
1038
1039 /// Return true if all the users of N are contained in Nodes.
1040 /// NOTE: Requires at least one match, but doesn't require them all.
1042 const SDNode *N);
1043
1044 /// Return the number of values used by this operation.
1045 unsigned getNumOperands() const { return NumOperands; }
1046
1047 /// Return the maximum number of operands that a SDNode can hold.
1048 static constexpr size_t getMaxNumOperands() {
1049 return std::numeric_limits<decltype(SDNode::NumOperands)>::max();
1050 }
1051
1052 /// Helper method returns the integer value of a ConstantSDNode operand.
1053 inline uint64_t getConstantOperandVal(unsigned Num) const;
1054
1055 /// Helper method returns the zero-extended integer value of a ConstantSDNode.
1056 inline uint64_t getAsZExtVal() const;
1057
1058 /// Helper method returns the APInt of a ConstantSDNode operand.
1059 inline const APInt &getConstantOperandAPInt(unsigned Num) const;
1060
1061 /// Helper method returns the APInt value of a ConstantSDNode.
1062 inline const APInt &getAsAPIntVal() const;
1063
1064 /// Helper method returns the CondCode of a CondCodeSDNode.
1065 inline ISD::CondCode getOperandCondCode(unsigned Num) const;
1066
1067 inline std::optional<APInt> bitcastToAPInt() const;
1068
1069 const SDValue &getOperand(unsigned Num) const {
1070 assert(Num < NumOperands && "Invalid child # of SDNode!");
1071 return OperandList[Num];
1072 }
1073
1075
1076 op_iterator op_begin() const { return OperandList; }
1077 op_iterator op_end() const { return OperandList+NumOperands; }
1078 ArrayRef<SDUse> ops() const { return ArrayRef(op_begin(), op_end()); }
1079
1080 /// Iterator for directly iterating over the operand SDValue's.
1082 : iterator_adaptor_base<value_op_iterator, op_iterator,
1083 std::random_access_iterator_tag, SDValue,
1084 ptrdiff_t, value_op_iterator *,
1085 value_op_iterator *> {
1086 explicit value_op_iterator(SDUse *U = nullptr)
1087 : iterator_adaptor_base(U) {}
1088
1089 const SDValue &operator*() const { return I->get(); }
1090 };
1091
1096
1098 SDVTList X = { ValueList, NumValues };
1099 return X;
1100 }
1101
1102 /// If this node has a glue operand, return the node
1103 /// to which the glue operand points. Otherwise return NULL.
1105 if (getNumOperands() != 0 &&
1106 getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
1107 return getOperand(getNumOperands()-1).getNode();
1108 return nullptr;
1109 }
1110
1111 /// If this node has a glue value with a user, return
1112 /// the user (there is at most one). Otherwise return NULL.
1114 for (SDUse &U : uses())
1115 if (U.getValueType() == MVT::Glue)
1116 return U.getUser();
1117 return nullptr;
1118 }
1119
1120 SDNodeFlags getFlags() const { return Flags; }
1121 void setFlags(SDNodeFlags NewFlags) { Flags = NewFlags; }
1122 void dropFlags(unsigned Mask) { Flags &= ~Mask; }
1123
1124 /// Clear any flags in this node that aren't also set in Flags.
1125 /// If Flags is not in a defined state then this has no effect.
1126 LLVM_ABI void intersectFlagsWith(const SDNodeFlags Flags);
1127
1129 return Flags.Flags & SDNodeFlags::PoisonGeneratingFlags;
1130 }
1131
1132 void setCFIType(uint32_t Type) { CFIType = Type; }
1133 uint32_t getCFIType() const { return CFIType; }
1134
1135 /// Return the number of values defined/returned by this operator.
1136 unsigned getNumValues() const { return NumValues; }
1137
1138 /// Return the type of a specified result.
1139 EVT getValueType(unsigned ResNo) const {
1140 assert(ResNo < NumValues && "Illegal result number!");
1141 return ValueList[ResNo];
1142 }
1143
1144 /// Return the type of a specified result as a simple type.
1145 MVT getSimpleValueType(unsigned ResNo) const {
1146 return getValueType(ResNo).getSimpleVT();
1147 }
1148
1149 /// Returns MVT::getSizeInBits(getValueType(ResNo)).
1150 ///
1151 /// If the value type is a scalable vector type, the scalable property will
1152 /// be set and the runtime size will be a positive integer multiple of the
1153 /// base size.
1154 TypeSize getValueSizeInBits(unsigned ResNo) const {
1155 return getValueType(ResNo).getSizeInBits();
1156 }
1157
1158 using value_iterator = const EVT *;
1159
1160 value_iterator value_begin() const { return ValueList; }
1161 value_iterator value_end() const { return ValueList+NumValues; }
1165
1166 /// Return the opcode of this operation for printing.
1167 LLVM_ABI std::string getOperationName(const SelectionDAG *G = nullptr) const;
1168 LLVM_ABI static const char *getIndexedModeName(ISD::MemIndexedMode AM);
1169 LLVM_ABI void print_types(raw_ostream &OS, const SelectionDAG *G) const;
1170 LLVM_ABI void print_details(raw_ostream &OS, const SelectionDAG *G) const;
1171 LLVM_ABI void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
1172 LLVM_ABI void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
1173
1174 /// Print a SelectionDAG node and all children down to
1175 /// the leaves. The given SelectionDAG allows target-specific nodes
1176 /// to be printed in human-readable form. Unlike printr, this will
1177 /// print the whole DAG, including children that appear multiple
1178 /// times.
1179 ///
1181 const SelectionDAG *G = nullptr) const;
1182
1183 /// Print a SelectionDAG node and children up to
1184 /// depth "depth." The given SelectionDAG allows target-specific
1185 /// nodes to be printed in human-readable form. Unlike printr, this
1186 /// will print children that appear multiple times wherever they are
1187 /// used.
1188 ///
1189 LLVM_ABI void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
1190 unsigned depth = 100) const;
1191
1192 /// Dump this node, for debugging.
1193 LLVM_ABI void dump() const;
1194
1195 /// Dump (recursively) this node and its use-def subgraph.
1196 LLVM_ABI void dumpr() const;
1197
1198 /// Dump this node, for debugging.
1199 /// The given SelectionDAG allows target-specific nodes to be printed
1200 /// in human-readable form.
1201 LLVM_ABI void dump(const SelectionDAG *G) const;
1202
1203 /// Dump (recursively) this node and its use-def subgraph.
1204 /// The given SelectionDAG allows target-specific nodes to be printed
1205 /// in human-readable form.
1206 LLVM_ABI void dumpr(const SelectionDAG *G) const;
1207
1208 /// printrFull to dbgs(). The given SelectionDAG allows
1209 /// target-specific nodes to be printed in human-readable form.
1210 /// Unlike dumpr, this will print the whole DAG, including children
1211 /// that appear multiple times.
1212 LLVM_ABI void dumprFull(const SelectionDAG *G = nullptr) const;
1213
1214 /// printrWithDepth to dbgs(). The given
1215 /// SelectionDAG allows target-specific nodes to be printed in
1216 /// human-readable form. Unlike dumpr, this will print children
1217 /// that appear multiple times wherever they are used.
1218 ///
1219 LLVM_ABI void dumprWithDepth(const SelectionDAG *G = nullptr,
1220 unsigned depth = 100) const;
1221
1222 /// This method should only be used by the SDUse class.
1223 void addUse(SDUse &U) { U.addToList(&UseList); }
1224
1225protected:
1227 SDVTList Ret = { getValueTypeList(VT), 1 };
1228 return Ret;
1229 }
1230
1231 /// Create an SDNode.
1232 ///
1233 /// SDNodes are created without any operands, and never own the operand
1234 /// storage. To add operands, see SelectionDAG::createOperands.
1235 SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
1236 : NodeType(Opc), ValueList(VTs.VTs), NumValues(VTs.NumVTs),
1237 IROrder(Order), debugLoc(std::move(dl)) {
1238 memset(&RawSDNodeBits, 0, sizeof(RawSDNodeBits));
1239 assert(NumValues == VTs.NumVTs &&
1240 "NumValues wasn't wide enough for its operands!");
1241 }
1242
1243 /// Release the operands and set this node to have zero operands.
1244 LLVM_ABI void DropOperands();
1245};
1246
1247/// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
1248/// into SDNode creation functions.
1249/// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
1250/// from the original Instruction, and IROrder is the ordinal position of
1251/// the instruction.
1252/// When an SDNode is created after the DAG is being built, both DebugLoc and
1253/// the IROrder are propagated from the original SDNode.
1254/// So SDLoc class provides two constructors besides the default one, one to
1255/// be used by the DAGBuilder, the other to be used by others.
1256class SDLoc {
1257private:
1258 DebugLoc DL;
1259 int IROrder = 0;
1260
1261public:
1262 SDLoc() = default;
1263 SDLoc(const SDNode *N) : DL(N->getDebugLoc()), IROrder(N->getIROrder()) {}
1264 SDLoc(const SDValue V) : SDLoc(V.getNode()) {}
1265 SDLoc(const Instruction *I, int Order) : IROrder(Order) {
1266 assert(Order >= 0 && "bad IROrder");
1267 if (I)
1268 DL = I->getDebugLoc();
1269 }
1270
1271 unsigned getIROrder() const { return IROrder; }
1272 const DebugLoc &getDebugLoc() const { return DL; }
1273
1274 /// Merge the source location without changing the IR order.
1277 }
1278};
1279
1280// Define inline functions from the SDValue class.
1281
1282inline SDValue::SDValue(SDNode *node, unsigned resno)
1283 : Node(node), ResNo(resno) {
1284 // Explicitly check for !ResNo to avoid use-after-free, because there are
1285 // callers that use SDValue(N, 0) with a deleted N to indicate successful
1286 // combines.
1287 assert((!Node || !ResNo || ResNo < Node->getNumValues()) &&
1288 "Invalid result number for the given node!");
1289 assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
1290}
1291
1292inline unsigned SDValue::getOpcode() const {
1293 return Node->getOpcode();
1294}
1295
1297 return Node->getValueType(ResNo);
1298}
1299
1300inline unsigned SDValue::getNumOperands() const {
1301 return Node->getNumOperands();
1302}
1303
1304inline const SDValue &SDValue::getOperand(unsigned i) const {
1305 return Node->getOperand(i);
1306}
1307
1309 return Node->getConstantOperandVal(i);
1310}
1311
1312inline const APInt &SDValue::getConstantOperandAPInt(unsigned i) const {
1313 return Node->getConstantOperandAPInt(i);
1314}
1315
1317 return Node->getOperandCondCode(i);
1318}
1319
1320inline bool SDValue::isTargetOpcode() const {
1321 return Node->isTargetOpcode();
1322}
1323
1324inline bool SDValue::isMachineOpcode() const {
1325 return Node->isMachineOpcode();
1326}
1327
1328inline unsigned SDValue::getMachineOpcode() const {
1329 return Node->getMachineOpcode();
1330}
1331
1332inline bool SDValue::isUndef() const {
1333 return Node->isUndef();
1334}
1335
1336inline bool SDValue::isAnyAdd() const { return Node->isAnyAdd(); }
1337
1338inline bool SDValue::use_empty() const {
1339 return !Node->hasAnyUseOfValue(ResNo);
1340}
1341
1342inline bool SDValue::hasOneUse() const {
1343 return Node->hasNUsesOfValue(1, ResNo);
1344}
1345
1346inline bool SDValue::hasOneUser() const {
1347 auto Uses = make_filter_range(Node->uses(),
1348 [this](SDUse &U) { return U.get() == *this; });
1349 auto Users = map_range(Uses, [](SDUse &U) { return U.getUser(); });
1350 return all_equal(Users);
1351}
1352
1353inline const DebugLoc &SDValue::getDebugLoc() const {
1354 return Node->getDebugLoc();
1355}
1356
1357inline void SDValue::dump() const {
1358 return Node->dump();
1359}
1360
1361inline void SDValue::dump(const SelectionDAG *G) const {
1362 return Node->dump(G);
1363}
1364
1365inline void SDValue::dumpr() const {
1366 return Node->dumpr();
1367}
1368
1369inline void SDValue::dumpr(const SelectionDAG *G) const {
1370 return Node->dumpr(G);
1371}
1372
1373// Define inline functions from the SDUse class.
1374inline unsigned SDUse::getOperandNo() const {
1375 return this - getUser()->op_begin();
1376}
1377
1378inline void SDUse::set(const SDValue &V) {
1379 if (Val.getNode()) removeFromList();
1380 Val = V;
1381 if (V.getNode())
1382 V->addUse(*this);
1383}
1384
1385inline void SDUse::setInitial(const SDValue &V) {
1386 Val = V;
1387 V->addUse(*this);
1388}
1389
1390inline void SDUse::setNode(SDNode *N) {
1391 if (Val.getNode()) removeFromList();
1392 Val.setNode(N);
1393 if (N) N->addUse(*this);
1394}
1395
1396/// This class is used to form a handle around another node that
1397/// is persistent and is updated across invocations of replaceAllUsesWith on its
1398/// operand. This node should be directly created by end-users and not added to
1399/// the AllNodes list.
1400class HandleSDNode : public SDNode {
1401 SDUse Op;
1402
1403public:
1405 : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1406 // HandleSDNodes are never inserted into the DAG, so they won't be
1407 // auto-numbered. Use ID 65535 as a sentinel.
1408 PersistentId = 0xffff;
1409
1410 // Manually set up the operand list. This node type is special in that it's
1411 // always stack allocated and SelectionDAG does not manage its operands.
1412 // TODO: This should either (a) not be in the SDNode hierarchy, or (b) not
1413 // be so special.
1414 Op.setUser(this);
1415 Op.setInitial(X);
1416 NumOperands = 1;
1417 OperandList = &Op;
1418 }
1420
1421 const SDValue &getValue() const { return Op; }
1422};
1423
1425private:
1426 unsigned SrcAddrSpace;
1427 unsigned DestAddrSpace;
1428
1429public:
1430 AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
1431 unsigned SrcAS, unsigned DestAS)
1432 : SDNode(ISD::ADDRSPACECAST, Order, dl, VTs), SrcAddrSpace(SrcAS),
1433 DestAddrSpace(DestAS) {}
1434
1435 unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1436 unsigned getDestAddressSpace() const { return DestAddrSpace; }
1437
1438 static bool classof(const SDNode *N) {
1439 return N->getOpcode() == ISD::ADDRSPACECAST;
1440 }
1441};
1442
1443/// This is an abstract virtual class for memory operations.
1444class MemSDNode : public SDNode {
1445private:
1446 // VT of in-memory value.
1447 EVT MemoryVT;
1448
1449protected:
1450 /// Memory reference information. Must always have at least one MMO.
1451 /// - MachineMemOperand*: exactly 1 MMO (common case)
1452 /// - MachineMemOperand**: pointer to array, size at offset -1
1454
1455public:
1456 /// Constructor that supports single or multiple MMOs. For single MMO, pass
1457 /// the MMO pointer directly. For multiple MMOs, pre-allocate storage with
1458 /// count at offset -1 and pass pointer to array.
1459 LLVM_ABI
1460 MemSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs,
1461 EVT memvt,
1463
1464 bool readMem() const { return getMemOperand()->isLoad(); }
1465 bool writeMem() const { return getMemOperand()->isStore(); }
1466
1467 /// Returns alignment and volatility of the memory access
1469 Align getAlign() const { return getMemOperand()->getAlign(); }
1470
1471 /// Return the SubclassData value, without HasDebugValue. This contains an
1472 /// encoding of the volatile flag, as well as bits used by subclasses. This
1473 /// function should only be used to compute a FoldingSetNodeID value.
1474 /// The HasDebugValue bit is masked out because CSE map needs to match
1475 /// nodes with debug info with nodes without debug info. Same is about
1476 /// isDivergent bit.
1477 unsigned getRawSubclassData() const {
1478 uint16_t Data;
1479 union {
1480 char RawSDNodeBits[sizeof(uint16_t)];
1482 };
1483 memcpy(&RawSDNodeBits, &this->RawSDNodeBits, sizeof(this->RawSDNodeBits));
1484 SDNodeBits.HasDebugValue = 0;
1485 SDNodeBits.IsDivergent = false;
1486 memcpy(&Data, &RawSDNodeBits, sizeof(RawSDNodeBits));
1487 return Data;
1488 }
1489
1490 bool isVolatile() const { return MemSDNodeBits.IsVolatile; }
1491 bool isNonTemporal() const { return MemSDNodeBits.IsNonTemporal; }
1492 bool isDereferenceable() const { return MemSDNodeBits.IsDereferenceable; }
1493 bool isInvariant() const { return MemSDNodeBits.IsInvariant; }
1494
1495 // Returns the offset from the location of the access.
1496 int64_t getSrcValueOffset() const { return getMemOperand()->getOffset(); }
1497
1498 /// Returns the AA info that describes the dereference.
1500
1501 /// Returns the Ranges that describes the dereference.
1502 const MDNode *getRanges() const { return getMemOperand()->getRanges(); }
1503
1504 /// Returns the cache hint metadata for this memory access.
1505 const MDNode *getMemCacheHint() const {
1506 return getMemOperand()->getMemCacheHint();
1507 }
1508
1509 /// Returns metadata that can be copied unchanged to an access covering
1510 /// all or part of this access's bytes, even if the value type changes.
1511 /// Metadata describing the loaded value (e.g. !range) is excluded, since
1512 /// it may not apply to a value loaded with a different type or byte range.
1514 return MMOMetadata(getAAInfo(), /*Ranges=*/nullptr, getMemCacheHint());
1515 }
1516
1517 /// Returns the synchronization scope ID for this memory operation.
1519 return getMemOperand()->getSyncScopeID();
1520 }
1521
1522 /// Return the atomic ordering requirements for this memory operation. For
1523 /// cmpxchg atomic operations, return the atomic ordering requirements when
1524 /// store occurs.
1528
1529 /// Return a single atomic ordering that is at least as strong as both the
1530 /// success and failure orderings for an atomic operation. (For operations
1531 /// other than cmpxchg, this is equivalent to getSuccessOrdering().)
1535
1536 /// Return true if the memory operation ordering is Unordered or higher.
1537 bool isAtomic() const { return getMemOperand()->isAtomic(); }
1538
1539 /// Returns true if the memory operation doesn't imply any ordering
1540 /// constraints on surrounding memory operations beyond the normal memory
1541 /// aliasing rules.
1542 bool isUnordered() const { return getMemOperand()->isUnordered(); }
1543
1544 /// Returns true if the memory operation is neither atomic or volatile.
1545 bool isSimple() const { return !isAtomic() && !isVolatile(); }
1546
1547 /// Return the type of the in-memory value.
1548 EVT getMemoryVT() const { return MemoryVT; }
1549
1550 /// Return the unique MachineMemOperand object describing the memory
1551 /// reference performed by operation.
1552 /// Asserts if multiple MMOs are present - use memoperands() instead.
1555 "Use memoperands() for nodes with multiple memory operands");
1557 }
1558
1559 /// Return the number of memory operands.
1560 size_t getNumMemOperands() const {
1562 return 1;
1564 return reinterpret_cast<size_t *>(Array)[-1];
1565 }
1566
1567 /// Return true if this node has exactly one memory operand.
1569
1570 /// Return the memory operands for this node.
1573 return ArrayRef(MemRefs.getAddrOfPtr1(), 1);
1575 size_t Count = reinterpret_cast<size_t *>(Array)[-1];
1576 return ArrayRef(Array, Count);
1577 }
1578
1580 return getMemOperand()->getPointerInfo();
1581 }
1582
1583 /// Return the address space for the associated pointer
1584 unsigned getAddressSpace() const {
1585 return getPointerInfo().getAddrSpace();
1586 }
1587
1588 /// Update this MemSDNode's MachineMemOperand information
1589 /// to reflect the alignment of NewMMOs, if they have greater alignment.
1590 /// This must only be used when the new alignment applies to all users of
1591 /// these MachineMemOperands. The NewMMOs array must parallel memoperands().
1594 assert(NewMMOs.size() == MMOs.size() && "MMO count mismatch");
1595 for (auto [MMO, NewMMO] : zip(MMOs, NewMMOs))
1596 MMO->refineAlignment(NewMMO);
1597 }
1598
1600 refineAlignment(ArrayRef(NewMMO));
1601 }
1602
1603 /// Refine LLVM IR metadata for all MMOs. The NewMMOs array must parallel
1604 /// memoperands(). For each pair, if metadata differs, the stored metadata is
1605 /// cleared conservatively.
1608 assert(NewMMOs.size() == MMOs.size() && "MMO count mismatch");
1609 for (auto [MMO, NewMMO] : zip(MMOs, NewMMOs)) {
1610 // FIXME: Union the ranges instead?
1611 if (MMO->getRanges() && MMO->getRanges() != NewMMO->getRanges())
1612 MMO->clearRanges();
1613 if (MMO->getMemCacheHint() &&
1614 MMO->getMemCacheHint() != NewMMO->getMemCacheHint())
1615 MMO->clearMemCacheHint();
1616 }
1617 }
1618
1620 refineMMOMetadata(ArrayRef(NewMMO));
1621 }
1622
1623 const SDValue &getChain() const { return getOperand(0); }
1624
1625 const SDValue &getBasePtr() const {
1626 switch (getOpcode()) {
1627 case ISD::STORE:
1628 case ISD::ATOMIC_STORE:
1629 case ISD::VP_STORE:
1630 case ISD::MSTORE:
1631 case ISD::VP_SCATTER:
1632 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
1633 return getOperand(2);
1634 case ISD::MGATHER:
1635 case ISD::MSCATTER:
1637 return getOperand(3);
1638 default:
1639 return getOperand(1);
1640 }
1641 }
1642
1643 // Methods to support isa and dyn_cast
1644 static bool classof(const SDNode *N) {
1645 // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1646 // with either an intrinsic or a target opcode.
1647 switch (N->getOpcode()) {
1648 case ISD::LOAD:
1649 case ISD::STORE:
1652 case ISD::ATOMIC_SWAP:
1676 case ISD::ATOMIC_LOAD:
1677 case ISD::ATOMIC_STORE:
1678 case ISD::MLOAD:
1679 case ISD::MSTORE:
1680 case ISD::MGATHER:
1681 case ISD::MSCATTER:
1682 case ISD::VP_LOAD:
1683 case ISD::VP_STORE:
1684 case ISD::VP_GATHER:
1685 case ISD::VP_SCATTER:
1686 case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
1687 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
1688 case ISD::GET_FPENV_MEM:
1689 case ISD::SET_FPENV_MEM:
1691 return true;
1692 default:
1693 return N->isMemIntrinsic();
1694 }
1695 }
1696};
1697
1698/// This is an SDNode representing atomic operations.
1699class AtomicSDNode : public MemSDNode {
1700public:
1701 AtomicSDNode(unsigned Order, const DebugLoc &dl, unsigned Opc, SDVTList VTL,
1702 EVT MemVT, MachineMemOperand *MMO, ISD::LoadExtType ETy)
1703 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1705 MMO->isAtomic()) && "then why are we using an AtomicSDNode?");
1707 "Only atomic load uses ExtTy");
1708 LoadSDNodeBits.ExtTy = ETy;
1709 }
1710
1712 assert(getOpcode() == ISD::ATOMIC_LOAD && "Only used for atomic loads.");
1713 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
1714 }
1715
1716 const SDValue &getBasePtr() const {
1717 return getOpcode() == ISD::ATOMIC_STORE ? getOperand(2) : getOperand(1);
1718 }
1719 const SDValue &getVal() const {
1720 return getOpcode() == ISD::ATOMIC_STORE ? getOperand(1) : getOperand(2);
1721 }
1722
1723 /// Returns true if this SDNode represents cmpxchg atomic operation, false
1724 /// otherwise.
1725 bool isCompareAndSwap() const {
1726 unsigned Op = getOpcode();
1727 return Op == ISD::ATOMIC_CMP_SWAP ||
1729 }
1730
1731 /// For cmpxchg atomic operations, return the atomic ordering requirements
1732 /// when store does not occur.
1734 assert(isCompareAndSwap() && "Must be cmpxchg operation");
1736 }
1737
1738 // Methods to support isa and dyn_cast
1739 static bool classof(const SDNode *N) {
1740 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1741 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1742 N->getOpcode() == ISD::ATOMIC_SWAP ||
1743 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1744 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1745 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1746 N->getOpcode() == ISD::ATOMIC_LOAD_CLR ||
1747 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1748 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1749 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1750 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1751 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1752 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1753 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1754 N->getOpcode() == ISD::ATOMIC_LOAD_FADD ||
1755 N->getOpcode() == ISD::ATOMIC_LOAD_FSUB ||
1756 N->getOpcode() == ISD::ATOMIC_LOAD_FMAX ||
1757 N->getOpcode() == ISD::ATOMIC_LOAD_FMIN ||
1758 N->getOpcode() == ISD::ATOMIC_LOAD_FMAXIMUM ||
1759 N->getOpcode() == ISD::ATOMIC_LOAD_FMINIMUM ||
1760 N->getOpcode() == ISD::ATOMIC_LOAD_FMAXIMUMNUM ||
1761 N->getOpcode() == ISD::ATOMIC_LOAD_FMINIMUMNUM ||
1762 N->getOpcode() == ISD::ATOMIC_LOAD_UINC_WRAP ||
1763 N->getOpcode() == ISD::ATOMIC_LOAD_UDEC_WRAP ||
1764 N->getOpcode() == ISD::ATOMIC_LOAD_USUB_COND ||
1765 N->getOpcode() == ISD::ATOMIC_LOAD_USUB_SAT ||
1766 N->getOpcode() == ISD::ATOMIC_LOAD ||
1767 N->getOpcode() == ISD::ATOMIC_STORE;
1768 }
1769};
1770
1771/// This SDNode is used for target intrinsics that touch memory and need
1772/// an associated MachineMemOperand. Its opcode may be INTRINSIC_VOID,
1773/// INTRINSIC_W_CHAIN, PREFETCH, or a target-specific memory-referencing
1774/// opcode (see `SelectionDAGTargetInfo::isTargetMemoryOpcode`).
1776public:
1778 unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs,
1779 EVT MemoryVT,
1781 : MemSDNode(Opc, Order, dl, VTs, MemoryVT, MemRefs) {
1782 SDNodeBits.IsMemIntrinsic = true;
1783 }
1784
1785 // Methods to support isa and dyn_cast
1786 static bool classof(const SDNode *N) {
1787 // We lower some target intrinsics to their target opcode
1788 // early a node with a target opcode can be of this class
1789 return N->isMemIntrinsic();
1790 }
1791};
1792
1793/// This SDNode is used to implement the code generator
1794/// support for the llvm IR shufflevector instruction. It combines elements
1795/// from two input vectors into a new input vector, with the selection and
1796/// ordering of elements determined by an array of integers, referred to as
1797/// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1798/// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1799/// An index of -1 is treated as undef, such that the code generator may put
1800/// any value in the corresponding element of the result.
1802 // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1803 // is freed when the SelectionDAG object is destroyed.
1804 const int *Mask;
1805
1806protected:
1807 friend class SelectionDAG;
1808
1809 ShuffleVectorSDNode(SDVTList VTs, unsigned Order, const DebugLoc &dl,
1810 const int *M)
1811 : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, VTs), Mask(M) {}
1812
1813public:
1815 EVT VT = getValueType(0);
1816 return ArrayRef(Mask, VT.getVectorNumElements());
1817 }
1818
1819 int getMaskElt(unsigned Idx) const {
1820 assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1821 return Mask[Idx];
1822 }
1823
1824 bool isSplat() const { return isSplatMask(getMask()); }
1825
1826 int getSplatIndex() const { return getSplatMaskIndex(getMask()); }
1827
1828 LLVM_ABI static bool isSplatMask(ArrayRef<int> Mask);
1829
1831 assert(isSplatMask(Mask) && "Cannot get splat index for non-splat!");
1832 for (int Elem : Mask)
1833 if (Elem >= 0)
1834 return Elem;
1835
1836 // We can choose any index value here and be correct because all elements
1837 // are undefined. Return 0 for better potential for callers to simplify.
1838 return 0;
1839 }
1840
1841 /// Change values in a shuffle permute mask assuming
1842 /// the two vector operands have swapped position.
1844 unsigned NumElems = Mask.size();
1845 for (unsigned i = 0; i != NumElems; ++i) {
1846 int idx = Mask[i];
1847 if (idx < 0)
1848 continue;
1849 else if (idx < (int)NumElems)
1850 Mask[i] = idx + NumElems;
1851 else
1852 Mask[i] = idx - NumElems;
1853 }
1854 }
1855
1856 static bool classof(const SDNode *N) {
1857 return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1858 }
1859};
1860
1861class ConstantSDNode : public SDNode {
1862 friend class SelectionDAG;
1863
1864 const ConstantInt *Value;
1865
1866 ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val,
1867 SDVTList VTs)
1868 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, 0, DebugLoc(),
1869 VTs),
1870 Value(val) {
1871 assert(!isa<VectorType>(val->getType()) && "Unexpected vector type!");
1872 ConstantSDNodeBits.IsOpaque = isOpaque;
1873 }
1874
1875public:
1876 const ConstantInt *getConstantIntValue() const { return Value; }
1877 const APInt &getAPIntValue() const { return Value->getValue(); }
1878 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1879 int64_t getSExtValue() const { return Value->getSExtValue(); }
1881 return Value->getLimitedValue(Limit);
1882 }
1883 MaybeAlign getMaybeAlignValue() const { return Value->getMaybeAlignValue(); }
1884 Align getAlignValue() const { return Value->getAlignValue(); }
1885
1886 bool isOne() const { return Value->isOne(); }
1887 bool isZero() const { return Value->isZero(); }
1888 bool isAllOnes() const { return Value->isMinusOne(); }
1889 bool isMaxSignedValue() const { return Value->isMaxValue(true); }
1890 bool isMinSignedValue() const { return Value->isMinValue(true); }
1891
1892 bool isOpaque() const { return ConstantSDNodeBits.IsOpaque; }
1893
1894 static bool classof(const SDNode *N) {
1895 return N->getOpcode() == ISD::Constant ||
1896 N->getOpcode() == ISD::TargetConstant;
1897 }
1898};
1899
1901 return cast<ConstantSDNode>(getOperand(Num))->getZExtValue();
1902}
1903
1905 return cast<ConstantSDNode>(this)->getZExtValue();
1906}
1907
1908const APInt &SDNode::getConstantOperandAPInt(unsigned Num) const {
1909 return cast<ConstantSDNode>(getOperand(Num))->getAPIntValue();
1910}
1911
1913 return cast<ConstantSDNode>(this)->getAPIntValue();
1914}
1915
1916class ConstantFPSDNode : public SDNode {
1917 friend class SelectionDAG;
1918
1919 const ConstantFP *Value;
1920
1921 ConstantFPSDNode(bool isTarget, const ConstantFP *val, SDVTList VTs)
1922 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 0,
1923 DebugLoc(), VTs),
1924 Value(val) {
1925 assert(!isa<VectorType>(val->getType()) && "Unexpected vector type!");
1926 }
1927
1928public:
1929 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1930 const ConstantFP *getConstantFPValue() const { return Value; }
1931
1932 /// Return true if the value is positive or negative zero.
1933 bool isZero() const { return Value->isZero(); }
1934
1935 /// Return true if the value is positive zero.
1936 bool isPosZero() const { return Value->isPosZero(); }
1937
1938 /// Return true if the value is negative zero.
1939 bool isNegZero() const { return Value->isNegZero(); }
1940
1941 /// Return true if the value is a NaN.
1942 bool isNaN() const { return Value->isNaN(); }
1943
1944 /// Return true if the value is an infinity
1945 bool isInfinity() const { return Value->isInfinity(); }
1946
1947 /// Return true if the value is negative.
1948 bool isNegative() const { return Value->isNegative(); }
1949
1950 /// Returns true if this value is exactly +1.0.
1951 bool isOne() const { return Value->isOne(); }
1952
1953 /// Returns true if this value is exactly -1.0.
1954 bool isMinusOne() const { return Value->isMinusOne(); }
1955
1956 /// We don't rely on operator== working on double values, as
1957 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1958 /// As such, this method can be used to do an exact bit-for-bit comparison of
1959 /// two floating point values.
1960
1961 /// We leave the version with the double argument here because it's just so
1962 /// convenient to write "2.0" and the like. Without this function we'd
1963 /// have to duplicate its logic everywhere it's called.
1964 bool isExactlyValue(double V) const {
1965 return Value->getValueAPF().isExactlyValue(V);
1966 }
1967 LLVM_ABI bool isExactlyValue(const APFloat &V) const;
1968
1969 LLVM_ABI static bool isValueValidForType(EVT VT, const APFloat &Val);
1970
1971 static bool classof(const SDNode *N) {
1972 return N->getOpcode() == ISD::ConstantFP ||
1973 N->getOpcode() == ISD::TargetConstantFP;
1974 }
1975};
1976
1977std::optional<APInt> SDNode::bitcastToAPInt() const {
1978 if (auto *CN = dyn_cast<ConstantSDNode>(this))
1979 return CN->getAPIntValue();
1980 if (auto *CFPN = dyn_cast<ConstantFPSDNode>(this))
1981 return CFPN->getValueAPF().bitcastToAPInt();
1982 return std::nullopt;
1983}
1984
1985/// Returns true if \p V is a constant integer zero.
1987
1988/// Returns true if \p V is a constant integer zero or an UNDEF node.
1990
1991/// Returns true if \p V is an FP constant with a value of positive zero.
1993
1994/// Returns true if \p V is an integer constant with all bits set.
1996
1997/// Returns true if \p V is a constant integer one.
1999
2000/// Returns true if \p V is a constant min signed integer value.
2002
2003/// Return the non-bitcasted source operand of \p V if it exists.
2004/// If \p V is not a bitcasted value, it is returned as-is.
2006
2007/// Return the non-bitcasted and one-use source operand of \p V if it exists.
2008/// If \p V is not a bitcasted one-use value, it is returned as-is.
2010
2011/// Return the non-extracted vector source operand of \p V if it exists.
2012/// If \p V is not an extracted subvector, it is returned as-is.
2014
2015/// Recursively peek through INSERT_VECTOR_ELT nodes, returning the source
2016/// vector operand of \p V, as long as \p V is an INSERT_VECTOR_ELT operation
2017/// that do not insert into any of the demanded vector elts.
2019 const APInt &DemandedElts);
2020
2021/// Return the non-truncated source operand of \p V if it exists.
2022/// If \p V is not a truncation, it is returned as-is.
2024
2025/// Return the non-frozen source operand of \p V if it exists.
2026/// If \p V is not a freeze, it is returned as-is.
2028 if (V.getOpcode() == ISD::FREEZE)
2029 return V.getOperand(0);
2030 return V;
2031}
2032
2033/// Return the non-frozen source operand of \p V if it exists and \p V has
2034/// a single use. If \p V is not a single-use freeze, it is returned as-is.
2036 if (V.getOpcode() == ISD::FREEZE && V.hasOneUse())
2037 return V.getOperand(0);
2038 return V;
2039}
2040
2041/// Returns true if \p V is a bitwise not operation. Assumes that an all ones
2042/// constant is canonicalized to be operand 1.
2043LLVM_ABI bool isBitwiseNot(SDValue V, bool AllowUndefs = false);
2044
2045/// If \p V is a bitwise not, returns the inverted operand. Otherwise returns
2046/// an empty SDValue. Only bits set in \p Mask are required to be inverted,
2047/// other bits may be arbitrary.
2049 bool AllowUndefs);
2050
2051/// Returns the SDNode if it is a constant splat BuildVector or constant int.
2052LLVM_ABI ConstantSDNode *isConstOrConstSplat(SDValue N,
2053 bool AllowUndefs = false,
2054 bool AllowTruncation = false);
2055
2056/// Returns the SDNode if it is a demanded constant splat BuildVector or
2057/// constant int.
2058LLVM_ABI ConstantSDNode *isConstOrConstSplat(SDValue N,
2059 const APInt &DemandedElts,
2060 bool AllowUndefs = false,
2061 bool AllowTruncation = false);
2062
2063/// Returns the SDNode if it is a constant splat BuildVector or constant float.
2064LLVM_ABI ConstantFPSDNode *isConstOrConstSplatFP(SDValue N,
2065 bool AllowUndefs = false);
2066
2067/// Returns the SDNode if it is a demanded constant splat BuildVector or
2068/// constant float.
2069LLVM_ABI ConstantFPSDNode *isConstOrConstSplatFP(SDValue N,
2070 const APInt &DemandedElts,
2071 bool AllowUndefs = false);
2072
2073/// Return true if the value is a constant 0 integer or a splatted vector of
2074/// a constant 0 integer (with no undefs by default).
2075/// Build vector implicit truncation is not an issue for null values.
2076LLVM_ABI bool isNullOrNullSplat(SDValue V, bool AllowUndefs = false);
2077
2078/// Return true if the value is a constant 1 integer or a splatted vector of a
2079/// constant 1 integer (with no undefs).
2080/// Build vector implicit truncation is allowed, but the truncated bits need to
2081/// be zero.
2082LLVM_ABI bool isOneOrOneSplat(SDValue V, bool AllowUndefs = false);
2083
2084/// Return true if the value is a constant floating-point value, or a splatted
2085/// vector of a constant floating-point value, of 1.0 (with no undefs).
2086LLVM_ABI bool isOneOrOneSplatFP(SDValue V, bool AllowUndefs = false);
2087
2088/// Return true if the value is a constant -1 integer or a splatted vector of a
2089/// constant -1 integer (with no undefs).
2090/// Does not permit build vector implicit truncation.
2091LLVM_ABI bool isAllOnesOrAllOnesSplat(SDValue V, bool AllowUndefs = false);
2092
2093/// Return true if the value is a constant 0 integer or a splatted vector of a
2094/// constant 0 integer (with no undefs).
2095/// Build vector implicit truncation is allowed.
2096LLVM_ABI bool isZeroOrZeroSplat(SDValue N, bool AllowUndefs = false);
2097
2098/// Return true if the value is a constant (+/-)0.0 floating-point value or a
2099/// splatted vector thereof (with no undefs).
2100LLVM_ABI bool isZeroOrZeroSplatFP(SDValue N, bool AllowUndefs = false);
2101
2102/// Return true if \p V is either a integer or FP constant.
2106
2107class GlobalAddressSDNode : public SDNode {
2108 friend class SelectionDAG;
2109
2110 const GlobalValue *TheGlobal;
2111 int64_t Offset;
2112 unsigned TargetFlags;
2113
2114 GlobalAddressSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL,
2115 const GlobalValue *GA, SDVTList VTs, int64_t o,
2116 unsigned TF)
2117 : SDNode(Opc, Order, DL, VTs), TheGlobal(GA), Offset(o), TargetFlags(TF) {
2118 }
2119
2120public:
2121 const GlobalValue *getGlobal() const { return TheGlobal; }
2122 int64_t getOffset() const { return Offset; }
2123 unsigned getTargetFlags() const { return TargetFlags; }
2124 // Return the address space this GlobalAddress belongs to.
2125 LLVM_ABI unsigned getAddressSpace() const;
2126
2127 static bool classof(const SDNode *N) {
2128 return N->getOpcode() == ISD::GlobalAddress ||
2129 N->getOpcode() == ISD::TargetGlobalAddress ||
2130 N->getOpcode() == ISD::GlobalTLSAddress ||
2131 N->getOpcode() == ISD::TargetGlobalTLSAddress;
2132 }
2133};
2134
2135class DeactivationSymbolSDNode : public SDNode {
2136 friend class SelectionDAG;
2137
2138 const GlobalValue *TheGlobal;
2139
2140 DeactivationSymbolSDNode(const GlobalValue *GV, SDVTList VTs)
2141 : SDNode(ISD::DEACTIVATION_SYMBOL, 0, DebugLoc(), VTs), TheGlobal(GV) {}
2142
2143public:
2144 const GlobalValue *getGlobal() const { return TheGlobal; }
2145
2146 static bool classof(const SDNode *N) {
2147 return N->getOpcode() == ISD::DEACTIVATION_SYMBOL;
2148 }
2149};
2150
2151class FrameIndexSDNode : public SDNode {
2152 friend class SelectionDAG;
2153
2154 int FI;
2155
2156 FrameIndexSDNode(int fi, SDVTList VTs, bool isTarg)
2157 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, 0, DebugLoc(),
2158 VTs),
2159 FI(fi) {}
2160
2161public:
2162 int getIndex() const { return FI; }
2163
2164 static bool classof(const SDNode *N) {
2165 return N->getOpcode() == ISD::FrameIndex ||
2166 N->getOpcode() == ISD::TargetFrameIndex;
2167 }
2168};
2169
2170/// This SDNode is used for LIFETIME_START/LIFETIME_END values.
2171class LifetimeSDNode : public SDNode {
2172 friend class SelectionDAG;
2173
2174 LifetimeSDNode(unsigned Opcode, unsigned Order, const DebugLoc &dl,
2175 SDVTList VTs)
2176 : SDNode(Opcode, Order, dl, VTs) {}
2177
2178public:
2179 int64_t getFrameIndex() const {
2180 return cast<FrameIndexSDNode>(getOperand(1))->getIndex();
2181 }
2182
2183 // Methods to support isa and dyn_cast
2184 static bool classof(const SDNode *N) {
2185 return N->getOpcode() == ISD::LIFETIME_START ||
2186 N->getOpcode() == ISD::LIFETIME_END;
2187 }
2188};
2189
2190/// This SDNode is used for PSEUDO_PROBE values, which are the function guid and
2191/// the index of the basic block being probed. A pseudo probe serves as a place
2192/// holder and will be removed at the end of compilation. It does not have any
2193/// operand because we do not want the instruction selection to deal with any.
2194class PseudoProbeSDNode : public SDNode {
2195 friend class SelectionDAG;
2196 uint64_t Guid;
2197 uint64_t Index;
2198 uint32_t Attributes;
2199
2200 PseudoProbeSDNode(unsigned Opcode, unsigned Order, const DebugLoc &Dl,
2201 SDVTList VTs, uint64_t Guid, uint64_t Index, uint32_t Attr)
2202 : SDNode(Opcode, Order, Dl, VTs), Guid(Guid), Index(Index),
2203 Attributes(Attr) {}
2204
2205public:
2206 uint64_t getGuid() const { return Guid; }
2207 uint64_t getIndex() const { return Index; }
2208 uint32_t getAttributes() const { return Attributes; }
2209
2210 // Methods to support isa and dyn_cast
2211 static bool classof(const SDNode *N) {
2212 return N->getOpcode() == ISD::PSEUDO_PROBE;
2213 }
2214};
2215
2216class JumpTableSDNode : public SDNode {
2217 friend class SelectionDAG;
2218
2219 int JTI;
2220 unsigned TargetFlags;
2221
2222 JumpTableSDNode(int jti, SDVTList VTs, bool isTarg, unsigned TF)
2223 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, 0, DebugLoc(),
2224 VTs),
2225 JTI(jti), TargetFlags(TF) {}
2226
2227public:
2228 int getIndex() const { return JTI; }
2229 unsigned getTargetFlags() const { return TargetFlags; }
2230
2231 static bool classof(const SDNode *N) {
2232 return N->getOpcode() == ISD::JumpTable ||
2233 N->getOpcode() == ISD::TargetJumpTable;
2234 }
2235};
2236
2237class ConstantPoolSDNode : public SDNode {
2238 friend class SelectionDAG;
2239
2240 union {
2243 } Val;
2244 int Offset; // It's a MachineConstantPoolValue if top bit is set.
2245 Align Alignment; // Minimum alignment requirement of CP.
2246 unsigned TargetFlags;
2247
2248 ConstantPoolSDNode(bool isTarget, const Constant *c, SDVTList VTs, int o,
2249 Align Alignment, unsigned TF)
2250 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
2251 DebugLoc(), VTs),
2252 Offset(o), Alignment(Alignment), TargetFlags(TF) {
2253 assert(Offset >= 0 && "Offset is too large");
2254 Val.ConstVal = c;
2255 }
2256
2257 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v, SDVTList VTs,
2258 int o, Align Alignment, unsigned TF)
2259 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
2260 DebugLoc(), VTs),
2261 Offset(o), Alignment(Alignment), TargetFlags(TF) {
2262 assert(Offset >= 0 && "Offset is too large");
2263 Val.MachineCPVal = v;
2264 Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
2265 }
2266
2267public:
2269 return Offset < 0;
2270 }
2271
2272 const Constant *getConstVal() const {
2273 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
2274 return Val.ConstVal;
2275 }
2276
2278 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
2279 return Val.MachineCPVal;
2280 }
2281
2282 int getOffset() const {
2283 return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
2284 }
2285
2286 // Return the alignment of this constant pool object, which is either 0 (for
2287 // default alignment) or the desired value.
2288 Align getAlign() const { return Alignment; }
2289 unsigned getTargetFlags() const { return TargetFlags; }
2290
2291 LLVM_ABI Type *getType() const;
2292
2293 static bool classof(const SDNode *N) {
2294 return N->getOpcode() == ISD::ConstantPool ||
2295 N->getOpcode() == ISD::TargetConstantPool;
2296 }
2297};
2298
2299/// Completely target-dependent object reference.
2301 friend class SelectionDAG;
2302
2303 unsigned TargetFlags;
2304 int Index;
2305 int64_t Offset;
2306
2307public:
2308 TargetIndexSDNode(int Idx, SDVTList VTs, int64_t Ofs, unsigned TF)
2309 : SDNode(ISD::TargetIndex, 0, DebugLoc(), VTs), TargetFlags(TF),
2310 Index(Idx), Offset(Ofs) {}
2311
2312 unsigned getTargetFlags() const { return TargetFlags; }
2313 int getIndex() const { return Index; }
2314 int64_t getOffset() const { return Offset; }
2315
2316 static bool classof(const SDNode *N) {
2317 return N->getOpcode() == ISD::TargetIndex;
2318 }
2319};
2320
2321class BasicBlockSDNode : public SDNode {
2322 friend class SelectionDAG;
2323
2324 MachineBasicBlock *MBB;
2325
2326 /// Debug info is meaningful and potentially useful here, but we create
2327 /// blocks out of order when they're jumped to, which makes it a bit
2328 /// harder. Let's see if we need it first.
2329 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
2330 : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
2331 {}
2332
2333public:
2334 MachineBasicBlock *getBasicBlock() const { return MBB; }
2335
2336 static bool classof(const SDNode *N) {
2337 return N->getOpcode() == ISD::BasicBlock;
2338 }
2339};
2340
2341/// A "pseudo-class" with methods for operating on BUILD_VECTORs.
2343public:
2344 // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
2345 explicit BuildVectorSDNode() = delete;
2346
2347 /// Check if this is a constant splat, and if so, find the
2348 /// smallest element size that splats the vector. If MinSplatBits is
2349 /// nonzero, the element size must be at least that large. Note that the
2350 /// splat element may be the entire vector (i.e., a one element vector).
2351 /// Returns the splat element value in SplatValue. Any undefined bits in
2352 /// that value are zero, and the corresponding bits in the SplatUndef mask
2353 /// are set. The SplatBitSize value is set to the splat element size in
2354 /// bits. HasAnyUndefs is set to true if any bits in the vector are
2355 /// undefined. isBigEndian describes the endianness of the target.
2356 LLVM_ABI bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
2357 unsigned &SplatBitSize, bool &HasAnyUndefs,
2358 unsigned MinSplatBits = 0,
2359 bool isBigEndian = false) const;
2360
2361 /// Returns the demanded splatted value or a null value if this is not a
2362 /// splat.
2363 ///
2364 /// The DemandedElts mask indicates the elements that must be in the splat.
2365 /// If passed a non-null UndefElements bitvector, it will resize it to match
2366 /// the vector width and set the bits where elements are undef.
2367 LLVM_ABI SDValue getSplatValue(const APInt &DemandedElts,
2368 BitVector *UndefElements = nullptr) const;
2369
2370 /// Returns the splatted value or a null value if this is not a splat.
2371 ///
2372 /// If passed a non-null UndefElements bitvector, it will resize it to match
2373 /// the vector width and set the bits where elements are undef.
2374 LLVM_ABI SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
2375
2376 /// Find the shortest repeating sequence of values in the build vector.
2377 ///
2378 /// e.g. { u, X, u, X, u, u, X, u } -> { X }
2379 /// { X, Y, u, Y, u, u, X, u } -> { X, Y }
2380 ///
2381 /// Currently this must be a power-of-2 build vector.
2382 /// The DemandedElts mask indicates the elements that must be present,
2383 /// undemanded elements in Sequence may be null (SDValue()). If passed a
2384 /// non-null UndefElements bitvector, it will resize it to match the original
2385 /// vector width and set the bits where elements are undef. If result is
2386 /// false, Sequence will be empty.
2387 LLVM_ABI bool getRepeatedSequence(const APInt &DemandedElts,
2388 SmallVectorImpl<SDValue> &Sequence,
2389 BitVector *UndefElements = nullptr) const;
2390
2391 /// Find the shortest repeating sequence of values in the build vector.
2392 ///
2393 /// e.g. { u, X, u, X, u, u, X, u } -> { X }
2394 /// { X, Y, u, Y, u, u, X, u } -> { X, Y }
2395 ///
2396 /// Currently this must be a power-of-2 build vector.
2397 /// If passed a non-null UndefElements bitvector, it will resize it to match
2398 /// the original vector width and set the bits where elements are undef.
2399 /// If result is false, Sequence will be empty.
2401 BitVector *UndefElements = nullptr) const;
2402
2403 /// Returns the demanded splatted constant or null if this is not a constant
2404 /// splat.
2405 ///
2406 /// The DemandedElts mask indicates the elements that must be in the splat.
2407 /// If passed a non-null UndefElements bitvector, it will resize it to match
2408 /// the vector width and set the bits where elements are undef.
2410 getConstantSplatNode(const APInt &DemandedElts,
2411 BitVector *UndefElements = nullptr) const;
2412
2413 /// Returns the splatted constant or null if this is not a constant
2414 /// splat.
2415 ///
2416 /// If passed a non-null UndefElements bitvector, it will resize it to match
2417 /// the vector width and set the bits where elements are undef.
2419 getConstantSplatNode(BitVector *UndefElements = nullptr) const;
2420
2421 /// Returns the demanded splatted constant FP or null if this is not a
2422 /// constant FP splat.
2423 ///
2424 /// The DemandedElts mask indicates the elements that must be in the splat.
2425 /// If passed a non-null UndefElements bitvector, it will resize it to match
2426 /// the vector width and set the bits where elements are undef.
2428 getConstantFPSplatNode(const APInt &DemandedElts,
2429 BitVector *UndefElements = nullptr) const;
2430
2431 /// Returns the splatted constant FP or null if this is not a constant
2432 /// FP splat.
2433 ///
2434 /// If passed a non-null UndefElements bitvector, it will resize it to match
2435 /// the vector width and set the bits where elements are undef.
2437 getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
2438
2439 /// If this is a constant FP splat and the splatted constant FP is an
2440 /// exact power or 2, return the log base 2 integer value. Otherwise,
2441 /// return -1.
2442 ///
2443 /// The BitWidth specifies the necessary bit precision.
2444 LLVM_ABI int32_t getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements,
2445 uint32_t BitWidth) const;
2446
2447 /// Extract the raw bit data from a build vector of Undef, Constant or
2448 /// ConstantFP node elements. Each raw bit element will be \p
2449 /// DstEltSizeInBits wide, undef elements are treated as zero, and entirely
2450 /// undefined elements are flagged in \p UndefElements.
2451 LLVM_ABI bool getConstantRawBits(bool IsLittleEndian,
2452 unsigned DstEltSizeInBits,
2453 SmallVectorImpl<APInt> &RawBitElements,
2454 BitVector &UndefElements) const;
2455
2456 LLVM_ABI bool isConstant() const;
2457
2458 /// If this BuildVector is constant and represents an arithmetic sequence
2459 /// "<a, a+n, a+2n, a+3n, ...>" where a is integer and n is a non-zero
2460 /// integer, the value "<a, n>" is returned. Arithmetic is performed modulo
2461 /// 2^BitWidth, so this also matches sequences that wrap around. Poison
2462 /// elements are ignored and can take any value.
2463 LLVM_ABI std::optional<std::pair<APInt, APInt>> isArithmeticSequence() const;
2464
2465 /// Recast bit data \p SrcBitElements to \p DstEltSizeInBits wide elements.
2466 /// Undef elements are treated as zero, and entirely undefined elements are
2467 /// flagged in \p DstUndefElements.
2468 LLVM_ABI static void recastRawBits(bool IsLittleEndian,
2469 unsigned DstEltSizeInBits,
2470 SmallVectorImpl<APInt> &DstBitElements,
2471 ArrayRef<APInt> SrcBitElements,
2472 BitVector &DstUndefElements,
2473 const BitVector &SrcUndefElements);
2474
2475 static bool classof(const SDNode *N) {
2476 return N->getOpcode() == ISD::BUILD_VECTOR;
2477 }
2478};
2479
2480/// An SDNode that holds an arbitrary LLVM IR Value. This is
2481/// used when the SelectionDAG needs to make a simple reference to something
2482/// in the LLVM IR representation.
2483///
2484class SrcValueSDNode : public SDNode {
2485 friend class SelectionDAG;
2486
2487 const Value *V;
2488
2489 /// Create a SrcValue for a general value.
2490 explicit SrcValueSDNode(const Value *v)
2491 : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
2492
2493public:
2494 /// Return the contained Value.
2495 const Value *getValue() const { return V; }
2496
2497 static bool classof(const SDNode *N) {
2498 return N->getOpcode() == ISD::SRCVALUE;
2499 }
2500};
2501
2502class MDNodeSDNode : public SDNode {
2503 friend class SelectionDAG;
2504
2505 const MDNode *MD;
2506
2507 explicit MDNodeSDNode(const MDNode *md)
2508 : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
2509 {}
2510
2511public:
2512 const MDNode *getMD() const { return MD; }
2513
2514 static bool classof(const SDNode *N) {
2515 return N->getOpcode() == ISD::MDNODE_SDNODE;
2516 }
2517};
2518
2519class RegisterSDNode : public SDNode {
2520 friend class SelectionDAG;
2521
2522 Register Reg;
2523
2524 RegisterSDNode(Register reg, SDVTList VTs)
2525 : SDNode(ISD::Register, 0, DebugLoc(), VTs), Reg(reg) {}
2526
2527public:
2528 Register getReg() const { return Reg; }
2529
2530 static bool classof(const SDNode *N) {
2531 return N->getOpcode() == ISD::Register;
2532 }
2533};
2534
2535class RegisterMaskSDNode : public SDNode {
2536 friend class SelectionDAG;
2537
2538 // The memory for RegMask is not owned by the node.
2539 const uint32_t *RegMask;
2540
2541 RegisterMaskSDNode(const uint32_t *mask)
2542 : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
2543 RegMask(mask) {}
2544
2545public:
2546 const uint32_t *getRegMask() const { return RegMask; }
2547
2548 static bool classof(const SDNode *N) {
2549 return N->getOpcode() == ISD::RegisterMask;
2550 }
2551};
2552
2553class BlockAddressSDNode : public SDNode {
2554 friend class SelectionDAG;
2555
2556 const BlockAddress *BA;
2557 int64_t Offset;
2558 unsigned TargetFlags;
2559
2560 BlockAddressSDNode(unsigned NodeTy, SDVTList VTs, const BlockAddress *ba,
2561 int64_t o, unsigned Flags)
2562 : SDNode(NodeTy, 0, DebugLoc(), VTs), BA(ba), Offset(o),
2563 TargetFlags(Flags) {}
2564
2565public:
2566 const BlockAddress *getBlockAddress() const { return BA; }
2567 int64_t getOffset() const { return Offset; }
2568 unsigned getTargetFlags() const { return TargetFlags; }
2569
2570 static bool classof(const SDNode *N) {
2571 return N->getOpcode() == ISD::BlockAddress ||
2572 N->getOpcode() == ISD::TargetBlockAddress;
2573 }
2574};
2575
2576class LabelSDNode : public SDNode {
2577 friend class SelectionDAG;
2578
2579 MCSymbol *Label;
2580
2581 LabelSDNode(unsigned Opcode, unsigned Order, const DebugLoc &dl, MCSymbol *L)
2582 : SDNode(Opcode, Order, dl, getSDVTList(MVT::Other)), Label(L) {
2583 assert(LabelSDNode::classof(this) && "not a label opcode");
2584 }
2585
2586public:
2587 MCSymbol *getLabel() const { return Label; }
2588
2589 static bool classof(const SDNode *N) {
2590 return N->getOpcode() == ISD::EH_LABEL ||
2591 N->getOpcode() == ISD::ANNOTATION_LABEL;
2592 }
2593};
2594
2595class ExternalSymbolSDNode : public SDNode {
2596 friend class SelectionDAG;
2597
2598 const char *Symbol;
2599 unsigned TargetFlags;
2600
2601 ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned TF,
2602 SDVTList VTs)
2603 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol, 0,
2604 DebugLoc(), VTs),
2605 Symbol(Sym), TargetFlags(TF) {}
2606
2607public:
2608 const char *getSymbol() const { return Symbol; }
2609 unsigned getTargetFlags() const { return TargetFlags; }
2610
2611 static bool classof(const SDNode *N) {
2612 return N->getOpcode() == ISD::ExternalSymbol ||
2613 N->getOpcode() == ISD::TargetExternalSymbol;
2614 }
2615};
2616
2617class MCSymbolSDNode : public SDNode {
2618 friend class SelectionDAG;
2619
2620 MCSymbol *Symbol;
2621
2622 MCSymbolSDNode(MCSymbol *Symbol, SDVTList VTs)
2623 : SDNode(ISD::MCSymbol, 0, DebugLoc(), VTs), Symbol(Symbol) {}
2624
2625public:
2626 MCSymbol *getMCSymbol() const { return Symbol; }
2627
2628 static bool classof(const SDNode *N) {
2629 return N->getOpcode() == ISD::MCSymbol;
2630 }
2631};
2632
2633class CondCodeSDNode : public SDNode {
2634 friend class SelectionDAG;
2635
2636 ISD::CondCode Condition;
2637
2638 explicit CondCodeSDNode(ISD::CondCode Cond)
2639 : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
2640 Condition(Cond) {}
2641
2642public:
2643 ISD::CondCode get() const { return Condition; }
2644
2645 static bool classof(const SDNode *N) {
2646 return N->getOpcode() == ISD::CONDCODE;
2647 }
2648};
2649
2651 return cast<CondCodeSDNode>(getOperand(Num))->get();
2652}
2653
2654/// This class is used to represent EVT's, which are used
2655/// to parameterize some operations.
2656class VTSDNode : public SDNode {
2657 friend class SelectionDAG;
2658
2659 EVT ValueType;
2660
2661 explicit VTSDNode(EVT VT)
2662 : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
2663 ValueType(VT) {}
2664
2665public:
2666 EVT getVT() const { return ValueType; }
2667
2668 static bool classof(const SDNode *N) {
2669 return N->getOpcode() == ISD::VALUETYPE;
2670 }
2671};
2672
2673/// Base class for LoadSDNode and StoreSDNode
2674class LSBaseSDNode : public MemSDNode {
2675public:
2676 LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl,
2677 SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
2678 MachineMemOperand *MMO)
2679 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
2680 LSBaseSDNodeBits.AddressingMode = AM;
2681 assert(getAddressingMode() == AM && "Value truncated");
2682 }
2683
2684 const SDValue &getOffset() const {
2685 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2686 }
2687
2688 /// Return the addressing mode for this load or store:
2689 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2691 return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
2692 }
2693
2694 /// Return true if this is a pre/post inc/dec load/store.
2695 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2696
2697 /// Return true if this is NOT a pre/post inc/dec load/store.
2698 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2699
2700 static bool classof(const SDNode *N) {
2701 return N->getOpcode() == ISD::LOAD ||
2702 N->getOpcode() == ISD::STORE;
2703 }
2704};
2705
2706/// This class is used to represent ISD::LOAD nodes.
2707class LoadSDNode : public LSBaseSDNode {
2708 friend class SelectionDAG;
2709
2710 LoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2712 MachineMemOperand *MMO)
2713 : LSBaseSDNode(ISD::LOAD, Order, dl, VTs, AM, MemVT, MMO) {
2714 LoadSDNodeBits.ExtTy = ETy;
2715 assert(readMem() && "Load MachineMemOperand is not a load!");
2716 assert(!writeMem() && "Load MachineMemOperand is a store!");
2717 }
2718
2719public:
2720 /// Return whether this is a plain node,
2721 /// or one of the varieties of value-extending loads.
2723 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2724 }
2725
2726 const SDValue &getBasePtr() const { return getOperand(1); }
2727 const SDValue &getOffset() const { return getOperand(2); }
2728
2729 static bool classof(const SDNode *N) {
2730 return N->getOpcode() == ISD::LOAD;
2731 }
2732};
2733
2734/// This class is used to represent ISD::STORE nodes.
2735class StoreSDNode : public LSBaseSDNode {
2736 friend class SelectionDAG;
2737
2738 StoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2739 ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
2740 MachineMemOperand *MMO)
2741 : LSBaseSDNode(ISD::STORE, Order, dl, VTs, AM, MemVT, MMO) {
2742 StoreSDNodeBits.IsTruncating = isTrunc;
2743 assert(!readMem() && "Store MachineMemOperand is a load!");
2744 assert(writeMem() && "Store MachineMemOperand is not a store!");
2745 }
2746
2747public:
2748 /// Return true if the op does a truncation before store.
2749 /// For integers this is the same as doing a TRUNCATE and storing the result.
2750 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2751 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2752
2753 const SDValue &getValue() const { return getOperand(1); }
2754 const SDValue &getBasePtr() const { return getOperand(2); }
2755 const SDValue &getOffset() const { return getOperand(3); }
2756
2757 static bool classof(const SDNode *N) {
2758 return N->getOpcode() == ISD::STORE;
2759 }
2760};
2761
2762/// This base class is used to represent VP_LOAD, VP_STORE,
2763/// EXPERIMENTAL_VP_STRIDED_LOAD and EXPERIMENTAL_VP_STRIDED_STORE nodes
2765public:
2766 friend class SelectionDAG;
2767
2768 VPBaseLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order,
2769 const DebugLoc &DL, SDVTList VTs,
2770 ISD::MemIndexedMode AM, EVT MemVT,
2771 MachineMemOperand *MMO)
2772 : MemSDNode(NodeTy, Order, DL, VTs, MemVT, MMO) {
2773 LSBaseSDNodeBits.AddressingMode = AM;
2774 assert(getAddressingMode() == AM && "Value truncated");
2775 }
2776
2777 // VPStridedStoreSDNode (Chain, Data, Ptr, Offset, Stride, Mask, EVL)
2778 // VPStoreSDNode (Chain, Data, Ptr, Offset, Mask, EVL)
2779 // VPStridedLoadSDNode (Chain, Ptr, Offset, Stride, Mask, EVL)
2780 // VPLoadSDNode (Chain, Ptr, Offset, Mask, EVL)
2781 // Mask is a vector of i1 elements;
2782 // the type of EVL is TLI.getVPExplicitVectorLengthTy().
2783 const SDValue &getOffset() const {
2784 return getOperand((getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD ||
2785 getOpcode() == ISD::VP_LOAD)
2786 ? 2
2787 : 3);
2788 }
2789 const SDValue &getBasePtr() const {
2790 return getOperand((getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD ||
2791 getOpcode() == ISD::VP_LOAD)
2792 ? 1
2793 : 2);
2794 }
2795 const SDValue &getMask() const {
2796 switch (getOpcode()) {
2797 default:
2798 llvm_unreachable("Invalid opcode");
2799 case ISD::VP_LOAD:
2800 return getOperand(3);
2801 case ISD::VP_STORE:
2802 case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
2803 return getOperand(4);
2804 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
2805 return getOperand(5);
2806 }
2807 }
2808 const SDValue &getVectorLength() const {
2809 switch (getOpcode()) {
2810 default:
2811 llvm_unreachable("Invalid opcode");
2812 case ISD::VP_LOAD:
2813 return getOperand(4);
2814 case ISD::VP_STORE:
2815 case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
2816 return getOperand(5);
2817 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
2818 return getOperand(6);
2819 }
2820 }
2821
2822 /// Return the addressing mode for this load or store:
2823 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2825 return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
2826 }
2827
2828 /// Return true if this is a pre/post inc/dec load/store.
2829 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2830
2831 /// Return true if this is NOT a pre/post inc/dec load/store.
2832 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2833
2834 static bool classof(const SDNode *N) {
2835 return N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD ||
2836 N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_STORE ||
2837 N->getOpcode() == ISD::VP_LOAD || N->getOpcode() == ISD::VP_STORE;
2838 }
2839};
2840
2841/// This class is used to represent a VP_LOAD node
2843public:
2844 friend class SelectionDAG;
2845
2846 VPLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2847 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, bool isExpanding,
2848 EVT MemVT, MachineMemOperand *MMO)
2849 : VPBaseLoadStoreSDNode(ISD::VP_LOAD, Order, dl, VTs, AM, MemVT, MMO) {
2850 LoadSDNodeBits.ExtTy = ETy;
2851 LoadSDNodeBits.IsExpanding = isExpanding;
2852 }
2853
2855 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2856 }
2857
2858 const SDValue &getBasePtr() const { return getOperand(1); }
2859 const SDValue &getOffset() const { return getOperand(2); }
2860 const SDValue &getMask() const { return getOperand(3); }
2861 const SDValue &getVectorLength() const { return getOperand(4); }
2862
2863 static bool classof(const SDNode *N) {
2864 return N->getOpcode() == ISD::VP_LOAD;
2865 }
2866 bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
2867};
2868
2869/// This class is used to represent an EXPERIMENTAL_VP_STRIDED_LOAD node.
2871public:
2872 friend class SelectionDAG;
2873
2874 VPStridedLoadSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs,
2876 bool IsExpanding, EVT MemVT, MachineMemOperand *MMO)
2877 : VPBaseLoadStoreSDNode(ISD::EXPERIMENTAL_VP_STRIDED_LOAD, Order, DL, VTs,
2878 AM, MemVT, MMO) {
2879 LoadSDNodeBits.ExtTy = ETy;
2880 LoadSDNodeBits.IsExpanding = IsExpanding;
2881 }
2882
2884 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2885 }
2886
2887 const SDValue &getBasePtr() const { return getOperand(1); }
2888 const SDValue &getOffset() const { return getOperand(2); }
2889 const SDValue &getStride() const { return getOperand(3); }
2890 const SDValue &getMask() const { return getOperand(4); }
2891 const SDValue &getVectorLength() const { return getOperand(5); }
2892
2893 static bool classof(const SDNode *N) {
2894 return N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD;
2895 }
2896 bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
2897};
2898
2899/// This class is used to represent a VP_STORE node
2901public:
2902 friend class SelectionDAG;
2903
2904 VPStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2905 ISD::MemIndexedMode AM, bool isTrunc, bool isCompressing,
2906 EVT MemVT, MachineMemOperand *MMO)
2907 : VPBaseLoadStoreSDNode(ISD::VP_STORE, Order, dl, VTs, AM, MemVT, MMO) {
2908 StoreSDNodeBits.IsTruncating = isTrunc;
2909 StoreSDNodeBits.IsCompressing = isCompressing;
2910 }
2911
2912 /// Return true if this is a truncating store.
2913 /// For integers this is the same as doing a TRUNCATE and storing the result.
2914 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2915 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2916
2917 /// Returns true if the op does a compression to the vector before storing.
2918 /// The node contiguously stores the active elements (integers or floats)
2919 /// in src (those with their respective bit set in writemask k) to unaligned
2920 /// memory at base_addr.
2921 bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
2922
2923 const SDValue &getValue() const { return getOperand(1); }
2924 const SDValue &getBasePtr() const { return getOperand(2); }
2925 const SDValue &getOffset() const { return getOperand(3); }
2926 const SDValue &getMask() const { return getOperand(4); }
2927 const SDValue &getVectorLength() const { return getOperand(5); }
2928
2929 static bool classof(const SDNode *N) {
2930 return N->getOpcode() == ISD::VP_STORE;
2931 }
2932};
2933
2934/// This class is used to represent an EXPERIMENTAL_VP_STRIDED_STORE node.
2936public:
2937 friend class SelectionDAG;
2938
2939 VPStridedStoreSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs,
2940 ISD::MemIndexedMode AM, bool IsTrunc, bool IsCompressing,
2941 EVT MemVT, MachineMemOperand *MMO)
2942 : VPBaseLoadStoreSDNode(ISD::EXPERIMENTAL_VP_STRIDED_STORE, Order, DL,
2943 VTs, AM, MemVT, MMO) {
2944 StoreSDNodeBits.IsTruncating = IsTrunc;
2945 StoreSDNodeBits.IsCompressing = IsCompressing;
2946 }
2947
2948 /// Return true if this is a truncating store.
2949 /// For integers this is the same as doing a TRUNCATE and storing the result.
2950 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2951 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2952
2953 /// Returns true if the op does a compression to the vector before storing.
2954 /// The node contiguously stores the active elements (integers or floats)
2955 /// in src (those with their respective bit set in writemask k) to unaligned
2956 /// memory at base_addr.
2957 bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
2958
2959 const SDValue &getValue() const { return getOperand(1); }
2960 const SDValue &getBasePtr() const { return getOperand(2); }
2961 const SDValue &getOffset() const { return getOperand(3); }
2962 const SDValue &getStride() const { return getOperand(4); }
2963 const SDValue &getMask() const { return getOperand(5); }
2964 const SDValue &getVectorLength() const { return getOperand(6); }
2965
2966 static bool classof(const SDNode *N) {
2967 return N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_STORE;
2968 }
2969};
2970
2971/// This base class is used to represent MLOAD and MSTORE nodes
2973public:
2974 friend class SelectionDAG;
2975
2976 MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order,
2977 const DebugLoc &dl, SDVTList VTs,
2978 ISD::MemIndexedMode AM, EVT MemVT,
2979 MachineMemOperand *MMO)
2980 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
2981 LSBaseSDNodeBits.AddressingMode = AM;
2982 assert(getAddressingMode() == AM && "Value truncated");
2983 }
2984
2985 // MaskedLoadSDNode (Chain, ptr, offset, mask, passthru)
2986 // MaskedStoreSDNode (Chain, data, ptr, offset, mask)
2987 // Mask is a vector of i1 elements
2988 const SDValue &getOffset() const {
2989 return getOperand(getOpcode() == ISD::MLOAD ? 2 : 3);
2990 }
2991 const SDValue &getMask() const {
2992 return getOperand(getOpcode() == ISD::MLOAD ? 3 : 4);
2993 }
2994
2995 /// Return the addressing mode for this load or store:
2996 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2998 return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
2999 }
3000
3001 /// Return true if this is a pre/post inc/dec load/store.
3002 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
3003
3004 /// Return true if this is NOT a pre/post inc/dec load/store.
3005 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
3006
3007 static bool classof(const SDNode *N) {
3008 return N->getOpcode() == ISD::MLOAD ||
3009 N->getOpcode() == ISD::MSTORE;
3010 }
3011};
3012
3013/// This class is used to represent an MLOAD node
3015public:
3016 friend class SelectionDAG;
3017
3018 MaskedLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
3020 bool IsExpanding, EVT MemVT, MachineMemOperand *MMO)
3021 : MaskedLoadStoreSDNode(ISD::MLOAD, Order, dl, VTs, AM, MemVT, MMO) {
3022 LoadSDNodeBits.ExtTy = ETy;
3023 LoadSDNodeBits.IsExpanding = IsExpanding;
3024 }
3025
3027 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
3028 }
3029
3030 const SDValue &getBasePtr() const { return getOperand(1); }
3031 const SDValue &getOffset() const { return getOperand(2); }
3032 const SDValue &getMask() const { return getOperand(3); }
3033 const SDValue &getPassThru() const { return getOperand(4); }
3034
3035 static bool classof(const SDNode *N) {
3036 return N->getOpcode() == ISD::MLOAD;
3037 }
3038
3039 bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
3040};
3041
3042/// This class is used to represent an MSTORE node
3044public:
3045 friend class SelectionDAG;
3046
3047 MaskedStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
3048 ISD::MemIndexedMode AM, bool isTrunc, bool isCompressing,
3049 EVT MemVT, MachineMemOperand *MMO)
3050 : MaskedLoadStoreSDNode(ISD::MSTORE, Order, dl, VTs, AM, MemVT, MMO) {
3051 StoreSDNodeBits.IsTruncating = isTrunc;
3052 StoreSDNodeBits.IsCompressing = isCompressing;
3053 }
3054
3055 /// Return true if the op does a truncation before store.
3056 /// For integers this is the same as doing a TRUNCATE and storing the result.
3057 /// For floats, it is the same as doing an FP_ROUND and storing the result.
3058 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
3059
3060 /// Returns true if the op does a compression to the vector before storing.
3061 /// The node contiguously stores the active elements (integers or floats)
3062 /// in src (those with their respective bit set in writemask k) to unaligned
3063 /// memory at base_addr.
3064 bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
3065
3066 const SDValue &getValue() const { return getOperand(1); }
3067 const SDValue &getBasePtr() const { return getOperand(2); }
3068 const SDValue &getOffset() const { return getOperand(3); }
3069 const SDValue &getMask() const { return getOperand(4); }
3070
3071 static bool classof(const SDNode *N) {
3072 return N->getOpcode() == ISD::MSTORE;
3073 }
3074};
3075
3076/// This is a base class used to represent
3077/// VP_GATHER and VP_SCATTER nodes
3078///
3080public:
3081 friend class SelectionDAG;
3082
3083 VPGatherScatterSDNode(ISD::NodeType NodeTy, unsigned Order,
3084 const DebugLoc &dl, SDVTList VTs, EVT MemVT,
3085 MachineMemOperand *MMO, ISD::MemIndexType IndexType)
3086 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
3087 LSBaseSDNodeBits.AddressingMode = IndexType;
3088 assert(getIndexType() == IndexType && "Value truncated");
3089 }
3090
3091 /// How is Index applied to BasePtr when computing addresses.
3093 return static_cast<ISD::MemIndexType>(LSBaseSDNodeBits.AddressingMode);
3094 }
3095 bool isIndexScaled() const {
3096 return !cast<ConstantSDNode>(getScale())->isOne();
3097 }
3098 bool isIndexSigned() const { return isIndexTypeSigned(getIndexType()); }
3099
3100 // In the both nodes address is Op1, mask is Op2:
3101 // VPGatherSDNode (Chain, base, index, scale, mask, vlen)
3102 // VPScatterSDNode (Chain, value, base, index, scale, mask, vlen)
3103 // Mask is a vector of i1 elements
3104 const SDValue &getBasePtr() const {
3105 return getOperand((getOpcode() == ISD::VP_GATHER) ? 1 : 2);
3106 }
3107 const SDValue &getIndex() const {
3108 return getOperand((getOpcode() == ISD::VP_GATHER) ? 2 : 3);
3109 }
3110 const SDValue &getScale() const {
3111 return getOperand((getOpcode() == ISD::VP_GATHER) ? 3 : 4);
3112 }
3113 const SDValue &getMask() const {
3114 return getOperand((getOpcode() == ISD::VP_GATHER) ? 4 : 5);
3115 }
3116 const SDValue &getVectorLength() const {
3117 return getOperand((getOpcode() == ISD::VP_GATHER) ? 5 : 6);
3118 }
3119
3120 static bool classof(const SDNode *N) {
3121 return N->getOpcode() == ISD::VP_GATHER ||
3122 N->getOpcode() == ISD::VP_SCATTER;
3123 }
3124};
3125
3126/// This class is used to represent an VP_GATHER node
3127///
3129public:
3130 friend class SelectionDAG;
3131
3132 VPGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT,
3133 MachineMemOperand *MMO, ISD::MemIndexType IndexType)
3134 : VPGatherScatterSDNode(ISD::VP_GATHER, Order, dl, VTs, MemVT, MMO,
3135 IndexType) {}
3136
3137 static bool classof(const SDNode *N) {
3138 return N->getOpcode() == ISD::VP_GATHER;
3139 }
3140};
3141
3142/// This class is used to represent an VP_SCATTER node
3143///
3145public:
3146 friend class SelectionDAG;
3147
3148 VPScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT,
3149 MachineMemOperand *MMO, ISD::MemIndexType IndexType)
3150 : VPGatherScatterSDNode(ISD::VP_SCATTER, Order, dl, VTs, MemVT, MMO,
3151 IndexType) {}
3152
3153 const SDValue &getValue() const { return getOperand(1); }
3154
3155 static bool classof(const SDNode *N) {
3156 return N->getOpcode() == ISD::VP_SCATTER;
3157 }
3158};
3159
3160/// This is a base class used to represent
3161/// MGATHER and MSCATTER nodes
3162///
3164public:
3165 friend class SelectionDAG;
3166
3168 const DebugLoc &dl, SDVTList VTs, EVT MemVT,
3169 MachineMemOperand *MMO, ISD::MemIndexType IndexType)
3170 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
3171 LSBaseSDNodeBits.AddressingMode = IndexType;
3172 assert(getIndexType() == IndexType && "Value truncated");
3173 }
3174
3175 /// How is Index applied to BasePtr when computing addresses.
3177 return static_cast<ISD::MemIndexType>(LSBaseSDNodeBits.AddressingMode);
3178 }
3179 bool isIndexScaled() const {
3180 return !cast<ConstantSDNode>(getScale())->isOne();
3181 }
3182 bool isIndexSigned() const { return isIndexTypeSigned(getIndexType()); }
3183
3184 // In the both nodes address is Op1, mask is Op2:
3185 // MaskedGatherSDNode (Chain, passthru, mask, base, index, scale)
3186 // MaskedScatterSDNode (Chain, value, mask, base, index, scale)
3187 // Mask is a vector of i1 elements
3188 const SDValue &getBasePtr() const { return getOperand(3); }
3189 const SDValue &getIndex() const { return getOperand(4); }
3190 const SDValue &getMask() const { return getOperand(2); }
3191 const SDValue &getScale() const { return getOperand(5); }
3192
3193 static bool classof(const SDNode *N) {
3194 return N->getOpcode() == ISD::MGATHER || N->getOpcode() == ISD::MSCATTER ||
3195 N->getOpcode() == ISD::EXPERIMENTAL_VECTOR_HISTOGRAM;
3196 }
3197};
3198
3199/// This class is used to represent an MGATHER node
3200///
3202public:
3203 friend class SelectionDAG;
3204
3205 MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
3206 EVT MemVT, MachineMemOperand *MMO,
3207 ISD::MemIndexType IndexType, ISD::LoadExtType ETy)
3208 : MaskedGatherScatterSDNode(ISD::MGATHER, Order, dl, VTs, MemVT, MMO,
3209 IndexType) {
3210 LoadSDNodeBits.ExtTy = ETy;
3211 }
3212
3213 const SDValue &getPassThru() const { return getOperand(1); }
3214
3218
3219 static bool classof(const SDNode *N) {
3220 return N->getOpcode() == ISD::MGATHER;
3221 }
3222};
3223
3224/// This class is used to represent an MSCATTER node
3225///
3227public:
3228 friend class SelectionDAG;
3229
3230 MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
3231 EVT MemVT, MachineMemOperand *MMO,
3232 ISD::MemIndexType IndexType, bool IsTrunc)
3233 : MaskedGatherScatterSDNode(ISD::MSCATTER, Order, dl, VTs, MemVT, MMO,
3234 IndexType) {
3235 StoreSDNodeBits.IsTruncating = IsTrunc;
3236 }
3237
3238 /// Return true if the op does a truncation before store.
3239 /// For integers this is the same as doing a TRUNCATE and storing the result.
3240 /// For floats, it is the same as doing an FP_ROUND and storing the result.
3241 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
3242
3243 const SDValue &getValue() const { return getOperand(1); }
3244
3245 static bool classof(const SDNode *N) {
3246 return N->getOpcode() == ISD::MSCATTER;
3247 }
3248};
3249
3251public:
3252 friend class SelectionDAG;
3253
3254 MaskedHistogramSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs,
3255 EVT MemVT, MachineMemOperand *MMO,
3256 ISD::MemIndexType IndexType)
3257 : MaskedGatherScatterSDNode(ISD::EXPERIMENTAL_VECTOR_HISTOGRAM, Order, DL,
3258 VTs, MemVT, MMO, IndexType) {}
3259
3261 return static_cast<ISD::MemIndexType>(LSBaseSDNodeBits.AddressingMode);
3262 }
3263
3264 const SDValue &getBasePtr() const { return getOperand(3); }
3265 const SDValue &getIndex() const { return getOperand(4); }
3266 const SDValue &getMask() const { return getOperand(2); }
3267 const SDValue &getScale() const { return getOperand(5); }
3268 const SDValue &getInc() const { return getOperand(1); }
3269 const SDValue &getIntID() const { return getOperand(6); }
3270
3271 static bool classof(const SDNode *N) {
3272 return N->getOpcode() == ISD::EXPERIMENTAL_VECTOR_HISTOGRAM;
3273 }
3274};
3275
3277public:
3278 friend class SelectionDAG;
3279
3280 VPLoadFFSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs, EVT MemVT,
3281 MachineMemOperand *MMO)
3282 : MemSDNode(ISD::VP_LOAD_FF, Order, DL, VTs, MemVT, MMO) {}
3283
3284 const SDValue &getBasePtr() const { return getOperand(1); }
3285 const SDValue &getMask() const { return getOperand(2); }
3286 const SDValue &getVectorLength() const { return getOperand(3); }
3287
3288 static bool classof(const SDNode *N) {
3289 return N->getOpcode() == ISD::VP_LOAD_FF;
3290 }
3291};
3292
3294public:
3295 friend class SelectionDAG;
3296
3297 FPStateAccessSDNode(unsigned NodeTy, unsigned Order, const DebugLoc &dl,
3298 SDVTList VTs, EVT MemVT, MachineMemOperand *MMO)
3299 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
3300 assert((NodeTy == ISD::GET_FPENV_MEM || NodeTy == ISD::SET_FPENV_MEM) &&
3301 "Expected FP state access node");
3302 }
3303
3304 static bool classof(const SDNode *N) {
3305 return N->getOpcode() == ISD::GET_FPENV_MEM ||
3306 N->getOpcode() == ISD::SET_FPENV_MEM;
3307 }
3308};
3309
3310/// An SDNode that represents everything that will be needed
3311/// to construct a MachineInstr. These nodes are created during the
3312/// instruction selection proper phase.
3313///
3314/// Note that the only supported way to set the `memoperands` is by calling the
3315/// `SelectionDAG::setNodeMemRefs` function as the memory management happens
3316/// inside the DAG rather than in the node.
3317class MachineSDNode : public SDNode {
3318private:
3319 friend class SelectionDAG;
3320
3321 MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL, SDVTList VTs)
3322 : SDNode(Opc, Order, DL, VTs) {}
3323
3324 // We use a pointer union between a single `MachineMemOperand` pointer and
3325 // a pointer to an array of `MachineMemOperand` pointers. This is null when
3326 // the number of these is zero, the single pointer variant used when the
3327 // number is one, and the array is used for larger numbers.
3328 //
3329 // The array is allocated via the `SelectionDAG`'s allocator and so will
3330 // always live until the DAG is cleaned up and doesn't require ownership here.
3331 //
3332 // We can't use something simpler like `TinyPtrVector` here because `SDNode`
3333 // subclasses aren't managed in a conforming C++ manner. See the comments on
3334 // `SelectionDAG::MorphNodeTo` which details what all goes on, but the
3335 // constraint here is that these don't manage memory with their constructor or
3336 // destructor and can be initialized to a good state even if they start off
3337 // uninitialized.
3339
3340 // Note that this could be folded into the above `MemRefs` member if doing so
3341 // is advantageous at some point. We don't need to store this in most cases.
3342 // However, at the moment this doesn't appear to make the allocation any
3343 // smaller and makes the code somewhat simpler to read.
3344 int NumMemRefs = 0;
3345
3346public:
3348
3350 // Special case the common cases.
3351 if (NumMemRefs == 0)
3352 return {};
3353 if (NumMemRefs == 1)
3354 return ArrayRef(MemRefs.getAddrOfPtr1(), 1);
3355
3356 // Otherwise we have an actual array.
3357 return ArrayRef(cast<MachineMemOperand **>(MemRefs), NumMemRefs);
3358 }
3359 mmo_iterator memoperands_begin() const { return memoperands().begin(); }
3360 mmo_iterator memoperands_end() const { return memoperands().end(); }
3361 bool memoperands_empty() const { return memoperands().empty(); }
3362
3363 /// Clear out the memory reference descriptor list.
3365 MemRefs = nullptr;
3366 NumMemRefs = 0;
3367 }
3368
3369 static bool classof(const SDNode *N) {
3370 return N->isMachineOpcode();
3371 }
3372};
3373
3374/// An SDNode that records if a register contains a value that is guaranteed to
3375/// be aligned accordingly.
3377 Align Alignment;
3378
3379public:
3380 AssertAlignSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs, Align A)
3381 : SDNode(ISD::AssertAlign, Order, DL, VTs), Alignment(A) {}
3382
3383 Align getAlign() const { return Alignment; }
3384
3385 static bool classof(const SDNode *N) {
3386 return N->getOpcode() == ISD::AssertAlign;
3387 }
3388};
3389
3390class SDNodeIterator {
3391 const SDNode *Node;
3392 unsigned Operand;
3393
3394 SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
3395
3396public:
3397 using iterator_category = std::forward_iterator_tag;
3399 using difference_type = std::ptrdiff_t;
3402
3403 bool operator==(const SDNodeIterator& x) const {
3404 return Operand == x.Operand;
3405 }
3406 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
3407
3409 return Node->getOperand(Operand).getNode();
3410 }
3411 pointer operator->() const { return operator*(); }
3412
3413 SDNodeIterator& operator++() { // Preincrement
3414 ++Operand;
3415 return *this;
3416 }
3417 SDNodeIterator operator++(int) { // Postincrement
3418 SDNodeIterator tmp = *this; ++*this; return tmp;
3419 }
3420 size_t operator-(SDNodeIterator Other) const {
3421 assert(Node == Other.Node &&
3422 "Cannot compare iterators of two different nodes!");
3423 return Operand - Other.Operand;
3424 }
3425
3426 static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
3427 static SDNodeIterator end (const SDNode *N) {
3428 return SDNodeIterator(N, N->getNumOperands());
3429 }
3430
3431 unsigned getOperand() const { return Operand; }
3432 const SDNode *getNode() const { return Node; }
3433};
3434
3435template <> struct GraphTraits<SDNode*> {
3436 using NodeRef = SDNode *;
3438
3439 static NodeRef getEntryNode(SDNode *N) { return N; }
3440
3444
3448};
3449
3450/// A representation of the largest SDNode, for use in sizeof().
3451///
3452/// This needs to be a union because the largest node differs on 32 bit systems
3453/// with 4 and 8 byte pointer alignment, respectively.
3458
3459/// The SDNode class with the greatest alignment requirement.
3461
3462namespace ISD {
3463
3464 /// Returns true if the specified node is a non-extending and unindexed load.
3465 inline bool isNormalLoad(const SDNode *N) {
3466 auto *Ld = dyn_cast<LoadSDNode>(N);
3467 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
3468 Ld->getAddressingMode() == ISD::UNINDEXED;
3469 }
3470
3471 /// Returns true if the specified node is a non-extending load.
3472 inline bool isNON_EXTLoad(const SDNode *N) {
3473 auto *Ld = dyn_cast<LoadSDNode>(N);
3474 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD;
3475 }
3476
3477 /// Returns true if the specified node is a EXTLOAD.
3478 inline bool isEXTLoad(const SDNode *N) {
3479 auto *Ld = dyn_cast<LoadSDNode>(N);
3480 return Ld && Ld->getExtensionType() == ISD::EXTLOAD;
3481 }
3482
3483 /// Returns true if the specified node is a SEXTLOAD.
3484 inline bool isSEXTLoad(const SDNode *N) {
3485 auto *Ld = dyn_cast<LoadSDNode>(N);
3486 return Ld && Ld->getExtensionType() == ISD::SEXTLOAD;
3487 }
3488
3489 /// Returns true if the specified node is a ZEXTLOAD.
3490 inline bool isZEXTLoad(const SDNode *N) {
3491 auto *Ld = dyn_cast<LoadSDNode>(N);
3492 return Ld && Ld->getExtensionType() == ISD::ZEXTLOAD;
3493 }
3494
3495 /// Returns true if the specified node is an unindexed load.
3496 inline bool isUNINDEXEDLoad(const SDNode *N) {
3497 auto *Ld = dyn_cast<LoadSDNode>(N);
3498 return Ld && Ld->getAddressingMode() == ISD::UNINDEXED;
3499 }
3500
3501 /// Returns true if the specified node is a non-truncating
3502 /// and unindexed store.
3503 inline bool isNormalStore(const SDNode *N) {
3504 auto *St = dyn_cast<StoreSDNode>(N);
3505 return St && !St->isTruncatingStore() &&
3506 St->getAddressingMode() == ISD::UNINDEXED;
3507 }
3508
3509 /// Returns true if the specified node is an unindexed store.
3510 inline bool isUNINDEXEDStore(const SDNode *N) {
3511 auto *St = dyn_cast<StoreSDNode>(N);
3512 return St && St->getAddressingMode() == ISD::UNINDEXED;
3513 }
3514
3515 /// Returns true if the specified node is a non-extending, non-expanding, and
3516 /// unindexed masked load.
3517 inline bool isNormalMaskedLoad(const SDNode *N) {
3518 auto *Ld = dyn_cast<MaskedLoadSDNode>(N);
3519 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
3520 Ld->getAddressingMode() == ISD::UNINDEXED && !Ld->isExpandingLoad();
3521 }
3522
3523 /// Returns true if the specified node is a non-extending, non-compressing,
3524 /// and unindexed masked store.
3525 inline bool isNormalMaskedStore(const SDNode *N) {
3526 auto *St = dyn_cast<MaskedStoreSDNode>(N);
3527 return St && !St->isTruncatingStore() &&
3528 St->getAddressingMode() == ISD::UNINDEXED &&
3529 !St->isCompressingStore();
3530 }
3531
3532 /// Attempt to match a unary predicate against a scalar/splat constant or
3533 /// every element of a constant BUILD_VECTOR. The DemandedElts argument
3534 /// allows us to only collect the known bits that are shared by the requested
3535 /// vector elements.
3536 /// If AllowUndef is true, then UNDEF elements will pass nullptr to Match.
3537 template <typename ConstNodeType>
3538 bool matchUnaryPredicateImpl(SDValue Op, const APInt &DemandedElts,
3539 std::function<bool(ConstNodeType *)> Match,
3540 bool AllowUndefs = false,
3541 bool AllowTruncation = false);
3542
3543 /// Hook for matching ConstantSDNode predicate
3544 inline bool matchUnaryPredicate(SDValue Op, const APInt &DemandedElts,
3545 std::function<bool(ConstantSDNode *)> Match,
3546 bool AllowUndefs = false,
3547 bool AllowTruncation = false) {
3549 Op, DemandedElts, Match, AllowUndefs, AllowTruncation);
3550 }
3551
3553 std::function<bool(ConstantSDNode *)> Match,
3554 bool AllowUndefs = false,
3555 bool AllowTruncation = false) {
3556 EVT VT = Op.getValueType();
3557 APInt DemandedElts = VT.isFixedLengthVector()
3559 : APInt(1, 1);
3560 return matchUnaryPredicate(Op, DemandedElts, Match, AllowUndefs,
3561 AllowTruncation);
3562 }
3563
3564 /// Hook for matching ConstantFPSDNode predicate
3565 inline bool
3567 std::function<bool(ConstantFPSDNode *)> Match,
3568 bool AllowUndefs = false) {
3569 return matchUnaryPredicateImpl<ConstantFPSDNode>(Op, DemandedElts, Match,
3570 AllowUndefs);
3571 }
3572
3573 inline bool
3575 std::function<bool(ConstantFPSDNode *)> Match,
3576 bool AllowUndefs = false) {
3577 EVT VT = Op.getValueType();
3578 APInt DemandedElts = VT.isFixedLengthVector()
3580 : APInt(1, 1);
3581 return matchUnaryFpPredicate(Op, DemandedElts, Match, AllowUndefs);
3582 }
3583
3584 /// Attempt to match a binary predicate against a pair of scalar/splat
3585 /// constants or every element of a pair of constant BUILD_VECTORs.
3586 /// The DemandedElts argument allows us to only collect the
3587 /// known bits that are shared by the requested vector elements.
3588 /// If AllowUndef is true, then UNDEF elements will pass nullptr to Match.
3589 /// If AllowTypeMismatch is true then RetType + ArgTypes don't need to match.
3591 SDValue LHS, SDValue RHS, const APInt &DemandedElts,
3592 std::function<bool(ConstantSDNode *, ConstantSDNode *)> Match,
3593 bool AllowUndefs = false, bool AllowTypeMismatch = false);
3594
3597 std::function<bool(ConstantSDNode *, ConstantSDNode *)> Match,
3598 bool AllowUndefs = false, bool AllowTypeMismatch = false) {
3599 EVT VT = LHS.getValueType();
3600 APInt DemandedElts = VT.isFixedLengthVector()
3602 : APInt(1, 1);
3603 return matchBinaryPredicate(LHS, RHS, DemandedElts, Match, AllowUndefs,
3604 AllowTypeMismatch);
3605 }
3606
3607 /// Returns true if the specified value is the overflow result from one
3608 /// of the overflow intrinsic nodes.
3610 unsigned Opc = Op.getOpcode();
3611 return (Op.getResNo() == 1 &&
3612 (Opc == ISD::SADDO || Opc == ISD::UADDO || Opc == ISD::SSUBO ||
3613 Opc == ISD::USUBO || Opc == ISD::SMULO || Opc == ISD::UMULO));
3614 }
3615
3616} // end namespace ISD
3617
3618} // end namespace llvm
3619
3620#endif // LLVM_CODEGEN_SELECTIONDAGNODES_H
return SDValue()
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
static msgpack::DocNode getNode(msgpack::DocNode DN, msgpack::Type Type, MCValue Val)
uint64_t uint64_t
This file declares a class to represent arbitrary precision floating point values and provide a varie...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Atomic ordering constants.
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
This file implements the BitVector class.
#define LLVM_DECLARE_ENUM_AS_BITMASK(Enum, LargestValue)
LLVM_DECLARE_ENUM_AS_BITMASK can be used to declare an enum type as a bit set, so that bitwise operat...
Definition BitmaskEnum.h:66
static constexpr unsigned long long mask(BlockVerifier::State S)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static std::optional< bool > isBigEndian(const SmallDenseMap< int64_t, int64_t, 8 > &MemOffset2Idx, int64_t LowestIdx)
Given a map from byte offsets in memory to indices in a load/store, determine if that map corresponds...
#define LLVM_ABI
Definition Compiler.h:211
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines a hash set that can be used to remove duplication of nodes in a graph.
This file defines the little GraphTraits<X> template class that should be specialized by classes that...
#define op(i)
iv Induction Variable Users
Definition IVUsers.cpp:48
#define I(x, y, z)
Definition MD5.cpp:57
#define G(x, y, z)
Definition MD5.cpp:55
This file contains the declarations for metadata subclasses.
SmallVector< MachineOperand, 4 > Cond
Remove Loads Into Fake Uses
#define END_TWO_BYTE_PACK()
#define BEGIN_TWO_BYTE_PACK()
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
Definition APInt.h:230
unsigned getSrcAddressSpace() const
AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, unsigned SrcAS, unsigned DestAS)
unsigned getDestAddressSpace() const
static bool classof(const SDNode *N)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
const_pointer const_iterator
Definition ArrayRef.h:48
size_t size() const
Get the array size.
Definition ArrayRef.h:141
static bool classof(const SDNode *N)
AssertAlignSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs, Align A)
This is an SDNode representing atomic operations.
static bool classof(const SDNode *N)
const SDValue & getBasePtr() const
ISD::LoadExtType getExtensionType() const
AtomicOrdering getFailureOrdering() const
For cmpxchg atomic operations, return the atomic ordering requirements when store does not occur.
AtomicSDNode(unsigned Order, const DebugLoc &dl, unsigned Opc, SDVTList VTL, EVT MemVT, MachineMemOperand *MMO, ISD::LoadExtType ETy)
bool isCompareAndSwap() const
Returns true if this SDNode represents cmpxchg atomic operation, false otherwise.
const SDValue & getVal() const
MachineBasicBlock * getBasicBlock() const
static bool classof(const SDNode *N)
LLVM Basic Block Representation.
Definition BasicBlock.h:62
static bool classof(const SDNode *N)
const BlockAddress * getBlockAddress() const
The address of a basic block.
Definition Constants.h:1088
LLVM_ABI bool getConstantRawBits(bool IsLittleEndian, unsigned DstEltSizeInBits, SmallVectorImpl< APInt > &RawBitElements, BitVector &UndefElements) const
Extract the raw bit data from a build vector of Undef, Constant or ConstantFP node elements.
static LLVM_ABI void recastRawBits(bool IsLittleEndian, unsigned DstEltSizeInBits, SmallVectorImpl< APInt > &DstBitElements, ArrayRef< APInt > SrcBitElements, BitVector &DstUndefElements, const BitVector &SrcUndefElements)
Recast bit data SrcBitElements to DstEltSizeInBits wide elements.
LLVM_ABI bool getRepeatedSequence(const APInt &DemandedElts, SmallVectorImpl< SDValue > &Sequence, BitVector *UndefElements=nullptr) const
Find the shortest repeating sequence of values in the build vector.
LLVM_ABI ConstantFPSDNode * getConstantFPSplatNode(const APInt &DemandedElts, BitVector *UndefElements=nullptr) const
Returns the demanded splatted constant FP or null if this is not a constant FP splat.
LLVM_ABI SDValue getSplatValue(const APInt &DemandedElts, BitVector *UndefElements=nullptr) const
Returns the demanded splatted value or a null value if this is not a splat.
LLVM_ABI bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef, unsigned &SplatBitSize, bool &HasAnyUndefs, unsigned MinSplatBits=0, bool isBigEndian=false) const
Check if this is a constant splat, and if so, find the smallest element size that splats the vector.
LLVM_ABI ConstantSDNode * getConstantSplatNode(const APInt &DemandedElts, BitVector *UndefElements=nullptr) const
Returns the demanded splatted constant or null if this is not a constant splat.
LLVM_ABI int32_t getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements, uint32_t BitWidth) const
If this is a constant FP splat and the splatted constant FP is an exact power or 2,...
LLVM_ABI std::optional< std::pair< APInt, APInt > > isArithmeticSequence() const
If this BuildVector is constant and represents an arithmetic sequence "<a, a+n, a+2n,...
LLVM_ABI bool isConstant() const
static bool classof(const SDNode *N)
ISD::CondCode get() const
static bool classof(const SDNode *N)
static LLVM_ABI bool isValueValidForType(EVT VT, const APFloat &Val)
const APFloat & getValueAPF() const
bool isPosZero() const
Return true if the value is positive zero.
bool isOne() const
Returns true if this value is exactly +1.0.
bool isNegZero() const
Return true if the value is negative zero.
bool isNaN() const
Return true if the value is a NaN.
bool isMinusOne() const
Returns true if this value is exactly -1.0.
const ConstantFP * getConstantFPValue() const
bool isExactlyValue(double V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
bool isNegative() const
Return true if the value is negative.
bool isInfinity() const
Return true if the value is an infinity.
static bool classof(const SDNode *N)
bool isZero() const
Return true if the value is positive or negative zero.
ConstantFP - Floating Point Values [float, double].
Definition Constants.h:420
This is the shared class of boolean and integer constants.
Definition Constants.h:87
static bool classof(const SDNode *N)
MachineConstantPoolValue * getMachineCPVal() const
MachineConstantPoolValue * MachineCPVal
const Constant * getConstVal() const
LLVM_ABI Type * getType() const
MaybeAlign getMaybeAlignValue() const
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX)
const ConstantInt * getConstantIntValue() const
uint64_t getZExtValue() const
const APInt & getAPIntValue() const
int64_t getSExtValue() const
static bool classof(const SDNode *N)
This is an important base class in LLVM.
Definition Constant.h:44
static bool classof(const SDNode *N)
const GlobalValue * getGlobal() const
A debug info location.
Definition DebugLoc.h:126
static LLVM_ABI DebugLoc getMergedLocation(DebugLoc LocA, DebugLoc LocB)
When two instructions are combined into a single instruction we also need to combine the original loc...
Definition DebugLoc.cpp:186
const char * getSymbol() const
static bool classof(const SDNode *N)
Utility class for floating point operations which can have information about relaxed accuracy require...
Definition Operator.h:202
bool hasAllowReassoc() const
Test if this operation may be simplified with reassociative transforms.
Definition Operator.h:267
bool hasNoNaNs() const
Test if this operation's arguments and results are assumed not-NaN.
Definition Operator.h:270
bool hasAllowReciprocal() const
Test if this operation can use reciprocal multiply instead of division.
Definition Operator.h:279
bool hasNoSignedZeros() const
Test if this operation can ignore the sign of zero.
Definition Operator.h:276
bool hasAllowContract() const
Test if this operation can be floating-point contracted (FMA).
Definition Operator.h:284
bool hasNoInfs() const
Test if this operation's arguments and results are assumed not-infinite.
Definition Operator.h:273
bool hasApproxFunc() const
Test if this operation allows approximations of math library functions or intrinsics.
Definition Operator.h:288
static bool classof(const SDNode *N)
FPStateAccessSDNode(unsigned NodeTy, unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO)
FoldingSetNode()=default
static bool classof(const SDNode *N)
LLVM_ABI unsigned getAddressSpace() const
static bool classof(const SDNode *N)
const GlobalValue * getGlobal() const
const SDValue & getValue() const
static bool classof(const SDNode *N)
unsigned getTargetFlags() const
LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl, SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT, MachineMemOperand *MMO)
ISD::MemIndexedMode getAddressingMode() const
Return the addressing mode for this load or store: unindexed, pre-inc, pre-dec, post-inc,...
const SDValue & getOffset() const
bool isUnindexed() const
Return true if this is NOT a pre/post inc/dec load/store.
bool isIndexed() const
Return true if this is a pre/post inc/dec load/store.
static bool classof(const SDNode *N)
MCSymbol * getLabel() const
static bool classof(const SDNode *N)
int64_t getFrameIndex() const
static bool classof(const SDNode *N)
const SDValue & getBasePtr() const
friend class SelectionDAG
const SDValue & getOffset() const
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
static bool classof(const SDNode *N)
MCSymbol * getMCSymbol() const
static bool classof(const SDNode *N)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
static bool classof(const SDNode *N)
const MDNode * getMD() const
Metadata node.
Definition Metadata.h:1087
Machine Value Type.
Abstract base class for all machine specific constantpool value subclasses.
A description of a memory reference used in the backend.
AtomicOrdering getFailureOrdering() const
For cmpxchg atomic operations, return the atomic ordering requirements when store does not occur.
bool isUnordered() const
Returns true if this memory operation doesn't have any ordering constraints other than normal aliasin...
const MDNode * getRanges() const
Return the range tag for the memory reference.
bool isAtomic() const
Returns true if this operation has an atomic ordering requirement of unordered or higher,...
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID for this memory operation.
AtomicOrdering getMergedOrdering() const
Return a single atomic ordering that is at least as strong as both the success and failure orderings ...
AtomicOrdering getSuccessOrdering() const
Return the atomic ordering requirements for this memory operation.
const MachinePointerInfo & getPointerInfo() const
LLVM_ABI Align getAlign() const
Return the minimum known alignment in bytes of the actual memory reference.
AAMDNodes getAAInfo() const
Return the AA tags for the memory reference.
Align getBaseAlign() const
Return the minimum known alignment in bytes of the base address, without the offset.
const MDNode * getMemCacheHint() const
Return the cache hint metadata for the memory reference.
int64_t getOffset() const
For normal values, this is a byte offset added to the base address.
ArrayRef< MachineMemOperand * > memoperands() const
void clearMemRefs()
Clear out the memory reference descriptor list.
mmo_iterator memoperands_begin() const
static bool classof(const SDNode *N)
ArrayRef< MachineMemOperand * >::const_iterator mmo_iterator
mmo_iterator memoperands_end() const
static bool classof(const SDNode *N)
MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexType IndexType, ISD::LoadExtType ETy)
const SDValue & getPassThru() const
ISD::LoadExtType getExtensionType() const
static bool classof(const SDNode *N)
MaskedGatherScatterSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexType IndexType)
const SDValue & getBasePtr() const
ISD::MemIndexType getIndexType() const
How is Index applied to BasePtr when computing addresses.
const SDValue & getInc() const
MaskedHistogramSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexType IndexType)
const SDValue & getScale() const
static bool classof(const SDNode *N)
const SDValue & getMask() const
const SDValue & getIntID() const
const SDValue & getIndex() const
const SDValue & getBasePtr() const
ISD::MemIndexType getIndexType() const
MaskedLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, ISD::MemIndexedMode AM, ISD::LoadExtType ETy, bool IsExpanding, EVT MemVT, MachineMemOperand *MMO)
const SDValue & getBasePtr() const
ISD::LoadExtType getExtensionType() const
const SDValue & getMask() const
const SDValue & getPassThru() const
static bool classof(const SDNode *N)
const SDValue & getOffset() const
const SDValue & getMask() const
MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl, SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT, MachineMemOperand *MMO)
bool isIndexed() const
Return true if this is a pre/post inc/dec load/store.
static bool classof(const SDNode *N)
const SDValue & getOffset() const
bool isUnindexed() const
Return true if this is NOT a pre/post inc/dec load/store.
ISD::MemIndexedMode getAddressingMode() const
Return the addressing mode for this load or store: unindexed, pre-inc, pre-dec, post-inc,...
MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexType IndexType, bool IsTrunc)
const SDValue & getValue() const
static bool classof(const SDNode *N)
bool isTruncatingStore() const
Return true if the op does a truncation before store.
bool isCompressingStore() const
Returns true if the op does a compression to the vector before storing.
MaskedStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, ISD::MemIndexedMode AM, bool isTrunc, bool isCompressing, EVT MemVT, MachineMemOperand *MMO)
const SDValue & getOffset() const
const SDValue & getBasePtr() const
const SDValue & getMask() const
const SDValue & getValue() const
bool isTruncatingStore() const
Return true if the op does a truncation before store.
static bool classof(const SDNode *N)
MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemoryVT, PointerUnion< MachineMemOperand *, MachineMemOperand ** > MemRefs)
static bool classof(const SDNode *N)
void refineAlignment(ArrayRef< MachineMemOperand * > NewMMOs)
Update this MemSDNode's MachineMemOperand information to reflect the alignment of NewMMOs,...
void refineAlignment(MachineMemOperand *NewMMO)
unsigned getAddressSpace() const
Return the address space for the associated pointer.
size_t getNumMemOperands() const
Return the number of memory operands.
Align getBaseAlign() const
Returns alignment and volatility of the memory access.
void refineMMOMetadata(MachineMemOperand *NewMMO)
const MDNode * getRanges() const
Returns the Ranges that describes the dereference.
LLVM_ABI MemSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT memvt, PointerUnion< MachineMemOperand *, MachineMemOperand ** > memrefs)
Constructor that supports single or multiple MMOs.
Align getAlign() const
PointerUnion< MachineMemOperand *, MachineMemOperand ** > MemRefs
Memory reference information.
bool isVolatile() const
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID for this memory operation.
int64_t getSrcValueOffset() const
bool isSimple() const
Returns true if the memory operation is neither atomic or volatile.
AtomicOrdering getSuccessOrdering() const
Return the atomic ordering requirements for this memory operation.
MachineMemOperand * getMemOperand() const
Return the unique MachineMemOperand object describing the memory reference performed by operation.
const SDValue & getBasePtr() const
MMOMetadata getMMOMetadataForSubAccess() const
Returns metadata that can be copied unchanged to an access covering all or part of this access's byte...
const MachinePointerInfo & getPointerInfo() const
bool hasUniqueMemOperand() const
Return true if this node has exactly one memory operand.
AtomicOrdering getMergedOrdering() const
Return a single atomic ordering that is at least as strong as both the success and failure orderings ...
const SDValue & getChain() const
bool isNonTemporal() const
void refineMMOMetadata(ArrayRef< MachineMemOperand * > NewMMOs)
Refine LLVM IR metadata for all MMOs.
bool isInvariant() const
bool isDereferenceable() const
bool isUnordered() const
Returns true if the memory operation doesn't imply any ordering constraints on surrounding memory ope...
bool isAtomic() const
Return true if the memory operation ordering is Unordered or higher.
static bool classof(const SDNode *N)
ArrayRef< MachineMemOperand * > memoperands() const
Return the memory operands for this node.
unsigned getRawSubclassData() const
Return the SubclassData value, without HasDebugValue.
EVT getMemoryVT() const
Return the type of the in-memory value.
const MDNode * getMemCacheHint() const
Returns the cache hint metadata for this memory access.
LLVM_ABI void dump() const
User-friendly dump.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
A discriminated union of two or more pointer types, with the discriminator in the low bits of the poi...
This SDNode is used for PSEUDO_PROBE values, which are the function guid and the index of the basic b...
static bool classof(const SDNode *N)
const uint32_t * getRegMask() const
static bool classof(const SDNode *N)
static bool classof(const SDNode *N)
Wrapper class representing virtual and physical registers.
Definition Register.h:20
const DebugLoc & getDebugLoc() const
unsigned getIROrder() const
void mergeDebugLoc(const DebugLoc &Other)
Merge the source location without changing the IR order.
SDLoc(const SDValue V)
SDLoc()=default
SDLoc(const SDNode *N)
SDLoc(const Instruction *I, int Order)
static SDNodeIterator end(const SDNode *N)
size_t operator-(SDNodeIterator Other) const
SDNodeIterator operator++(int)
std::ptrdiff_t difference_type
std::forward_iterator_tag iterator_category
unsigned getOperand() const
SDNodeIterator & operator++()
bool operator==(const SDNodeIterator &x) const
const SDNode * getNode() const
static SDNodeIterator begin(const SDNode *N)
bool operator!=(const SDNodeIterator &x) const
This class provides iterator support for SDUse operands that use a specific SDNode.
bool operator!=(const use_iterator &x) const
use_iterator & operator=(const use_iterator &)=default
std::forward_iterator_tag iterator_category
bool operator==(const use_iterator &x) const
SDUse & operator*() const
Retrieve a pointer to the current user node.
use_iterator(const use_iterator &I)=default
std::forward_iterator_tag iterator_category
bool operator!=(const user_iterator &x) const
bool operator==(const user_iterator &x) const
Represents one node in the SelectionDAG.
void setDebugLoc(DebugLoc dl)
Set source location info.
uint32_t getCFIType() const
void setIROrder(unsigned Order)
Set the node ordering.
bool isStrictFPOpcode()
Test if this node is a strict floating point pseudo-op.
ArrayRef< SDUse > ops() const
char RawSDNodeBits[sizeof(uint16_t)]
const APInt & getAsAPIntVal() const
Helper method returns the APInt value of a ConstantSDNode.
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode.
bool SchedulerWorklistVisited
Visited state in ScheduleDAGSDNodes::BuildSchedUnits.
void setSchedulerWorklistVisited(bool Visited)
Set visited state for ScheduleDAGSDNodes::BuildSchedUnits.
LLVM_ABI void dumprFull(const SelectionDAG *G=nullptr) const
printrFull to dbgs().
int getNodeId() const
Return the unique node id.
LLVM_ABI void dump() const
Dump this node, for debugging.
iterator_range< value_iterator > values() const
iterator_range< use_iterator > uses() const
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
SDNode * getGluedUser() const
If this node has a glue value with a user, return the user (there is at most one).
bool isDivergent() const
bool hasOneUse() const
Return true if there is exactly one use of this node.
LLVM_ABI bool isOnlyUserOf(const SDNode *N) const
Return true if this node is the only use of N.
static LLVM_ABI const char * getIndexedModeName(ISD::MemIndexedMode AM)
iterator_range< value_op_iterator > op_values() const
unsigned getIROrder() const
Return the node ordering.
LoadSDNodeBitfields LoadSDNodeBits
void dropFlags(unsigned Mask)
static constexpr size_t getMaxNumOperands()
Return the maximum number of operands that a SDNode can hold.
int getCombinerWorklistIndex() const
Get worklist index for DAGCombiner.
value_iterator value_end() const
ISD::CondCode getOperandCondCode(unsigned Num) const
Helper method returns the CondCode of a CondCodeSDNode.
void setHasDebugValue(bool b)
LSBaseSDNodeBitfields LSBaseSDNodeBits
iterator_range< use_iterator > uses()
MemSDNodeBitfields MemSDNodeBits
bool getHasDebugValue() const
LLVM_ABI void dumpr() const
Dump (recursively) this node and its use-def subgraph.
SDNodeFlags getFlags() const
void setNodeId(int Id)
Set unique node id.
LLVM_ABI std::string getOperationName(const SelectionDAG *G=nullptr) const
Return the opcode of this operation for printing.
LLVM_ABI void printrFull(raw_ostream &O, const SelectionDAG *G=nullptr) const
Print a SelectionDAG node and all children down to the leaves.
size_t use_size() const
Return the number of uses of this node.
friend class SelectionDAG
LLVM_ABI void intersectFlagsWith(const SDNodeFlags Flags)
Clear any flags in this node that aren't also set in Flags.
static bool isMachineOpcode(unsigned Opc)
As above, for an opcode not held by a node.
int CombinerWorklistIndex
Index in worklist of DAGCombiner, or negative if the node is not in the worklist.
LLVM_ABI void printr(raw_ostream &OS, const SelectionDAG *G=nullptr) const
const EVT * value_iterator
StoreSDNodeBitfields StoreSDNodeBits
static SDVTList getSDVTList(MVT VT)
TypeSize getValueSizeInBits(unsigned ResNo) const
Returns MVT::getSizeInBits(getValueType(ResNo)).
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
static bool hasPredecessorHelper(const SDNode *N, SmallPtrSetImpl< const SDNode * > &Visited, SmallVectorImpl< const SDNode * > &Worklist, unsigned int MaxSteps=0, bool TopologicalPrune=false)
Returns true if N is a predecessor of any node in Worklist.
uint64_t getAsZExtVal() const
Helper method returns the zero-extended integer value of a ConstantSDNode.
bool use_empty() const
Return true if there are no uses of this node.
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
unsigned getNumOperands() const
Return the number of values used by this operation.
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
SDVTList getVTList() const
const SDValue & getOperand(unsigned Num) const
bool isMemIntrinsic() const
Test if this node is a memory intrinsic (with valid pointer information).
void setCombinerWorklistIndex(int Index)
Set worklist index for DAGCombiner.
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
static LLVM_ABI bool areOnlyUsersOf(ArrayRef< const SDNode * > Nodes, const SDNode *N)
Return true if all the users of N are contained in Nodes.
bool hasNUsesOfValue(unsigned NUses, unsigned Value) const
Return true if there are exactly NUSES uses of the indicated value.
use_iterator use_begin() const
Provide iteration support to walk over all uses of an SDNode.
LLVM_ABI bool isOperandOf(const SDNode *N) const
Return true if this node is an operand of N.
LLVM_ABI void print(raw_ostream &OS, const SelectionDAG *G=nullptr) const
const DebugLoc & getDebugLoc() const
Return the source location info.
friend class HandleSDNode
LLVM_ABI void printrWithDepth(raw_ostream &O, const SelectionDAG *G=nullptr, unsigned depth=100) const
Print a SelectionDAG node and children up to depth "depth." The given SelectionDAG allows target-spec...
const APInt & getConstantOperandAPInt(unsigned Num) const
Helper method returns the APInt of a ConstantSDNode operand.
uint16_t PersistentId
Unique and persistent id per SDNode in the DAG.
std::optional< APInt > bitcastToAPInt() const
LLVM_ABI void dumprWithDepth(const SelectionDAG *G=nullptr, unsigned depth=100) const
printrWithDepth to dbgs().
bool getSchedulerWorklistVisited() const
Get visited state for ScheduleDAGSDNodes::BuildSchedUnits.
static user_iterator user_end()
bool isPredecessorOf(const SDNode *N) const
Return true if this node is a predecessor of N.
LLVM_ABI bool hasPredecessor(const SDNode *N) const
Return true if N is a predecessor of this node.
void addUse(SDUse &U)
This method should only be used by the SDUse class.
LLVM_ABI bool hasAnyUseOfValue(unsigned Value) const
Return true if there are any use of the indicated value.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
LLVM_ABI void print_details(raw_ostream &OS, const SelectionDAG *G) const
void setCFIType(uint32_t Type)
bool isUndef() const
Returns true if the node type is UNDEF or POISON.
LLVM_ABI void print_types(raw_ostream &OS, const SelectionDAG *G) const
iterator_range< user_iterator > users()
iterator_range< user_iterator > users() const
bool isVPOpcode() const
Test if this node is a vector predication operation.
bool hasPoisonGeneratingFlags() const
void setFlags(SDNodeFlags NewFlags)
user_iterator user_begin() const
Provide iteration support to walk over all users of an SDNode.
SDNode * getGluedNode() const
If this node has a glue operand, return the node to which the glue operand points.
bool isTargetOpcode() const
Test if this node has a target-specific opcode (in the <target>ISD namespace).
op_iterator op_end() const
ConstantSDNodeBitfields ConstantSDNodeBits
bool isAnyAdd() const
Returns true if the node type is ADD or PTRADD.
value_iterator value_begin() const
bool isAssert() const
Test if this node is an assert operation.
op_iterator op_begin() const
static use_iterator use_end()
LLVM_ABI void DropOperands()
Release the operands and set this node to have zero operands.
SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
Create an SDNode.
SDNodeBitfields SDNodeBits
Represents a use of a SDNode.
const SDNode * getUser() const
SDUse & operator=(const SDUse &)=delete
EVT getValueType() const
Convenience function for get().getValueType().
friend class SDNode
const SDValue & get() const
If implicit conversion to SDValue doesn't work, the get() method returns the SDValue.
SDUse * getNext() const
Get the next SDUse in the use list.
SDNode * getNode() const
Convenience function for get().getNode().
friend class SelectionDAG
bool operator!=(const SDValue &V) const
Convenience function for get().operator!=.
SDUse()=default
SDUse(const SDUse &U)=delete
friend class HandleSDNode
unsigned getResNo() const
Convenience function for get().getResNo().
bool operator==(const SDValue &V) const
Convenience function for get().operator==.
unsigned getOperandNo() const
Return the operand # of this use in its user.
bool operator<(const SDValue &V) const
Convenience function for get().operator<.
SDNode * getUser()
This returns the SDNode that contains this Use.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
bool hasOneUser() const
Return true if there is exactly one node using value ResNo of Node, in potentially multiple operands.
bool isUndef() const
SDNode * getNode() const
get the SDNode which holds the desired result
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node, in exactly one operand.
LLVM_ABI bool isOperandOf(const SDNode *N) const
Return true if the referenced return value is an operand of N.
SDValue()=default
LLVM_ABI bool reachesChainWithoutSideEffects(SDValue Dest, unsigned Depth=2) const
Return true if this operand (which must be a chain) reaches the specified operand without crossing an...
bool operator!=(const SDValue &O) const
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
bool isTargetOpcode() const
bool isMachineOpcode() const
bool isAnyAdd() const
TypeSize getValueSizeInBits() const
Returns the size of the value in bits.
const DebugLoc & getDebugLoc() const
SDNode * operator->() const
bool operator==(const SDValue &O) const
const SDValue & getOperand(unsigned i) const
ISD::CondCode getOperandCondCode(unsigned i) const
bool use_empty() const
Return true if there are no nodes using value ResNo of Node.
bool operator<(const SDValue &O) const
const APInt & getConstantOperandAPInt(unsigned i) const
uint64_t getScalarValueSizeInBits() const
unsigned getResNo() const
get the index which selects a specific result in the SDNode
uint64_t getConstantOperandVal(unsigned i) const
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
void setNode(SDNode *N)
set the SDNode
unsigned getMachineOpcode() const
unsigned getOpcode() const
unsigned getNumOperands() const
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
int getMaskElt(unsigned Idx) const
static int getSplatMaskIndex(ArrayRef< int > Mask)
ShuffleVectorSDNode(SDVTList VTs, unsigned Order, const DebugLoc &dl, const int *M)
ArrayRef< int > getMask() const
static void commuteMask(MutableArrayRef< int > Mask)
Change values in a shuffle permute mask assuming the two vector operands have swapped position.
static bool classof(const SDNode *N)
static LLVM_ABI bool isSplatMask(ArrayRef< int > Mask)
size_type size() const
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const Value * getValue() const
Return the contained Value.
static bool classof(const SDNode *N)
const SDValue & getBasePtr() const
const SDValue & getOffset() const
const SDValue & getValue() const
bool isTruncatingStore() const
Return true if the op does a truncation before store.
static bool classof(const SDNode *N)
Completely target-dependent object reference.
TargetIndexSDNode(int Idx, SDVTList VTs, int64_t Ofs, unsigned TF)
static bool classof(const SDNode *N)
unsigned getTargetFlags() const
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
const SDValue & getMask() const
static bool classof(const SDNode *N)
bool isIndexed() const
Return true if this is a pre/post inc/dec load/store.
VPBaseLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &DL, SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT, MachineMemOperand *MMO)
const SDValue & getOffset() const
ISD::MemIndexedMode getAddressingMode() const
Return the addressing mode for this load or store: unindexed, pre-inc, pre-dec, post-inc,...
const SDValue & getVectorLength() const
bool isUnindexed() const
Return true if this is NOT a pre/post inc/dec load/store.
const SDValue & getBasePtr() const
VPGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexType IndexType)
static bool classof(const SDNode *N)
const SDValue & getScale() const
ISD::MemIndexType getIndexType() const
How is Index applied to BasePtr when computing addresses.
const SDValue & getVectorLength() const
const SDValue & getIndex() const
VPGatherScatterSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexType IndexType)
const SDValue & getBasePtr() const
static bool classof(const SDNode *N)
const SDValue & getMask() const
const SDValue & getMask() const
const SDValue & getBasePtr() const
VPLoadFFSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO)
static bool classof(const SDNode *N)
const SDValue & getVectorLength() const
const SDValue & getOffset() const
const SDValue & getVectorLength() const
ISD::LoadExtType getExtensionType() const
const SDValue & getMask() const
VPLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, ISD::MemIndexedMode AM, ISD::LoadExtType ETy, bool isExpanding, EVT MemVT, MachineMemOperand *MMO)
const SDValue & getBasePtr() const
static bool classof(const SDNode *N)
static bool classof(const SDNode *N)
VPScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexType IndexType)
const SDValue & getValue() const
const SDValue & getMask() const
VPStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, ISD::MemIndexedMode AM, bool isTrunc, bool isCompressing, EVT MemVT, MachineMemOperand *MMO)
static bool classof(const SDNode *N)
const SDValue & getVectorLength() const
bool isCompressingStore() const
Returns true if the op does a compression to the vector before storing.
const SDValue & getOffset() const
bool isTruncatingStore() const
Return true if this is a truncating store.
const SDValue & getBasePtr() const
const SDValue & getValue() const
const SDValue & getMask() const
ISD::LoadExtType getExtensionType() const
const SDValue & getStride() const
const SDValue & getOffset() const
const SDValue & getVectorLength() const
static bool classof(const SDNode *N)
const SDValue & getBasePtr() const
VPStridedLoadSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs, ISD::MemIndexedMode AM, ISD::LoadExtType ETy, bool IsExpanding, EVT MemVT, MachineMemOperand *MMO)
const SDValue & getBasePtr() const
const SDValue & getMask() const
const SDValue & getValue() const
bool isTruncatingStore() const
Return true if this is a truncating store.
VPStridedStoreSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs, ISD::MemIndexedMode AM, bool IsTrunc, bool IsCompressing, EVT MemVT, MachineMemOperand *MMO)
const SDValue & getOffset() const
const SDValue & getVectorLength() const
static bool classof(const SDNode *N)
const SDValue & getStride() const
bool isCompressingStore() const
Returns true if the op does a compression to the vector before storing.
friend class SelectionDAG
static bool classof(const SDNode *N)
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This file defines the ilist_node class template, which is a convenient base class for creating classe...
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define UINT64_MAX
Definition DataTypes.h:77
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
ISD namespace - This namespace contains an enum which represents all of the SelectionDAG node types a...
Definition ISDOpcodes.h:26
LLVM_ABI bool isConstantSplatVector(SDValue V, APInt &SplatValue)
Node predicates.
bool isNormalMaskedLoad(const SDNode *N)
Returns true if the specified node is a non-extending, non-expanding, and unindexed masked load.
LLVM_ABI bool isBuildVectorOfConstantFPSDNodes(SDValue V)
Return true if the specified value is a BUILD_VECTOR node of all ConstantFPSDNode or undef.
bool isNormalMaskedStore(const SDNode *N)
Returns true if the specified node is a non-extending, non-compressing, and unindexed masked store.
bool isNON_EXTLoad(const SDNode *N)
Returns true if the specified node is a non-extending load.
LLVM_ABI bool isConstantSplatVectorAllZeros(SDValue V, bool BuildVectorOnly=false)
Return true if the specified value is a BUILD_VECTOR or SPLAT_VECTOR where all of the elements are 0 ...
bool matchUnaryPredicateImpl(SDValue Op, const APInt &DemandedElts, std::function< bool(ConstNodeType *)> Match, bool AllowUndefs=false, bool AllowTruncation=false)
Attempt to match a unary predicate against a scalar/splat constant or every element of a constant BUI...
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition ISDOpcodes.h:43
@ TargetConstantPool
Definition ISDOpcodes.h:191
@ MDNODE_SDNODE
MDNODE_SDNODE - This is a node that holdes an MDNode*, which is used to reference metadata in the IR.
@ PTRADD
PTRADD represents pointer arithmetic semantics, for targets that opt in using shouldPreservePtrArith(...
@ POISON
POISON - A poison node.
Definition ISDOpcodes.h:238
@ ATOMIC_LOAD_FMINIMUMNUM
@ MLOAD
Masked load and store - consecutive vector load and store operations with additional mask operand tha...
@ TargetBlockAddress
Definition ISDOpcodes.h:193
@ DEACTIVATION_SYMBOL
Untyped node storing deactivation symbol reference (DeactivationSymbolSDNode).
@ ATOMIC_STORE
OUTCHAIN = ATOMIC_STORE(INCHAIN, val, ptr) This corresponds to "store atomic" instruction.
@ ADD
Simple integer binary arithmetic operators.
Definition ISDOpcodes.h:266
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
@ ATOMIC_LOAD_USUB_COND
@ GlobalAddress
Definition ISDOpcodes.h:90
@ ATOMIC_CMP_SWAP_WITH_SUCCESS
Val, Success, OUTCHAIN = ATOMIC_CMP_SWAP_WITH_SUCCESS(INCHAIN, ptr, cmp, swap) N.b.
@ BUILTIN_OP_END
BUILTIN_OP_END - This must be the last enum value in this list.
@ GlobalTLSAddress
Definition ISDOpcodes.h:91
@ SRCVALUE
SRCVALUE - This is a node type that holds a Value* that is used to make reference to a value in the L...
@ EH_LABEL
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
@ ATOMIC_LOAD_USUB_SAT
@ ANNOTATION_LABEL
ANNOTATION_LABEL - Represents a mid basic block label used by annotations.
@ TargetExternalSymbol
Definition ISDOpcodes.h:192
@ TargetJumpTable
Definition ISDOpcodes.h:190
@ TargetIndex
TargetIndex - Like a constant pool entry, but with completely target-dependent semantics.
Definition ISDOpcodes.h:200
@ SSUBO
Same for subtraction.
Definition ISDOpcodes.h:355
@ ATOMIC_LOAD
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
@ UNDEF
UNDEF - An undefined node.
Definition ISDOpcodes.h:235
@ AssertAlign
AssertAlign - These nodes record if a register contains a value that has a known alignment and the tr...
Definition ISDOpcodes.h:71
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:83
@ SADDO
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
Definition ISDOpcodes.h:351
@ TargetGlobalAddress
TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or anything else with this node...
Definition ISDOpcodes.h:187
@ STRICT_FP_TO_FP16
@ ATOMIC_LOAD_FMAXIMUM
@ STRICT_FP16_TO_FP
@ AssertNoFPClass
AssertNoFPClass - These nodes record if a register contains a float value that is known to be not som...
Definition ISDOpcodes.h:80
@ VECTOR_SHUFFLE
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
Definition ISDOpcodes.h:659
@ TargetConstantFP
Definition ISDOpcodes.h:182
@ ATOMIC_CMP_SWAP
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo,...
@ SMULO
Same for multiplication.
Definition ISDOpcodes.h:359
@ ATOMIC_LOAD_FMINIMUM
@ TargetFrameIndex
Definition ISDOpcodes.h:189
@ LIFETIME_START
This corresponds to the llvm.lifetime.
@ MGATHER
Masked gather and scatter - load and store operations for a vector of random addresses with additiona...
@ STRICT_BF16_TO_FP
@ ATOMIC_LOAD_FMAXIMUMNUM
@ ATOMIC_LOAD_UDEC_WRAP
@ TargetConstant
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification,...
Definition ISDOpcodes.h:181
@ GET_FPENV_MEM
Gets the current floating-point environment.
@ PSEUDO_PROBE
Pseudo probe for AutoFDO, as a place holder in a basic block to improve the sample counts quality.
@ STRICT_FP_TO_BF16
@ FREEZE
FREEZE - FREEZE(VAL) returns an arbitrary value if VAL is UNDEF (or is evaluated to UNDEF),...
Definition ISDOpcodes.h:243
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
Definition ISDOpcodes.h:55
@ ATOMIC_SWAP
Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt) Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN,...
@ ExternalSymbol
Definition ISDOpcodes.h:95
@ ADDRSPACECAST
ADDRSPACECAST - This operator converts between pointers of different address spaces.
@ EXPERIMENTAL_VECTOR_HISTOGRAM
Experimental vector histogram intrinsic Operands: Input Chain, Inc, Mask, Base, Index,...
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition ISDOpcodes.h:64
@ ATOMIC_LOAD_UINC_WRAP
@ SET_FPENV_MEM
Sets the current floating point environment.
@ TargetGlobalTLSAddress
Definition ISDOpcodes.h:188
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
Definition ISDOpcodes.h:561
bool isOverflowIntrOpRes(SDValue Op)
Returns true if the specified value is the overflow result from one of the overflow intrinsic nodes.
bool isNormalStore(const SDNode *N)
Returns true if the specified node is a non-truncating and unindexed store.
bool isZEXTLoad(const SDNode *N)
Returns true if the specified node is a ZEXTLOAD.
LLVM_ABI bool isConstantSplatVectorAllOnes(SDValue V, bool BuildVectorOnly=false)
Return true if the specified value is a BUILD_VECTOR or SPLAT_VECTOR where all of the elements are ~0...
LLVM_ABI bool isFreezeUndef(SDValue V)
Return true if the specified value is FREEZE(UNDEF).
LLVM_ABI bool allOperandsUndef(SDValue V)
Return true if the value has at least one operand and all operands of the specified value are ISD::UN...
LLVM_ABI bool isBuildVectorAllOnes(SDValue V)
Return true if the specified value is a BUILD_VECTOR where all of the elements are ~0 or undef.
LLVM_ABI bool isVectorShrinkable(SDValue V, unsigned NewEltSize, bool Signed)
Returns true if the specified value is a vector where all elements can be truncated to the specified ...
bool isUNINDEXEDLoad(const SDNode *N)
Returns true if the specified node is an unindexed load.
LLVM_ABI bool matchBinaryPredicate(SDValue LHS, SDValue RHS, const APInt &DemandedElts, std::function< bool(ConstantSDNode *, ConstantSDNode *)> Match, bool AllowUndefs=false, bool AllowTypeMismatch=false)
Attempt to match a binary predicate against a pair of scalar/splat constants or every element of a pa...
bool isEXTLoad(const SDNode *N)
Returns true if the specified node is a EXTLOAD.
MemIndexType
MemIndexType enum - This enum defines how to interpret MGATHER/SCATTER's index parameter when calcula...
LLVM_ABI bool isBuildVectorAllZeros(SDValue V)
Return true if the specified value is a BUILD_VECTOR where all of the elements are 0 or undef.
bool isUNINDEXEDStore(const SDNode *N)
Returns true if the specified node is an unindexed store.
MemIndexedMode
MemIndexedMode enum - This enum defines the load / store indexed addressing modes.
bool isSEXTLoad(const SDNode *N)
Returns true if the specified node is a SEXTLOAD.
bool matchUnaryFpPredicate(SDValue Op, const APInt &DemandedElts, std::function< bool(ConstantFPSDNode *)> Match, bool AllowUndefs=false)
Hook for matching ConstantFPSDNode predicate.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
LLVM_ABI bool isBuildVectorOfConstantSDNodes(SDValue V)
Return true if the specified value is a BUILD_VECTOR node of all ConstantSDNode or undef.
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
LLVM_ABI bool isVPOpcode(unsigned Opcode)
Whether this is a vector-predicated Opcode.
bool matchUnaryPredicate(SDValue Op, const APInt &DemandedElts, std::function< bool(ConstantSDNode *)> Match, bool AllowUndefs=false, bool AllowTruncation=false)
Hook for matching ConstantSDNode predicate.
bool isNormalLoad(const SDNode *N)
Returns true if the specified node is a non-extending and unindexed load.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
Definition STLExtras.h:846
LLVM_ABI SDValue peekThroughExtractSubvectors(SDValue V)
Return the non-extracted vector source operand of V if it exists.
SDValue peekThroughFreeze(SDValue V)
Return the non-frozen source operand of V if it exists.
LLVM_ABI bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
LLVM_ABI bool isAllOnesOrAllOnesSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndefs=false)
Return true if the value is a constant -1 integer or a splatted vector of a constant -1 integer (with...
Definition Utils.cpp:1717
APInt operator&(APInt a, const APInt &b)
Definition APInt.h:2149
LLVM_ABI SDValue getBitwiseNotOperand(SDValue V, SDValue Mask, bool AllowUndefs)
If V is a bitwise not, returns the inverted operand.
LLVM_ABI SDValue peekThroughBitcasts(SDValue V)
Return the non-bitcasted source operand of V if it exists.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
bool isIntOrFPConstant(SDValue V)
Return true if V is either a integer or FP constant.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ABI bool isOneOrOneSplatFP(SDValue V, bool AllowUndefs=false)
Return true if the value is a constant floating-point value, or a splatted vector of a constant float...
LLVM_ABI bool isNullOrNullSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndefs=false)
Return true if the value is a constant 0 integer or a splatted vector of a constant 0 integer (with n...
Definition Utils.cpp:1699
LLVM_ABI bool isMinSignedConstant(SDValue V)
Returns true if V is a constant min signed integer value.
LLVM_ABI ConstantFPSDNode * isConstOrConstSplatFP(SDValue N, bool AllowUndefs=false)
Returns the SDNode if it is a constant splat BuildVector or constant float.
auto map_range(ContainerTy &&C, FuncTy F)
Return a range that applies F to the elements of C.
Definition STLExtras.h:366
LLVM_ABI bool isBitwiseNot(SDValue V, bool AllowUndefs=false)
Returns true if V is a bitwise not operation.
LLVM_ABI SDValue peekThroughInsertVectorElt(SDValue V, const APInt &DemandedElts)
Recursively peek through INSERT_VECTOR_ELT nodes, returning the source vector operand of V,...
LLVM_ABI void checkForCycles(const SelectionDAG *DAG, bool force=false)
LLVM_ABI SDValue peekThroughTruncates(SDValue V)
Return the non-truncated source operand of V if it exists.
AlignedCharArrayUnion< AtomicSDNode, TargetIndexSDNode, BlockAddressSDNode, GlobalAddressSDNode, PseudoProbeSDNode > LargestSDNode
A representation of the largest SDNode, for use in sizeof().
GlobalAddressSDNode MostAlignedSDNode
The SDNode class with the greatest alignment requirement.
bool hasSingleElement(ContainerTy &&C)
Returns true if the given container only contains a single element.
Definition STLExtras.h:300
LLVM_ABI SDValue peekThroughOneUseBitcasts(SDValue V)
Return the non-bitcasted and one-use source operand of V if it exists.
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition STLExtras.h:552
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
LLVM_ABI bool isOneOrOneSplat(SDValue V, bool AllowUndefs=false)
Return true if the value is a constant 1 integer or a splatted vector of a constant 1 integer (with n...
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Other
Any other memory.
Definition ModRef.h:68
constexpr NextUseDistance max(NextUseDistance A, NextUseDistance B)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
LLVM_ABI bool isNullConstantOrUndef(SDValue V)
Returns true if V is a constant integer zero or an UNDEF node.
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI ConstantSDNode * isConstOrConstSplat(SDValue N, bool AllowUndefs=false, bool AllowTruncation=false)
Returns the SDNode if it is a constant splat BuildVector or constant int.
constexpr unsigned BitWidth
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1933
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI bool isZeroOrZeroSplat(SDValue N, bool AllowUndefs=false)
Return true if the value is a constant 0 integer or a splatted vector of a constant 0 integer (with n...
LLVM_ABI bool isOneConstant(SDValue V)
Returns true if V is a constant integer one.
LLVM_ABI bool isNullFPConstant(SDValue V)
Returns true if V is an FP constant with a value of positive zero.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
Definition InstrProf.h:147
bool all_equal(std::initializer_list< T > Values)
Returns true if all Values in the initializer lists are equal or the list.
Definition STLExtras.h:2182
LLVM_ABI bool isZeroOrZeroSplatFP(SDValue N, bool AllowUndefs=false)
Return true if the value is a constant (+/-)0.0 floating-point value or a splatted vector thereof (wi...
APInt operator|(APInt a, const APInt &b)
Definition APInt.h:2169
SDValue peekThroughOneUseFreeze(SDValue V)
Return the non-frozen source operand of V if it exists and V has a single use.
LLVM_ABI bool isAllOnesConstant(SDValue V)
Returns true if V is an integer constant with all bits set.
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
#define N
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition Metadata.h:775
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
A suitably aligned and sized character array member which can hold elements of any type.
Definition AlignOf.h:22
static unsigned getHashValue(const SDValue &Val)
static bool isEqual(const SDValue &LHS, const SDValue &RHS)
An information struct used to provide DenseMap with the various necessary components for a given valu...
Extended Value Type.
Definition ValueTypes.h:35
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition ValueTypes.h:411
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition ValueTypes.h:354
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
Definition ValueTypes.h:419
bool isFixedLengthVector() const
Definition ValueTypes.h:214
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Definition ValueTypes.h:361
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition ValueTypes.h:374
static ChildIteratorType child_begin(NodeRef N)
static ChildIteratorType child_end(NodeRef N)
static NodeRef getEntryNode(SDNode *N)
LLVM IR metadata carried by a MachineMemOperand.
This class contains a discriminated union of information about pointers in memory operands,...
LLVM_ABI unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:111
These are IR-level optimization flags that may be propagated to SDNodes.
void setNoConvergent(bool b)
void copyFMF(const FPMathOperator &FPMO)
Propagate the fast-math-flags from an IR FPMathOperator.
void setNoFPExcept(bool b)
void setAllowContract(bool b)
void setNoSignedZeros(bool b)
bool hasNoFPExcept() const
bool operator==(const SDNodeFlags &Other) const
void operator&=(const SDNodeFlags &OtherFlags)
void operator|=(const SDNodeFlags &OtherFlags)
bool hasNoUnsignedWrap() const
void setAllowReassociation(bool b)
void setUnpredictable(bool b)
void setAllowReciprocal(bool b)
bool hasAllowContract() const
bool hasNoSignedZeros() const
bool hasApproximateFuncs() const
bool hasUnpredictable() const
void setApproximateFuncs(bool b)
bool hasNoSignedWrap() const
SDNodeFlags(unsigned Flags=SDNodeFlags::None)
Default constructor turns off all optimization flags.
bool hasAllowReciprocal() const
bool hasNoConvergent() const
bool hasAllowReassociation() const
void setNoUnsignedWrap(bool b)
void setNoSignedWrap(bool b)
Iterator for directly iterating over the operand SDValue's.
const SDValue & operator*() const
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
unsigned int NumVTs
static SimpleType getSimplifiedValue(SDUse &Val)
static SimpleType getSimplifiedValue(SDValue &Val)
static SimpleType getSimplifiedValue(const SDValue &Val)
Define a template that can be specialized by smart pointers to reflect the fact that they are automat...
Definition Casting.h:34