LLVM 22.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;
64class MachineBasicBlock;
65class MachineConstantPoolValue;
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
207 }
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
422 // NOTE: Please update LargestValue in LLVM_DECLARE_ENUM_AS_BITMASK below
423 // the class definition when adding new flags.
424
429 };
430
431 /// Default constructor turns off all optimization flags.
432 SDNodeFlags(unsigned Flags = SDNodeFlags::None) : Flags(Flags) {}
433
434 /// Propagate the fast-math-flags from an IR FPMathOperator.
435 void copyFMF(const FPMathOperator &FPMO) {
436 setNoNaNs(FPMO.hasNoNaNs());
437 setNoInfs(FPMO.hasNoInfs());
443 }
444
445 // These are mutators for each flag.
446 void setNoUnsignedWrap(bool b) { setFlag<NoUnsignedWrap>(b); }
447 void setNoSignedWrap(bool b) { setFlag<NoSignedWrap>(b); }
448 void setExact(bool b) { setFlag<Exact>(b); }
449 void setDisjoint(bool b) { setFlag<Disjoint>(b); }
450 void setSameSign(bool b) { setFlag<SameSign>(b); }
451 void setNonNeg(bool b) { setFlag<NonNeg>(b); }
452 void setNoNaNs(bool b) { setFlag<NoNaNs>(b); }
453 void setNoInfs(bool b) { setFlag<NoInfs>(b); }
454 void setNoSignedZeros(bool b) { setFlag<NoSignedZeros>(b); }
455 void setAllowReciprocal(bool b) { setFlag<AllowReciprocal>(b); }
456 void setAllowContract(bool b) { setFlag<AllowContract>(b); }
457 void setApproximateFuncs(bool b) { setFlag<ApproximateFuncs>(b); }
458 void setAllowReassociation(bool b) { setFlag<AllowReassociation>(b); }
459 void setNoFPExcept(bool b) { setFlag<NoFPExcept>(b); }
460 void setUnpredictable(bool b) { setFlag<Unpredictable>(b); }
461
462 // These are accessors for each flag.
463 bool hasNoUnsignedWrap() const { return Flags & NoUnsignedWrap; }
464 bool hasNoSignedWrap() const { return Flags & NoSignedWrap; }
465 bool hasExact() const { return Flags & Exact; }
466 bool hasDisjoint() const { return Flags & Disjoint; }
467 bool hasSameSign() const { return Flags & SameSign; }
468 bool hasNonNeg() const { return Flags & NonNeg; }
469 bool hasNoNaNs() const { return Flags & NoNaNs; }
470 bool hasNoInfs() const { return Flags & NoInfs; }
471 bool hasNoSignedZeros() const { return Flags & NoSignedZeros; }
472 bool hasAllowReciprocal() const { return Flags & AllowReciprocal; }
473 bool hasAllowContract() const { return Flags & AllowContract; }
474 bool hasApproximateFuncs() const { return Flags & ApproximateFuncs; }
475 bool hasAllowReassociation() const { return Flags & AllowReassociation; }
476 bool hasNoFPExcept() const { return Flags & NoFPExcept; }
477 bool hasUnpredictable() const { return Flags & Unpredictable; }
478
479 bool operator==(const SDNodeFlags &Other) const {
480 return Flags == Other.Flags;
481 }
482 void operator&=(const SDNodeFlags &OtherFlags) { Flags &= OtherFlags.Flags; }
483 void operator|=(const SDNodeFlags &OtherFlags) { Flags |= OtherFlags.Flags; }
484};
485
488
490 LHS |= RHS;
491 return LHS;
492}
493
495 LHS &= RHS;
496 return LHS;
497}
498
499/// Represents one node in the SelectionDAG.
500///
501class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
502private:
503 /// The operation that this node performs.
504 int32_t NodeType;
505
506 SDNodeFlags Flags;
507
508protected:
509 // We define a set of mini-helper classes to help us interpret the bits in our
510 // SubclassData. These are designed to fit within a uint16_t so they pack
511 // with SDNodeFlags.
512
513#if defined(_AIX) && (!defined(__GNUC__) || defined(__clang__))
514// Except for GCC; by default, AIX compilers store bit-fields in 4-byte words
515// and give the `pack` pragma push semantics.
516#define BEGIN_TWO_BYTE_PACK() _Pragma("pack(2)")
517#define END_TWO_BYTE_PACK() _Pragma("pack(pop)")
518#else
519#define BEGIN_TWO_BYTE_PACK()
520#define END_TWO_BYTE_PACK()
521#endif
522
525 friend class SDNode;
526 friend class MemIntrinsicSDNode;
527 friend class MemSDNode;
528 friend class SelectionDAG;
529
530 uint16_t HasDebugValue : 1;
531 uint16_t IsMemIntrinsic : 1;
532 uint16_t IsDivergent : 1;
533 };
534 enum { NumSDNodeBits = 3 };
535
537 friend class ConstantSDNode;
538
540
541 uint16_t IsOpaque : 1;
542 };
543
545 friend class MemSDNode;
546 friend class MemIntrinsicSDNode;
547 friend class AtomicSDNode;
548
550
551 uint16_t IsVolatile : 1;
552 uint16_t IsNonTemporal : 1;
553 uint16_t IsDereferenceable : 1;
554 uint16_t IsInvariant : 1;
555 };
557
559 friend class LSBaseSDNode;
565
567
568 // This storage is shared between disparate class hierarchies to hold an
569 // enumeration specific to the class hierarchy in use.
570 // LSBaseSDNode => enum ISD::MemIndexedMode
571 // VPLoadStoreBaseSDNode => enum ISD::MemIndexedMode
572 // MaskedLoadStoreBaseSDNode => enum ISD::MemIndexedMode
573 // VPGatherScatterSDNode => enum ISD::MemIndexType
574 // MaskedGatherScatterSDNode => enum ISD::MemIndexType
575 // MaskedHistogramSDNode => enum ISD::MemIndexType
577 };
579
581 friend class LoadSDNode;
582 friend class AtomicSDNode;
583 friend class VPLoadSDNode;
585 friend class MaskedLoadSDNode;
586 friend class MaskedGatherSDNode;
587 friend class VPGatherSDNode;
589
591
592 uint16_t ExtTy : 2; // enum ISD::LoadExtType
593 uint16_t IsExpanding : 1;
594 };
595
597 friend class StoreSDNode;
598 friend class VPStoreSDNode;
600 friend class MaskedStoreSDNode;
602 friend class VPScatterSDNode;
603
605
606 uint16_t IsTruncating : 1;
607 uint16_t IsCompressing : 1;
608 };
609
610 union {
611 char RawSDNodeBits[sizeof(uint16_t)];
618 };
620#undef BEGIN_TWO_BYTE_PACK
621#undef END_TWO_BYTE_PACK
622
623 // RawSDNodeBits must cover the entirety of the union. This means that all of
624 // the union's members must have size <= RawSDNodeBits. We write the RHS as
625 // "2" instead of sizeof(RawSDNodeBits) because MSVC can't handle the latter.
626 static_assert(sizeof(SDNodeBitfields) <= 2, "field too wide");
627 static_assert(sizeof(ConstantSDNodeBitfields) <= 2, "field too wide");
628 static_assert(sizeof(MemSDNodeBitfields) <= 2, "field too wide");
629 static_assert(sizeof(LSBaseSDNodeBitfields) <= 2, "field too wide");
630 static_assert(sizeof(LoadSDNodeBitfields) <= 2, "field too wide");
631 static_assert(sizeof(StoreSDNodeBitfields) <= 2, "field too wide");
632
633public:
634 /// Unique and persistent id per SDNode in the DAG. Used for debug printing.
635 /// We do not place that under `#if LLVM_ENABLE_ABI_BREAKING_CHECKS`
636 /// intentionally because it adds unneeded complexity without noticeable
637 /// benefits (see discussion with @thakis in D120714). Currently, there are
638 /// two padding bytes after this field.
640
641private:
642 friend class SelectionDAG;
643 // TODO: unfriend HandleSDNode once we fix its operand handling.
644 friend class HandleSDNode;
645
646 /// Unique id per SDNode in the DAG.
647 int NodeId = -1;
648
649 /// The values that are used by this operation.
650 SDUse *OperandList = nullptr;
651
652 /// The types of the values this node defines. SDNode's may
653 /// define multiple values simultaneously.
654 const EVT *ValueList;
655
656 /// List of uses for this SDNode.
657 SDUse *UseList = nullptr;
658
659 /// The number of entries in the Operand/Value list.
660 unsigned short NumOperands = 0;
661 unsigned short NumValues;
662
663 // The ordering of the SDNodes. It roughly corresponds to the ordering of the
664 // original LLVM instructions.
665 // This is used for turning off scheduling, because we'll forgo
666 // the normal scheduling algorithms and output the instructions according to
667 // this ordering.
668 unsigned IROrder;
669
670 /// Source line information.
671 DebugLoc debugLoc;
672
673 /// Return a pointer to the specified value type.
674 LLVM_ABI static const EVT *getValueTypeList(MVT VT);
675
676 /// Index in worklist of DAGCombiner, or negative if the node is not in the
677 /// worklist. -1 = not in worklist; -2 = not in worklist, but has already been
678 /// combined at least once.
679 int CombinerWorklistIndex = -1;
680
681 uint32_t CFIType = 0;
682
683public:
684 //===--------------------------------------------------------------------===//
685 // Accessors
686 //
687
688 /// Return the SelectionDAG opcode value for this node. For
689 /// pre-isel nodes (those for which isMachineOpcode returns false), these
690 /// are the opcode values in the ISD and <target>ISD namespaces. For
691 /// post-isel opcodes, see getMachineOpcode.
692 unsigned getOpcode() const { return (unsigned)NodeType; }
693
694 /// Test if this node has a target-specific opcode (in the
695 /// <target>ISD namespace).
696 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
697
698 /// Returns true if the node type is UNDEF or POISON.
699 bool isUndef() const {
700 return NodeType == ISD::UNDEF || NodeType == ISD::POISON;
701 }
702
703 /// Returns true if the node type is ADD or PTRADD.
704 bool isAnyAdd() const {
705 return NodeType == ISD::ADD || NodeType == ISD::PTRADD;
706 }
707
708 /// Test if this node is a memory intrinsic (with valid pointer information).
709 bool isMemIntrinsic() const { return SDNodeBits.IsMemIntrinsic; }
710
711 /// Test if this node is a strict floating point pseudo-op.
713 switch (NodeType) {
714 default:
715 return false;
720#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
721 case ISD::STRICT_##DAGN:
722#include "llvm/IR/ConstrainedOps.def"
723 return true;
724 }
725 }
726
727 /// Test if this node is an assert operation.
728 bool isAssert() const {
729 switch (NodeType) {
730 default:
731 return false;
732 case ISD::AssertAlign:
734 case ISD::AssertSext:
735 case ISD::AssertZext:
736 return true;
737 }
738 }
739
740 /// Test if this node is a vector predication operation.
741 bool isVPOpcode() const { return ISD::isVPOpcode(getOpcode()); }
742
743 /// Test if this node has a post-isel opcode, directly
744 /// corresponding to a MachineInstr opcode.
745 bool isMachineOpcode() const { return NodeType < 0; }
746
747 /// This may only be called if isMachineOpcode returns
748 /// true. It returns the MachineInstr opcode value that the node's opcode
749 /// corresponds to.
750 unsigned getMachineOpcode() const {
751 assert(isMachineOpcode() && "Not a MachineInstr opcode!");
752 return ~NodeType;
753 }
754
755 bool getHasDebugValue() const { return SDNodeBits.HasDebugValue; }
756 void setHasDebugValue(bool b) { SDNodeBits.HasDebugValue = b; }
757
758 bool isDivergent() const { return SDNodeBits.IsDivergent; }
759
760 /// Return true if there are no uses of this node.
761 bool use_empty() const { return UseList == nullptr; }
762
763 /// Return true if there is exactly one use of this node.
764 bool hasOneUse() const { return hasSingleElement(uses()); }
765
766 /// Return the number of uses of this node. This method takes
767 /// time proportional to the number of uses.
768 size_t use_size() const { return std::distance(use_begin(), use_end()); }
769
770 /// Return the unique node id.
771 int getNodeId() const { return NodeId; }
772
773 /// Set unique node id.
774 void setNodeId(int Id) { NodeId = Id; }
775
776 /// Get worklist index for DAGCombiner
777 int getCombinerWorklistIndex() const { return CombinerWorklistIndex; }
778
779 /// Set worklist index for DAGCombiner
780 void setCombinerWorklistIndex(int Index) { CombinerWorklistIndex = Index; }
781
782 /// Return the node ordering.
783 unsigned getIROrder() const { return IROrder; }
784
785 /// Set the node ordering.
786 void setIROrder(unsigned Order) { IROrder = Order; }
787
788 /// Return the source location info.
789 const DebugLoc &getDebugLoc() const { return debugLoc; }
790
791 /// Set source location info. Try to avoid this, putting
792 /// it in the constructor is preferable.
793 void setDebugLoc(DebugLoc dl) { debugLoc = std::move(dl); }
794
795 /// This class provides iterator support for SDUse
796 /// operands that use a specific SDNode.
798 friend class SDNode;
799
800 SDUse *Op = nullptr;
801
802 explicit use_iterator(SDUse *op) : Op(op) {}
803
804 public:
805 using iterator_category = std::forward_iterator_tag;
807 using difference_type = std::ptrdiff_t;
810
811 use_iterator() = default;
812 use_iterator(const use_iterator &I) = default;
814
815 bool operator==(const use_iterator &x) const { return Op == x.Op; }
816 bool operator!=(const use_iterator &x) const {
817 return !operator==(x);
818 }
819
820 // Iterator traversal: forward iteration only.
821 use_iterator &operator++() { // Preincrement
822 assert(Op && "Cannot increment end iterator!");
823 Op = Op->getNext();
824 return *this;
825 }
826
827 use_iterator operator++(int) { // Postincrement
828 use_iterator tmp = *this; ++*this; return tmp;
829 }
830
831 /// Retrieve a pointer to the current user node.
832 SDUse &operator*() const {
833 assert(Op && "Cannot dereference end iterator!");
834 return *Op;
835 }
836
837 SDUse *operator->() const { return &operator*(); }
838 };
839
841 friend class SDNode;
842 use_iterator UI;
843
844 explicit user_iterator(SDUse *op) : UI(op) {};
845
846 public:
847 using iterator_category = std::forward_iterator_tag;
849 using difference_type = std::ptrdiff_t;
852
853 user_iterator() = default;
854
855 bool operator==(const user_iterator &x) const { return UI == x.UI; }
856 bool operator!=(const user_iterator &x) const { return !operator==(x); }
857
858 user_iterator &operator++() { // Preincrement
859 ++UI;
860 return *this;
861 }
862
863 user_iterator operator++(int) { // Postincrement
864 auto tmp = *this;
865 ++*this;
866 return tmp;
867 }
868
869 // Retrieve a pointer to the current User.
870 SDNode *operator*() const { return UI->getUser(); }
871
872 SDNode *operator->() const { return operator*(); }
873
874 SDUse &getUse() const { return *UI; }
875 };
876
877 /// Provide iteration support to walk over all uses of an SDNode.
879 return use_iterator(UseList);
880 }
881
882 static use_iterator use_end() { return use_iterator(nullptr); }
883
885 return make_range(use_begin(), use_end());
886 }
888 return make_range(use_begin(), use_end());
889 }
890
891 /// Provide iteration support to walk over all users of an SDNode.
892 user_iterator user_begin() const { return user_iterator(UseList); }
893
894 static user_iterator user_end() { return user_iterator(nullptr); }
895
897 return make_range(user_begin(), user_end());
898 }
900 return make_range(user_begin(), user_end());
901 }
902
903 /// Return true if there are exactly NUSES uses of the indicated value.
904 /// This method ignores uses of other values defined by this operation.
905 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const {
906 assert(Value < getNumValues() && "Bad value!");
907
908 // TODO: Only iterate over uses of a given value of the node
909 for (SDUse &U : uses()) {
910 if (U.getResNo() == Value) {
911 if (NUses == 0)
912 return false;
913 --NUses;
914 }
915 }
916
917 // Found exactly the right number of uses?
918 return NUses == 0;
919 }
920
921 /// Return true if there are any use of the indicated value.
922 /// This method ignores uses of other values defined by this operation.
923 LLVM_ABI bool hasAnyUseOfValue(unsigned Value) const;
924
925 /// Return true if this node is the only use of N.
926 LLVM_ABI bool isOnlyUserOf(const SDNode *N) const;
927
928 /// Return true if this node is an operand of N.
929 LLVM_ABI bool isOperandOf(const SDNode *N) const;
930
931 /// Return true if this node is a predecessor of N.
932 /// NOTE: Implemented on top of hasPredecessor and every bit as
933 /// expensive. Use carefully.
934 bool isPredecessorOf(const SDNode *N) const {
935 return N->hasPredecessor(this);
936 }
937
938 /// Return true if N is a predecessor of this node.
939 /// N is either an operand of this node, or can be reached by recursively
940 /// traversing up the operands.
941 /// NOTE: This is an expensive method. Use it carefully.
942 LLVM_ABI bool hasPredecessor(const SDNode *N) const;
943
944 /// Returns true if N is a predecessor of any node in Worklist. This
945 /// helper keeps Visited and Worklist sets externally to allow unions
946 /// searches to be performed in parallel, caching of results across
947 /// queries and incremental addition to Worklist. Stops early if N is
948 /// found but will resume. Remember to clear Visited and Worklists
949 /// if DAG changes. MaxSteps gives a maximum number of nodes to visit before
950 /// giving up. The TopologicalPrune flag signals that positive NodeIds are
951 /// topologically ordered (Operands have strictly smaller node id) and search
952 /// can be pruned leveraging this.
953 static bool hasPredecessorHelper(const SDNode *N,
956 unsigned int MaxSteps = 0,
957 bool TopologicalPrune = false) {
958 if (Visited.count(N))
959 return true;
960
961 SmallVector<const SDNode *, 8> DeferredNodes;
962 // Node Id's are assigned in three places: As a topological
963 // ordering (> 0), during legalization (results in values set to
964 // 0), new nodes (set to -1). If N has a topolgical id then we
965 // know that all nodes with ids smaller than it cannot be
966 // successors and we need not check them. Filter out all node
967 // that can't be matches. We add them to the worklist before exit
968 // in case of multiple calls. Note that during selection the topological id
969 // may be violated if a node's predecessor is selected before it. We mark
970 // this at selection negating the id of unselected successors and
971 // restricting topological pruning to positive ids.
972
973 int NId = N->getNodeId();
974 // If we Invalidated the Id, reconstruct original NId.
975 if (NId < -1)
976 NId = -(NId + 1);
977
978 bool Found = false;
979 while (!Worklist.empty()) {
980 const SDNode *M = Worklist.pop_back_val();
981 int MId = M->getNodeId();
982 if (TopologicalPrune && M->getOpcode() != ISD::TokenFactor && (NId > 0) &&
983 (MId > 0) && (MId < NId)) {
984 DeferredNodes.push_back(M);
985 continue;
986 }
987 for (const SDValue &OpV : M->op_values()) {
988 SDNode *Op = OpV.getNode();
989 if (Visited.insert(Op).second)
990 Worklist.push_back(Op);
991 if (Op == N)
992 Found = true;
993 }
994 if (Found)
995 break;
996 if (MaxSteps != 0 && Visited.size() >= MaxSteps)
997 break;
998 }
999 // Push deferred nodes back on worklist.
1000 Worklist.append(DeferredNodes.begin(), DeferredNodes.end());
1001 // If we bailed early, conservatively return found.
1002 if (MaxSteps != 0 && Visited.size() >= MaxSteps)
1003 return true;
1004 return Found;
1005 }
1006
1007 /// Return true if all the users of N are contained in Nodes.
1008 /// NOTE: Requires at least one match, but doesn't require them all.
1010 const SDNode *N);
1011
1012 /// Return the number of values used by this operation.
1013 unsigned getNumOperands() const { return NumOperands; }
1014
1015 /// Return the maximum number of operands that a SDNode can hold.
1016 static constexpr size_t getMaxNumOperands() {
1017 return std::numeric_limits<decltype(SDNode::NumOperands)>::max();
1018 }
1019
1020 /// Helper method returns the integer value of a ConstantSDNode operand.
1021 inline uint64_t getConstantOperandVal(unsigned Num) const;
1022
1023 /// Helper method returns the zero-extended integer value of a ConstantSDNode.
1024 inline uint64_t getAsZExtVal() const;
1025
1026 /// Helper method returns the APInt of a ConstantSDNode operand.
1027 inline const APInt &getConstantOperandAPInt(unsigned Num) const;
1028
1029 /// Helper method returns the APInt value of a ConstantSDNode.
1030 inline const APInt &getAsAPIntVal() const;
1031
1032 inline std::optional<APInt> bitcastToAPInt() const;
1033
1034 const SDValue &getOperand(unsigned Num) const {
1035 assert(Num < NumOperands && "Invalid child # of SDNode!");
1036 return OperandList[Num];
1037 }
1038
1040
1041 op_iterator op_begin() const { return OperandList; }
1042 op_iterator op_end() const { return OperandList+NumOperands; }
1043 ArrayRef<SDUse> ops() const { return ArrayRef(op_begin(), op_end()); }
1044
1045 /// Iterator for directly iterating over the operand SDValue's.
1047 : iterator_adaptor_base<value_op_iterator, op_iterator,
1048 std::random_access_iterator_tag, SDValue,
1049 ptrdiff_t, value_op_iterator *,
1050 value_op_iterator *> {
1051 explicit value_op_iterator(SDUse *U = nullptr)
1052 : iterator_adaptor_base(U) {}
1053
1054 const SDValue &operator*() const { return I->get(); }
1055 };
1056
1060 }
1061
1063 SDVTList X = { ValueList, NumValues };
1064 return X;
1065 }
1066
1067 /// If this node has a glue operand, return the node
1068 /// to which the glue operand points. Otherwise return NULL.
1070 if (getNumOperands() != 0 &&
1071 getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
1072 return getOperand(getNumOperands()-1).getNode();
1073 return nullptr;
1074 }
1075
1076 /// If this node has a glue value with a user, return
1077 /// the user (there is at most one). Otherwise return NULL.
1079 for (SDUse &U : uses())
1080 if (U.getValueType() == MVT::Glue)
1081 return U.getUser();
1082 return nullptr;
1083 }
1084
1085 SDNodeFlags getFlags() const { return Flags; }
1086 void setFlags(SDNodeFlags NewFlags) { Flags = NewFlags; }
1087 void dropFlags(unsigned Mask) { Flags &= ~Mask; }
1088
1089 /// Clear any flags in this node that aren't also set in Flags.
1090 /// If Flags is not in a defined state then this has no effect.
1091 LLVM_ABI void intersectFlagsWith(const SDNodeFlags Flags);
1092
1094 return Flags.Flags & SDNodeFlags::PoisonGeneratingFlags;
1095 }
1096
1097 void setCFIType(uint32_t Type) { CFIType = Type; }
1098 uint32_t getCFIType() const { return CFIType; }
1099
1100 /// Return the number of values defined/returned by this operator.
1101 unsigned getNumValues() const { return NumValues; }
1102
1103 /// Return the type of a specified result.
1104 EVT getValueType(unsigned ResNo) const {
1105 assert(ResNo < NumValues && "Illegal result number!");
1106 return ValueList[ResNo];
1107 }
1108
1109 /// Return the type of a specified result as a simple type.
1110 MVT getSimpleValueType(unsigned ResNo) const {
1111 return getValueType(ResNo).getSimpleVT();
1112 }
1113
1114 /// Returns MVT::getSizeInBits(getValueType(ResNo)).
1115 ///
1116 /// If the value type is a scalable vector type, the scalable property will
1117 /// be set and the runtime size will be a positive integer multiple of the
1118 /// base size.
1119 TypeSize getValueSizeInBits(unsigned ResNo) const {
1120 return getValueType(ResNo).getSizeInBits();
1121 }
1122
1123 using value_iterator = const EVT *;
1124
1125 value_iterator value_begin() const { return ValueList; }
1126 value_iterator value_end() const { return ValueList+NumValues; }
1129 }
1130
1131 /// Return the opcode of this operation for printing.
1132 LLVM_ABI std::string getOperationName(const SelectionDAG *G = nullptr) const;
1133 LLVM_ABI static const char *getIndexedModeName(ISD::MemIndexedMode AM);
1134 LLVM_ABI void print_types(raw_ostream &OS, const SelectionDAG *G) const;
1135 LLVM_ABI void print_details(raw_ostream &OS, const SelectionDAG *G) const;
1136 LLVM_ABI void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
1137 LLVM_ABI void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
1138
1139 /// Print a SelectionDAG node and all children down to
1140 /// the leaves. The given SelectionDAG allows target-specific nodes
1141 /// to be printed in human-readable form. Unlike printr, this will
1142 /// print the whole DAG, including children that appear multiple
1143 /// times.
1144 ///
1146 const SelectionDAG *G = nullptr) const;
1147
1148 /// Print a SelectionDAG node and children up to
1149 /// depth "depth." The given SelectionDAG allows target-specific
1150 /// nodes to be printed in human-readable form. Unlike printr, this
1151 /// will print children that appear multiple times wherever they are
1152 /// used.
1153 ///
1154 LLVM_ABI void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
1155 unsigned depth = 100) const;
1156
1157 /// Dump this node, for debugging.
1158 LLVM_ABI void dump() const;
1159
1160 /// Dump (recursively) this node and its use-def subgraph.
1161 LLVM_ABI void dumpr() const;
1162
1163 /// Dump this node, for debugging.
1164 /// The given SelectionDAG allows target-specific nodes to be printed
1165 /// in human-readable form.
1166 LLVM_ABI void dump(const SelectionDAG *G) const;
1167
1168 /// Dump (recursively) this node and its use-def subgraph.
1169 /// The given SelectionDAG allows target-specific nodes to be printed
1170 /// in human-readable form.
1171 LLVM_ABI void dumpr(const SelectionDAG *G) const;
1172
1173 /// printrFull to dbgs(). The given SelectionDAG allows
1174 /// target-specific nodes to be printed in human-readable form.
1175 /// Unlike dumpr, this will print the whole DAG, including children
1176 /// that appear multiple times.
1177 LLVM_ABI void dumprFull(const SelectionDAG *G = nullptr) const;
1178
1179 /// printrWithDepth to dbgs(). The given
1180 /// SelectionDAG allows target-specific nodes to be printed in
1181 /// human-readable form. Unlike dumpr, this will print children
1182 /// that appear multiple times wherever they are used.
1183 ///
1184 LLVM_ABI void dumprWithDepth(const SelectionDAG *G = nullptr,
1185 unsigned depth = 100) const;
1186
1187 /// Gather unique data for the node.
1188 LLVM_ABI void Profile(FoldingSetNodeID &ID) const;
1189
1190 /// This method should only be used by the SDUse class.
1191 void addUse(SDUse &U) { U.addToList(&UseList); }
1192
1193protected:
1195 SDVTList Ret = { getValueTypeList(VT), 1 };
1196 return Ret;
1197 }
1198
1199 /// Create an SDNode.
1200 ///
1201 /// SDNodes are created without any operands, and never own the operand
1202 /// storage. To add operands, see SelectionDAG::createOperands.
1203 SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
1204 : NodeType(Opc), ValueList(VTs.VTs), NumValues(VTs.NumVTs),
1205 IROrder(Order), debugLoc(std::move(dl)) {
1206 memset(&RawSDNodeBits, 0, sizeof(RawSDNodeBits));
1207 assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
1208 assert(NumValues == VTs.NumVTs &&
1209 "NumValues wasn't wide enough for its operands!");
1210 }
1211
1212 /// Release the operands and set this node to have zero operands.
1213 LLVM_ABI void DropOperands();
1214};
1215
1216/// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
1217/// into SDNode creation functions.
1218/// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
1219/// from the original Instruction, and IROrder is the ordinal position of
1220/// the instruction.
1221/// When an SDNode is created after the DAG is being built, both DebugLoc and
1222/// the IROrder are propagated from the original SDNode.
1223/// So SDLoc class provides two constructors besides the default one, one to
1224/// be used by the DAGBuilder, the other to be used by others.
1225class SDLoc {
1226private:
1227 DebugLoc DL;
1228 int IROrder = 0;
1229
1230public:
1231 SDLoc() = default;
1232 SDLoc(const SDNode *N) : DL(N->getDebugLoc()), IROrder(N->getIROrder()) {}
1233 SDLoc(const SDValue V) : SDLoc(V.getNode()) {}
1234 SDLoc(const Instruction *I, int Order) : IROrder(Order) {
1235 assert(Order >= 0 && "bad IROrder");
1236 if (I)
1237 DL = I->getDebugLoc();
1238 }
1239
1240 unsigned getIROrder() const { return IROrder; }
1241 const DebugLoc &getDebugLoc() const { return DL; }
1242};
1243
1244// Define inline functions from the SDValue class.
1245
1246inline SDValue::SDValue(SDNode *node, unsigned resno)
1247 : Node(node), ResNo(resno) {
1248 // Explicitly check for !ResNo to avoid use-after-free, because there are
1249 // callers that use SDValue(N, 0) with a deleted N to indicate successful
1250 // combines.
1251 assert((!Node || !ResNo || ResNo < Node->getNumValues()) &&
1252 "Invalid result number for the given node!");
1253 assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
1254}
1255
1256inline unsigned SDValue::getOpcode() const {
1257 return Node->getOpcode();
1258}
1259
1261 return Node->getValueType(ResNo);
1262}
1263
1264inline unsigned SDValue::getNumOperands() const {
1265 return Node->getNumOperands();
1266}
1267
1268inline const SDValue &SDValue::getOperand(unsigned i) const {
1269 return Node->getOperand(i);
1270}
1271
1273 return Node->getConstantOperandVal(i);
1274}
1275
1276inline const APInt &SDValue::getConstantOperandAPInt(unsigned i) const {
1277 return Node->getConstantOperandAPInt(i);
1278}
1279
1280inline bool SDValue::isTargetOpcode() const {
1281 return Node->isTargetOpcode();
1282}
1283
1284inline bool SDValue::isMachineOpcode() const {
1285 return Node->isMachineOpcode();
1286}
1287
1288inline unsigned SDValue::getMachineOpcode() const {
1289 return Node->getMachineOpcode();
1290}
1291
1292inline bool SDValue::isUndef() const {
1293 return Node->isUndef();
1294}
1295
1296inline bool SDValue::isAnyAdd() const { return Node->isAnyAdd(); }
1297
1298inline bool SDValue::use_empty() const {
1299 return !Node->hasAnyUseOfValue(ResNo);
1300}
1301
1302inline bool SDValue::hasOneUse() const {
1303 return Node->hasNUsesOfValue(1, ResNo);
1304}
1305
1306inline const DebugLoc &SDValue::getDebugLoc() const {
1307 return Node->getDebugLoc();
1308}
1309
1310inline void SDValue::dump() const {
1311 return Node->dump();
1312}
1313
1314inline void SDValue::dump(const SelectionDAG *G) const {
1315 return Node->dump(G);
1316}
1317
1318inline void SDValue::dumpr() const {
1319 return Node->dumpr();
1320}
1321
1322inline void SDValue::dumpr(const SelectionDAG *G) const {
1323 return Node->dumpr(G);
1324}
1325
1326// Define inline functions from the SDUse class.
1327inline unsigned SDUse::getOperandNo() const {
1328 return this - getUser()->op_begin();
1329}
1330
1331inline void SDUse::set(const SDValue &V) {
1332 if (Val.getNode()) removeFromList();
1333 Val = V;
1334 if (V.getNode())
1335 V->addUse(*this);
1336}
1337
1338inline void SDUse::setInitial(const SDValue &V) {
1339 Val = V;
1340 V->addUse(*this);
1341}
1342
1343inline void SDUse::setNode(SDNode *N) {
1344 if (Val.getNode()) removeFromList();
1345 Val.setNode(N);
1346 if (N) N->addUse(*this);
1347}
1348
1349/// This class is used to form a handle around another node that
1350/// is persistent and is updated across invocations of replaceAllUsesWith on its
1351/// operand. This node should be directly created by end-users and not added to
1352/// the AllNodes list.
1353class HandleSDNode : public SDNode {
1354 SDUse Op;
1355
1356public:
1358 : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1359 // HandleSDNodes are never inserted into the DAG, so they won't be
1360 // auto-numbered. Use ID 65535 as a sentinel.
1361 PersistentId = 0xffff;
1362
1363 // Manually set up the operand list. This node type is special in that it's
1364 // always stack allocated and SelectionDAG does not manage its operands.
1365 // TODO: This should either (a) not be in the SDNode hierarchy, or (b) not
1366 // be so special.
1367 Op.setUser(this);
1368 Op.setInitial(X);
1369 NumOperands = 1;
1370 OperandList = &Op;
1371 }
1373
1374 const SDValue &getValue() const { return Op; }
1375};
1376
1378private:
1379 unsigned SrcAddrSpace;
1380 unsigned DestAddrSpace;
1381
1382public:
1383 AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
1384 unsigned SrcAS, unsigned DestAS)
1385 : SDNode(ISD::ADDRSPACECAST, Order, dl, VTs), SrcAddrSpace(SrcAS),
1386 DestAddrSpace(DestAS) {}
1387
1388 unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1389 unsigned getDestAddressSpace() const { return DestAddrSpace; }
1390
1391 static bool classof(const SDNode *N) {
1392 return N->getOpcode() == ISD::ADDRSPACECAST;
1393 }
1394};
1395
1396/// This is an abstract virtual class for memory operations.
1397class MemSDNode : public SDNode {
1398private:
1399 // VT of in-memory value.
1400 EVT MemoryVT;
1401
1402protected:
1403 /// Memory reference information.
1405
1406public:
1407 LLVM_ABI MemSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl,
1408 SDVTList VTs, EVT memvt, MachineMemOperand *MMO);
1409
1410 bool readMem() const { return MMO->isLoad(); }
1411 bool writeMem() const { return MMO->isStore(); }
1412
1413 /// Returns alignment and volatility of the memory access
1414 Align getBaseAlign() const { return MMO->getBaseAlign(); }
1415 Align getAlign() const { return MMO->getAlign(); }
1416
1417 /// Return the SubclassData value, without HasDebugValue. This contains an
1418 /// encoding of the volatile flag, as well as bits used by subclasses. This
1419 /// function should only be used to compute a FoldingSetNodeID value.
1420 /// The HasDebugValue bit is masked out because CSE map needs to match
1421 /// nodes with debug info with nodes without debug info. Same is about
1422 /// isDivergent bit.
1423 unsigned getRawSubclassData() const {
1424 uint16_t Data;
1425 union {
1426 char RawSDNodeBits[sizeof(uint16_t)];
1428 };
1429 memcpy(&RawSDNodeBits, &this->RawSDNodeBits, sizeof(this->RawSDNodeBits));
1430 SDNodeBits.HasDebugValue = 0;
1431 SDNodeBits.IsDivergent = false;
1432 memcpy(&Data, &RawSDNodeBits, sizeof(RawSDNodeBits));
1433 return Data;
1434 }
1435
1436 bool isVolatile() const { return MemSDNodeBits.IsVolatile; }
1437 bool isNonTemporal() const { return MemSDNodeBits.IsNonTemporal; }
1438 bool isDereferenceable() const { return MemSDNodeBits.IsDereferenceable; }
1439 bool isInvariant() const { return MemSDNodeBits.IsInvariant; }
1440
1441 // Returns the offset from the location of the access.
1442 int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1443
1444 /// Returns the AA info that describes the dereference.
1445 AAMDNodes getAAInfo() const { return MMO->getAAInfo(); }
1446
1447 /// Returns the Ranges that describes the dereference.
1448 const MDNode *getRanges() const { return MMO->getRanges(); }
1449
1450 /// Returns the synchronization scope ID for this memory operation.
1452
1453 /// Return the atomic ordering requirements for this memory operation. For
1454 /// cmpxchg atomic operations, return the atomic ordering requirements when
1455 /// store occurs.
1457 return MMO->getSuccessOrdering();
1458 }
1459
1460 /// Return a single atomic ordering that is at least as strong as both the
1461 /// success and failure orderings for an atomic operation. (For operations
1462 /// other than cmpxchg, this is equivalent to getSuccessOrdering().)
1464
1465 /// Return true if the memory operation ordering is Unordered or higher.
1466 bool isAtomic() const { return MMO->isAtomic(); }
1467
1468 /// Returns true if the memory operation doesn't imply any ordering
1469 /// constraints on surrounding memory operations beyond the normal memory
1470 /// aliasing rules.
1471 bool isUnordered() const { return MMO->isUnordered(); }
1472
1473 /// Returns true if the memory operation is neither atomic or volatile.
1474 bool isSimple() const { return !isAtomic() && !isVolatile(); }
1475
1476 /// Return the type of the in-memory value.
1477 EVT getMemoryVT() const { return MemoryVT; }
1478
1479 /// Return a MachineMemOperand object describing the memory
1480 /// reference performed by operation.
1482
1484 return MMO->getPointerInfo();
1485 }
1486
1487 /// Return the address space for the associated pointer
1488 unsigned getAddressSpace() const {
1489 return getPointerInfo().getAddrSpace();
1490 }
1491
1492 /// Update this MemSDNode's MachineMemOperand information
1493 /// to reflect the alignment of NewMMO, if it has a greater alignment.
1494 /// This must only be used when the new alignment applies to all users of
1495 /// this MachineMemOperand.
1497 MMO->refineAlignment(NewMMO);
1498 }
1499
1500 void refineRanges(const MachineMemOperand *NewMMO) {
1501 // If this node has range metadata that is different than NewMMO, clear the
1502 // range metadata.
1503 // FIXME: Union the ranges instead?
1504 if (getRanges() && getRanges() != NewMMO->getRanges())
1505 MMO->clearRanges();
1506 }
1507
1508 const SDValue &getChain() const { return getOperand(0); }
1509
1510 const SDValue &getBasePtr() const {
1511 switch (getOpcode()) {
1512 case ISD::STORE:
1513 case ISD::ATOMIC_STORE:
1514 case ISD::VP_STORE:
1515 case ISD::MSTORE:
1516 case ISD::VP_SCATTER:
1517 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
1518 return getOperand(2);
1519 case ISD::MGATHER:
1520 case ISD::MSCATTER:
1522 return getOperand(3);
1523 default:
1524 return getOperand(1);
1525 }
1526 }
1527
1528 // Methods to support isa and dyn_cast
1529 static bool classof(const SDNode *N) {
1530 // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1531 // with either an intrinsic or a target opcode.
1532 switch (N->getOpcode()) {
1533 case ISD::LOAD:
1534 case ISD::STORE:
1537 case ISD::ATOMIC_SWAP:
1559 case ISD::ATOMIC_LOAD:
1560 case ISD::ATOMIC_STORE:
1561 case ISD::MLOAD:
1562 case ISD::MSTORE:
1563 case ISD::MGATHER:
1564 case ISD::MSCATTER:
1565 case ISD::VP_LOAD:
1566 case ISD::VP_STORE:
1567 case ISD::VP_GATHER:
1568 case ISD::VP_SCATTER:
1569 case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
1570 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
1571 case ISD::GET_FPENV_MEM:
1572 case ISD::SET_FPENV_MEM:
1574 return true;
1575 default:
1576 return N->isMemIntrinsic();
1577 }
1578 }
1579};
1580
1581/// This is an SDNode representing atomic operations.
1582class AtomicSDNode : public MemSDNode {
1583public:
1584 AtomicSDNode(unsigned Order, const DebugLoc &dl, unsigned Opc, SDVTList VTL,
1586 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1588 MMO->isAtomic()) && "then why are we using an AtomicSDNode?");
1590 "Only atomic load uses ExtTy");
1591 LoadSDNodeBits.ExtTy = ETy;
1592 }
1593
1595 assert(getOpcode() == ISD::ATOMIC_LOAD && "Only used for atomic loads.");
1596 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
1597 }
1598
1599 const SDValue &getBasePtr() const {
1600 return getOpcode() == ISD::ATOMIC_STORE ? getOperand(2) : getOperand(1);
1601 }
1602 const SDValue &getVal() const {
1603 return getOpcode() == ISD::ATOMIC_STORE ? getOperand(1) : getOperand(2);
1604 }
1605
1606 /// Returns true if this SDNode represents cmpxchg atomic operation, false
1607 /// otherwise.
1608 bool isCompareAndSwap() const {
1609 unsigned Op = getOpcode();
1610 return Op == ISD::ATOMIC_CMP_SWAP ||
1612 }
1613
1614 /// For cmpxchg atomic operations, return the atomic ordering requirements
1615 /// when store does not occur.
1617 assert(isCompareAndSwap() && "Must be cmpxchg operation");
1618 return MMO->getFailureOrdering();
1619 }
1620
1621 // Methods to support isa and dyn_cast
1622 static bool classof(const SDNode *N) {
1623 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1624 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1625 N->getOpcode() == ISD::ATOMIC_SWAP ||
1626 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1627 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1628 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1629 N->getOpcode() == ISD::ATOMIC_LOAD_CLR ||
1630 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1631 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1632 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1633 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1634 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1635 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1636 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1637 N->getOpcode() == ISD::ATOMIC_LOAD_FADD ||
1638 N->getOpcode() == ISD::ATOMIC_LOAD_FSUB ||
1639 N->getOpcode() == ISD::ATOMIC_LOAD_FMAX ||
1640 N->getOpcode() == ISD::ATOMIC_LOAD_FMIN ||
1641 N->getOpcode() == ISD::ATOMIC_LOAD_FMAXIMUM ||
1642 N->getOpcode() == ISD::ATOMIC_LOAD_FMINIMUM ||
1643 N->getOpcode() == ISD::ATOMIC_LOAD_UINC_WRAP ||
1644 N->getOpcode() == ISD::ATOMIC_LOAD_UDEC_WRAP ||
1645 N->getOpcode() == ISD::ATOMIC_LOAD_USUB_COND ||
1646 N->getOpcode() == ISD::ATOMIC_LOAD_USUB_SAT ||
1647 N->getOpcode() == ISD::ATOMIC_LOAD ||
1648 N->getOpcode() == ISD::ATOMIC_STORE;
1649 }
1650};
1651
1652/// This SDNode is used for target intrinsics that touch memory and need
1653/// an associated MachineMemOperand. Its opcode may be INTRINSIC_VOID,
1654/// INTRINSIC_W_CHAIN, PREFETCH, or a target-specific memory-referencing
1655/// opcode (see `SelectionDAGTargetInfo::isTargetMemoryOpcode`).
1657public:
1658 MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl,
1659 SDVTList VTs, EVT MemoryVT, MachineMemOperand *MMO)
1660 : MemSDNode(Opc, Order, dl, VTs, MemoryVT, MMO) {
1661 SDNodeBits.IsMemIntrinsic = true;
1662 }
1663
1664 // Methods to support isa and dyn_cast
1665 static bool classof(const SDNode *N) {
1666 // We lower some target intrinsics to their target opcode
1667 // early a node with a target opcode can be of this class
1668 return N->isMemIntrinsic();
1669 }
1670};
1671
1672/// This SDNode is used to implement the code generator
1673/// support for the llvm IR shufflevector instruction. It combines elements
1674/// from two input vectors into a new input vector, with the selection and
1675/// ordering of elements determined by an array of integers, referred to as
1676/// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1677/// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1678/// An index of -1 is treated as undef, such that the code generator may put
1679/// any value in the corresponding element of the result.
1681 // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1682 // is freed when the SelectionDAG object is destroyed.
1683 const int *Mask;
1684
1685protected:
1686 friend class SelectionDAG;
1687
1688 ShuffleVectorSDNode(SDVTList VTs, unsigned Order, const DebugLoc &dl,
1689 const int *M)
1690 : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, VTs), Mask(M) {}
1691
1692public:
1694 EVT VT = getValueType(0);
1695 return ArrayRef(Mask, VT.getVectorNumElements());
1696 }
1697
1698 int getMaskElt(unsigned Idx) const {
1699 assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1700 return Mask[Idx];
1701 }
1702
1703 bool isSplat() const { return isSplatMask(getMask()); }
1704
1705 int getSplatIndex() const { return getSplatMaskIndex(getMask()); }
1706
1707 LLVM_ABI static bool isSplatMask(ArrayRef<int> Mask);
1708
1710 assert(isSplatMask(Mask) && "Cannot get splat index for non-splat!");
1711 for (int Elem : Mask)
1712 if (Elem >= 0)
1713 return Elem;
1714
1715 // We can choose any index value here and be correct because all elements
1716 // are undefined. Return 0 for better potential for callers to simplify.
1717 return 0;
1718 }
1719
1720 /// Change values in a shuffle permute mask assuming
1721 /// the two vector operands have swapped position.
1723 unsigned NumElems = Mask.size();
1724 for (unsigned i = 0; i != NumElems; ++i) {
1725 int idx = Mask[i];
1726 if (idx < 0)
1727 continue;
1728 else if (idx < (int)NumElems)
1729 Mask[i] = idx + NumElems;
1730 else
1731 Mask[i] = idx - NumElems;
1732 }
1733 }
1734
1735 static bool classof(const SDNode *N) {
1736 return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1737 }
1738};
1739
1740class ConstantSDNode : public SDNode {
1741 friend class SelectionDAG;
1742
1743 const ConstantInt *Value;
1744
1745 ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val,
1746 SDVTList VTs)
1747 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, 0, DebugLoc(),
1748 VTs),
1749 Value(val) {
1750 assert(!isa<VectorType>(val->getType()) && "Unexpected vector type!");
1751 ConstantSDNodeBits.IsOpaque = isOpaque;
1752 }
1753
1754public:
1755 const ConstantInt *getConstantIntValue() const { return Value; }
1756 const APInt &getAPIntValue() const { return Value->getValue(); }
1757 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1758 int64_t getSExtValue() const { return Value->getSExtValue(); }
1760 return Value->getLimitedValue(Limit);
1761 }
1762 MaybeAlign getMaybeAlignValue() const { return Value->getMaybeAlignValue(); }
1763 Align getAlignValue() const { return Value->getAlignValue(); }
1764
1765 bool isOne() const { return Value->isOne(); }
1766 bool isZero() const { return Value->isZero(); }
1767 bool isAllOnes() const { return Value->isMinusOne(); }
1768 bool isMaxSignedValue() const { return Value->isMaxValue(true); }
1769 bool isMinSignedValue() const { return Value->isMinValue(true); }
1770
1771 bool isOpaque() const { return ConstantSDNodeBits.IsOpaque; }
1772
1773 static bool classof(const SDNode *N) {
1774 return N->getOpcode() == ISD::Constant ||
1775 N->getOpcode() == ISD::TargetConstant;
1776 }
1777};
1778
1780 return cast<ConstantSDNode>(getOperand(Num))->getZExtValue();
1781}
1782
1784 return cast<ConstantSDNode>(this)->getZExtValue();
1785}
1786
1787const APInt &SDNode::getConstantOperandAPInt(unsigned Num) const {
1788 return cast<ConstantSDNode>(getOperand(Num))->getAPIntValue();
1789}
1790
1792 return cast<ConstantSDNode>(this)->getAPIntValue();
1793}
1794
1795class ConstantFPSDNode : public SDNode {
1796 friend class SelectionDAG;
1797
1798 const ConstantFP *Value;
1799
1800 ConstantFPSDNode(bool isTarget, const ConstantFP *val, SDVTList VTs)
1801 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 0,
1802 DebugLoc(), VTs),
1803 Value(val) {
1804 assert(!isa<VectorType>(val->getType()) && "Unexpected vector type!");
1805 }
1806
1807public:
1808 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1809 const ConstantFP *getConstantFPValue() const { return Value; }
1810
1811 /// Return true if the value is positive or negative zero.
1812 bool isZero() const { return Value->isZero(); }
1813
1814 /// Return true if the value is a NaN.
1815 bool isNaN() const { return Value->isNaN(); }
1816
1817 /// Return true if the value is an infinity
1818 bool isInfinity() const { return Value->isInfinity(); }
1819
1820 /// Return true if the value is negative.
1821 bool isNegative() const { return Value->isNegative(); }
1822
1823 /// We don't rely on operator== working on double values, as
1824 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1825 /// As such, this method can be used to do an exact bit-for-bit comparison of
1826 /// two floating point values.
1827
1828 /// We leave the version with the double argument here because it's just so
1829 /// convenient to write "2.0" and the like. Without this function we'd
1830 /// have to duplicate its logic everywhere it's called.
1831 bool isExactlyValue(double V) const {
1832 return Value->getValueAPF().isExactlyValue(V);
1833 }
1834 LLVM_ABI bool isExactlyValue(const APFloat &V) const;
1835
1836 LLVM_ABI static bool isValueValidForType(EVT VT, const APFloat &Val);
1837
1838 static bool classof(const SDNode *N) {
1839 return N->getOpcode() == ISD::ConstantFP ||
1840 N->getOpcode() == ISD::TargetConstantFP;
1841 }
1842};
1843
1844std::optional<APInt> SDNode::bitcastToAPInt() const {
1845 if (auto *CN = dyn_cast<ConstantSDNode>(this))
1846 return CN->getAPIntValue();
1847 if (auto *CFPN = dyn_cast<ConstantFPSDNode>(this))
1848 return CFPN->getValueAPF().bitcastToAPInt();
1849 return std::nullopt;
1850}
1851
1852/// Returns true if \p V is a constant integer zero.
1854
1855/// Returns true if \p V is a constant integer zero or an UNDEF node.
1857
1858/// Returns true if \p V is an FP constant with a value of positive zero.
1860
1861/// Returns true if \p V is an integer constant with all bits set.
1863
1864/// Returns true if \p V is a constant integer one.
1866
1867/// Returns true if \p V is a constant min signed integer value.
1869
1870/// Returns true if \p V is a neutral element of Opc with Flags.
1871/// When OperandNo is 0, it checks that V is a left identity. Otherwise, it
1872/// checks that V is a right identity.
1873LLVM_ABI bool isNeutralConstant(unsigned Opc, SDNodeFlags Flags, SDValue V,
1874 unsigned OperandNo);
1875
1876/// Return the non-bitcasted source operand of \p V if it exists.
1877/// If \p V is not a bitcasted value, it is returned as-is.
1879
1880/// Return the non-bitcasted and one-use source operand of \p V if it exists.
1881/// If \p V is not a bitcasted one-use value, it is returned as-is.
1883
1884/// Return the non-extracted vector source operand of \p V if it exists.
1885/// If \p V is not an extracted subvector, it is returned as-is.
1887
1888/// Return the non-truncated source operand of \p V if it exists.
1889/// If \p V is not a truncation, it is returned as-is.
1891
1892/// Returns true if \p V is a bitwise not operation. Assumes that an all ones
1893/// constant is canonicalized to be operand 1.
1894LLVM_ABI bool isBitwiseNot(SDValue V, bool AllowUndefs = false);
1895
1896/// If \p V is a bitwise not, returns the inverted operand. Otherwise returns
1897/// an empty SDValue. Only bits set in \p Mask are required to be inverted,
1898/// other bits may be arbitrary.
1900 bool AllowUndefs);
1901
1902/// Returns the SDNode if it is a constant splat BuildVector or constant int.
1904 bool AllowUndefs = false,
1905 bool AllowTruncation = false);
1906
1907/// Returns the SDNode if it is a demanded constant splat BuildVector or
1908/// constant int.
1910 const APInt &DemandedElts,
1911 bool AllowUndefs = false,
1912 bool AllowTruncation = false);
1913
1914/// Returns the SDNode if it is a constant splat BuildVector or constant float.
1916 bool AllowUndefs = false);
1917
1918/// Returns the SDNode if it is a demanded constant splat BuildVector or
1919/// constant float.
1921 const APInt &DemandedElts,
1922 bool AllowUndefs = false);
1923
1924/// Return true if the value is a constant 0 integer or a splatted vector of
1925/// a constant 0 integer (with no undefs by default).
1926/// Build vector implicit truncation is not an issue for null values.
1927LLVM_ABI bool isNullOrNullSplat(SDValue V, bool AllowUndefs = false);
1928
1929/// Return true if the value is a constant 1 integer or a splatted vector of a
1930/// constant 1 integer (with no undefs).
1931/// Build vector implicit truncation is allowed, but the truncated bits need to
1932/// be zero.
1933LLVM_ABI bool isOneOrOneSplat(SDValue V, bool AllowUndefs = false);
1934
1935/// Return true if the value is a constant -1 integer or a splatted vector of a
1936/// constant -1 integer (with no undefs).
1937/// Does not permit build vector implicit truncation.
1938LLVM_ABI bool isAllOnesOrAllOnesSplat(SDValue V, bool AllowUndefs = false);
1939
1940/// Return true if the value is a constant 1 integer or a splatted vector of a
1941/// constant 1 integer (with no undefs).
1942/// Does not permit build vector implicit truncation.
1943LLVM_ABI bool isOnesOrOnesSplat(SDValue N, bool AllowUndefs = false);
1944
1945/// Return true if the value is a constant 0 integer or a splatted vector of a
1946/// constant 0 integer (with no undefs).
1947/// Does not permit build vector implicit truncation.
1948LLVM_ABI bool isZeroOrZeroSplat(SDValue N, bool AllowUndefs = false);
1949
1950/// Return true if \p V is either a integer or FP constant.
1952 return isa<ConstantSDNode>(V) || isa<ConstantFPSDNode>(V);
1953}
1954
1956 friend class SelectionDAG;
1957
1958 const GlobalValue *TheGlobal;
1959 int64_t Offset;
1960 unsigned TargetFlags;
1961
1962 GlobalAddressSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL,
1963 const GlobalValue *GA, SDVTList VTs, int64_t o,
1964 unsigned TF)
1965 : SDNode(Opc, Order, DL, VTs), TheGlobal(GA), Offset(o), TargetFlags(TF) {
1966 }
1967
1968public:
1969 const GlobalValue *getGlobal() const { return TheGlobal; }
1970 int64_t getOffset() const { return Offset; }
1971 unsigned getTargetFlags() const { return TargetFlags; }
1972 // Return the address space this GlobalAddress belongs to.
1973 LLVM_ABI unsigned getAddressSpace() const;
1974
1975 static bool classof(const SDNode *N) {
1976 return N->getOpcode() == ISD::GlobalAddress ||
1977 N->getOpcode() == ISD::TargetGlobalAddress ||
1978 N->getOpcode() == ISD::GlobalTLSAddress ||
1979 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1980 }
1981};
1982
1983class FrameIndexSDNode : public SDNode {
1984 friend class SelectionDAG;
1985
1986 int FI;
1987
1988 FrameIndexSDNode(int fi, SDVTList VTs, bool isTarg)
1989 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, 0, DebugLoc(),
1990 VTs),
1991 FI(fi) {}
1992
1993public:
1994 int getIndex() const { return FI; }
1995
1996 static bool classof(const SDNode *N) {
1997 return N->getOpcode() == ISD::FrameIndex ||
1998 N->getOpcode() == ISD::TargetFrameIndex;
1999 }
2000};
2001
2002/// This SDNode is used for LIFETIME_START/LIFETIME_END values.
2003class LifetimeSDNode : public SDNode {
2004 friend class SelectionDAG;
2005
2006 LifetimeSDNode(unsigned Opcode, unsigned Order, const DebugLoc &dl,
2007 SDVTList VTs)
2008 : SDNode(Opcode, Order, dl, VTs) {}
2009
2010public:
2011 int64_t getFrameIndex() const {
2012 return cast<FrameIndexSDNode>(getOperand(1))->getIndex();
2013 }
2014
2015 // Methods to support isa and dyn_cast
2016 static bool classof(const SDNode *N) {
2017 return N->getOpcode() == ISD::LIFETIME_START ||
2018 N->getOpcode() == ISD::LIFETIME_END;
2019 }
2020};
2021
2022/// This SDNode is used for PSEUDO_PROBE values, which are the function guid and
2023/// the index of the basic block being probed. A pseudo probe serves as a place
2024/// holder and will be removed at the end of compilation. It does not have any
2025/// operand because we do not want the instruction selection to deal with any.
2027 friend class SelectionDAG;
2028 uint64_t Guid;
2030 uint32_t Attributes;
2031
2032 PseudoProbeSDNode(unsigned Opcode, unsigned Order, const DebugLoc &Dl,
2033 SDVTList VTs, uint64_t Guid, uint64_t Index, uint32_t Attr)
2034 : SDNode(Opcode, Order, Dl, VTs), Guid(Guid), Index(Index),
2035 Attributes(Attr) {}
2036
2037public:
2038 uint64_t getGuid() const { return Guid; }
2039 uint64_t getIndex() const { return Index; }
2041
2042 // Methods to support isa and dyn_cast
2043 static bool classof(const SDNode *N) {
2044 return N->getOpcode() == ISD::PSEUDO_PROBE;
2045 }
2046};
2047
2048class JumpTableSDNode : public SDNode {
2049 friend class SelectionDAG;
2050
2051 int JTI;
2052 unsigned TargetFlags;
2053
2054 JumpTableSDNode(int jti, SDVTList VTs, bool isTarg, unsigned TF)
2055 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, 0, DebugLoc(),
2056 VTs),
2057 JTI(jti), TargetFlags(TF) {}
2058
2059public:
2060 int getIndex() const { return JTI; }
2061 unsigned getTargetFlags() const { return TargetFlags; }
2062
2063 static bool classof(const SDNode *N) {
2064 return N->getOpcode() == ISD::JumpTable ||
2065 N->getOpcode() == ISD::TargetJumpTable;
2066 }
2067};
2068
2070 friend class SelectionDAG;
2071
2072 union {
2075 } Val;
2076 int Offset; // It's a MachineConstantPoolValue if top bit is set.
2077 Align Alignment; // Minimum alignment requirement of CP.
2078 unsigned TargetFlags;
2079
2080 ConstantPoolSDNode(bool isTarget, const Constant *c, SDVTList VTs, int o,
2081 Align Alignment, unsigned TF)
2082 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
2083 DebugLoc(), VTs),
2084 Offset(o), Alignment(Alignment), TargetFlags(TF) {
2085 assert(Offset >= 0 && "Offset is too large");
2086 Val.ConstVal = c;
2087 }
2088
2089 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v, SDVTList VTs,
2090 int o, Align Alignment, unsigned TF)
2091 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
2092 DebugLoc(), VTs),
2093 Offset(o), Alignment(Alignment), TargetFlags(TF) {
2094 assert(Offset >= 0 && "Offset is too large");
2095 Val.MachineCPVal = v;
2096 Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
2097 }
2098
2099public:
2101 return Offset < 0;
2102 }
2103
2104 const Constant *getConstVal() const {
2105 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
2106 return Val.ConstVal;
2107 }
2108
2110 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
2111 return Val.MachineCPVal;
2112 }
2113
2114 int getOffset() const {
2115 return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
2116 }
2117
2118 // Return the alignment of this constant pool object, which is either 0 (for
2119 // default alignment) or the desired value.
2120 Align getAlign() const { return Alignment; }
2121 unsigned getTargetFlags() const { return TargetFlags; }
2122
2123 LLVM_ABI Type *getType() const;
2124
2125 static bool classof(const SDNode *N) {
2126 return N->getOpcode() == ISD::ConstantPool ||
2127 N->getOpcode() == ISD::TargetConstantPool;
2128 }
2129};
2130
2131/// Completely target-dependent object reference.
2133 friend class SelectionDAG;
2134
2135 unsigned TargetFlags;
2136 int Index;
2137 int64_t Offset;
2138
2139public:
2140 TargetIndexSDNode(int Idx, SDVTList VTs, int64_t Ofs, unsigned TF)
2141 : SDNode(ISD::TargetIndex, 0, DebugLoc(), VTs), TargetFlags(TF),
2142 Index(Idx), Offset(Ofs) {}
2143
2144 unsigned getTargetFlags() const { return TargetFlags; }
2145 int getIndex() const { return Index; }
2146 int64_t getOffset() const { return Offset; }
2147
2148 static bool classof(const SDNode *N) {
2149 return N->getOpcode() == ISD::TargetIndex;
2150 }
2151};
2152
2153class BasicBlockSDNode : public SDNode {
2154 friend class SelectionDAG;
2155
2157
2158 /// Debug info is meaningful and potentially useful here, but we create
2159 /// blocks out of order when they're jumped to, which makes it a bit
2160 /// harder. Let's see if we need it first.
2161 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
2162 : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
2163 {}
2164
2165public:
2167
2168 static bool classof(const SDNode *N) {
2169 return N->getOpcode() == ISD::BasicBlock;
2170 }
2171};
2172
2173/// A "pseudo-class" with methods for operating on BUILD_VECTORs.
2175public:
2176 // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
2177 explicit BuildVectorSDNode() = delete;
2178
2179 /// Check if this is a constant splat, and if so, find the
2180 /// smallest element size that splats the vector. If MinSplatBits is
2181 /// nonzero, the element size must be at least that large. Note that the
2182 /// splat element may be the entire vector (i.e., a one element vector).
2183 /// Returns the splat element value in SplatValue. Any undefined bits in
2184 /// that value are zero, and the corresponding bits in the SplatUndef mask
2185 /// are set. The SplatBitSize value is set to the splat element size in
2186 /// bits. HasAnyUndefs is set to true if any bits in the vector are
2187 /// undefined. isBigEndian describes the endianness of the target.
2188 LLVM_ABI bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
2189 unsigned &SplatBitSize, bool &HasAnyUndefs,
2190 unsigned MinSplatBits = 0,
2191 bool isBigEndian = false) const;
2192
2193 /// Returns the demanded splatted value or a null value if this is not a
2194 /// splat.
2195 ///
2196 /// The DemandedElts mask indicates the elements that must be in the splat.
2197 /// If passed a non-null UndefElements bitvector, it will resize it to match
2198 /// the vector width and set the bits where elements are undef.
2199 LLVM_ABI SDValue getSplatValue(const APInt &DemandedElts,
2200 BitVector *UndefElements = nullptr) const;
2201
2202 /// Returns the splatted value or a null value if this is not a splat.
2203 ///
2204 /// If passed a non-null UndefElements bitvector, it will resize it to match
2205 /// the vector width and set the bits where elements are undef.
2206 LLVM_ABI SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
2207
2208 /// Find the shortest repeating sequence of values in the build vector.
2209 ///
2210 /// e.g. { u, X, u, X, u, u, X, u } -> { X }
2211 /// { X, Y, u, Y, u, u, X, u } -> { X, Y }
2212 ///
2213 /// Currently this must be a power-of-2 build vector.
2214 /// The DemandedElts mask indicates the elements that must be present,
2215 /// undemanded elements in Sequence may be null (SDValue()). If passed a
2216 /// non-null UndefElements bitvector, it will resize it to match the original
2217 /// vector width and set the bits where elements are undef. If result is
2218 /// false, Sequence will be empty.
2219 LLVM_ABI bool getRepeatedSequence(const APInt &DemandedElts,
2220 SmallVectorImpl<SDValue> &Sequence,
2221 BitVector *UndefElements = nullptr) const;
2222
2223 /// Find the shortest repeating sequence of values in the build vector.
2224 ///
2225 /// e.g. { u, X, u, X, u, u, X, u } -> { X }
2226 /// { X, Y, u, Y, u, u, X, u } -> { X, Y }
2227 ///
2228 /// Currently this must be a power-of-2 build vector.
2229 /// If passed a non-null UndefElements bitvector, it will resize it to match
2230 /// the original vector width and set the bits where elements are undef.
2231 /// If result is false, Sequence will be empty.
2233 BitVector *UndefElements = nullptr) const;
2234
2235 /// Returns the demanded splatted constant or null if this is not a constant
2236 /// splat.
2237 ///
2238 /// The DemandedElts mask indicates the elements that must be in the splat.
2239 /// If passed a non-null UndefElements bitvector, it will resize it to match
2240 /// the vector width and set the bits where elements are undef.
2242 getConstantSplatNode(const APInt &DemandedElts,
2243 BitVector *UndefElements = nullptr) const;
2244
2245 /// Returns the splatted constant or null if this is not a constant
2246 /// splat.
2247 ///
2248 /// If passed a non-null UndefElements bitvector, it will resize it to match
2249 /// the vector width and set the bits where elements are undef.
2251 getConstantSplatNode(BitVector *UndefElements = nullptr) const;
2252
2253 /// Returns the demanded splatted constant FP or null if this is not a
2254 /// constant FP splat.
2255 ///
2256 /// The DemandedElts mask indicates the elements that must be in the splat.
2257 /// If passed a non-null UndefElements bitvector, it will resize it to match
2258 /// the vector width and set the bits where elements are undef.
2260 getConstantFPSplatNode(const APInt &DemandedElts,
2261 BitVector *UndefElements = nullptr) const;
2262
2263 /// Returns the splatted constant FP or null if this is not a constant
2264 /// FP splat.
2265 ///
2266 /// If passed a non-null UndefElements bitvector, it will resize it to match
2267 /// the vector width and set the bits where elements are undef.
2269 getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
2270
2271 /// If this is a constant FP splat and the splatted constant FP is an
2272 /// exact power or 2, return the log base 2 integer value. Otherwise,
2273 /// return -1.
2274 ///
2275 /// The BitWidth specifies the necessary bit precision.
2276 LLVM_ABI int32_t getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements,
2277 uint32_t BitWidth) const;
2278
2279 /// Extract the raw bit data from a build vector of Undef, Constant or
2280 /// ConstantFP node elements. Each raw bit element will be \p
2281 /// DstEltSizeInBits wide, undef elements are treated as zero, and entirely
2282 /// undefined elements are flagged in \p UndefElements.
2283 LLVM_ABI bool getConstantRawBits(bool IsLittleEndian,
2284 unsigned DstEltSizeInBits,
2285 SmallVectorImpl<APInt> &RawBitElements,
2286 BitVector &UndefElements) const;
2287
2288 LLVM_ABI bool isConstant() const;
2289
2290 /// If this BuildVector is constant and represents the numerical series
2291 /// "<a, a+n, a+2n, a+3n, ...>" where a is integer and n is a non-zero integer,
2292 /// the value "<a,n>" is returned.
2293 LLVM_ABI std::optional<std::pair<APInt, APInt>> isConstantSequence() const;
2294
2295 /// Recast bit data \p SrcBitElements to \p DstEltSizeInBits wide elements.
2296 /// Undef elements are treated as zero, and entirely undefined elements are
2297 /// flagged in \p DstUndefElements.
2298 LLVM_ABI static void recastRawBits(bool IsLittleEndian,
2299 unsigned DstEltSizeInBits,
2300 SmallVectorImpl<APInt> &DstBitElements,
2301 ArrayRef<APInt> SrcBitElements,
2302 BitVector &DstUndefElements,
2303 const BitVector &SrcUndefElements);
2304
2305 static bool classof(const SDNode *N) {
2306 return N->getOpcode() == ISD::BUILD_VECTOR;
2307 }
2308};
2309
2310/// An SDNode that holds an arbitrary LLVM IR Value. This is
2311/// used when the SelectionDAG needs to make a simple reference to something
2312/// in the LLVM IR representation.
2313///
2314class SrcValueSDNode : public SDNode {
2315 friend class SelectionDAG;
2316
2317 const Value *V;
2318
2319 /// Create a SrcValue for a general value.
2320 explicit SrcValueSDNode(const Value *v)
2321 : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
2322
2323public:
2324 /// Return the contained Value.
2325 const Value *getValue() const { return V; }
2326
2327 static bool classof(const SDNode *N) {
2328 return N->getOpcode() == ISD::SRCVALUE;
2329 }
2330};
2331
2332class MDNodeSDNode : public SDNode {
2333 friend class SelectionDAG;
2334
2335 const MDNode *MD;
2336
2337 explicit MDNodeSDNode(const MDNode *md)
2338 : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
2339 {}
2340
2341public:
2342 const MDNode *getMD() const { return MD; }
2343
2344 static bool classof(const SDNode *N) {
2345 return N->getOpcode() == ISD::MDNODE_SDNODE;
2346 }
2347};
2348
2349class RegisterSDNode : public SDNode {
2350 friend class SelectionDAG;
2351
2352 Register Reg;
2353
2355 : SDNode(ISD::Register, 0, DebugLoc(), VTs), Reg(reg) {}
2356
2357public:
2358 Register getReg() const { return Reg; }
2359
2360 static bool classof(const SDNode *N) {
2361 return N->getOpcode() == ISD::Register;
2362 }
2363};
2364
2366 friend class SelectionDAG;
2367
2368 // The memory for RegMask is not owned by the node.
2369 const uint32_t *RegMask;
2370
2371 RegisterMaskSDNode(const uint32_t *mask)
2372 : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
2373 RegMask(mask) {}
2374
2375public:
2376 const uint32_t *getRegMask() const { return RegMask; }
2377
2378 static bool classof(const SDNode *N) {
2379 return N->getOpcode() == ISD::RegisterMask;
2380 }
2381};
2382
2384 friend class SelectionDAG;
2385
2386 const BlockAddress *BA;
2387 int64_t Offset;
2388 unsigned TargetFlags;
2389
2390 BlockAddressSDNode(unsigned NodeTy, SDVTList VTs, const BlockAddress *ba,
2391 int64_t o, unsigned Flags)
2392 : SDNode(NodeTy, 0, DebugLoc(), VTs), BA(ba), Offset(o),
2393 TargetFlags(Flags) {}
2394
2395public:
2396 const BlockAddress *getBlockAddress() const { return BA; }
2397 int64_t getOffset() const { return Offset; }
2398 unsigned getTargetFlags() const { return TargetFlags; }
2399
2400 static bool classof(const SDNode *N) {
2401 return N->getOpcode() == ISD::BlockAddress ||
2402 N->getOpcode() == ISD::TargetBlockAddress;
2403 }
2404};
2405
2406class LabelSDNode : public SDNode {
2407 friend class SelectionDAG;
2408
2409 MCSymbol *Label;
2410
2411 LabelSDNode(unsigned Opcode, unsigned Order, const DebugLoc &dl, MCSymbol *L)
2412 : SDNode(Opcode, Order, dl, getSDVTList(MVT::Other)), Label(L) {
2413 assert(LabelSDNode::classof(this) && "not a label opcode");
2414 }
2415
2416public:
2417 MCSymbol *getLabel() const { return Label; }
2418
2419 static bool classof(const SDNode *N) {
2420 return N->getOpcode() == ISD::EH_LABEL ||
2421 N->getOpcode() == ISD::ANNOTATION_LABEL;
2422 }
2423};
2424
2426 friend class SelectionDAG;
2427
2428 const char *Symbol;
2429 unsigned TargetFlags;
2430
2431 ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned TF,
2432 SDVTList VTs)
2433 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol, 0,
2434 DebugLoc(), VTs),
2435 Symbol(Sym), TargetFlags(TF) {}
2436
2437public:
2438 const char *getSymbol() const { return Symbol; }
2439 unsigned getTargetFlags() const { return TargetFlags; }
2440
2441 static bool classof(const SDNode *N) {
2442 return N->getOpcode() == ISD::ExternalSymbol ||
2443 N->getOpcode() == ISD::TargetExternalSymbol;
2444 }
2445};
2446
2447class MCSymbolSDNode : public SDNode {
2448 friend class SelectionDAG;
2449
2450 MCSymbol *Symbol;
2451
2452 MCSymbolSDNode(MCSymbol *Symbol, SDVTList VTs)
2453 : SDNode(ISD::MCSymbol, 0, DebugLoc(), VTs), Symbol(Symbol) {}
2454
2455public:
2456 MCSymbol *getMCSymbol() const { return Symbol; }
2457
2458 static bool classof(const SDNode *N) {
2459 return N->getOpcode() == ISD::MCSymbol;
2460 }
2461};
2462
2463class CondCodeSDNode : public SDNode {
2464 friend class SelectionDAG;
2465
2466 ISD::CondCode Condition;
2467
2469 : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
2470 Condition(Cond) {}
2471
2472public:
2473 ISD::CondCode get() const { return Condition; }
2474
2475 static bool classof(const SDNode *N) {
2476 return N->getOpcode() == ISD::CONDCODE;
2477 }
2478};
2479
2480/// This class is used to represent EVT's, which are used
2481/// to parameterize some operations.
2482class VTSDNode : public SDNode {
2483 friend class SelectionDAG;
2484
2485 EVT ValueType;
2486
2487 explicit VTSDNode(EVT VT)
2488 : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
2489 ValueType(VT) {}
2490
2491public:
2492 EVT getVT() const { return ValueType; }
2493
2494 static bool classof(const SDNode *N) {
2495 return N->getOpcode() == ISD::VALUETYPE;
2496 }
2497};
2498
2499/// Base class for LoadSDNode and StoreSDNode
2500class LSBaseSDNode : public MemSDNode {
2501public:
2502 LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl,
2503 SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
2505 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
2506 LSBaseSDNodeBits.AddressingMode = AM;
2507 assert(getAddressingMode() == AM && "Value truncated");
2508 }
2509
2510 const SDValue &getOffset() const {
2511 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2512 }
2513
2514 /// Return the addressing mode for this load or store:
2515 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2517 return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
2518 }
2519
2520 /// Return true if this is a pre/post inc/dec load/store.
2521 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2522
2523 /// Return true if this is NOT a pre/post inc/dec load/store.
2524 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2525
2526 static bool classof(const SDNode *N) {
2527 return N->getOpcode() == ISD::LOAD ||
2528 N->getOpcode() == ISD::STORE;
2529 }
2530};
2531
2532/// This class is used to represent ISD::LOAD nodes.
2533class LoadSDNode : public LSBaseSDNode {
2534 friend class SelectionDAG;
2535
2536 LoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2539 : LSBaseSDNode(ISD::LOAD, Order, dl, VTs, AM, MemVT, MMO) {
2540 LoadSDNodeBits.ExtTy = ETy;
2541 assert(readMem() && "Load MachineMemOperand is not a load!");
2542 assert(!writeMem() && "Load MachineMemOperand is a store!");
2543 }
2544
2545public:
2546 /// Return whether this is a plain node,
2547 /// or one of the varieties of value-extending loads.
2549 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2550 }
2551
2552 const SDValue &getBasePtr() const { return getOperand(1); }
2553 const SDValue &getOffset() const { return getOperand(2); }
2554
2555 static bool classof(const SDNode *N) {
2556 return N->getOpcode() == ISD::LOAD;
2557 }
2558};
2559
2560/// This class is used to represent ISD::STORE nodes.
2562 friend class SelectionDAG;
2563
2564 StoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2565 ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
2567 : LSBaseSDNode(ISD::STORE, Order, dl, VTs, AM, MemVT, MMO) {
2568 StoreSDNodeBits.IsTruncating = isTrunc;
2569 assert(!readMem() && "Store MachineMemOperand is a load!");
2570 assert(writeMem() && "Store MachineMemOperand is not a store!");
2571 }
2572
2573public:
2574 /// Return true if the op does a truncation before store.
2575 /// For integers this is the same as doing a TRUNCATE and storing the result.
2576 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2577 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2578
2579 const SDValue &getValue() const { return getOperand(1); }
2580 const SDValue &getBasePtr() const { return getOperand(2); }
2581 const SDValue &getOffset() const { return getOperand(3); }
2582
2583 static bool classof(const SDNode *N) {
2584 return N->getOpcode() == ISD::STORE;
2585 }
2586};
2587
2588/// This base class is used to represent VP_LOAD, VP_STORE,
2589/// EXPERIMENTAL_VP_STRIDED_LOAD and EXPERIMENTAL_VP_STRIDED_STORE nodes
2591public:
2592 friend class SelectionDAG;
2593
2594 VPBaseLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order,
2595 const DebugLoc &DL, SDVTList VTs,
2596 ISD::MemIndexedMode AM, EVT MemVT,
2598 : MemSDNode(NodeTy, Order, DL, VTs, MemVT, MMO) {
2599 LSBaseSDNodeBits.AddressingMode = AM;
2600 assert(getAddressingMode() == AM && "Value truncated");
2601 }
2602
2603 // VPStridedStoreSDNode (Chain, Data, Ptr, Offset, Stride, Mask, EVL)
2604 // VPStoreSDNode (Chain, Data, Ptr, Offset, Mask, EVL)
2605 // VPStridedLoadSDNode (Chain, Ptr, Offset, Stride, Mask, EVL)
2606 // VPLoadSDNode (Chain, Ptr, Offset, Mask, EVL)
2607 // Mask is a vector of i1 elements;
2608 // the type of EVL is TLI.getVPExplicitVectorLengthTy().
2609 const SDValue &getOffset() const {
2610 return getOperand((getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD ||
2611 getOpcode() == ISD::VP_LOAD)
2612 ? 2
2613 : 3);
2614 }
2615 const SDValue &getBasePtr() const {
2616 return getOperand((getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD ||
2617 getOpcode() == ISD::VP_LOAD)
2618 ? 1
2619 : 2);
2620 }
2621 const SDValue &getMask() const {
2622 switch (getOpcode()) {
2623 default:
2624 llvm_unreachable("Invalid opcode");
2625 case ISD::VP_LOAD:
2626 return getOperand(3);
2627 case ISD::VP_STORE:
2628 case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
2629 return getOperand(4);
2630 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
2631 return getOperand(5);
2632 }
2633 }
2634 const SDValue &getVectorLength() const {
2635 switch (getOpcode()) {
2636 default:
2637 llvm_unreachable("Invalid opcode");
2638 case ISD::VP_LOAD:
2639 return getOperand(4);
2640 case ISD::VP_STORE:
2641 case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
2642 return getOperand(5);
2643 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
2644 return getOperand(6);
2645 }
2646 }
2647
2648 /// Return the addressing mode for this load or store:
2649 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2651 return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
2652 }
2653
2654 /// Return true if this is a pre/post inc/dec load/store.
2655 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2656
2657 /// Return true if this is NOT a pre/post inc/dec load/store.
2658 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2659
2660 static bool classof(const SDNode *N) {
2661 return N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD ||
2662 N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_STORE ||
2663 N->getOpcode() == ISD::VP_LOAD || N->getOpcode() == ISD::VP_STORE;
2664 }
2665};
2666
2667/// This class is used to represent a VP_LOAD node
2669public:
2670 friend class SelectionDAG;
2671
2672 VPLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2673 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, bool isExpanding,
2674 EVT MemVT, MachineMemOperand *MMO)
2675 : VPBaseLoadStoreSDNode(ISD::VP_LOAD, Order, dl, VTs, AM, MemVT, MMO) {
2676 LoadSDNodeBits.ExtTy = ETy;
2677 LoadSDNodeBits.IsExpanding = isExpanding;
2678 }
2679
2681 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2682 }
2683
2684 const SDValue &getBasePtr() const { return getOperand(1); }
2685 const SDValue &getOffset() const { return getOperand(2); }
2686 const SDValue &getMask() const { return getOperand(3); }
2687 const SDValue &getVectorLength() const { return getOperand(4); }
2688
2689 static bool classof(const SDNode *N) {
2690 return N->getOpcode() == ISD::VP_LOAD;
2691 }
2692 bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
2693};
2694
2695/// This class is used to represent an EXPERIMENTAL_VP_STRIDED_LOAD node.
2697public:
2698 friend class SelectionDAG;
2699
2700 VPStridedLoadSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs,
2702 bool IsExpanding, EVT MemVT, MachineMemOperand *MMO)
2703 : VPBaseLoadStoreSDNode(ISD::EXPERIMENTAL_VP_STRIDED_LOAD, Order, DL, VTs,
2704 AM, MemVT, MMO) {
2705 LoadSDNodeBits.ExtTy = ETy;
2706 LoadSDNodeBits.IsExpanding = IsExpanding;
2707 }
2708
2710 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2711 }
2712
2713 const SDValue &getBasePtr() const { return getOperand(1); }
2714 const SDValue &getOffset() const { return getOperand(2); }
2715 const SDValue &getStride() const { return getOperand(3); }
2716 const SDValue &getMask() const { return getOperand(4); }
2717 const SDValue &getVectorLength() const { return getOperand(5); }
2718
2719 static bool classof(const SDNode *N) {
2720 return N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD;
2721 }
2722 bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
2723};
2724
2725/// This class is used to represent a VP_STORE node
2727public:
2728 friend class SelectionDAG;
2729
2730 VPStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2731 ISD::MemIndexedMode AM, bool isTrunc, bool isCompressing,
2732 EVT MemVT, MachineMemOperand *MMO)
2733 : VPBaseLoadStoreSDNode(ISD::VP_STORE, Order, dl, VTs, AM, MemVT, MMO) {
2734 StoreSDNodeBits.IsTruncating = isTrunc;
2735 StoreSDNodeBits.IsCompressing = isCompressing;
2736 }
2737
2738 /// Return true if this is a truncating store.
2739 /// For integers this is the same as doing a TRUNCATE and storing the result.
2740 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2741 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2742
2743 /// Returns true if the op does a compression to the vector before storing.
2744 /// The node contiguously stores the active elements (integers or floats)
2745 /// in src (those with their respective bit set in writemask k) to unaligned
2746 /// memory at base_addr.
2747 bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
2748
2749 const SDValue &getValue() const { return getOperand(1); }
2750 const SDValue &getBasePtr() const { return getOperand(2); }
2751 const SDValue &getOffset() const { return getOperand(3); }
2752 const SDValue &getMask() const { return getOperand(4); }
2753 const SDValue &getVectorLength() const { return getOperand(5); }
2754
2755 static bool classof(const SDNode *N) {
2756 return N->getOpcode() == ISD::VP_STORE;
2757 }
2758};
2759
2760/// This class is used to represent an EXPERIMENTAL_VP_STRIDED_STORE node.
2762public:
2763 friend class SelectionDAG;
2764
2765 VPStridedStoreSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs,
2766 ISD::MemIndexedMode AM, bool IsTrunc, bool IsCompressing,
2767 EVT MemVT, MachineMemOperand *MMO)
2768 : VPBaseLoadStoreSDNode(ISD::EXPERIMENTAL_VP_STRIDED_STORE, Order, DL,
2769 VTs, AM, MemVT, MMO) {
2770 StoreSDNodeBits.IsTruncating = IsTrunc;
2771 StoreSDNodeBits.IsCompressing = IsCompressing;
2772 }
2773
2774 /// Return true if this is a truncating store.
2775 /// For integers this is the same as doing a TRUNCATE and storing the result.
2776 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2777 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2778
2779 /// Returns true if the op does a compression to the vector before storing.
2780 /// The node contiguously stores the active elements (integers or floats)
2781 /// in src (those with their respective bit set in writemask k) to unaligned
2782 /// memory at base_addr.
2783 bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
2784
2785 const SDValue &getValue() const { return getOperand(1); }
2786 const SDValue &getBasePtr() const { return getOperand(2); }
2787 const SDValue &getOffset() const { return getOperand(3); }
2788 const SDValue &getStride() const { return getOperand(4); }
2789 const SDValue &getMask() const { return getOperand(5); }
2790 const SDValue &getVectorLength() const { return getOperand(6); }
2791
2792 static bool classof(const SDNode *N) {
2793 return N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_STORE;
2794 }
2795};
2796
2797/// This base class is used to represent MLOAD and MSTORE nodes
2799public:
2800 friend class SelectionDAG;
2801
2802 MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order,
2803 const DebugLoc &dl, SDVTList VTs,
2804 ISD::MemIndexedMode AM, EVT MemVT,
2806 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
2807 LSBaseSDNodeBits.AddressingMode = AM;
2808 assert(getAddressingMode() == AM && "Value truncated");
2809 }
2810
2811 // MaskedLoadSDNode (Chain, ptr, offset, mask, passthru)
2812 // MaskedStoreSDNode (Chain, data, ptr, offset, mask)
2813 // Mask is a vector of i1 elements
2814 const SDValue &getOffset() const {
2815 return getOperand(getOpcode() == ISD::MLOAD ? 2 : 3);
2816 }
2817 const SDValue &getMask() const {
2818 return getOperand(getOpcode() == ISD::MLOAD ? 3 : 4);
2819 }
2820
2821 /// Return the addressing mode for this load or store:
2822 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2824 return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
2825 }
2826
2827 /// Return true if this is a pre/post inc/dec load/store.
2828 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2829
2830 /// Return true if this is NOT a pre/post inc/dec load/store.
2831 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2832
2833 static bool classof(const SDNode *N) {
2834 return N->getOpcode() == ISD::MLOAD ||
2835 N->getOpcode() == ISD::MSTORE;
2836 }
2837};
2838
2839/// This class is used to represent an MLOAD node
2841public:
2842 friend class SelectionDAG;
2843
2844 MaskedLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2846 bool IsExpanding, EVT MemVT, MachineMemOperand *MMO)
2847 : MaskedLoadStoreSDNode(ISD::MLOAD, Order, dl, VTs, AM, MemVT, MMO) {
2848 LoadSDNodeBits.ExtTy = ETy;
2849 LoadSDNodeBits.IsExpanding = IsExpanding;
2850 }
2851
2853 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2854 }
2855
2856 const SDValue &getBasePtr() const { return getOperand(1); }
2857 const SDValue &getOffset() const { return getOperand(2); }
2858 const SDValue &getMask() const { return getOperand(3); }
2859 const SDValue &getPassThru() const { return getOperand(4); }
2860
2861 static bool classof(const SDNode *N) {
2862 return N->getOpcode() == ISD::MLOAD;
2863 }
2864
2865 bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
2866};
2867
2868/// This class is used to represent an MSTORE node
2870public:
2871 friend class SelectionDAG;
2872
2873 MaskedStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2874 ISD::MemIndexedMode AM, bool isTrunc, bool isCompressing,
2875 EVT MemVT, MachineMemOperand *MMO)
2876 : MaskedLoadStoreSDNode(ISD::MSTORE, Order, dl, VTs, AM, MemVT, MMO) {
2877 StoreSDNodeBits.IsTruncating = isTrunc;
2878 StoreSDNodeBits.IsCompressing = isCompressing;
2879 }
2880
2881 /// Return true if the op does a truncation before store.
2882 /// For integers this is the same as doing a TRUNCATE and storing the result.
2883 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2884 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2885
2886 /// Returns true if the op does a compression to the vector before storing.
2887 /// The node contiguously stores the active elements (integers or floats)
2888 /// in src (those with their respective bit set in writemask k) to unaligned
2889 /// memory at base_addr.
2890 bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
2891
2892 const SDValue &getValue() const { return getOperand(1); }
2893 const SDValue &getBasePtr() const { return getOperand(2); }
2894 const SDValue &getOffset() const { return getOperand(3); }
2895 const SDValue &getMask() const { return getOperand(4); }
2896
2897 static bool classof(const SDNode *N) {
2898 return N->getOpcode() == ISD::MSTORE;
2899 }
2900};
2901
2902/// This is a base class used to represent
2903/// VP_GATHER and VP_SCATTER nodes
2904///
2906public:
2907 friend class SelectionDAG;
2908
2909 VPGatherScatterSDNode(ISD::NodeType NodeTy, unsigned Order,
2910 const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2912 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
2913 LSBaseSDNodeBits.AddressingMode = IndexType;
2914 assert(getIndexType() == IndexType && "Value truncated");
2915 }
2916
2917 /// How is Index applied to BasePtr when computing addresses.
2919 return static_cast<ISD::MemIndexType>(LSBaseSDNodeBits.AddressingMode);
2920 }
2921 bool isIndexScaled() const {
2922 return !cast<ConstantSDNode>(getScale())->isOne();
2923 }
2924 bool isIndexSigned() const { return isIndexTypeSigned(getIndexType()); }
2925
2926 // In the both nodes address is Op1, mask is Op2:
2927 // VPGatherSDNode (Chain, base, index, scale, mask, vlen)
2928 // VPScatterSDNode (Chain, value, base, index, scale, mask, vlen)
2929 // Mask is a vector of i1 elements
2930 const SDValue &getBasePtr() const {
2931 return getOperand((getOpcode() == ISD::VP_GATHER) ? 1 : 2);
2932 }
2933 const SDValue &getIndex() const {
2934 return getOperand((getOpcode() == ISD::VP_GATHER) ? 2 : 3);
2935 }
2936 const SDValue &getScale() const {
2937 return getOperand((getOpcode() == ISD::VP_GATHER) ? 3 : 4);
2938 }
2939 const SDValue &getMask() const {
2940 return getOperand((getOpcode() == ISD::VP_GATHER) ? 4 : 5);
2941 }
2942 const SDValue &getVectorLength() const {
2943 return getOperand((getOpcode() == ISD::VP_GATHER) ? 5 : 6);
2944 }
2945
2946 static bool classof(const SDNode *N) {
2947 return N->getOpcode() == ISD::VP_GATHER ||
2948 N->getOpcode() == ISD::VP_SCATTER;
2949 }
2950};
2951
2952/// This class is used to represent an VP_GATHER node
2953///
2955public:
2956 friend class SelectionDAG;
2957
2958 VPGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2960 : VPGatherScatterSDNode(ISD::VP_GATHER, Order, dl, VTs, MemVT, MMO,
2961 IndexType) {}
2962
2963 static bool classof(const SDNode *N) {
2964 return N->getOpcode() == ISD::VP_GATHER;
2965 }
2966};
2967
2968/// This class is used to represent an VP_SCATTER node
2969///
2971public:
2972 friend class SelectionDAG;
2973
2974 VPScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2976 : VPGatherScatterSDNode(ISD::VP_SCATTER, Order, dl, VTs, MemVT, MMO,
2977 IndexType) {}
2978
2979 const SDValue &getValue() const { return getOperand(1); }
2980
2981 static bool classof(const SDNode *N) {
2982 return N->getOpcode() == ISD::VP_SCATTER;
2983 }
2984};
2985
2986/// This is a base class used to represent
2987/// MGATHER and MSCATTER nodes
2988///
2990public:
2991 friend class SelectionDAG;
2992
2994 const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2996 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
2997 LSBaseSDNodeBits.AddressingMode = IndexType;
2998 assert(getIndexType() == IndexType && "Value truncated");
2999 }
3000
3001 /// How is Index applied to BasePtr when computing addresses.
3003 return static_cast<ISD::MemIndexType>(LSBaseSDNodeBits.AddressingMode);
3004 }
3005 bool isIndexScaled() const {
3006 return !cast<ConstantSDNode>(getScale())->isOne();
3007 }
3008 bool isIndexSigned() const { return isIndexTypeSigned(getIndexType()); }
3009
3010 // In the both nodes address is Op1, mask is Op2:
3011 // MaskedGatherSDNode (Chain, passthru, mask, base, index, scale)
3012 // MaskedScatterSDNode (Chain, value, mask, base, index, scale)
3013 // Mask is a vector of i1 elements
3014 const SDValue &getBasePtr() const { return getOperand(3); }
3015 const SDValue &getIndex() const { return getOperand(4); }
3016 const SDValue &getMask() const { return getOperand(2); }
3017 const SDValue &getScale() const { return getOperand(5); }
3018
3019 static bool classof(const SDNode *N) {
3020 return N->getOpcode() == ISD::MGATHER || N->getOpcode() == ISD::MSCATTER ||
3021 N->getOpcode() == ISD::EXPERIMENTAL_VECTOR_HISTOGRAM;
3022 }
3023};
3024
3025/// This class is used to represent an MGATHER node
3026///
3028public:
3029 friend class SelectionDAG;
3030
3031 MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
3032 EVT MemVT, MachineMemOperand *MMO,
3033 ISD::MemIndexType IndexType, ISD::LoadExtType ETy)
3034 : MaskedGatherScatterSDNode(ISD::MGATHER, Order, dl, VTs, MemVT, MMO,
3035 IndexType) {
3036 LoadSDNodeBits.ExtTy = ETy;
3037 }
3038
3039 const SDValue &getPassThru() const { return getOperand(1); }
3040
3042 return ISD::LoadExtType(LoadSDNodeBits.ExtTy);
3043 }
3044
3045 static bool classof(const SDNode *N) {
3046 return N->getOpcode() == ISD::MGATHER;
3047 }
3048};
3049
3050/// This class is used to represent an MSCATTER node
3051///
3053public:
3054 friend class SelectionDAG;
3055
3056 MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
3057 EVT MemVT, MachineMemOperand *MMO,
3058 ISD::MemIndexType IndexType, bool IsTrunc)
3059 : MaskedGatherScatterSDNode(ISD::MSCATTER, Order, dl, VTs, MemVT, MMO,
3060 IndexType) {
3061 StoreSDNodeBits.IsTruncating = IsTrunc;
3062 }
3063
3064 /// Return true if the op does a truncation before store.
3065 /// For integers this is the same as doing a TRUNCATE and storing the result.
3066 /// For floats, it is the same as doing an FP_ROUND and storing the result.
3067 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
3068
3069 const SDValue &getValue() const { return getOperand(1); }
3070
3071 static bool classof(const SDNode *N) {
3072 return N->getOpcode() == ISD::MSCATTER;
3073 }
3074};
3075
3077public:
3078 friend class SelectionDAG;
3079
3080 MaskedHistogramSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs,
3081 EVT MemVT, MachineMemOperand *MMO,
3082 ISD::MemIndexType IndexType)
3083 : MaskedGatherScatterSDNode(ISD::EXPERIMENTAL_VECTOR_HISTOGRAM, Order, DL,
3084 VTs, MemVT, MMO, IndexType) {}
3085
3087 return static_cast<ISD::MemIndexType>(LSBaseSDNodeBits.AddressingMode);
3088 }
3089
3090 const SDValue &getBasePtr() const { return getOperand(3); }
3091 const SDValue &getIndex() const { return getOperand(4); }
3092 const SDValue &getMask() const { return getOperand(2); }
3093 const SDValue &getScale() const { return getOperand(5); }
3094 const SDValue &getInc() const { return getOperand(1); }
3095 const SDValue &getIntID() const { return getOperand(6); }
3096
3097 static bool classof(const SDNode *N) {
3098 return N->getOpcode() == ISD::EXPERIMENTAL_VECTOR_HISTOGRAM;
3099 }
3100};
3101
3103public:
3104 friend class SelectionDAG;
3105
3106 VPLoadFFSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs, EVT MemVT,
3108 : MemSDNode(ISD::VP_LOAD_FF, Order, DL, VTs, MemVT, MMO) {}
3109
3110 const SDValue &getBasePtr() const { return getOperand(1); }
3111 const SDValue &getMask() const { return getOperand(2); }
3112 const SDValue &getVectorLength() const { return getOperand(3); }
3113
3114 static bool classof(const SDNode *N) {
3115 return N->getOpcode() == ISD::VP_LOAD_FF;
3116 }
3117};
3118
3120public:
3121 friend class SelectionDAG;
3122
3123 FPStateAccessSDNode(unsigned NodeTy, unsigned Order, const DebugLoc &dl,
3124 SDVTList VTs, EVT MemVT, MachineMemOperand *MMO)
3125 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
3126 assert((NodeTy == ISD::GET_FPENV_MEM || NodeTy == ISD::SET_FPENV_MEM) &&
3127 "Expected FP state access node");
3128 }
3129
3130 static bool classof(const SDNode *N) {
3131 return N->getOpcode() == ISD::GET_FPENV_MEM ||
3132 N->getOpcode() == ISD::SET_FPENV_MEM;
3133 }
3134};
3135
3136/// An SDNode that represents everything that will be needed
3137/// to construct a MachineInstr. These nodes are created during the
3138/// instruction selection proper phase.
3139///
3140/// Note that the only supported way to set the `memoperands` is by calling the
3141/// `SelectionDAG::setNodeMemRefs` function as the memory management happens
3142/// inside the DAG rather than in the node.
3143class MachineSDNode : public SDNode {
3144private:
3145 friend class SelectionDAG;
3146
3147 MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL, SDVTList VTs)
3148 : SDNode(Opc, Order, DL, VTs) {}
3149
3150 // We use a pointer union between a single `MachineMemOperand` pointer and
3151 // a pointer to an array of `MachineMemOperand` pointers. This is null when
3152 // the number of these is zero, the single pointer variant used when the
3153 // number is one, and the array is used for larger numbers.
3154 //
3155 // The array is allocated via the `SelectionDAG`'s allocator and so will
3156 // always live until the DAG is cleaned up and doesn't require ownership here.
3157 //
3158 // We can't use something simpler like `TinyPtrVector` here because `SDNode`
3159 // subclasses aren't managed in a conforming C++ manner. See the comments on
3160 // `SelectionDAG::MorphNodeTo` which details what all goes on, but the
3161 // constraint here is that these don't manage memory with their constructor or
3162 // destructor and can be initialized to a good state even if they start off
3163 // uninitialized.
3165
3166 // Note that this could be folded into the above `MemRefs` member if doing so
3167 // is advantageous at some point. We don't need to store this in most cases.
3168 // However, at the moment this doesn't appear to make the allocation any
3169 // smaller and makes the code somewhat simpler to read.
3170 int NumMemRefs = 0;
3171
3172public:
3174
3176 // Special case the common cases.
3177 if (NumMemRefs == 0)
3178 return {};
3179 if (NumMemRefs == 1)
3180 return ArrayRef(MemRefs.getAddrOfPtr1(), 1);
3181
3182 // Otherwise we have an actual array.
3183 return ArrayRef(cast<MachineMemOperand **>(MemRefs), NumMemRefs);
3184 }
3185 mmo_iterator memoperands_begin() const { return memoperands().begin(); }
3186 mmo_iterator memoperands_end() const { return memoperands().end(); }
3187 bool memoperands_empty() const { return memoperands().empty(); }
3188
3189 /// Clear out the memory reference descriptor list.
3191 MemRefs = nullptr;
3192 NumMemRefs = 0;
3193 }
3194
3195 static bool classof(const SDNode *N) {
3196 return N->isMachineOpcode();
3197 }
3198};
3199
3200/// An SDNode that records if a register contains a value that is guaranteed to
3201/// be aligned accordingly.
3203 Align Alignment;
3204
3205public:
3206 AssertAlignSDNode(unsigned Order, const DebugLoc &DL, SDVTList VTs, Align A)
3207 : SDNode(ISD::AssertAlign, Order, DL, VTs), Alignment(A) {}
3208
3209 Align getAlign() const { return Alignment; }
3210
3211 static bool classof(const SDNode *N) {
3212 return N->getOpcode() == ISD::AssertAlign;
3213 }
3214};
3215
3217 const SDNode *Node;
3218 unsigned Operand;
3219
3220 SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
3221
3222public:
3223 using iterator_category = std::forward_iterator_tag;
3225 using difference_type = std::ptrdiff_t;
3228
3229 bool operator==(const SDNodeIterator& x) const {
3230 return Operand == x.Operand;
3231 }
3232 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
3233
3235 return Node->getOperand(Operand).getNode();
3236 }
3237 pointer operator->() const { return operator*(); }
3238
3239 SDNodeIterator& operator++() { // Preincrement
3240 ++Operand;
3241 return *this;
3242 }
3243 SDNodeIterator operator++(int) { // Postincrement
3244 SDNodeIterator tmp = *this; ++*this; return tmp;
3245 }
3247 assert(Node == Other.Node &&
3248 "Cannot compare iterators of two different nodes!");
3249 return Operand - Other.Operand;
3250 }
3251
3252 static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
3253 static SDNodeIterator end (const SDNode *N) {
3254 return SDNodeIterator(N, N->getNumOperands());
3255 }
3256
3257 unsigned getOperand() const { return Operand; }
3258 const SDNode *getNode() const { return Node; }
3259};
3260
3261template <> struct GraphTraits<SDNode*> {
3262 using NodeRef = SDNode *;
3264
3265 static NodeRef getEntryNode(SDNode *N) { return N; }
3266
3268 return SDNodeIterator::begin(N);
3269 }
3270
3272 return SDNodeIterator::end(N);
3273 }
3274};
3275
3276/// A representation of the largest SDNode, for use in sizeof().
3277///
3278/// This needs to be a union because the largest node differs on 32 bit systems
3279/// with 4 and 8 byte pointer alignment, respectively.
3284
3285/// The SDNode class with the greatest alignment requirement.
3287
3288namespace ISD {
3289
3290 /// Returns true if the specified node is a non-extending and unindexed load.
3291 inline bool isNormalLoad(const SDNode *N) {
3292 auto *Ld = dyn_cast<LoadSDNode>(N);
3293 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
3294 Ld->getAddressingMode() == ISD::UNINDEXED;
3295 }
3296
3297 /// Returns true if the specified node is a non-extending load.
3298 inline bool isNON_EXTLoad(const SDNode *N) {
3299 auto *Ld = dyn_cast<LoadSDNode>(N);
3300 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD;
3301 }
3302
3303 /// Returns true if the specified node is a EXTLOAD.
3304 inline bool isEXTLoad(const SDNode *N) {
3305 auto *Ld = dyn_cast<LoadSDNode>(N);
3306 return Ld && Ld->getExtensionType() == ISD::EXTLOAD;
3307 }
3308
3309 /// Returns true if the specified node is a SEXTLOAD.
3310 inline bool isSEXTLoad(const SDNode *N) {
3311 auto *Ld = dyn_cast<LoadSDNode>(N);
3312 return Ld && Ld->getExtensionType() == ISD::SEXTLOAD;
3313 }
3314
3315 /// Returns true if the specified node is a ZEXTLOAD.
3316 inline bool isZEXTLoad(const SDNode *N) {
3317 auto *Ld = dyn_cast<LoadSDNode>(N);
3318 return Ld && Ld->getExtensionType() == ISD::ZEXTLOAD;
3319 }
3320
3321 /// Returns true if the specified node is an unindexed load.
3322 inline bool isUNINDEXEDLoad(const SDNode *N) {
3323 auto *Ld = dyn_cast<LoadSDNode>(N);
3324 return Ld && Ld->getAddressingMode() == ISD::UNINDEXED;
3325 }
3326
3327 /// Returns true if the specified node is a non-truncating
3328 /// and unindexed store.
3329 inline bool isNormalStore(const SDNode *N) {
3330 auto *St = dyn_cast<StoreSDNode>(N);
3331 return St && !St->isTruncatingStore() &&
3332 St->getAddressingMode() == ISD::UNINDEXED;
3333 }
3334
3335 /// Returns true if the specified node is an unindexed store.
3336 inline bool isUNINDEXEDStore(const SDNode *N) {
3337 auto *St = dyn_cast<StoreSDNode>(N);
3338 return St && St->getAddressingMode() == ISD::UNINDEXED;
3339 }
3340
3341 /// Attempt to match a unary predicate against a scalar/splat constant or
3342 /// every element of a constant BUILD_VECTOR.
3343 /// If AllowUndef is true, then UNDEF elements will pass nullptr to Match.
3344 template <typename ConstNodeType>
3346 std::function<bool(ConstNodeType *)> Match,
3347 bool AllowUndefs = false,
3348 bool AllowTruncation = false);
3349
3350 /// Hook for matching ConstantSDNode predicate
3352 std::function<bool(ConstantSDNode *)> Match,
3353 bool AllowUndefs = false,
3354 bool AllowTruncation = false) {
3355 return matchUnaryPredicateImpl<ConstantSDNode>(Op, Match, AllowUndefs,
3356 AllowTruncation);
3357 }
3358
3359 /// Hook for matching ConstantFPSDNode predicate
3360 inline bool
3362 std::function<bool(ConstantFPSDNode *)> Match,
3363 bool AllowUndefs = false) {
3364 return matchUnaryPredicateImpl<ConstantFPSDNode>(Op, Match, AllowUndefs);
3365 }
3366
3367 /// Attempt to match a binary predicate against a pair of scalar/splat
3368 /// constants or every element of a pair of constant BUILD_VECTORs.
3369 /// If AllowUndef is true, then UNDEF elements will pass nullptr to Match.
3370 /// If AllowTypeMismatch is true then RetType + ArgTypes don't need to match.
3373 std::function<bool(ConstantSDNode *, ConstantSDNode *)> Match,
3374 bool AllowUndefs = false, bool AllowTypeMismatch = false);
3375
3376 /// Returns true if the specified value is the overflow result from one
3377 /// of the overflow intrinsic nodes.
3379 unsigned Opc = Op.getOpcode();
3380 return (Op.getResNo() == 1 &&
3381 (Opc == ISD::SADDO || Opc == ISD::UADDO || Opc == ISD::SSUBO ||
3382 Opc == ISD::USUBO || Opc == ISD::SMULO || Opc == ISD::UMULO));
3383 }
3384
3385} // end namespace ISD
3386
3387} // end namespace llvm
3388
3389#endif // LLVM_CODEGEN_SELECTIONDAGNODES_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
static msgpack::DocNode getNode(msgpack::DocNode DN, msgpack::Type Type, MCValue Val)
AMDGPU Kernel Attributes
This file declares a class to represent arbitrary precision floating point values and provide a varie...
MachineBasicBlock & MBB
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 GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
RelocType Type
Definition: COFFYAML.cpp:410
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...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
uint32_t Index
uint64_t Offset
Definition: ELF_riscv.cpp:478
Symbol * Sym
Definition: ELF_riscv.cpp:479
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
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:58
#define G(x, y, z)
Definition: MD5.cpp:56
Load MIR Sample Profile
Register Reg
This file contains the declarations for metadata subclasses.
const SmallVectorImpl< MachineOperand > & Cond
raw_pwrite_stream & OS
#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.
Value * RHS
Value * LHS
DEMANGLE_DUMP_METHOD void dump() const
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:41
An SDNode that records if a register contains a value that is guaranteed to be aligned accordingly.
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)
unsigned getTargetFlags() const
const BlockAddress * getBlockAddress() const
The address of a basic block.
Definition: Constants.h:899
A "pseudo-class" with methods for operating on BUILD_VECTORs.
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 std::optional< std::pair< APInt, APInt > > isConstantSequence() const
If this BuildVector is constant and represents the numerical series "<a, a+n, a+2n,...
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 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:277
This is the shared class of boolean and integer constants.
Definition: Constants.h:87
static bool classof(const SDNode *N)
MachineConstantPoolValue * getMachineCPVal() const
bool isMachineConstantPoolEntry() const
MachineConstantPoolValue * MachineCPVal
const Constant * getConstVal() const
LLVM_ABI Type * getType() const
unsigned getTargetFlags() 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
This class represents an Operation in the Expression.
A debug info location.
Definition: DebugLoc.h:124
bool hasTrivialDestructor() const
Check whether this has a trivial destructor.
Definition: DebugLoc.h:244
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)
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:22
Node - This class is used to maintain the singly linked bucket list in a folding set.
Definition: FoldingSet.h:139
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:330
static bool classof(const SDNode *N)
LLVM_ABI unsigned getAddressSpace() const
static bool classof(const SDNode *N)
const GlobalValue * getGlobal() const
This class is used to form a handle around another node that is persistent and is updated across invo...
const SDValue & getValue() const
static bool classof(const SDNode *N)
unsigned getTargetFlags() const
Base class for LoadSDNode and StoreSDNode.
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)
This SDNode is used for LIFETIME_START/LIFETIME_END values.
int64_t getFrameIndex() const
static bool classof(const SDNode *N)
This class is used to represent ISD::LOAD nodes.
const SDValue & getBasePtr() const
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:1077
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.
void clearRanges()
Unset the tracked range metadata.
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,...
LLVM_ABI void refineAlignment(const MachineMemOperand *MMO)
Update this MachineMemOperand to reflect the alignment of MMO, if it has a greater alignment.
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.
An SDNode that represents everything that will be needed to construct a MachineInstr.
ArrayRef< MachineMemOperand * > memoperands() const
bool memoperands_empty() const
void clearMemRefs()
Clear out the memory reference descriptor list.
mmo_iterator memoperands_begin() const
static bool classof(const SDNode *N)
mmo_iterator memoperands_end() const
This class is used to represent an MGATHER node.
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
This is a base class used to represent MGATHER and MSCATTER nodes.
const SDValue & getIndex() const
const SDValue & getScale() 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
const SDValue & getMask() 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
This class is used to represent an MLOAD node.
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
This base class is used to represent MLOAD and MSTORE nodes.
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,...
This class is used to represent an MSCATTER node.
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.
This class is used to represent an MSTORE node.
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)
This SDNode is used for target intrinsics that touch memory and need an associated MachineMemOperand.
MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemoryVT, MachineMemOperand *MMO)
static bool classof(const SDNode *N)
This is an abstract virtual class for memory operations.
MachineMemOperand * MMO
Memory reference information.
unsigned getAddressSpace() const
Return the address space for the associated pointer.
Align getBaseAlign() const
Returns alignment and volatility of the memory access.
const MDNode * getRanges() const
Returns the Ranges that describes the dereference.
void refineRanges(const MachineMemOperand *NewMMO)
Align getAlign() const
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 readMem() const
bool isSimple() const
Returns true if the memory operation is neither atomic or volatile.
AtomicOrdering getSuccessOrdering() const
Return the atomic ordering requirements for this memory operation.
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
const SDValue & getBasePtr() const
void refineAlignment(const MachineMemOperand *NewMMO)
Update this MemSDNode's MachineMemOperand information to reflect the alignment of NewMMO,...
const MachinePointerInfo & getPointerInfo() const
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 writeMem() 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)
unsigned getRawSubclassData() const
Return the SubclassData value, without HasDebugValue.
EVT getMemoryVT() const
Return the type of the in-memory value.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:303
First const * getAddrOfPtr1() const
If the union is set to the first pointer type get an address pointing to it.
Definition: PointerUnion.h:174
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)
uint32_t getAttributes() const
const uint32_t * getRegMask() const
static bool classof(const SDNode *N)
static bool classof(const SDNode *N)
Register getReg() const
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
const DebugLoc & getDebugLoc() const
unsigned getIROrder() const
SDLoc(const SDValue V)
SDLoc()=default
SDLoc(const SDNode *N)
SDLoc(const Instruction *I, int Order)
pointer operator->() const
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
pointer operator*() 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.
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
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.
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().
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().
bool operator!=(const SDValue &V) const
Convenience function for get().operator!=.
SDUse()=default
SDUse(const SDUse &U)=delete
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
void dump() 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
void dumpr() const
unsigned getNumOperands() const
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:229
This SDNode is used to implement the code generator support for the llvm IR shufflevector instruction...
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...
Definition: SmallPtrSet.h:380
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:470
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:401
bool empty() const
Definition: SmallVector.h:82
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:684
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
An SDNode that holds an arbitrary LLVM IR Value.
const Value * getValue() const
Return the contained Value.
static bool classof(const SDNode *N)
This class is used to represent ISD::STORE nodes.
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
This base class is used to represent VP_LOAD, VP_STORE, EXPERIMENTAL_VP_STRIDED_LOAD and EXPERIMENTAL...
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
This class is used to represent an VP_GATHER node.
VPGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexType IndexType)
static bool classof(const SDNode *N)
This is a base class used to represent VP_GATHER and VP_SCATTER nodes.
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
This class is used to represent a VP_LOAD node.
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)
bool isExpandingLoad() const
This class is used to represent an VP_SCATTER node.
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
This class is used to represent a VP_STORE node.
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
This class is used to represent an EXPERIMENTAL_VP_STRIDED_LOAD node.
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)
This class is used to represent an EXPERIMENTAL_VP_STRIDED_STORE node.
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.
This class is used to represent EVT's, which are used to parameterize some operations.
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
CRTP base class for adapting an iterator to a different type.
Definition: iterator.h:237
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.
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 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:184
@ MDNODE_SDNODE
MDNODE_SDNODE - This is a node that holdes an MDNode*, which is used to reference metadata in the IR.
Definition: ISDOpcodes.h:1281
@ ATOMIC_LOAD_FMAX
Definition: ISDOpcodes.h:1386
@ POISON
POISON - A poison node.
Definition: ISDOpcodes.h:231
@ MLOAD
Masked load and store - consecutive vector load and store operations with additional mask operand tha...
Definition: ISDOpcodes.h:1401
@ ATOMIC_LOAD_NAND
Definition: ISDOpcodes.h:1379
@ TargetBlockAddress
Definition: ISDOpcodes.h:186
@ ConstantFP
Definition: ISDOpcodes.h:87
@ ATOMIC_LOAD_MAX
Definition: ISDOpcodes.h:1381
@ ATOMIC_STORE
OUTCHAIN = ATOMIC_STORE(INCHAIN, val, ptr) This corresponds to "store atomic" instruction.
Definition: ISDOpcodes.h:1351
@ ATOMIC_LOAD_UMIN
Definition: ISDOpcodes.h:1382
@ ADD
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:259
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition: ISDOpcodes.h:1141
@ ATOMIC_LOAD_USUB_COND
Definition: ISDOpcodes.h:1392
@ GlobalAddress
Definition: ISDOpcodes.h:88
@ ATOMIC_CMP_SWAP_WITH_SUCCESS
Val, Success, OUTCHAIN = ATOMIC_CMP_SWAP_WITH_SUCCESS(INCHAIN, ptr, cmp, swap) N.b.
Definition: ISDOpcodes.h:1364
@ ATOMIC_LOAD_OR
Definition: ISDOpcodes.h:1377
@ ATOMIC_LOAD_XOR
Definition: ISDOpcodes.h:1378
@ BUILTIN_OP_END
BUILTIN_OP_END - This must be the last enum value in this list.
Definition: ISDOpcodes.h:1568
@ ATOMIC_LOAD_FADD
Definition: ISDOpcodes.h:1384
@ 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...
Definition: ISDOpcodes.h:1277
@ FrameIndex
Definition: ISDOpcodes.h:90
@ EH_LABEL
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
Definition: ISDOpcodes.h:1212
@ ATOMIC_LOAD_USUB_SAT
Definition: ISDOpcodes.h:1393
@ ANNOTATION_LABEL
ANNOTATION_LABEL - Represents a mid basic block label used by annotations.
Definition: ISDOpcodes.h:1218
@ TargetExternalSymbol
Definition: ISDOpcodes.h:185
@ TargetJumpTable
Definition: ISDOpcodes.h:183
@ TargetIndex
TargetIndex - Like a constant pool entry, but with completely target-dependent semantics.
Definition: ISDOpcodes.h:193
@ ATOMIC_LOAD_FSUB
Definition: ISDOpcodes.h:1385
@ SSUBO
Same for subtraction.
Definition: ISDOpcodes.h:347
@ ATOMIC_LOAD_MIN
Definition: ISDOpcodes.h:1380
@ ATOMIC_LOAD
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
Definition: ISDOpcodes.h:1347
@ UNDEF
UNDEF - An undefined node.
Definition: ISDOpcodes.h:228
@ RegisterMask
Definition: ISDOpcodes.h:85
@ AssertAlign
AssertAlign - These nodes record if a register contains a value that has a known alignment and the tr...
Definition: ISDOpcodes.h:69
@ ATOMIC_LOAD_FMIN
Definition: ISDOpcodes.h:1387
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:81
@ SADDO
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
Definition: ISDOpcodes.h:343
@ TargetGlobalAddress
TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or anything else with this node...
Definition: ISDOpcodes.h:180
@ STRICT_FP_TO_FP16
Definition: ISDOpcodes.h:988
@ ATOMIC_LOAD_FMAXIMUM
Definition: ISDOpcodes.h:1388
@ STRICT_FP16_TO_FP
Definition: ISDOpcodes.h:987
@ ATOMIC_LOAD_CLR
Definition: ISDOpcodes.h:1376
@ 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:636
@ ATOMIC_LOAD_AND
Definition: ISDOpcodes.h:1375
@ TargetConstantFP
Definition: ISDOpcodes.h:175
@ ATOMIC_CMP_SWAP
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo,...
Definition: ISDOpcodes.h:1358
@ ATOMIC_LOAD_UMAX
Definition: ISDOpcodes.h:1383
@ SMULO
Same for multiplication.
Definition: ISDOpcodes.h:351
@ ATOMIC_LOAD_FMINIMUM
Definition: ISDOpcodes.h:1389
@ TargetFrameIndex
Definition: ISDOpcodes.h:182
@ ConstantPool
Definition: ISDOpcodes.h:92
@ LIFETIME_START
This corresponds to the llvm.lifetime.
Definition: ISDOpcodes.h:1418
@ MGATHER
Masked gather and scatter - load and store operations for a vector of random addresses with additiona...
Definition: ISDOpcodes.h:1413
@ STRICT_BF16_TO_FP
Definition: ISDOpcodes.h:996
@ ATOMIC_LOAD_UDEC_WRAP
Definition: ISDOpcodes.h:1391
@ ATOMIC_LOAD_ADD
Definition: ISDOpcodes.h:1373
@ ATOMIC_LOAD_SUB
Definition: ISDOpcodes.h:1374
@ TargetConstant
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification,...
Definition: ISDOpcodes.h:174
@ GET_FPENV_MEM
Gets the current floating-point environment.
Definition: ISDOpcodes.h:1117
@ PSEUDO_PROBE
Pseudo probe for AutoFDO, as a place holder in a basic block to improve the sample counts quality.
Definition: ISDOpcodes.h:1443
@ STRICT_FP_TO_BF16
Definition: ISDOpcodes.h:997
@ 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,...
Definition: ISDOpcodes.h:1372
@ ExternalSymbol
Definition: ISDOpcodes.h:93
@ ADDRSPACECAST
ADDRSPACECAST - This operator converts between pointers of different address spaces.
Definition: ISDOpcodes.h:979
@ EXPERIMENTAL_VECTOR_HISTOGRAM
Definition: ISDOpcodes.h:1546
@ BlockAddress
Definition: ISDOpcodes.h:94
@ 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
Definition: ISDOpcodes.h:1390
@ AssertZext
Definition: ISDOpcodes.h:63
@ SET_FPENV_MEM
Sets the current floating point environment.
Definition: ISDOpcodes.h:1122
@ TargetGlobalTLSAddress
Definition: ISDOpcodes.h:181
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
Definition: ISDOpcodes.h:543
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...
Definition: ISDOpcodes.h:1647
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.
Definition: ISDOpcodes.h:1634
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,...
Definition: ISDOpcodes.h:1685
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).
Definition: ISDOpcodes.h:1665
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: AddressRanges.h:18
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
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:1605
APInt operator&(APInt a, const APInt &b)
Definition: APInt.h:2123
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.
bool isIntOrFPConstant(SDValue V)
Return true if V is either a integer or FP constant.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ABI bool 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:1587
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 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.
bool hasSingleElement(ContainerTy &&C)
Returns true if the given container only contains a single element.
Definition: STLExtras.h:322
LLVM_ABI SDValue peekThroughOneUseBitcasts(SDValue V)
Return the non-bitcasted and one-use source operand of V if it exists.
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.
LLVM_ABI bool isNullConstantOrUndef(SDValue V)
Returns true if V is a constant integer zero or an UNDEF node.
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
Definition: BitmaskEnum.h:223
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:1886
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.
APInt operator|(APInt a, const APInt &b)
Definition: APInt.h:2143
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:856
#define N
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:760
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...
Definition: DenseMapInfo.h:54
Extended Value Type.
Definition: ValueTypes.h:35
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:368
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:311
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
Definition: ValueTypes.h:376
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Definition: ValueTypes.h:318
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:331
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:117
These are IR-level optimization flags that may be propagated to SDNodes.
void setSameSign(bool b)
void copyFMF(const FPMathOperator &FPMO)
Propagate the fast-math-flags from an IR FPMathOperator.
bool hasNoInfs() const
void setNoFPExcept(bool b)
void setDisjoint(bool b)
void setAllowContract(bool b)
void setNoSignedZeros(bool b)
bool hasNoFPExcept() const
bool operator==(const SDNodeFlags &Other) const
void setNoNaNs(bool b)
void operator&=(const SDNodeFlags &OtherFlags)
void operator|=(const SDNodeFlags &OtherFlags)
bool hasNoUnsignedWrap() const
void setAllowReassociation(bool b)
bool hasNoNaNs() const
void setUnpredictable(bool b)
void setNoInfs(bool b)
void setAllowReciprocal(bool b)
bool hasAllowContract() const
bool hasNoSignedZeros() const
bool hasDisjoint() const
bool hasApproximateFuncs() const
bool hasUnpredictable() const
void setApproximateFuncs(bool b)
bool hasNoSignedWrap() const
bool hasSameSign() const
void setNonNeg(bool b)
SDNodeFlags(unsigned Flags=SDNodeFlags::None)
Default constructor turns off all optimization flags.
bool hasAllowReciprocal() const
bool hasNonNeg() 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