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