LLVM  9.0.0svn
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"
25 #include "llvm/ADT/GraphTraits.h"
26 #include "llvm/ADT/SmallPtrSet.h"
27 #include "llvm/ADT/SmallVector.h"
28 #include "llvm/ADT/ilist_node.h"
29 #include "llvm/ADT/iterator.h"
34 #include "llvm/IR/Constants.h"
35 #include "llvm/IR/DebugLoc.h"
36 #include "llvm/IR/Instruction.h"
37 #include "llvm/IR/Instructions.h"
38 #include "llvm/IR/Metadata.h"
39 #include "llvm/IR/Operator.h"
40 #include "llvm/Support/AlignOf.h"
42 #include "llvm/Support/Casting.h"
45 #include <algorithm>
46 #include <cassert>
47 #include <climits>
48 #include <cstddef>
49 #include <cstdint>
50 #include <cstring>
51 #include <iterator>
52 #include <string>
53 #include <tuple>
54 
55 namespace llvm {
56 
57 class APInt;
58 class Constant;
59 template <typename T> struct DenseMapInfo;
60 class GlobalValue;
61 class MachineBasicBlock;
62 class MachineConstantPoolValue;
63 class MCSymbol;
64 class raw_ostream;
65 class SDNode;
66 class SelectionDAG;
67 class Type;
68 class Value;
69 
70 void checkForCycles(const SDNode *N, const SelectionDAG *DAG = nullptr,
71  bool force = false);
72 
73 /// This represents a list of ValueType's that has been intern'd by
74 /// a SelectionDAG. Instances of this simple value class are returned by
75 /// SelectionDAG::getVTList(...).
76 ///
77 struct SDVTList {
78  const EVT *VTs;
79  unsigned int NumVTs;
80 };
81 
82 namespace ISD {
83 
84  /// Node predicates
85 
86  /// If N is a BUILD_VECTOR node whose elements are all the same constant or
87  /// undefined, return true and return the constant value in \p SplatValue.
88  bool isConstantSplatVector(const SDNode *N, APInt &SplatValue);
89 
90  /// Return true if the specified node is a BUILD_VECTOR where all of the
91  /// elements are ~0 or undef.
92  bool isBuildVectorAllOnes(const SDNode *N);
93 
94  /// Return true if the specified node is a BUILD_VECTOR where all of the
95  /// elements are 0 or undef.
96  bool isBuildVectorAllZeros(const SDNode *N);
97 
98  /// Return true if the specified node is a BUILD_VECTOR node of all
99  /// ConstantSDNode or undef.
100  bool isBuildVectorOfConstantSDNodes(const SDNode *N);
101 
102  /// Return true if the specified node is a BUILD_VECTOR node of all
103  /// ConstantFPSDNode or undef.
105 
106  /// Return true if the node has at least one operand and all operands of the
107  /// specified node are ISD::UNDEF.
108  bool allOperandsUndef(const SDNode *N);
109 
110 } // end namespace ISD
111 
112 //===----------------------------------------------------------------------===//
113 /// Unlike LLVM values, Selection DAG nodes may return multiple
114 /// values as the result of a computation. Many nodes return multiple values,
115 /// from loads (which define a token and a return value) to ADDC (which returns
116 /// a result and a carry value), to calls (which may return an arbitrary number
117 /// of values).
118 ///
119 /// As such, each use of a SelectionDAG computation must indicate the node that
120 /// computes it as well as which return value to use from that node. This pair
121 /// of information is represented with the SDValue value type.
122 ///
123 class SDValue {
124  friend struct DenseMapInfo<SDValue>;
125 
126  SDNode *Node = nullptr; // The node defining the value we are using.
127  unsigned ResNo = 0; // Which return value of the node we are using.
128 
129 public:
130  SDValue() = default;
131  SDValue(SDNode *node, unsigned resno);
132 
133  /// get the index which selects a specific result in the SDNode
134  unsigned getResNo() const { return ResNo; }
135 
136  /// get the SDNode which holds the desired result
137  SDNode *getNode() const { return Node; }
138 
139  /// set the SDNode
140  void setNode(SDNode *N) { Node = N; }
141 
142  inline SDNode *operator->() const { return Node; }
143 
144  bool operator==(const SDValue &O) const {
145  return Node == O.Node && ResNo == O.ResNo;
146  }
147  bool operator!=(const SDValue &O) const {
148  return !operator==(O);
149  }
150  bool operator<(const SDValue &O) const {
151  return std::tie(Node, ResNo) < std::tie(O.Node, O.ResNo);
152  }
153  explicit operator bool() const {
154  return Node != nullptr;
155  }
156 
157  SDValue getValue(unsigned R) const {
158  return SDValue(Node, R);
159  }
160 
161  /// Return true if this node is an operand of N.
162  bool isOperandOf(const SDNode *N) const;
163 
164  /// Return the ValueType of the referenced return value.
165  inline EVT getValueType() const;
166 
167  /// Return the simple ValueType of the referenced return value.
169  return getValueType().getSimpleVT();
170  }
171 
172  /// Returns the size of the value in bits.
173  unsigned getValueSizeInBits() const {
174  return getValueType().getSizeInBits();
175  }
176 
177  unsigned getScalarValueSizeInBits() const {
178  return getValueType().getScalarType().getSizeInBits();
179  }
180 
181  // Forwarding methods - These forward to the corresponding methods in SDNode.
182  inline unsigned getOpcode() const;
183  inline unsigned getNumOperands() const;
184  inline const SDValue &getOperand(unsigned i) const;
185  inline uint64_t getConstantOperandVal(unsigned i) const;
186  inline const APInt &getConstantOperandAPInt(unsigned i) const;
187  inline bool isTargetMemoryOpcode() const;
188  inline bool isTargetOpcode() const;
189  inline bool isMachineOpcode() const;
190  inline bool isUndef() const;
191  inline unsigned getMachineOpcode() const;
192  inline const DebugLoc &getDebugLoc() const;
193  inline void dump() const;
194  inline void dump(const SelectionDAG *G) const;
195  inline void dumpr() const;
196  inline void dumpr(const SelectionDAG *G) const;
197 
198  /// Return true if this operand (which must be a chain) reaches the
199  /// specified operand without crossing any side-effecting instructions.
200  /// In practice, this looks through token factors and non-volatile loads.
201  /// In order to remain efficient, this only
202  /// looks a couple of nodes in, it does not do an exhaustive search.
203  bool reachesChainWithoutSideEffects(SDValue Dest,
204  unsigned Depth = 2) const;
205 
206  /// Return true if there are no nodes using value ResNo of Node.
207  inline bool use_empty() const;
208 
209  /// Return true if there is exactly one node using value ResNo of Node.
210  inline bool hasOneUse() const;
211 };
212 
213 template<> struct DenseMapInfo<SDValue> {
214  static inline SDValue getEmptyKey() {
215  SDValue V;
216  V.ResNo = -1U;
217  return V;
218  }
219 
220  static inline SDValue getTombstoneKey() {
221  SDValue V;
222  V.ResNo = -2U;
223  return V;
224  }
225 
226  static unsigned getHashValue(const SDValue &Val) {
227  return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
228  (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
229  }
230 
231  static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
232  return LHS == RHS;
233  }
234 };
235 
236 /// Allow casting operators to work directly on
237 /// SDValues as if they were SDNode*'s.
238 template<> struct simplify_type<SDValue> {
239  using SimpleType = SDNode *;
240 
242  return Val.getNode();
243  }
244 };
245 template<> struct simplify_type<const SDValue> {
246  using SimpleType = /*const*/ SDNode *;
247 
248  static SimpleType getSimplifiedValue(const SDValue &Val) {
249  return Val.getNode();
250  }
251 };
252 
253 /// Represents a use of a SDNode. This class holds an SDValue,
254 /// which records the SDNode being used and the result number, a
255 /// pointer to the SDNode using the value, and Next and Prev pointers,
256 /// which link together all the uses of an SDNode.
257 ///
258 class SDUse {
259  /// Val - The value being used.
260  SDValue Val;
261  /// User - The user of this value.
262  SDNode *User = nullptr;
263  /// Prev, Next - Pointers to the uses list of the SDNode referred by
264  /// this operand.
265  SDUse **Prev = nullptr;
266  SDUse *Next = nullptr;
267 
268 public:
269  SDUse() = default;
270  SDUse(const SDUse &U) = delete;
271  SDUse &operator=(const SDUse &) = delete;
272 
273  /// Normally SDUse will just implicitly convert to an SDValue that it holds.
274  operator const SDValue&() const { return Val; }
275 
276  /// If implicit conversion to SDValue doesn't work, the get() method returns
277  /// the SDValue.
278  const SDValue &get() const { return Val; }
279 
280  /// This returns the SDNode that contains this Use.
281  SDNode *getUser() { return User; }
282 
283  /// Get the next SDUse in the use list.
284  SDUse *getNext() const { return Next; }
285 
286  /// Convenience function for get().getNode().
287  SDNode *getNode() const { return Val.getNode(); }
288  /// Convenience function for get().getResNo().
289  unsigned getResNo() const { return Val.getResNo(); }
290  /// Convenience function for get().getValueType().
291  EVT getValueType() const { return Val.getValueType(); }
292 
293  /// Convenience function for get().operator==
294  bool operator==(const SDValue &V) const {
295  return Val == V;
296  }
297 
298  /// Convenience function for get().operator!=
299  bool operator!=(const SDValue &V) const {
300  return Val != V;
301  }
302 
303  /// Convenience function for get().operator<
304  bool operator<(const SDValue &V) const {
305  return Val < V;
306  }
307 
308 private:
309  friend class SelectionDAG;
310  friend class SDNode;
311  // TODO: unfriend HandleSDNode once we fix its operand handling.
312  friend class HandleSDNode;
313 
314  void setUser(SDNode *p) { User = p; }
315 
316  /// Remove this use from its existing use list, assign it the
317  /// given value, and add it to the new value's node's use list.
318  inline void set(const SDValue &V);
319  /// Like set, but only supports initializing a newly-allocated
320  /// SDUse with a non-null value.
321  inline void setInitial(const SDValue &V);
322  /// Like set, but only sets the Node portion of the value,
323  /// leaving the ResNo portion unmodified.
324  inline void setNode(SDNode *N);
325 
326  void addToList(SDUse **List) {
327  Next = *List;
328  if (Next) Next->Prev = &Next;
329  Prev = List;
330  *List = this;
331  }
332 
333  void removeFromList() {
334  *Prev = Next;
335  if (Next) Next->Prev = Prev;
336  }
337 };
338 
339 /// simplify_type specializations - Allow casting operators to work directly on
340 /// SDValues as if they were SDNode*'s.
341 template<> struct simplify_type<SDUse> {
342  using SimpleType = SDNode *;
343 
345  return Val.getNode();
346  }
347 };
348 
349 /// These are IR-level optimization flags that may be propagated to SDNodes.
350 /// TODO: This data structure should be shared by the IR optimizer and the
351 /// the backend.
352 struct SDNodeFlags {
353 private:
354  // This bit is used to determine if the flags are in a defined state.
355  // Flag bits can only be masked out during intersection if the masking flags
356  // are defined.
357  bool AnyDefined : 1;
358 
359  bool NoUnsignedWrap : 1;
360  bool NoSignedWrap : 1;
361  bool Exact : 1;
362  bool NoNaNs : 1;
363  bool NoInfs : 1;
364  bool NoSignedZeros : 1;
365  bool AllowReciprocal : 1;
366  bool VectorReduction : 1;
367  bool AllowContract : 1;
368  bool ApproximateFuncs : 1;
369  bool AllowReassociation : 1;
370 
371 public:
372  /// Default constructor turns off all optimization flags.
374  : AnyDefined(false), NoUnsignedWrap(false), NoSignedWrap(false),
375  Exact(false), NoNaNs(false), NoInfs(false),
376  NoSignedZeros(false), AllowReciprocal(false), VectorReduction(false),
377  AllowContract(false), ApproximateFuncs(false),
378  AllowReassociation(false) {}
379 
380  /// Propagate the fast-math-flags from an IR FPMathOperator.
381  void copyFMF(const FPMathOperator &FPMO) {
382  setNoNaNs(FPMO.hasNoNaNs());
383  setNoInfs(FPMO.hasNoInfs());
384  setNoSignedZeros(FPMO.hasNoSignedZeros());
385  setAllowReciprocal(FPMO.hasAllowReciprocal());
386  setAllowContract(FPMO.hasAllowContract());
387  setApproximateFuncs(FPMO.hasApproxFunc());
388  setAllowReassociation(FPMO.hasAllowReassoc());
389  }
390 
391  /// Sets the state of the flags to the defined state.
392  void setDefined() { AnyDefined = true; }
393  /// Returns true if the flags are in a defined state.
394  bool isDefined() const { return AnyDefined; }
395 
396  // These are mutators for each flag.
397  void setNoUnsignedWrap(bool b) {
398  setDefined();
399  NoUnsignedWrap = b;
400  }
401  void setNoSignedWrap(bool b) {
402  setDefined();
403  NoSignedWrap = b;
404  }
405  void setExact(bool b) {
406  setDefined();
407  Exact = b;
408  }
409  void setNoNaNs(bool b) {
410  setDefined();
411  NoNaNs = b;
412  }
413  void setNoInfs(bool b) {
414  setDefined();
415  NoInfs = b;
416  }
417  void setNoSignedZeros(bool b) {
418  setDefined();
419  NoSignedZeros = b;
420  }
421  void setAllowReciprocal(bool b) {
422  setDefined();
423  AllowReciprocal = b;
424  }
425  void setVectorReduction(bool b) {
426  setDefined();
427  VectorReduction = b;
428  }
429  void setAllowContract(bool b) {
430  setDefined();
431  AllowContract = b;
432  }
433  void setApproximateFuncs(bool b) {
434  setDefined();
435  ApproximateFuncs = b;
436  }
437  void setAllowReassociation(bool b) {
438  setDefined();
439  AllowReassociation = b;
440  }
441 
442  // These are accessors for each flag.
443  bool hasNoUnsignedWrap() const { return NoUnsignedWrap; }
444  bool hasNoSignedWrap() const { return NoSignedWrap; }
445  bool hasExact() const { return Exact; }
446  bool hasNoNaNs() const { return NoNaNs; }
447  bool hasNoInfs() const { return NoInfs; }
448  bool hasNoSignedZeros() const { return NoSignedZeros; }
449  bool hasAllowReciprocal() const { return AllowReciprocal; }
450  bool hasVectorReduction() const { return VectorReduction; }
451  bool hasAllowContract() const { return AllowContract; }
452  bool hasApproximateFuncs() const { return ApproximateFuncs; }
453  bool hasAllowReassociation() const { return AllowReassociation; }
454 
455  bool isFast() const {
456  return NoSignedZeros && AllowReciprocal && NoNaNs && NoInfs &&
457  AllowContract && ApproximateFuncs && AllowReassociation;
458  }
459 
460  /// Clear any flags in this flag set that aren't also set in Flags.
461  /// If the given Flags are undefined then don't do anything.
462  void intersectWith(const SDNodeFlags Flags) {
463  if (!Flags.isDefined())
464  return;
465  NoUnsignedWrap &= Flags.NoUnsignedWrap;
466  NoSignedWrap &= Flags.NoSignedWrap;
467  Exact &= Flags.Exact;
468  NoNaNs &= Flags.NoNaNs;
469  NoInfs &= Flags.NoInfs;
470  NoSignedZeros &= Flags.NoSignedZeros;
471  AllowReciprocal &= Flags.AllowReciprocal;
472  VectorReduction &= Flags.VectorReduction;
473  AllowContract &= Flags.AllowContract;
474  ApproximateFuncs &= Flags.ApproximateFuncs;
475  AllowReassociation &= Flags.AllowReassociation;
476  }
477 };
478 
479 /// Represents one node in the SelectionDAG.
480 ///
481 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
482 private:
483  /// The operation that this node performs.
484  int16_t NodeType;
485 
486 protected:
487  // We define a set of mini-helper classes to help us interpret the bits in our
488  // SubclassData. These are designed to fit within a uint16_t so they pack
489  // with NodeType.
490 
491 #if defined(_AIX) && (!defined(__GNUC__) || defined(__ibmxl__))
492 // Except for GCC; by default, AIX compilers store bit-fields in 4-byte words
493 // and give the `pack` pragma push semantics.
494 #define BEGIN_TWO_BYTE_PACK() _Pragma("pack(2)")
495 #define END_TWO_BYTE_PACK() _Pragma("pack(pop)")
496 #else
497 #define BEGIN_TWO_BYTE_PACK()
498 #define END_TWO_BYTE_PACK()
499 #endif
500 
503  friend class SDNode;
504  friend class MemIntrinsicSDNode;
505  friend class MemSDNode;
506  friend class SelectionDAG;
507 
508  uint16_t HasDebugValue : 1;
509  uint16_t IsMemIntrinsic : 1;
510  uint16_t IsDivergent : 1;
511  };
512  enum { NumSDNodeBits = 3 };
513 
515  friend class ConstantSDNode;
516 
517  uint16_t : NumSDNodeBits;
518 
519  uint16_t IsOpaque : 1;
520  };
521 
523  friend class MemSDNode;
524  friend class MemIntrinsicSDNode;
525  friend class AtomicSDNode;
526 
527  uint16_t : NumSDNodeBits;
528 
529  uint16_t IsVolatile : 1;
530  uint16_t IsNonTemporal : 1;
531  uint16_t IsDereferenceable : 1;
532  uint16_t IsInvariant : 1;
533  };
534  enum { NumMemSDNodeBits = NumSDNodeBits + 4 };
535 
537  friend class LSBaseSDNode;
538 
539  uint16_t : NumMemSDNodeBits;
540 
541  uint16_t AddressingMode : 3; // enum ISD::MemIndexedMode
542  };
543  enum { NumLSBaseSDNodeBits = NumMemSDNodeBits + 3 };
544 
546  friend class LoadSDNode;
547  friend class MaskedLoadSDNode;
548 
549  uint16_t : NumLSBaseSDNodeBits;
550 
551  uint16_t ExtTy : 2; // enum ISD::LoadExtType
552  uint16_t IsExpanding : 1;
553  };
554 
556  friend class StoreSDNode;
557  friend class MaskedStoreSDNode;
558 
559  uint16_t : NumLSBaseSDNodeBits;
560 
561  uint16_t IsTruncating : 1;
562  uint16_t IsCompressing : 1;
563  };
564 
565  union {
566  char RawSDNodeBits[sizeof(uint16_t)];
573  };
575 #undef BEGIN_TWO_BYTE_PACK
576 #undef END_TWO_BYTE_PACK
577 
578  // RawSDNodeBits must cover the entirety of the union. This means that all of
579  // the union's members must have size <= RawSDNodeBits. We write the RHS as
580  // "2" instead of sizeof(RawSDNodeBits) because MSVC can't handle the latter.
581  static_assert(sizeof(SDNodeBitfields) <= 2, "field too wide");
582  static_assert(sizeof(ConstantSDNodeBitfields) <= 2, "field too wide");
583  static_assert(sizeof(MemSDNodeBitfields) <= 2, "field too wide");
584  static_assert(sizeof(LSBaseSDNodeBitfields) <= 2, "field too wide");
585  static_assert(sizeof(LoadSDNodeBitfields) <= 2, "field too wide");
586  static_assert(sizeof(StoreSDNodeBitfields) <= 2, "field too wide");
587 
588 private:
589  friend class SelectionDAG;
590  // TODO: unfriend HandleSDNode once we fix its operand handling.
591  friend class HandleSDNode;
592 
593  /// Unique id per SDNode in the DAG.
594  int NodeId = -1;
595 
596  /// The values that are used by this operation.
597  SDUse *OperandList = nullptr;
598 
599  /// The types of the values this node defines. SDNode's may
600  /// define multiple values simultaneously.
601  const EVT *ValueList;
602 
603  /// List of uses for this SDNode.
604  SDUse *UseList = nullptr;
605 
606  /// The number of entries in the Operand/Value list.
607  unsigned short NumOperands = 0;
608  unsigned short NumValues;
609 
610  // The ordering of the SDNodes. It roughly corresponds to the ordering of the
611  // original LLVM instructions.
612  // This is used for turning off scheduling, because we'll forgo
613  // the normal scheduling algorithms and output the instructions according to
614  // this ordering.
615  unsigned IROrder;
616 
617  /// Source line information.
618  DebugLoc debugLoc;
619 
620  /// Return a pointer to the specified value type.
621  static const EVT *getValueTypeList(EVT VT);
622 
623  SDNodeFlags Flags;
624 
625 public:
626  /// Unique and persistent id per SDNode in the DAG.
627  /// Used for debug printing.
628  uint16_t PersistentId;
629 
630  //===--------------------------------------------------------------------===//
631  // Accessors
632  //
633 
634  /// Return the SelectionDAG opcode value for this node. For
635  /// pre-isel nodes (those for which isMachineOpcode returns false), these
636  /// are the opcode values in the ISD and <target>ISD namespaces. For
637  /// post-isel opcodes, see getMachineOpcode.
638  unsigned getOpcode() const { return (unsigned short)NodeType; }
639 
640  /// Test if this node has a target-specific opcode (in the
641  /// <target>ISD namespace).
642  bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
643 
644  /// Test if this node has a target-specific
645  /// memory-referencing opcode (in the <target>ISD namespace and
646  /// greater than FIRST_TARGET_MEMORY_OPCODE).
647  bool isTargetMemoryOpcode() const {
648  return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
649  }
650 
651  /// Return true if the type of the node type undefined.
652  bool isUndef() const { return NodeType == ISD::UNDEF; }
653 
654  /// Test if this node is a memory intrinsic (with valid pointer information).
655  /// INTRINSIC_W_CHAIN and INTRINSIC_VOID nodes are sometimes created for
656  /// non-memory intrinsics (with chains) that are not really instances of
657  /// MemSDNode. For such nodes, we need some extra state to determine the
658  /// proper classof relationship.
659  bool isMemIntrinsic() const {
660  return (NodeType == ISD::INTRINSIC_W_CHAIN ||
661  NodeType == ISD::INTRINSIC_VOID) &&
662  SDNodeBits.IsMemIntrinsic;
663  }
664 
665  /// Test if this node is a strict floating point pseudo-op.
667  switch (NodeType) {
668  default:
669  return false;
670  case ISD::STRICT_FADD:
671  case ISD::STRICT_FSUB:
672  case ISD::STRICT_FMUL:
673  case ISD::STRICT_FDIV:
674  case ISD::STRICT_FREM:
675  case ISD::STRICT_FMA:
676  case ISD::STRICT_FSQRT:
677  case ISD::STRICT_FPOW:
678  case ISD::STRICT_FPOWI:
679  case ISD::STRICT_FSIN:
680  case ISD::STRICT_FCOS:
681  case ISD::STRICT_FEXP:
682  case ISD::STRICT_FEXP2:
683  case ISD::STRICT_FLOG:
684  case ISD::STRICT_FLOG10:
685  case ISD::STRICT_FLOG2:
686  case ISD::STRICT_FRINT:
688  case ISD::STRICT_FMAXNUM:
689  case ISD::STRICT_FMINNUM:
690  case ISD::STRICT_FCEIL:
691  case ISD::STRICT_FFLOOR:
692  case ISD::STRICT_FROUND:
693  case ISD::STRICT_FTRUNC:
696  return true;
697  }
698  }
699 
700  /// Test if this node has a post-isel opcode, directly
701  /// corresponding to a MachineInstr opcode.
702  bool isMachineOpcode() const { return NodeType < 0; }
703 
704  /// This may only be called if isMachineOpcode returns
705  /// true. It returns the MachineInstr opcode value that the node's opcode
706  /// corresponds to.
707  unsigned getMachineOpcode() const {
708  assert(isMachineOpcode() && "Not a MachineInstr opcode!");
709  return ~NodeType;
710  }
711 
712  bool getHasDebugValue() const { return SDNodeBits.HasDebugValue; }
713  void setHasDebugValue(bool b) { SDNodeBits.HasDebugValue = b; }
714 
715  bool isDivergent() const { return SDNodeBits.IsDivergent; }
716 
717  /// Return true if there are no uses of this node.
718  bool use_empty() const { return UseList == nullptr; }
719 
720  /// Return true if there is exactly one use of this node.
721  bool hasOneUse() const {
722  return !use_empty() && std::next(use_begin()) == use_end();
723  }
724 
725  /// Return the number of uses of this node. This method takes
726  /// time proportional to the number of uses.
727  size_t use_size() const { return std::distance(use_begin(), use_end()); }
728 
729  /// Return the unique node id.
730  int getNodeId() const { return NodeId; }
731 
732  /// Set unique node id.
733  void setNodeId(int Id) { NodeId = Id; }
734 
735  /// Return the node ordering.
736  unsigned getIROrder() const { return IROrder; }
737 
738  /// Set the node ordering.
739  void setIROrder(unsigned Order) { IROrder = Order; }
740 
741  /// Return the source location info.
742  const DebugLoc &getDebugLoc() const { return debugLoc; }
743 
744  /// Set source location info. Try to avoid this, putting
745  /// it in the constructor is preferable.
746  void setDebugLoc(DebugLoc dl) { debugLoc = std::move(dl); }
747 
748  /// This class provides iterator support for SDUse
749  /// operands that use a specific SDNode.
751  : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
752  friend class SDNode;
753 
754  SDUse *Op = nullptr;
755 
756  explicit use_iterator(SDUse *op) : Op(op) {}
757 
758  public:
759  using reference = std::iterator<std::forward_iterator_tag,
761  using pointer = std::iterator<std::forward_iterator_tag,
763 
764  use_iterator() = default;
765  use_iterator(const use_iterator &I) : Op(I.Op) {}
766 
767  bool operator==(const use_iterator &x) const {
768  return Op == x.Op;
769  }
770  bool operator!=(const use_iterator &x) const {
771  return !operator==(x);
772  }
773 
774  /// Return true if this iterator is at the end of uses list.
775  bool atEnd() const { return Op == nullptr; }
776 
777  // Iterator traversal: forward iteration only.
778  use_iterator &operator++() { // Preincrement
779  assert(Op && "Cannot increment end iterator!");
780  Op = Op->getNext();
781  return *this;
782  }
783 
784  use_iterator operator++(int) { // Postincrement
785  use_iterator tmp = *this; ++*this; return tmp;
786  }
787 
788  /// Retrieve a pointer to the current user node.
789  SDNode *operator*() const {
790  assert(Op && "Cannot dereference end iterator!");
791  return Op->getUser();
792  }
793 
794  SDNode *operator->() const { return operator*(); }
795 
796  SDUse &getUse() const { return *Op; }
797 
798  /// Retrieve the operand # of this use in its user.
799  unsigned getOperandNo() const {
800  assert(Op && "Cannot dereference end iterator!");
801  return (unsigned)(Op - Op->getUser()->OperandList);
802  }
803  };
804 
805  /// Provide iteration support to walk over all uses of an SDNode.
807  return use_iterator(UseList);
808  }
809 
810  static use_iterator use_end() { return use_iterator(nullptr); }
811 
813  return make_range(use_begin(), use_end());
814  }
816  return make_range(use_begin(), use_end());
817  }
818 
819  /// Return true if there are exactly NUSES uses of the indicated value.
820  /// This method ignores uses of other values defined by this operation.
821  bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
822 
823  /// Return true if there are any use of the indicated value.
824  /// This method ignores uses of other values defined by this operation.
825  bool hasAnyUseOfValue(unsigned Value) const;
826 
827  /// Return true if this node is the only use of N.
828  bool isOnlyUserOf(const SDNode *N) const;
829 
830  /// Return true if this node is an operand of N.
831  bool isOperandOf(const SDNode *N) const;
832 
833  /// Return true if this node is a predecessor of N.
834  /// NOTE: Implemented on top of hasPredecessor and every bit as
835  /// expensive. Use carefully.
836  bool isPredecessorOf(const SDNode *N) const {
837  return N->hasPredecessor(this);
838  }
839 
840  /// Return true if N is a predecessor of this node.
841  /// N is either an operand of this node, or can be reached by recursively
842  /// traversing up the operands.
843  /// NOTE: This is an expensive method. Use it carefully.
844  bool hasPredecessor(const SDNode *N) const;
845 
846  /// Returns true if N is a predecessor of any node in Worklist. This
847  /// helper keeps Visited and Worklist sets externally to allow unions
848  /// searches to be performed in parallel, caching of results across
849  /// queries and incremental addition to Worklist. Stops early if N is
850  /// found but will resume. Remember to clear Visited and Worklists
851  /// if DAG changes. MaxSteps gives a maximum number of nodes to visit before
852  /// giving up. The TopologicalPrune flag signals that positive NodeIds are
853  /// topologically ordered (Operands have strictly smaller node id) and search
854  /// can be pruned leveraging this.
855  static bool hasPredecessorHelper(const SDNode *N,
858  unsigned int MaxSteps = 0,
859  bool TopologicalPrune = false) {
860  SmallVector<const SDNode *, 8> DeferredNodes;
861  if (Visited.count(N))
862  return true;
863 
864  // Node Id's are assigned in three places: As a topological
865  // ordering (> 0), during legalization (results in values set to
866  // 0), new nodes (set to -1). If N has a topolgical id then we
867  // know that all nodes with ids smaller than it cannot be
868  // successors and we need not check them. Filter out all node
869  // that can't be matches. We add them to the worklist before exit
870  // in case of multiple calls. Note that during selection the topological id
871  // may be violated if a node's predecessor is selected before it. We mark
872  // this at selection negating the id of unselected successors and
873  // restricting topological pruning to positive ids.
874 
875  int NId = N->getNodeId();
876  // If we Invalidated the Id, reconstruct original NId.
877  if (NId < -1)
878  NId = -(NId + 1);
879 
880  bool Found = false;
881  while (!Worklist.empty()) {
882  const SDNode *M = Worklist.pop_back_val();
883  int MId = M->getNodeId();
884  if (TopologicalPrune && M->getOpcode() != ISD::TokenFactor && (NId > 0) &&
885  (MId > 0) && (MId < NId)) {
886  DeferredNodes.push_back(M);
887  continue;
888  }
889  for (const SDValue &OpV : M->op_values()) {
890  SDNode *Op = OpV.getNode();
891  if (Visited.insert(Op).second)
892  Worklist.push_back(Op);
893  if (Op == N)
894  Found = true;
895  }
896  if (Found)
897  break;
898  if (MaxSteps != 0 && Visited.size() >= MaxSteps)
899  break;
900  }
901  // Push deferred nodes back on worklist.
902  Worklist.append(DeferredNodes.begin(), DeferredNodes.end());
903  // If we bailed early, conservatively return found.
904  if (MaxSteps != 0 && Visited.size() >= MaxSteps)
905  return true;
906  return Found;
907  }
908 
909  /// Return true if all the users of N are contained in Nodes.
910  /// NOTE: Requires at least one match, but doesn't require them all.
911  static bool areOnlyUsersOf(ArrayRef<const SDNode *> Nodes, const SDNode *N);
912 
913  /// Return the number of values used by this operation.
914  unsigned getNumOperands() const { return NumOperands; }
915 
916  /// Return the maximum number of operands that a SDNode can hold.
917  static constexpr size_t getMaxNumOperands() {
919  }
920 
921  /// Helper method returns the integer value of a ConstantSDNode operand.
922  inline uint64_t getConstantOperandVal(unsigned Num) const;
923 
924  /// Helper method returns the APInt of a ConstantSDNode operand.
925  inline const APInt &getConstantOperandAPInt(unsigned Num) const;
926 
927  const SDValue &getOperand(unsigned Num) const {
928  assert(Num < NumOperands && "Invalid child # of SDNode!");
929  return OperandList[Num];
930  }
931 
932  using op_iterator = SDUse *;
933 
934  op_iterator op_begin() const { return OperandList; }
935  op_iterator op_end() const { return OperandList+NumOperands; }
936  ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
937 
938  /// Iterator for directly iterating over the operand SDValue's.
940  : iterator_adaptor_base<value_op_iterator, op_iterator,
941  std::random_access_iterator_tag, SDValue,
942  ptrdiff_t, value_op_iterator *,
943  value_op_iterator *> {
944  explicit value_op_iterator(SDUse *U = nullptr)
945  : iterator_adaptor_base(U) {}
946 
947  const SDValue &operator*() const { return I->get(); }
948  };
949 
951  return make_range(value_op_iterator(op_begin()),
952  value_op_iterator(op_end()));
953  }
954 
955  SDVTList getVTList() const {
956  SDVTList X = { ValueList, NumValues };
957  return X;
958  }
959 
960  /// If this node has a glue operand, return the node
961  /// to which the glue operand points. Otherwise return NULL.
962  SDNode *getGluedNode() const {
963  if (getNumOperands() != 0 &&
964  getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
965  return getOperand(getNumOperands()-1).getNode();
966  return nullptr;
967  }
968 
969  /// If this node has a glue value with a user, return
970  /// the user (there is at most one). Otherwise return NULL.
971  SDNode *getGluedUser() const {
972  for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
973  if (UI.getUse().get().getValueType() == MVT::Glue)
974  return *UI;
975  return nullptr;
976  }
977 
978  const SDNodeFlags getFlags() const { return Flags; }
979  void setFlags(SDNodeFlags NewFlags) { Flags = NewFlags; }
980  bool isFast() { return Flags.isFast(); }
981 
982  /// Clear any flags in this node that aren't also set in Flags.
983  /// If Flags is not in a defined state then this has no effect.
984  void intersectFlagsWith(const SDNodeFlags Flags);
985 
986  /// Return the number of values defined/returned by this operator.
987  unsigned getNumValues() const { return NumValues; }
988 
989  /// Return the type of a specified result.
990  EVT getValueType(unsigned ResNo) const {
991  assert(ResNo < NumValues && "Illegal result number!");
992  return ValueList[ResNo];
993  }
994 
995  /// Return the type of a specified result as a simple type.
996  MVT getSimpleValueType(unsigned ResNo) const {
997  return getValueType(ResNo).getSimpleVT();
998  }
999 
1000  /// Returns MVT::getSizeInBits(getValueType(ResNo)).
1001  unsigned getValueSizeInBits(unsigned ResNo) const {
1002  return getValueType(ResNo).getSizeInBits();
1003  }
1004 
1005  using value_iterator = const EVT *;
1006 
1007  value_iterator value_begin() const { return ValueList; }
1008  value_iterator value_end() const { return ValueList+NumValues; }
1009 
1010  /// Return the opcode of this operation for printing.
1011  std::string getOperationName(const SelectionDAG *G = nullptr) const;
1012  static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1013  void print_types(raw_ostream &OS, const SelectionDAG *G) const;
1014  void print_details(raw_ostream &OS, const SelectionDAG *G) const;
1015  void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
1016  void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
1017 
1018  /// Print a SelectionDAG node and all children down to
1019  /// the leaves. The given SelectionDAG allows target-specific nodes
1020  /// to be printed in human-readable form. Unlike printr, this will
1021  /// print the whole DAG, including children that appear multiple
1022  /// times.
1023  ///
1024  void printrFull(raw_ostream &O, const SelectionDAG *G = nullptr) const;
1025 
1026  /// Print a SelectionDAG node and children up to
1027  /// depth "depth." The given SelectionDAG allows target-specific
1028  /// nodes to be printed in human-readable form. Unlike printr, this
1029  /// will print children that appear multiple times wherever they are
1030  /// used.
1031  ///
1032  void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
1033  unsigned depth = 100) const;
1034 
1035  /// Dump this node, for debugging.
1036  void dump() const;
1037 
1038  /// Dump (recursively) this node and its use-def subgraph.
1039  void dumpr() const;
1040 
1041  /// Dump this node, for debugging.
1042  /// The given SelectionDAG allows target-specific nodes to be printed
1043  /// in human-readable form.
1044  void dump(const SelectionDAG *G) const;
1045 
1046  /// Dump (recursively) this node and its use-def subgraph.
1047  /// The given SelectionDAG allows target-specific nodes to be printed
1048  /// in human-readable form.
1049  void dumpr(const SelectionDAG *G) const;
1050 
1051  /// printrFull to dbgs(). The given SelectionDAG allows
1052  /// target-specific nodes to be printed in human-readable form.
1053  /// Unlike dumpr, this will print the whole DAG, including children
1054  /// that appear multiple times.
1055  void dumprFull(const SelectionDAG *G = nullptr) const;
1056 
1057  /// printrWithDepth to dbgs(). The given
1058  /// SelectionDAG allows target-specific nodes to be printed in
1059  /// human-readable form. Unlike dumpr, this will print children
1060  /// that appear multiple times wherever they are used.
1061  ///
1062  void dumprWithDepth(const SelectionDAG *G = nullptr,
1063  unsigned depth = 100) const;
1064 
1065  /// Gather unique data for the node.
1066  void Profile(FoldingSetNodeID &ID) const;
1067 
1068  /// This method should only be used by the SDUse class.
1069  void addUse(SDUse &U) { U.addToList(&UseList); }
1070 
1071 protected:
1072  static SDVTList getSDVTList(EVT VT) {
1073  SDVTList Ret = { getValueTypeList(VT), 1 };
1074  return Ret;
1075  }
1076 
1077  /// Create an SDNode.
1078  ///
1079  /// SDNodes are created without any operands, and never own the operand
1080  /// storage. To add operands, see SelectionDAG::createOperands.
1081  SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
1082  : NodeType(Opc), ValueList(VTs.VTs), NumValues(VTs.NumVTs),
1083  IROrder(Order), debugLoc(std::move(dl)) {
1084  memset(&RawSDNodeBits, 0, sizeof(RawSDNodeBits));
1085  assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
1086  assert(NumValues == VTs.NumVTs &&
1087  "NumValues wasn't wide enough for its operands!");
1088  }
1089 
1090  /// Release the operands and set this node to have zero operands.
1091  void DropOperands();
1092 };
1093 
1094 /// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
1095 /// into SDNode creation functions.
1096 /// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
1097 /// from the original Instruction, and IROrder is the ordinal position of
1098 /// the instruction.
1099 /// When an SDNode is created after the DAG is being built, both DebugLoc and
1100 /// the IROrder are propagated from the original SDNode.
1101 /// So SDLoc class provides two constructors besides the default one, one to
1102 /// be used by the DAGBuilder, the other to be used by others.
1103 class SDLoc {
1104 private:
1105  DebugLoc DL;
1106  int IROrder = 0;
1107 
1108 public:
1109  SDLoc() = default;
1110  SDLoc(const SDNode *N) : DL(N->getDebugLoc()), IROrder(N->getIROrder()) {}
1111  SDLoc(const SDValue V) : SDLoc(V.getNode()) {}
1112  SDLoc(const Instruction *I, int Order) : IROrder(Order) {
1113  assert(Order >= 0 && "bad IROrder");
1114  if (I)
1115  DL = I->getDebugLoc();
1116  }
1117 
1118  unsigned getIROrder() const { return IROrder; }
1119  const DebugLoc &getDebugLoc() const { return DL; }
1120 };
1121 
1122 // Define inline functions from the SDValue class.
1123 
1124 inline SDValue::SDValue(SDNode *node, unsigned resno)
1125  : Node(node), ResNo(resno) {
1126  // Explicitly check for !ResNo to avoid use-after-free, because there are
1127  // callers that use SDValue(N, 0) with a deleted N to indicate successful
1128  // combines.
1129  assert((!Node || !ResNo || ResNo < Node->getNumValues()) &&
1130  "Invalid result number for the given node!");
1131  assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
1132 }
1133 
1134 inline unsigned SDValue::getOpcode() const {
1135  return Node->getOpcode();
1136 }
1137 
1138 inline EVT SDValue::getValueType() const {
1139  return Node->getValueType(ResNo);
1140 }
1141 
1142 inline unsigned SDValue::getNumOperands() const {
1143  return Node->getNumOperands();
1144 }
1145 
1146 inline const SDValue &SDValue::getOperand(unsigned i) const {
1147  return Node->getOperand(i);
1148 }
1149 
1150 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1151  return Node->getConstantOperandVal(i);
1152 }
1153 
1154 inline const APInt &SDValue::getConstantOperandAPInt(unsigned i) const {
1155  return Node->getConstantOperandAPInt(i);
1156 }
1157 
1158 inline bool SDValue::isTargetOpcode() const {
1159  return Node->isTargetOpcode();
1160 }
1161 
1162 inline bool SDValue::isTargetMemoryOpcode() const {
1163  return Node->isTargetMemoryOpcode();
1164 }
1165 
1166 inline bool SDValue::isMachineOpcode() const {
1167  return Node->isMachineOpcode();
1168 }
1169 
1170 inline unsigned SDValue::getMachineOpcode() const {
1171  return Node->getMachineOpcode();
1172 }
1173 
1174 inline bool SDValue::isUndef() const {
1175  return Node->isUndef();
1176 }
1177 
1178 inline bool SDValue::use_empty() const {
1179  return !Node->hasAnyUseOfValue(ResNo);
1180 }
1181 
1182 inline bool SDValue::hasOneUse() const {
1183  return Node->hasNUsesOfValue(1, ResNo);
1184 }
1185 
1186 inline const DebugLoc &SDValue::getDebugLoc() const {
1187  return Node->getDebugLoc();
1188 }
1189 
1190 inline void SDValue::dump() const {
1191  return Node->dump();
1192 }
1193 
1194 inline void SDValue::dump(const SelectionDAG *G) const {
1195  return Node->dump(G);
1196 }
1197 
1198 inline void SDValue::dumpr() const {
1199  return Node->dumpr();
1200 }
1201 
1202 inline void SDValue::dumpr(const SelectionDAG *G) const {
1203  return Node->dumpr(G);
1204 }
1205 
1206 // Define inline functions from the SDUse class.
1207 
1208 inline void SDUse::set(const SDValue &V) {
1209  if (Val.getNode()) removeFromList();
1210  Val = V;
1211  if (V.getNode()) V.getNode()->addUse(*this);
1212 }
1213 
1214 inline void SDUse::setInitial(const SDValue &V) {
1215  Val = V;
1216  V.getNode()->addUse(*this);
1217 }
1218 
1219 inline void SDUse::setNode(SDNode *N) {
1220  if (Val.getNode()) removeFromList();
1221  Val.setNode(N);
1222  if (N) N->addUse(*this);
1223 }
1224 
1225 /// This class is used to form a handle around another node that
1226 /// is persistent and is updated across invocations of replaceAllUsesWith on its
1227 /// operand. This node should be directly created by end-users and not added to
1228 /// the AllNodes list.
1229 class HandleSDNode : public SDNode {
1230  SDUse Op;
1231 
1232 public:
1234  : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1235  // HandleSDNodes are never inserted into the DAG, so they won't be
1236  // auto-numbered. Use ID 65535 as a sentinel.
1237  PersistentId = 0xffff;
1238 
1239  // Manually set up the operand list. This node type is special in that it's
1240  // always stack allocated and SelectionDAG does not manage its operands.
1241  // TODO: This should either (a) not be in the SDNode hierarchy, or (b) not
1242  // be so special.
1243  Op.setUser(this);
1244  Op.setInitial(X);
1245  NumOperands = 1;
1246  OperandList = &Op;
1247  }
1248  ~HandleSDNode();
1249 
1250  const SDValue &getValue() const { return Op; }
1251 };
1252 
1253 class AddrSpaceCastSDNode : public SDNode {
1254 private:
1255  unsigned SrcAddrSpace;
1256  unsigned DestAddrSpace;
1257 
1258 public:
1259  AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, EVT VT,
1260  unsigned SrcAS, unsigned DestAS);
1261 
1262  unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1263  unsigned getDestAddressSpace() const { return DestAddrSpace; }
1264 
1265  static bool classof(const SDNode *N) {
1266  return N->getOpcode() == ISD::ADDRSPACECAST;
1267  }
1268 };
1269 
1270 /// This is an abstract virtual class for memory operations.
1271 class MemSDNode : public SDNode {
1272 private:
1273  // VT of in-memory value.
1274  EVT MemoryVT;
1275 
1276 protected:
1277  /// Memory reference information.
1279 
1280 public:
1281  MemSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs,
1282  EVT memvt, MachineMemOperand *MMO);
1283 
1284  bool readMem() const { return MMO->isLoad(); }
1285  bool writeMem() const { return MMO->isStore(); }
1286 
1287  /// Returns alignment and volatility of the memory access
1288  unsigned getOriginalAlignment() const {
1289  return MMO->getBaseAlignment();
1290  }
1291  unsigned getAlignment() const {
1292  return MMO->getAlignment();
1293  }
1294 
1295  /// Return the SubclassData value, without HasDebugValue. This contains an
1296  /// encoding of the volatile flag, as well as bits used by subclasses. This
1297  /// function should only be used to compute a FoldingSetNodeID value.
1298  /// The HasDebugValue bit is masked out because CSE map needs to match
1299  /// nodes with debug info with nodes without debug info. Same is about
1300  /// isDivergent bit.
1301  unsigned getRawSubclassData() const {
1302  uint16_t Data;
1303  union {
1304  char RawSDNodeBits[sizeof(uint16_t)];
1305  SDNodeBitfields SDNodeBits;
1306  };
1307  memcpy(&RawSDNodeBits, &this->RawSDNodeBits, sizeof(this->RawSDNodeBits));
1308  SDNodeBits.HasDebugValue = 0;
1309  SDNodeBits.IsDivergent = false;
1310  memcpy(&Data, &RawSDNodeBits, sizeof(RawSDNodeBits));
1311  return Data;
1312  }
1313 
1314  bool isVolatile() const { return MemSDNodeBits.IsVolatile; }
1315  bool isNonTemporal() const { return MemSDNodeBits.IsNonTemporal; }
1316  bool isDereferenceable() const { return MemSDNodeBits.IsDereferenceable; }
1317  bool isInvariant() const { return MemSDNodeBits.IsInvariant; }
1318 
1319  // Returns the offset from the location of the access.
1320  int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1321 
1322  /// Returns the AA info that describes the dereference.
1323  AAMDNodes getAAInfo() const { return MMO->getAAInfo(); }
1324 
1325  /// Returns the Ranges that describes the dereference.
1326  const MDNode *getRanges() const { return MMO->getRanges(); }
1327 
1328  /// Returns the synchronization scope ID for this memory operation.
1329  SyncScope::ID getSyncScopeID() const { return MMO->getSyncScopeID(); }
1330 
1331  /// Return the atomic ordering requirements for this memory operation. For
1332  /// cmpxchg atomic operations, return the atomic ordering requirements when
1333  /// store occurs.
1334  AtomicOrdering getOrdering() const { return MMO->getOrdering(); }
1335 
1336  /// Return the type of the in-memory value.
1337  EVT getMemoryVT() const { return MemoryVT; }
1338 
1339  /// Return a MachineMemOperand object describing the memory
1340  /// reference performed by operation.
1341  MachineMemOperand *getMemOperand() const { return MMO; }
1342 
1344  return MMO->getPointerInfo();
1345  }
1346 
1347  /// Return the address space for the associated pointer
1348  unsigned getAddressSpace() const {
1349  return getPointerInfo().getAddrSpace();
1350  }
1351 
1352  /// Update this MemSDNode's MachineMemOperand information
1353  /// to reflect the alignment of NewMMO, if it has a greater alignment.
1354  /// This must only be used when the new alignment applies to all users of
1355  /// this MachineMemOperand.
1356  void refineAlignment(const MachineMemOperand *NewMMO) {
1357  MMO->refineAlignment(NewMMO);
1358  }
1359 
1360  const SDValue &getChain() const { return getOperand(0); }
1361  const SDValue &getBasePtr() const {
1362  return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1363  }
1364 
1365  // Methods to support isa and dyn_cast
1366  static bool classof(const SDNode *N) {
1367  // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1368  // with either an intrinsic or a target opcode.
1369  return N->getOpcode() == ISD::LOAD ||
1370  N->getOpcode() == ISD::STORE ||
1371  N->getOpcode() == ISD::PREFETCH ||
1372  N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1374  N->getOpcode() == ISD::ATOMIC_SWAP ||
1375  N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1376  N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1377  N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1378  N->getOpcode() == ISD::ATOMIC_LOAD_CLR ||
1379  N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1380  N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1381  N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1382  N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1383  N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1384  N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1385  N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1386  N->getOpcode() == ISD::ATOMIC_LOAD_FADD ||
1387  N->getOpcode() == ISD::ATOMIC_LOAD_FSUB ||
1388  N->getOpcode() == ISD::ATOMIC_LOAD ||
1389  N->getOpcode() == ISD::ATOMIC_STORE ||
1390  N->getOpcode() == ISD::MLOAD ||
1391  N->getOpcode() == ISD::MSTORE ||
1392  N->getOpcode() == ISD::MGATHER ||
1393  N->getOpcode() == ISD::MSCATTER ||
1394  N->isMemIntrinsic() ||
1395  N->isTargetMemoryOpcode();
1396  }
1397 };
1398 
1399 /// This is an SDNode representing atomic operations.
1400 class AtomicSDNode : public MemSDNode {
1401 public:
1402  AtomicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTL,
1403  EVT MemVT, MachineMemOperand *MMO)
1404  : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1405  assert(((Opc != ISD::ATOMIC_LOAD && Opc != ISD::ATOMIC_STORE) ||
1406  MMO->isAtomic()) && "then why are we using an AtomicSDNode?");
1407  }
1408 
1409  const SDValue &getBasePtr() const { return getOperand(1); }
1410  const SDValue &getVal() const { return getOperand(2); }
1411 
1412  /// Returns true if this SDNode represents cmpxchg atomic operation, false
1413  /// otherwise.
1414  bool isCompareAndSwap() const {
1415  unsigned Op = getOpcode();
1416  return Op == ISD::ATOMIC_CMP_SWAP ||
1418  }
1419 
1420  /// For cmpxchg atomic operations, return the atomic ordering requirements
1421  /// when store does not occur.
1423  assert(isCompareAndSwap() && "Must be cmpxchg operation");
1424  return MMO->getFailureOrdering();
1425  }
1426 
1427  // Methods to support isa and dyn_cast
1428  static bool classof(const SDNode *N) {
1429  return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1431  N->getOpcode() == ISD::ATOMIC_SWAP ||
1432  N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1433  N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1434  N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1435  N->getOpcode() == ISD::ATOMIC_LOAD_CLR ||
1436  N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1437  N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1438  N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1439  N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1440  N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1441  N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1442  N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1443  N->getOpcode() == ISD::ATOMIC_LOAD_FADD ||
1444  N->getOpcode() == ISD::ATOMIC_LOAD_FSUB ||
1445  N->getOpcode() == ISD::ATOMIC_LOAD ||
1446  N->getOpcode() == ISD::ATOMIC_STORE;
1447  }
1448 };
1449 
1450 /// This SDNode is used for target intrinsics that touch
1451 /// memory and need an associated MachineMemOperand. Its opcode may be
1452 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1453 /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1455 public:
1456  MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl,
1457  SDVTList VTs, EVT MemoryVT, MachineMemOperand *MMO)
1458  : MemSDNode(Opc, Order, dl, VTs, MemoryVT, MMO) {
1459  SDNodeBits.IsMemIntrinsic = true;
1460  }
1461 
1462  // Methods to support isa and dyn_cast
1463  static bool classof(const SDNode *N) {
1464  // We lower some target intrinsics to their target opcode
1465  // early a node with a target opcode can be of this class
1466  return N->isMemIntrinsic() ||
1467  N->getOpcode() == ISD::PREFETCH ||
1468  N->isTargetMemoryOpcode();
1469  }
1470 };
1471 
1472 /// This SDNode is used to implement the code generator
1473 /// support for the llvm IR shufflevector instruction. It combines elements
1474 /// from two input vectors into a new input vector, with the selection and
1475 /// ordering of elements determined by an array of integers, referred to as
1476 /// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1477 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1478 /// An index of -1 is treated as undef, such that the code generator may put
1479 /// any value in the corresponding element of the result.
1480 class ShuffleVectorSDNode : public SDNode {
1481  // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1482  // is freed when the SelectionDAG object is destroyed.
1483  const int *Mask;
1484 
1485 protected:
1486  friend class SelectionDAG;
1487 
1488  ShuffleVectorSDNode(EVT VT, unsigned Order, const DebugLoc &dl, const int *M)
1489  : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {}
1490 
1491 public:
1493  EVT VT = getValueType(0);
1494  return makeArrayRef(Mask, VT.getVectorNumElements());
1495  }
1496 
1497  int getMaskElt(unsigned Idx) const {
1498  assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1499  return Mask[Idx];
1500  }
1501 
1502  bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1503 
1504  int getSplatIndex() const {
1505  assert(isSplat() && "Cannot get splat index for non-splat!");
1506  EVT VT = getValueType(0);
1507  for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i)
1508  if (Mask[i] >= 0)
1509  return Mask[i];
1510 
1511  // We can choose any index value here and be correct because all elements
1512  // are undefined. Return 0 for better potential for callers to simplify.
1513  return 0;
1514  }
1515 
1516  static bool isSplatMask(const int *Mask, EVT VT);
1517 
1518  /// Change values in a shuffle permute mask assuming
1519  /// the two vector operands have swapped position.
1520  static void commuteMask(MutableArrayRef<int> Mask) {
1521  unsigned NumElems = Mask.size();
1522  for (unsigned i = 0; i != NumElems; ++i) {
1523  int idx = Mask[i];
1524  if (idx < 0)
1525  continue;
1526  else if (idx < (int)NumElems)
1527  Mask[i] = idx + NumElems;
1528  else
1529  Mask[i] = idx - NumElems;
1530  }
1531  }
1532 
1533  static bool classof(const SDNode *N) {
1534  return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1535  }
1536 };
1537 
1538 class ConstantSDNode : public SDNode {
1539  friend class SelectionDAG;
1540 
1541  const ConstantInt *Value;
1542 
1543  ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val, EVT VT)
1544  : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, 0, DebugLoc(),
1545  getSDVTList(VT)),
1546  Value(val) {
1547  ConstantSDNodeBits.IsOpaque = isOpaque;
1548  }
1549 
1550 public:
1551  const ConstantInt *getConstantIntValue() const { return Value; }
1552  const APInt &getAPIntValue() const { return Value->getValue(); }
1553  uint64_t getZExtValue() const { return Value->getZExtValue(); }
1554  int64_t getSExtValue() const { return Value->getSExtValue(); }
1555  uint64_t getLimitedValue(uint64_t Limit = UINT64_MAX) {
1556  return Value->getLimitedValue(Limit);
1557  }
1558 
1559  bool isOne() const { return Value->isOne(); }
1560  bool isNullValue() const { return Value->isZero(); }
1561  bool isAllOnesValue() const { return Value->isMinusOne(); }
1562 
1563  bool isOpaque() const { return ConstantSDNodeBits.IsOpaque; }
1564 
1565  static bool classof(const SDNode *N) {
1566  return N->getOpcode() == ISD::Constant ||
1568  }
1569 };
1570 
1571 uint64_t SDNode::getConstantOperandVal(unsigned Num) const {
1572  return cast<ConstantSDNode>(getOperand(Num))->getZExtValue();
1573 }
1574 
1575 const APInt &SDNode::getConstantOperandAPInt(unsigned Num) const {
1576  return cast<ConstantSDNode>(getOperand(Num))->getAPIntValue();
1577 }
1578 
1579 class ConstantFPSDNode : public SDNode {
1580  friend class SelectionDAG;
1581 
1582  const ConstantFP *Value;
1583 
1584  ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1585  : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 0,
1586  DebugLoc(), getSDVTList(VT)),
1587  Value(val) {}
1588 
1589 public:
1590  const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1591  const ConstantFP *getConstantFPValue() const { return Value; }
1592 
1593  /// Return true if the value is positive or negative zero.
1594  bool isZero() const { return Value->isZero(); }
1595 
1596  /// Return true if the value is a NaN.
1597  bool isNaN() const { return Value->isNaN(); }
1598 
1599  /// Return true if the value is an infinity
1600  bool isInfinity() const { return Value->isInfinity(); }
1601 
1602  /// Return true if the value is negative.
1603  bool isNegative() const { return Value->isNegative(); }
1604 
1605  /// We don't rely on operator== working on double values, as
1606  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1607  /// As such, this method can be used to do an exact bit-for-bit comparison of
1608  /// two floating point values.
1609 
1610  /// We leave the version with the double argument here because it's just so
1611  /// convenient to write "2.0" and the like. Without this function we'd
1612  /// have to duplicate its logic everywhere it's called.
1613  bool isExactlyValue(double V) const {
1614  return Value->getValueAPF().isExactlyValue(V);
1615  }
1616  bool isExactlyValue(const APFloat& V) const;
1617 
1618  static bool isValueValidForType(EVT VT, const APFloat& Val);
1619 
1620  static bool classof(const SDNode *N) {
1621  return N->getOpcode() == ISD::ConstantFP ||
1623  }
1624 };
1625 
1626 /// Returns true if \p V is a constant integer zero.
1627 bool isNullConstant(SDValue V);
1628 
1629 /// Returns true if \p V is an FP constant with a value of positive zero.
1630 bool isNullFPConstant(SDValue V);
1631 
1632 /// Returns true if \p V is an integer constant with all bits set.
1633 bool isAllOnesConstant(SDValue V);
1634 
1635 /// Returns true if \p V is a constant integer one.
1636 bool isOneConstant(SDValue V);
1637 
1638 /// Return the non-bitcasted source operand of \p V if it exists.
1639 /// If \p V is not a bitcasted value, it is returned as-is.
1641 
1642 /// Return the non-bitcasted and one-use source operand of \p V if it exists.
1643 /// If \p V is not a bitcasted one-use value, it is returned as-is.
1645 
1646 /// Return the non-extracted vector source operand of \p V if it exists.
1647 /// If \p V is not an extracted subvector, it is returned as-is.
1649 
1650 /// Returns true if \p V is a bitwise not operation. Assumes that an all ones
1651 /// constant is canonicalized to be operand 1.
1652 bool isBitwiseNot(SDValue V);
1653 
1654 /// Returns the SDNode if it is a constant splat BuildVector or constant int.
1655 ConstantSDNode *isConstOrConstSplat(SDValue N, bool AllowUndefs = false);
1656 
1657 /// Returns the SDNode if it is a demanded constant splat BuildVector or
1658 /// constant int.
1659 ConstantSDNode *isConstOrConstSplat(SDValue N, const APInt &DemandedElts,
1660  bool AllowUndefs = false);
1661 
1662 /// Returns the SDNode if it is a constant splat BuildVector or constant float.
1663 ConstantFPSDNode *isConstOrConstSplatFP(SDValue N, bool AllowUndefs = false);
1664 
1665 /// Returns the SDNode if it is a demanded constant splat BuildVector or
1666 /// constant float.
1667 ConstantFPSDNode *isConstOrConstSplatFP(SDValue N, const APInt &DemandedElts,
1668  bool AllowUndefs = false);
1669 
1670 /// Return true if the value is a constant 0 integer or a splatted vector of
1671 /// a constant 0 integer (with no undefs by default).
1672 /// Build vector implicit truncation is not an issue for null values.
1673 bool isNullOrNullSplat(SDValue V, bool AllowUndefs = false);
1674 
1675 /// Return true if the value is a constant 1 integer or a splatted vector of a
1676 /// constant 1 integer (with no undefs).
1677 /// Does not permit build vector implicit truncation.
1678 bool isOneOrOneSplat(SDValue V);
1679 
1680 /// Return true if the value is a constant -1 integer or a splatted vector of a
1681 /// constant -1 integer (with no undefs).
1682 /// Does not permit build vector implicit truncation.
1684 
1685 class GlobalAddressSDNode : public SDNode {
1686  friend class SelectionDAG;
1687 
1688  const GlobalValue *TheGlobal;
1689  int64_t Offset;
1690  unsigned char TargetFlags;
1691 
1692  GlobalAddressSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL,
1693  const GlobalValue *GA, EVT VT, int64_t o,
1694  unsigned char TF);
1695 
1696 public:
1697  const GlobalValue *getGlobal() const { return TheGlobal; }
1698  int64_t getOffset() const { return Offset; }
1699  unsigned char getTargetFlags() const { return TargetFlags; }
1700  // Return the address space this GlobalAddress belongs to.
1701  unsigned getAddressSpace() const;
1702 
1703  static bool classof(const SDNode *N) {
1704  return N->getOpcode() == ISD::GlobalAddress ||
1706  N->getOpcode() == ISD::GlobalTLSAddress ||
1708  }
1709 };
1710 
1711 class FrameIndexSDNode : public SDNode {
1712  friend class SelectionDAG;
1713 
1714  int FI;
1715 
1716  FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1717  : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1718  0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1719  }
1720 
1721 public:
1722  int getIndex() const { return FI; }
1723 
1724  static bool classof(const SDNode *N) {
1725  return N->getOpcode() == ISD::FrameIndex ||
1727  }
1728 };
1729 
1730 /// This SDNode is used for LIFETIME_START/LIFETIME_END values, which indicate
1731 /// the offet and size that are started/ended in the underlying FrameIndex.
1732 class LifetimeSDNode : public SDNode {
1733  friend class SelectionDAG;
1734  int64_t Size;
1735  int64_t Offset; // -1 if offset is unknown.
1736 
1737  LifetimeSDNode(unsigned Opcode, unsigned Order, const DebugLoc &dl,
1738  SDVTList VTs, int64_t Size, int64_t Offset)
1739  : SDNode(Opcode, Order, dl, VTs), Size(Size), Offset(Offset) {}
1740 public:
1741  int64_t getFrameIndex() const {
1742  return cast<FrameIndexSDNode>(getOperand(1))->getIndex();
1743  }
1744 
1745  bool hasOffset() const { return Offset >= 0; }
1746  int64_t getOffset() const {
1747  assert(hasOffset() && "offset is unknown");
1748  return Offset;
1749  }
1750  int64_t getSize() const {
1751  assert(hasOffset() && "offset is unknown");
1752  return Size;
1753  }
1754 
1755  // Methods to support isa and dyn_cast
1756  static bool classof(const SDNode *N) {
1757  return N->getOpcode() == ISD::LIFETIME_START ||
1758  N->getOpcode() == ISD::LIFETIME_END;
1759  }
1760 };
1761 
1762 class JumpTableSDNode : public SDNode {
1763  friend class SelectionDAG;
1764 
1765  int JTI;
1766  unsigned char TargetFlags;
1767 
1768  JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1769  : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1770  0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1771  }
1772 
1773 public:
1774  int getIndex() const { return JTI; }
1775  unsigned char getTargetFlags() const { return TargetFlags; }
1776 
1777  static bool classof(const SDNode *N) {
1778  return N->getOpcode() == ISD::JumpTable ||
1780  }
1781 };
1782 
1783 class ConstantPoolSDNode : public SDNode {
1784  friend class SelectionDAG;
1785 
1786  union {
1789  } Val;
1790  int Offset; // It's a MachineConstantPoolValue if top bit is set.
1791  unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
1792  unsigned char TargetFlags;
1793 
1794  ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1795  unsigned Align, unsigned char TF)
1796  : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1797  DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1798  TargetFlags(TF) {
1799  assert(Offset >= 0 && "Offset is too large");
1800  Val.ConstVal = c;
1801  }
1802 
1803  ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1804  EVT VT, int o, unsigned Align, unsigned char TF)
1806  DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1807  TargetFlags(TF) {
1808  assert(Offset >= 0 && "Offset is too large");
1809  Val.MachineCPVal = v;
1810  Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1811  }
1812 
1813 public:
1815  return Offset < 0;
1816  }
1817 
1818  const Constant *getConstVal() const {
1819  assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1820  return Val.ConstVal;
1821  }
1822 
1824  assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1825  return Val.MachineCPVal;
1826  }
1827 
1828  int getOffset() const {
1829  return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1830  }
1831 
1832  // Return the alignment of this constant pool object, which is either 0 (for
1833  // default alignment) or the desired value.
1834  unsigned getAlignment() const { return Alignment; }
1835  unsigned char getTargetFlags() const { return TargetFlags; }
1836 
1837  Type *getType() const;
1838 
1839  static bool classof(const SDNode *N) {
1840  return N->getOpcode() == ISD::ConstantPool ||
1842  }
1843 };
1844 
1845 /// Completely target-dependent object reference.
1846 class TargetIndexSDNode : public SDNode {
1847  friend class SelectionDAG;
1848 
1849  unsigned char TargetFlags;
1850  int Index;
1851  int64_t Offset;
1852 
1853 public:
1854  TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1855  : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
1856  TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1857 
1858  unsigned char getTargetFlags() const { return TargetFlags; }
1859  int getIndex() const { return Index; }
1860  int64_t getOffset() const { return Offset; }
1861 
1862  static bool classof(const SDNode *N) {
1863  return N->getOpcode() == ISD::TargetIndex;
1864  }
1865 };
1866 
1867 class BasicBlockSDNode : public SDNode {
1868  friend class SelectionDAG;
1869 
1870  MachineBasicBlock *MBB;
1871 
1872  /// Debug info is meaningful and potentially useful here, but we create
1873  /// blocks out of order when they're jumped to, which makes it a bit
1874  /// harder. Let's see if we need it first.
1875  explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1876  : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
1877  {}
1878 
1879 public:
1880  MachineBasicBlock *getBasicBlock() const { return MBB; }
1881 
1882  static bool classof(const SDNode *N) {
1883  return N->getOpcode() == ISD::BasicBlock;
1884  }
1885 };
1886 
1887 /// A "pseudo-class" with methods for operating on BUILD_VECTORs.
1888 class BuildVectorSDNode : public SDNode {
1889 public:
1890  // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1891  explicit BuildVectorSDNode() = delete;
1892 
1893  /// Check if this is a constant splat, and if so, find the
1894  /// smallest element size that splats the vector. If MinSplatBits is
1895  /// nonzero, the element size must be at least that large. Note that the
1896  /// splat element may be the entire vector (i.e., a one element vector).
1897  /// Returns the splat element value in SplatValue. Any undefined bits in
1898  /// that value are zero, and the corresponding bits in the SplatUndef mask
1899  /// are set. The SplatBitSize value is set to the splat element size in
1900  /// bits. HasAnyUndefs is set to true if any bits in the vector are
1901  /// undefined. isBigEndian describes the endianness of the target.
1902  bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1903  unsigned &SplatBitSize, bool &HasAnyUndefs,
1904  unsigned MinSplatBits = 0,
1905  bool isBigEndian = false) const;
1906 
1907  /// Returns the demanded splatted value or a null value if this is not a
1908  /// splat.
1909  ///
1910  /// The DemandedElts mask indicates the elements that must be in the splat.
1911  /// If passed a non-null UndefElements bitvector, it will resize it to match
1912  /// the vector width and set the bits where elements are undef.
1913  SDValue getSplatValue(const APInt &DemandedElts,
1914  BitVector *UndefElements = nullptr) const;
1915 
1916  /// Returns the splatted value or a null value if this is not a splat.
1917  ///
1918  /// If passed a non-null UndefElements bitvector, it will resize it to match
1919  /// the vector width and set the bits where elements are undef.
1920  SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
1921 
1922  /// Returns the demanded splatted constant or null if this is not a constant
1923  /// splat.
1924  ///
1925  /// The DemandedElts mask indicates the elements that must be in the splat.
1926  /// If passed a non-null UndefElements bitvector, it will resize it to match
1927  /// the vector width and set the bits where elements are undef.
1928  ConstantSDNode *
1929  getConstantSplatNode(const APInt &DemandedElts,
1930  BitVector *UndefElements = nullptr) const;
1931 
1932  /// Returns the splatted constant or null if this is not a constant
1933  /// splat.
1934  ///
1935  /// If passed a non-null UndefElements bitvector, it will resize it to match
1936  /// the vector width and set the bits where elements are undef.
1937  ConstantSDNode *
1938  getConstantSplatNode(BitVector *UndefElements = nullptr) const;
1939 
1940  /// Returns the demanded splatted constant FP or null if this is not a
1941  /// constant FP splat.
1942  ///
1943  /// The DemandedElts mask indicates the elements that must be in the splat.
1944  /// If passed a non-null UndefElements bitvector, it will resize it to match
1945  /// the vector width and set the bits where elements are undef.
1947  getConstantFPSplatNode(const APInt &DemandedElts,
1948  BitVector *UndefElements = nullptr) const;
1949 
1950  /// Returns the splatted constant FP or null if this is not a constant
1951  /// FP splat.
1952  ///
1953  /// If passed a non-null UndefElements bitvector, it will resize it to match
1954  /// the vector width and set the bits where elements are undef.
1956  getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
1957 
1958  /// If this is a constant FP splat and the splatted constant FP is an
1959  /// exact power or 2, return the log base 2 integer value. Otherwise,
1960  /// return -1.
1961  ///
1962  /// The BitWidth specifies the necessary bit precision.
1963  int32_t getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements,
1964  uint32_t BitWidth) const;
1965 
1966  bool isConstant() const;
1967 
1968  static bool classof(const SDNode *N) {
1969  return N->getOpcode() == ISD::BUILD_VECTOR;
1970  }
1971 };
1972 
1973 /// An SDNode that holds an arbitrary LLVM IR Value. This is
1974 /// used when the SelectionDAG needs to make a simple reference to something
1975 /// in the LLVM IR representation.
1976 ///
1977 class SrcValueSDNode : public SDNode {
1978  friend class SelectionDAG;
1979 
1980  const Value *V;
1981 
1982  /// Create a SrcValue for a general value.
1983  explicit SrcValueSDNode(const Value *v)
1984  : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1985 
1986 public:
1987  /// Return the contained Value.
1988  const Value *getValue() const { return V; }
1989 
1990  static bool classof(const SDNode *N) {
1991  return N->getOpcode() == ISD::SRCVALUE;
1992  }
1993 };
1994 
1995 class MDNodeSDNode : public SDNode {
1996  friend class SelectionDAG;
1997 
1998  const MDNode *MD;
1999 
2000  explicit MDNodeSDNode(const MDNode *md)
2001  : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
2002  {}
2003 
2004 public:
2005  const MDNode *getMD() const { return MD; }
2006 
2007  static bool classof(const SDNode *N) {
2008  return N->getOpcode() == ISD::MDNODE_SDNODE;
2009  }
2010 };
2011 
2012 class RegisterSDNode : public SDNode {
2013  friend class SelectionDAG;
2014 
2015  unsigned Reg;
2016 
2017  RegisterSDNode(unsigned reg, EVT VT)
2018  : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {}
2019 
2020 public:
2021  unsigned getReg() const { return Reg; }
2022 
2023  static bool classof(const SDNode *N) {
2024  return N->getOpcode() == ISD::Register;
2025  }
2026 };
2027 
2028 class RegisterMaskSDNode : public SDNode {
2029  friend class SelectionDAG;
2030 
2031  // The memory for RegMask is not owned by the node.
2032  const uint32_t *RegMask;
2033 
2034  RegisterMaskSDNode(const uint32_t *mask)
2035  : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
2036  RegMask(mask) {}
2037 
2038 public:
2039  const uint32_t *getRegMask() const { return RegMask; }
2040 
2041  static bool classof(const SDNode *N) {
2042  return N->getOpcode() == ISD::RegisterMask;
2043  }
2044 };
2045 
2046 class BlockAddressSDNode : public SDNode {
2047  friend class SelectionDAG;
2048 
2049  const BlockAddress *BA;
2050  int64_t Offset;
2051  unsigned char TargetFlags;
2052 
2053  BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
2054  int64_t o, unsigned char Flags)
2055  : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
2056  BA(ba), Offset(o), TargetFlags(Flags) {}
2057 
2058 public:
2059  const BlockAddress *getBlockAddress() const { return BA; }
2060  int64_t getOffset() const { return Offset; }
2061  unsigned char getTargetFlags() const { return TargetFlags; }
2062 
2063  static bool classof(const SDNode *N) {
2064  return N->getOpcode() == ISD::BlockAddress ||
2066  }
2067 };
2068 
2069 class LabelSDNode : public SDNode {
2070  friend class SelectionDAG;
2071 
2072  MCSymbol *Label;
2073 
2074  LabelSDNode(unsigned Opcode, unsigned Order, const DebugLoc &dl, MCSymbol *L)
2075  : SDNode(Opcode, Order, dl, getSDVTList(MVT::Other)), Label(L) {
2076  assert(LabelSDNode::classof(this) && "not a label opcode");
2077  }
2078 
2079 public:
2080  MCSymbol *getLabel() const { return Label; }
2081 
2082  static bool classof(const SDNode *N) {
2083  return N->getOpcode() == ISD::EH_LABEL ||
2085  }
2086 };
2087 
2089  friend class SelectionDAG;
2090 
2091  const char *Symbol;
2092  unsigned char TargetFlags;
2093 
2094  ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
2095  : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
2096  0, DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {}
2097 
2098 public:
2099  const char *getSymbol() const { return Symbol; }
2100  unsigned char getTargetFlags() const { return TargetFlags; }
2101 
2102  static bool classof(const SDNode *N) {
2103  return N->getOpcode() == ISD::ExternalSymbol ||
2105  }
2106 };
2107 
2108 class MCSymbolSDNode : public SDNode {
2109  friend class SelectionDAG;
2110 
2111  MCSymbol *Symbol;
2112 
2113  MCSymbolSDNode(MCSymbol *Symbol, EVT VT)
2114  : SDNode(ISD::MCSymbol, 0, DebugLoc(), getSDVTList(VT)), Symbol(Symbol) {}
2115 
2116 public:
2117  MCSymbol *getMCSymbol() const { return Symbol; }
2118 
2119  static bool classof(const SDNode *N) {
2120  return N->getOpcode() == ISD::MCSymbol;
2121  }
2122 };
2123 
2124 class CondCodeSDNode : public SDNode {
2125  friend class SelectionDAG;
2126 
2127  ISD::CondCode Condition;
2128 
2129  explicit CondCodeSDNode(ISD::CondCode Cond)
2130  : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
2131  Condition(Cond) {}
2132 
2133 public:
2134  ISD::CondCode get() const { return Condition; }
2135 
2136  static bool classof(const SDNode *N) {
2137  return N->getOpcode() == ISD::CONDCODE;
2138  }
2139 };
2140 
2141 /// This class is used to represent EVT's, which are used
2142 /// to parameterize some operations.
2143 class VTSDNode : public SDNode {
2144  friend class SelectionDAG;
2145 
2146  EVT ValueType;
2147 
2148  explicit VTSDNode(EVT VT)
2149  : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
2150  ValueType(VT) {}
2151 
2152 public:
2153  EVT getVT() const { return ValueType; }
2154 
2155  static bool classof(const SDNode *N) {
2156  return N->getOpcode() == ISD::VALUETYPE;
2157  }
2158 };
2159 
2160 /// Base class for LoadSDNode and StoreSDNode
2161 class LSBaseSDNode : public MemSDNode {
2162 public:
2163  LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl,
2164  SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
2165  MachineMemOperand *MMO)
2166  : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
2167  LSBaseSDNodeBits.AddressingMode = AM;
2168  assert(getAddressingMode() == AM && "Value truncated");
2169  assert((!MMO->isAtomic() || MMO->isVolatile()) &&
2170  "use an AtomicSDNode instead for non-volatile atomics");
2171  }
2172 
2173  const SDValue &getOffset() const {
2174  return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2175  }
2176 
2177  /// Return the addressing mode for this load or store:
2178  /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2180  return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
2181  }
2182 
2183  /// Return true if this is a pre/post inc/dec load/store.
2184  bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2185 
2186  /// Return true if this is NOT a pre/post inc/dec load/store.
2187  bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2188 
2189  static bool classof(const SDNode *N) {
2190  return N->getOpcode() == ISD::LOAD ||
2191  N->getOpcode() == ISD::STORE;
2192  }
2193 };
2194 
2195 /// This class is used to represent ISD::LOAD nodes.
2196 class LoadSDNode : public LSBaseSDNode {
2197  friend class SelectionDAG;
2198 
2199  LoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2200  ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
2201  MachineMemOperand *MMO)
2202  : LSBaseSDNode(ISD::LOAD, Order, dl, VTs, AM, MemVT, MMO) {
2203  LoadSDNodeBits.ExtTy = ETy;
2204  assert(readMem() && "Load MachineMemOperand is not a load!");
2205  assert(!writeMem() && "Load MachineMemOperand is a store!");
2206  }
2207 
2208 public:
2209  /// Return whether this is a plain node,
2210  /// or one of the varieties of value-extending loads.
2212  return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2213  }
2214 
2215  const SDValue &getBasePtr() const { return getOperand(1); }
2216  const SDValue &getOffset() const { return getOperand(2); }
2217 
2218  static bool classof(const SDNode *N) {
2219  return N->getOpcode() == ISD::LOAD;
2220  }
2221 };
2222 
2223 /// This class is used to represent ISD::STORE nodes.
2224 class StoreSDNode : public LSBaseSDNode {
2225  friend class SelectionDAG;
2226 
2227  StoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2228  ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
2229  MachineMemOperand *MMO)
2230  : LSBaseSDNode(ISD::STORE, Order, dl, VTs, AM, MemVT, MMO) {
2231  StoreSDNodeBits.IsTruncating = isTrunc;
2232  assert(!readMem() && "Store MachineMemOperand is a load!");
2233  assert(writeMem() && "Store MachineMemOperand is not a store!");
2234  }
2235 
2236 public:
2237  /// Return true if the op does a truncation before store.
2238  /// For integers this is the same as doing a TRUNCATE and storing the result.
2239  /// For floats, it is the same as doing an FP_ROUND and storing the result.
2240  bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2241  void setTruncatingStore(bool Truncating) {
2242  StoreSDNodeBits.IsTruncating = Truncating;
2243  }
2244 
2245  const SDValue &getValue() const { return getOperand(1); }
2246  const SDValue &getBasePtr() const { return getOperand(2); }
2247  const SDValue &getOffset() const { return getOperand(3); }
2248 
2249  static bool classof(const SDNode *N) {
2250  return N->getOpcode() == ISD::STORE;
2251  }
2252 };
2253 
2254 /// This base class is used to represent MLOAD and MSTORE nodes
2256 public:
2257  friend class SelectionDAG;
2258 
2259  MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order,
2260  const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2261  MachineMemOperand *MMO)
2262  : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2263 
2264  // MaskedLoadSDNode (Chain, ptr, mask, passthru)
2265  // MaskedStoreSDNode (Chain, data, ptr, mask)
2266  // Mask is a vector of i1 elements
2267  const SDValue &getBasePtr() const {
2268  return getOperand(getOpcode() == ISD::MLOAD ? 1 : 2);
2269  }
2270  const SDValue &getMask() const {
2271  return getOperand(getOpcode() == ISD::MLOAD ? 2 : 3);
2272  }
2273 
2274  static bool classof(const SDNode *N) {
2275  return N->getOpcode() == ISD::MLOAD ||
2276  N->getOpcode() == ISD::MSTORE;
2277  }
2278 };
2279 
2280 /// This class is used to represent an MLOAD node
2282 public:
2283  friend class SelectionDAG;
2284 
2285  MaskedLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2286  ISD::LoadExtType ETy, bool IsExpanding, EVT MemVT,
2287  MachineMemOperand *MMO)
2288  : MaskedLoadStoreSDNode(ISD::MLOAD, Order, dl, VTs, MemVT, MMO) {
2289  LoadSDNodeBits.ExtTy = ETy;
2290  LoadSDNodeBits.IsExpanding = IsExpanding;
2291  }
2292 
2294  return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2295  }
2296 
2297  const SDValue &getBasePtr() const { return getOperand(1); }
2298  const SDValue &getMask() const { return getOperand(2); }
2299  const SDValue &getPassThru() const { return getOperand(3); }
2300 
2301  static bool classof(const SDNode *N) {
2302  return N->getOpcode() == ISD::MLOAD;
2303  }
2304 
2305  bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
2306 };
2307 
2308 /// This class is used to represent an MSTORE node
2310 public:
2311  friend class SelectionDAG;
2312 
2313  MaskedStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2314  bool isTrunc, bool isCompressing, EVT MemVT,
2315  MachineMemOperand *MMO)
2316  : MaskedLoadStoreSDNode(ISD::MSTORE, Order, dl, VTs, MemVT, MMO) {
2317  StoreSDNodeBits.IsTruncating = isTrunc;
2318  StoreSDNodeBits.IsCompressing = isCompressing;
2319  }
2320 
2321  /// Return true if the op does a truncation before store.
2322  /// For integers this is the same as doing a TRUNCATE and storing the result.
2323  /// For floats, it is the same as doing an FP_ROUND and storing the result.
2324  bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2325 
2326  /// Returns true if the op does a compression to the vector before storing.
2327  /// The node contiguously stores the active elements (integers or floats)
2328  /// in src (those with their respective bit set in writemask k) to unaligned
2329  /// memory at base_addr.
2330  bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
2331 
2332  const SDValue &getValue() const { return getOperand(1); }
2333  const SDValue &getBasePtr() const { return getOperand(2); }
2334  const SDValue &getMask() const { return getOperand(3); }
2335 
2336  static bool classof(const SDNode *N) {
2337  return N->getOpcode() == ISD::MSTORE;
2338  }
2339 };
2340 
2341 /// This is a base class used to represent
2342 /// MGATHER and MSCATTER nodes
2343 ///
2345 public:
2346  friend class SelectionDAG;
2347 
2349  const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2350  MachineMemOperand *MMO)
2351  : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2352 
2353  // In the both nodes address is Op1, mask is Op2:
2354  // MaskedGatherSDNode (Chain, passthru, mask, base, index, scale)
2355  // MaskedScatterSDNode (Chain, value, mask, base, index, scale)
2356  // Mask is a vector of i1 elements
2357  const SDValue &getBasePtr() const { return getOperand(3); }
2358  const SDValue &getIndex() const { return getOperand(4); }
2359  const SDValue &getMask() const { return getOperand(2); }
2360  const SDValue &getScale() const { return getOperand(5); }
2361 
2362  static bool classof(const SDNode *N) {
2363  return N->getOpcode() == ISD::MGATHER ||
2364  N->getOpcode() == ISD::MSCATTER;
2365  }
2366 };
2367 
2368 /// This class is used to represent an MGATHER node
2369 ///
2371 public:
2372  friend class SelectionDAG;
2373 
2374  MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2375  EVT MemVT, MachineMemOperand *MMO)
2376  : MaskedGatherScatterSDNode(ISD::MGATHER, Order, dl, VTs, MemVT, MMO) {}
2377 
2378  const SDValue &getPassThru() const { return getOperand(1); }
2379 
2380  static bool classof(const SDNode *N) {
2381  return N->getOpcode() == ISD::MGATHER;
2382  }
2383 };
2384 
2385 /// This class is used to represent an MSCATTER node
2386 ///
2388 public:
2389  friend class SelectionDAG;
2390 
2391  MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2392  EVT MemVT, MachineMemOperand *MMO)
2393  : MaskedGatherScatterSDNode(ISD::MSCATTER, Order, dl, VTs, MemVT, MMO) {}
2394 
2395  const SDValue &getValue() const { return getOperand(1); }
2396 
2397  static bool classof(const SDNode *N) {
2398  return N->getOpcode() == ISD::MSCATTER;
2399  }
2400 };
2401 
2402 /// An SDNode that represents everything that will be needed
2403 /// to construct a MachineInstr. These nodes are created during the
2404 /// instruction selection proper phase.
2405 ///
2406 /// Note that the only supported way to set the `memoperands` is by calling the
2407 /// `SelectionDAG::setNodeMemRefs` function as the memory management happens
2408 /// inside the DAG rather than in the node.
2409 class MachineSDNode : public SDNode {
2410 private:
2411  friend class SelectionDAG;
2412 
2413  MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL, SDVTList VTs)
2414  : SDNode(Opc, Order, DL, VTs) {}
2415 
2416  // We use a pointer union between a single `MachineMemOperand` pointer and
2417  // a pointer to an array of `MachineMemOperand` pointers. This is null when
2418  // the number of these is zero, the single pointer variant used when the
2419  // number is one, and the array is used for larger numbers.
2420  //
2421  // The array is allocated via the `SelectionDAG`'s allocator and so will
2422  // always live until the DAG is cleaned up and doesn't require ownership here.
2423  //
2424  // We can't use something simpler like `TinyPtrVector` here because `SDNode`
2425  // subclasses aren't managed in a conforming C++ manner. See the comments on
2426  // `SelectionDAG::MorphNodeTo` which details what all goes on, but the
2427  // constraint here is that these don't manage memory with their constructor or
2428  // destructor and can be initialized to a good state even if they start off
2429  // uninitialized.
2431 
2432  // Note that this could be folded into the above `MemRefs` member if doing so
2433  // is advantageous at some point. We don't need to store this in most cases.
2434  // However, at the moment this doesn't appear to make the allocation any
2435  // smaller and makes the code somewhat simpler to read.
2436  int NumMemRefs = 0;
2437 
2438 public:
2440 
2442  // Special case the common cases.
2443  if (NumMemRefs == 0)
2444  return {};
2445  if (NumMemRefs == 1)
2446  return makeArrayRef(MemRefs.getAddrOfPtr1(), 1);
2447 
2448  // Otherwise we have an actual array.
2449  return makeArrayRef(MemRefs.get<MachineMemOperand **>(), NumMemRefs);
2450  }
2451  mmo_iterator memoperands_begin() const { return memoperands().begin(); }
2452  mmo_iterator memoperands_end() const { return memoperands().end(); }
2453  bool memoperands_empty() const { return memoperands().empty(); }
2454 
2455  /// Clear out the memory reference descriptor list.
2456  void clearMemRefs() {
2457  MemRefs = nullptr;
2458  NumMemRefs = 0;
2459  }
2460 
2461  static bool classof(const SDNode *N) {
2462  return N->isMachineOpcode();
2463  }
2464 };
2465 
2466 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
2467  SDNode, ptrdiff_t> {
2468  const SDNode *Node;
2469  unsigned Operand;
2470 
2471  SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2472 
2473 public:
2474  bool operator==(const SDNodeIterator& x) const {
2475  return Operand == x.Operand;
2476  }
2477  bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2478 
2479  pointer operator*() const {
2480  return Node->getOperand(Operand).getNode();
2481  }
2482  pointer operator->() const { return operator*(); }
2483 
2484  SDNodeIterator& operator++() { // Preincrement
2485  ++Operand;
2486  return *this;
2487  }
2488  SDNodeIterator operator++(int) { // Postincrement
2489  SDNodeIterator tmp = *this; ++*this; return tmp;
2490  }
2491  size_t operator-(SDNodeIterator Other) const {
2492  assert(Node == Other.Node &&
2493  "Cannot compare iterators of two different nodes!");
2494  return Operand - Other.Operand;
2495  }
2496 
2497  static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
2498  static SDNodeIterator end (const SDNode *N) {
2499  return SDNodeIterator(N, N->getNumOperands());
2500  }
2501 
2502  unsigned getOperand() const { return Operand; }
2503  const SDNode *getNode() const { return Node; }
2504 };
2505 
2506 template <> struct GraphTraits<SDNode*> {
2507  using NodeRef = SDNode *;
2509 
2510  static NodeRef getEntryNode(SDNode *N) { return N; }
2511 
2513  return SDNodeIterator::begin(N);
2514  }
2515 
2517  return SDNodeIterator::end(N);
2518  }
2519 };
2520 
2521 /// A representation of the largest SDNode, for use in sizeof().
2522 ///
2523 /// This needs to be a union because the largest node differs on 32 bit systems
2524 /// with 4 and 8 byte pointer alignment, respectively.
2528 
2529 /// The SDNode class with the greatest alignment requirement.
2531 
2532 namespace ISD {
2533 
2534  /// Returns true if the specified node is a non-extending and unindexed load.
2535  inline bool isNormalLoad(const SDNode *N) {
2536  const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2537  return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2539  }
2540 
2541  /// Returns true if the specified node is a non-extending load.
2542  inline bool isNON_EXTLoad(const SDNode *N) {
2543  return isa<LoadSDNode>(N) &&
2544  cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2545  }
2546 
2547  /// Returns true if the specified node is a EXTLOAD.
2548  inline bool isEXTLoad(const SDNode *N) {
2549  return isa<LoadSDNode>(N) &&
2550  cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2551  }
2552 
2553  /// Returns true if the specified node is a SEXTLOAD.
2554  inline bool isSEXTLoad(const SDNode *N) {
2555  return isa<LoadSDNode>(N) &&
2556  cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2557  }
2558 
2559  /// Returns true if the specified node is a ZEXTLOAD.
2560  inline bool isZEXTLoad(const SDNode *N) {
2561  return isa<LoadSDNode>(N) &&
2562  cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2563  }
2564 
2565  /// Returns true if the specified node is an unindexed load.
2566  inline bool isUNINDEXEDLoad(const SDNode *N) {
2567  return isa<LoadSDNode>(N) &&
2568  cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2569  }
2570 
2571  /// Returns true if the specified node is a non-truncating
2572  /// and unindexed store.
2573  inline bool isNormalStore(const SDNode *N) {
2574  const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2575  return St && !St->isTruncatingStore() &&
2577  }
2578 
2579  /// Returns true if the specified node is a non-truncating store.
2580  inline bool isNON_TRUNCStore(const SDNode *N) {
2581  return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2582  }
2583 
2584  /// Returns true if the specified node is a truncating store.
2585  inline bool isTRUNCStore(const SDNode *N) {
2586  return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2587  }
2588 
2589  /// Returns true if the specified node is an unindexed store.
2590  inline bool isUNINDEXEDStore(const SDNode *N) {
2591  return isa<StoreSDNode>(N) &&
2592  cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2593  }
2594 
2595  /// Attempt to match a unary predicate against a scalar/splat constant or
2596  /// every element of a constant BUILD_VECTOR.
2597  /// If AllowUndef is true, then UNDEF elements will pass nullptr to Match.
2600  bool AllowUndefs = false);
2601 
2602  /// Attempt to match a binary predicate against a pair of scalar/splat
2603  /// constants or every element of a pair of constant BUILD_VECTORs.
2604  /// If AllowUndef is true, then UNDEF elements will pass nullptr to Match.
2605  bool matchBinaryPredicate(
2606  SDValue LHS, SDValue RHS,
2608  bool AllowUndefs = false);
2609 } // end namespace ISD
2610 
2611 } // end namespace llvm
2612 
2613 #endif // LLVM_CODEGEN_SELECTIONDAGNODES_H
ANNOTATION_LABEL - Represents a mid basic block label used by annotations.
Definition: ISDOpcodes.h:709
bool isMachineConstantPoolEntry() const
Iterator for directly iterating over the operand SDValue&#39;s.
void setAllowReciprocal(bool b)
void setAllowReassociation(bool b)
bool isInvariant() const
BUILTIN_OP_END - This must be the last enum value in this list.
Definition: ISDOpcodes.h:913
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
EVT getValueType() const
Return the ValueType of the referenced return value.
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:48
static void commuteMask(MutableArrayRef< int > Mask)
Change values in a shuffle permute mask assuming the two vector operands have swapped position...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
const SDValue & getOffset() const
void setFlags(SDNodeFlags NewFlags)
static bool isConstant(const MachineInstr &MI)
bool isUndef() const
bool hasNoSignedZeros() const
First const * getAddrOfPtr1() const
If the union is set to the first pointer type get an address pointing to it.
Definition: PointerUnion.h:220
Constrained versions of libm-equivalent floating point intrinsics.
Definition: ISDOpcodes.h:300
This SDNode is used for target intrinsics that touch memory and need an associated MachineMemOperand...
bool hasNoNaNs() const
Test if this operation&#39;s arguments and results are assumed not-NaN.
Definition: Operator.h:332
const GlobalValue * getGlobal() const
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
MCSymbol * getLabel() const
bool hasNoInfs() const
Test if this operation&#39;s arguments and results are assumed not-infinite.
Definition: Operator.h:337
bool isBuildVectorOfConstantSDNodes(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR node of all ConstantSDNode or undef...
static bool classof(const SDNode *N)
bool isIndexed() const
Return true if this is a pre/post inc/dec load/store.
Atomic ordering constants.
unsigned char getTargetFlags() const
MDNODE_SDNODE - This is a node that holdes an MDNode*, which is used to reference metadata in the IR...
Definition: ISDOpcodes.h:767
int64_t getOffset() const
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool isNON_TRUNCStore(const SDNode *N)
Returns true if the specified node is a non-truncating store.
value_iterator value_end() const
Various leaf nodes.
Definition: ISDOpcodes.h:59
bool isCompareAndSwap() const
Returns true if this SDNode represents cmpxchg atomic operation, false otherwise. ...
void intersectWith(const SDNodeFlags Flags)
Clear any flags in this flag set that aren&#39;t also set in Flags.
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
Definition: ISDOpcodes.h:391
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Definition: ValueTypes.h:259
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
const SDValue & getVal() const
#define BEGIN_TWO_BYTE_PACK()
constexpr char IsVolatile[]
Key for Kernel::Arg::Metadata::mIsVolatile.
const Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
unsigned getIROrder() const
Return the node ordering.
const SDValue & getBasePtr() const
bool isNegative() const
Return true if the value is negative.
bool isTargetMemoryOpcode() const
Test if this node has a target-specific memory-referencing opcode (in the <target>ISD namespace and g...
const SDNode * getNode() const
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
bool operator<(const SDValue &O) const
MachineBasicBlock * getBasicBlock() const
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
StoreSDNodeBitfields StoreSDNodeBits
bool isMemIntrinsic() const
Test if this node is a memory intrinsic (with valid pointer information).
const SDValue & getValue() const
SDVTList getVTList() const
unsigned Reg
DEMANGLE_DUMP_METHOD void dump() const
This file contains the declarations for metadata subclasses.
bool isCompressingStore() const
Returns true if the op does a compression to the vector before storing.
MCSymbol * getMCSymbol() const
bool isTargetOpcode() const
bool atEnd() const
Return true if this iterator is at the end of uses list.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:252
const SDValue & getBasePtr() const
uint32_t NodeId
Definition: RDFGraph.h:260
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
Completely target-dependent object reference.
const SDValue & getBasePtr() const
void copyFMF(const FPMathOperator &FPMO)
Propagate the fast-math-flags from an IR FPMathOperator.
const SDValue & getChain() const
static bool classof(const SDNode *N)
unsigned getResNo() const
Convenience function for get().getResNo().
ISD::MemIndexedMode getAddressingMode() const
Return the addressing mode for this load or store: unindexed, pre-inc, pre-dec, post-inc, or post-dec.
TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or anything else with this node...
Definition: ISDOpcodes.h:130
unsigned getAlignment() const
bool operator==(const use_iterator &x) const
unsigned getValueSizeInBits(unsigned ResNo) const
Returns MVT::getSizeInBits(getValueType(ResNo)).
bool isBitwiseNot(SDValue V)
Returns true if V is a bitwise not operation.
Val, Success, OUTCHAIN = ATOMIC_CMP_SWAP_WITH_SUCCESS(INCHAIN, ptr, cmp, swap) N.b.
Definition: ISDOpcodes.h:833
bool isAllOnesOrAllOnesSplat(SDValue V)
Return true if the value is a constant -1 integer or a splatted vector of a constant -1 integer (with...
Constrained versions of the binary floating point operators.
Definition: ISDOpcodes.h:293
SDLoc(const SDNode *N)
A debug info location.
Definition: DebugLoc.h:33
Metadata node.
Definition: Metadata.h:863
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
bool hasAllowContract() const
Test if this operation can be floating-point contracted (FMA).
Definition: Operator.h:352
void setApproximateFuncs(bool b)
const SDNodeFlags getFlags() const
void setNodeId(int Id)
Set unique node id.
bool isTargetOpcode() const
Test if this node has a target-specific opcode (in the <target>ISD namespace).
SDNode * getNode() const
get the SDNode which holds the desired result
static bool classof(const SDNode *N)
#define op(i)
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
void setNoSignedZeros(bool b)
uint64_t getBaseAlignment() const
Return the minimum known alignment in bytes of the base address, without the offset.
static ChildIteratorType child_end(NodeRef N)
static SimpleType getSimplifiedValue(SDUse &Val)
uint16_t PersistentId
Unique and persistent id per SDNode in the DAG.
T get() const
Returns the value of the specified pointer type.
Definition: PointerUnion.h:205
unsigned int NumVTs
const DebugLoc & getDebugLoc() const
Return the source location info.
SDUse * getNext() const
Get the next SDUse in the use list.
unsigned getValueSizeInBits() const
Returns the size of the value in bits.
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition: ISDOpcodes.h:38
const ConstantFP * getConstantFPValue() const
const DebugLoc & getDebugLoc() const
This SDNode is used to implement the code generator support for the llvm IR shufflevector instruction...
static bool classof(const SDNode *N)
bool hasApproximateFuncs() const
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
Definition: ISDOpcodes.h:158
bool isTruncatingStore() const
Return true if the op does a truncation before store.
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.
unsigned getAddressSpace() const
Return the address space for the associated pointer.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:343
unsigned char getTargetFlags() const
static bool classof(const SDNode *N)
bool isAtomic() const
Returns true if this operation has an atomic ordering requirement of unordered or higher...
static SDVTList getSDVTList(EVT VT)
void setNoSignedWrap(bool b)
The address of a basic block.
Definition: Constants.h:839
AAMDNodes getAAInfo() const
Return the AA tags for the memory reference.
static bool classof(const SDNode *N)
bool isSEXTLoad(const SDNode *N)
Returns true if the specified node is a SEXTLOAD.
bool hasOneUse() const
Return true if there is exactly one use of this node.
A description of a memory reference used in the backend.
Definition: BitVector.h:937
std::iterator< std::forward_iterator_tag, SDUse, ptrdiff_t >::reference reference
static bool classof(const SDNode *N)
void setVectorReduction(bool b)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:450
bool matchUnaryPredicate(SDValue Op, std::function< bool(ConstantSDNode *)> Match, bool AllowUndefs=false)
Attempt to match a unary predicate against a scalar/splat constant or every element of a constant BUI...
bool isNormalStore(const SDNode *N)
Returns true if the specified node is a non-truncating and unindexed store.
const MDNode * getRanges() const
Return the range tag for the memory reference.
Base class for LoadSDNode and StoreSDNode.
bool isBuildVectorAllZeros(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR where all of the elements are 0 or undef...
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
Definition: VPlanSLP.cpp:196
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:41
const SDValue & getPassThru() const
const MDNode * getMD() const
ArrayRef< MachineMemOperand * > memoperands() const
op_iterator op_end() const
unsigned getScalarValueSizeInBits() const
uint64_t getConstantOperandVal(unsigned i) const
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
bool isZEXTLoad(const SDNode *N)
Returns true if the specified node is a ZEXTLOAD.
Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt) Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN, ptr, amt) For double-word atomic operations: ValLo, ValHi, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amtLo, amtHi) ValLo, ValHi, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN, ptr, amtLo, amtHi) These correspond to the atomicrmw instruction.
Definition: ISDOpcodes.h:841
const SDValue & getValue() const
bool hasAllowReciprocal() const
Test if this operation can use reciprocal multiply instead of division.
Definition: Operator.h:347
bool isTRUNCStore(const SDNode *N)
Returns true if the specified node is a truncating store.
This class is used to represent EVT&#39;s, which are used to parameterize some operations.
const BlockAddress * getBlockAddress() const
This is an SDNode representing atomic operations.
ShuffleVectorSDNode(EVT VT, unsigned Order, const DebugLoc &dl, const int *M)
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:851
AtomicOrdering getOrdering() const
Return the atomic ordering requirements for this memory operation.
static unsigned getHashValue(const SDValue &Val)
APInt operator*(APInt a, uint64_t RHS)
Definition: APInt.h:2090
This represents a list of ValueType&#39;s that has been intern&#39;d by a SelectionDAG.
bool isConstantSplatVector(const SDNode *N, APInt &SplatValue)
Node predicates.
This class is used to represent an MSTORE node.
AtomicOrdering
Atomic ordering for LLVM&#39;s memory model.
LoadSDNodeBitfields LoadSDNodeBits
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
Definition: Constants.h:200
int64_t getSExtValue() const
bool operator==(const SDValue &V) const
Convenience function for get().operator==.
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:291
#define UINT64_MAX
Definition: DataTypes.h:83
static bool classof(const SDNode *N)
SDValue()=default
AtomicOrdering getOrdering() const
Return the atomic ordering requirements for this memory operation.
static bool classof(const SDNode *N)
void checkForCycles(const SelectionDAG *DAG, bool force=false)
bool writeMem() const
bool isOneOrOneSplat(SDValue V)
Return true if the value is a constant 1 integer or a splatted vector of a constant 1 integer (with n...
void clearMemRefs()
Clear out the memory reference descriptor list.
static SDNodeIterator begin(const SDNode *N)
bool isUNINDEXEDStore(const SDNode *N)
Returns true if the specified node is an unindexed store.
static bool classof(const SDNode *N)
static bool classof(const SDNode *N)
#define END_TWO_BYTE_PACK()
const SDValue & getScale() const
bool isNegative() const
Return true if the sign bit is set.
Definition: Constants.h:308
SDValue peekThroughBitcasts(SDValue V)
Return the non-bitcasted source operand of V if it exists.
static SimpleType getSimplifiedValue(const SDValue &Val)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
static bool classof(const SDNode *N)
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:137
static bool classof(const SDNode *N)
bool isMinusOne() const
This function will return true iff every bit in this constant is set to true.
Definition: Constants.h:208
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
Definition: ISDOpcodes.h:995
op_iterator op_begin() const
X = STRICT_FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition: ISDOpcodes.h:323
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification, or lowering of the constant.
Definition: ISDOpcodes.h:124
MachineConstantPoolValue * MachineCPVal
ArrayRef< SDUse > ops() const
void setIROrder(unsigned Order)
Set the node ordering.
const SDValue & getMask() const
int64_t getSrcValueOffset() const
bool getHasDebugValue() const
mmo_iterator memoperands_end() const
unsigned getSrcAddressSpace() const
SDNodeBitfields SDNodeBits
const char * getSymbol() const
static bool classof(const SDNode *N)
bool use_empty() const
Return true if there are no nodes using value ResNo of Node.
UNDEF - An undefined node.
Definition: ISDOpcodes.h:177
This class is used to represent ISD::STORE nodes.
MaskedStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, bool isTrunc, bool isCompressing, EVT MemVT, MachineMemOperand *MMO)
bool hasAllowReciprocal() const
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the specified, possibly variable...
Definition: ISDOpcodes.h:351
bool isOneConstant(SDValue V)
Returns true if V is a constant integer one.
This corresponds to the llvm.lifetime.
Definition: ISDOpcodes.h:877
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
SDNode * operator->() const
bool isZero() const
Return true if the value is positive or negative zero.
bool hasAllowContract() const
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:305
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
const SDValue & getBasePtr() const
static bool classof(const SDNode *N)
bool isNormalLoad(const SDNode *N)
Returns true if the specified node is a non-extending and unindexed load.
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
Definition: ISDOpcodes.h:165
const SDValue & operator*() const
bool isNaN() const
Return true if the value is a NaN.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition: Constants.h:148
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:290
use_iterator use_begin() const
Provide iteration support to walk over all uses of an SDNode.
Machine Value Type.
static bool classof(const SDNode *N)
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
bool isMachineOpcode() const
CRTP base class for adapting an iterator to a different type.
Definition: iterator.h:205
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:272
static Optional< bool > isBigEndian(const SmallVector< int64_t, 4 > &ByteOffsets, int64_t FirstOffset)
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:148
This is an important base class in LLVM.
Definition: Constant.h:41
iterator_range< value_op_iterator > op_values() const
SDNode * getGluedUser() const
If this node has a glue value with a user, return the user (there is at most one).
static bool classof(const SDNode *N)
const SDValue & getOperand(unsigned Num) const
bool operator==(const SDValue &O) const
bool operator!=(const SDValue &V) const
Convenience function for get().operator!=.
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
Definition: ISDOpcodes.h:970
This SDNode is used for LIFETIME_START/LIFETIME_END values, which indicate the offet and size that ar...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool isOperandOf(const SUnit *SU, SDNode *N)
bool matchBinaryPredicate(SDValue LHS, SDValue RHS, std::function< bool(ConstantSDNode *, ConstantSDNode *)> Match, bool AllowUndefs=false)
Attempt to match a binary predicate against a pair of scalar/splat constants or every element of a pa...
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:263
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:370
unsigned char getTargetFlags() const
This is a base class used to represent MGATHER and MSCATTER nodes.
unsigned char getTargetFlags() const
const SDValue & getOffset() const
unsigned getDestAddressSpace() const
bool isTargetMemoryOpcode() const
bool isExactlyValue(double V) const
We don&#39;t rely on operator== working on double values, as it returns true for things that are clearly ...
Definition: APFloat.h:1129
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This class provides iterator support for SDUse operands that use a specific SDNode.
bool isExactlyValue(double V) const
We don&#39;t rely on operator== working on double values, as it returns true for things that are clearly ...
static bool classof(const SDNode *N)
unsigned getMachineOpcode() const
bool hasNoNaNs() const
void setNoInfs(bool b)
SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
Create an SDNode.
const APInt & getAPIntValue() const
TargetIndex - Like a constant pool entry, but with completely target-dependent semantics.
Definition: ISDOpcodes.h:143
static bool classof(const SDNode *N)
SDNodeIterator & operator++()
SDNodeIterator operator++(int)
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
bool isDefined() const
Returns true if the flags are in a defined state.
SDNode * getGluedNode() const
If this node has a glue operand, return the node to which the glue operand points.
static bool classof(const SDNode *N)
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:381
unsigned getOriginalAlignment() const
Returns alignment and volatility of the memory access.
void setAllowContract(bool b)
const SDValue & getValue() const
static bool classof(const SDNode *N)
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo...
Definition: ISDOpcodes.h:827
unsigned char getTargetFlags() const
void addUse(SDUse &U)
This method should only be used by the SDUse class.
static bool classof(const SDNode *N)
const SDValue & getIndex() const
Extended Value Type.
Definition: ValueTypes.h:33
static bool classof(const SDNode *N)
const SDValue & getBasePtr() const
Abstract base class for all machine specific constantpool value subclasses.
static bool classof(const SDNode *N)
static wasm::ValType getType(const TargetRegisterClass *RC)
static bool classof(const SDNode *N)
bool isVolatile() const
This class contains a discriminated union of information about pointers in memory operands...
bool hasApproxFunc() const
Test if this operation allows approximations of math library functions or intrinsics.
Definition: Operator.h:358
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
unsigned getNumOperands() const
Return the number of values used by this operation.
HANDLENODE node - Used as a handle for various purposes.
Definition: ISDOpcodes.h:781
uint64_t getAlignment() const
Return the minimum known alignment in bytes of the actual memory reference.
const SDValue & getMask() const
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
Definition: ISDOpcodes.h:703
bool isUnindexed() const
Return true if this is NOT a pre/post inc/dec load/store.
void refineAlignment(const MachineMemOperand *MMO)
Update this MachineMemOperand to reflect the alignment of MMO, if it has a greater alignment...
bool isEXTLoad(const SDNode *N)
Returns true if the specified node is a EXTLOAD.
ConstantFPSDNode * isConstOrConstSplatFP(SDValue N, bool AllowUndefs=false)
Returns the SDNode if it is a constant splat BuildVector or constant float.
MachineMemOperand * MMO
Memory reference information.
static bool classof(const SDNode *N)
bool isUNINDEXEDLoad(const SDNode *N)
Returns true if the specified node is an unindexed load.
const APFloat & getValueAPF() const
Definition: Constants.h:302
bool hasAllowReassoc() const
Test if this operation may be simplified with reassociative transforms.
Definition: Operator.h:327
const APInt & getConstantOperandAPInt(unsigned i) const
bool use_empty() const
Return true if there are no uses of this node.
size_type size() const
Definition: SmallPtrSet.h:92
SDNode * getNode() const
Convenience function for get().getNode().
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static bool isUndef(ArrayRef< int > Mask)
TokenFactor - This node takes multiple tokens as input and produces a single token result...
Definition: ISDOpcodes.h:49
bool isBuildVectorAllOnes(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR where all of the elements are ~0 or undef...
ConstantSDNodeBitfields ConstantSDNodeBits
static bool classof(const SDNode *N)
bool memoperands_empty() const
bool hasNoSignedZeros() const
Test if this operation can ignore the sign of zero.
Definition: Operator.h:342
void setNoUnsignedWrap(bool b)
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
Definition: Constants.h:250
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
void setNode(SDNode *N)
set the SDNode
bool isNullOrNullSplat(SDValue V, bool AllowUndefs=false)
Return true if the value is a constant 0 integer or a splatted vector of a constant 0 integer (with n...
use_iterator(const use_iterator &I)
TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:221
const SDValue & getMask() const
void setDefined()
Sets the state of the flags to the defined state.
ADDRSPACECAST - This operator converts between pointers of different address spaces.
Definition: ISDOpcodes.h:599
value_iterator value_begin() const
static bool classof(const SDNode *N)
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:841
Utility class for floating point operations which can have information about relaxed accuracy require...
Definition: Operator.h:245
const DebugLoc & getDebugLoc() const
void dump() const
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...
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
An SDNode that represents everything that will be needed to construct a MachineInstr.
const SDValue & getOffset() const
Promote Memory to Register
Definition: Mem2Reg.cpp:109
const SDValue & getPassThru() const
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:643
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:374
This is an abstract virtual class for memory operations.
const Constant * getConstVal() const
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
bool isDivergent() const
static const int FIRST_TARGET_MEMORY_OPCODE
FIRST_TARGET_MEMORY_OPCODE - Target-specific pre-isel operations which do not reference a specific me...
Definition: ISDOpcodes.h:920
void setNoNaNs(bool b)
Represents one node in the SelectionDAG.
bool readMem() const
bool operator==(const SDNodeIterator &x) const
unsigned char getTargetFlags() const
static bool classof(const SDNode *N)
bool isDereferenceable() const
size_t use_size() const
Return the number of uses of this node.
A range adaptor for a pair of iterators.
EVT getMemoryVT() const
Return the type of the in-memory value.
Class for arbitrary precision integers.
Definition: APInt.h:69
bool isBuildVectorOfConstantFPSDNodes(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR node of all ConstantFPSDNode or undef...
iterator_range< use_iterator > uses()
A "pseudo-class" with methods for operating on BUILD_VECTORs.
SDValue peekThroughOneUseBitcasts(SDValue V)
Return the non-bitcasted and one-use source operand of V if it exists.
static use_iterator use_end()
bool isNullFPConstant(SDValue V)
Returns true if V is an FP constant with a value of positive zero.
pointer operator->() const
This union template exposes a suitably aligned and sized character array member which can hold elemen...
Definition: AlignOf.h:137
unsigned getOperandNo() const
Retrieve the operand # of this use in its user.
iterator_range< use_iterator > uses() const
const SDValue & getBasePtr() const
const uint32_t * getRegMask() const
int getMaskElt(unsigned Idx) const
size_t operator-(SDNodeIterator Other) const
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:387
LSBaseSDNodeBitfields LSBaseSDNodeBits
bool hasVectorReduction() const
static bool classof(const SDNode *N)
static bool classof(const SDNode *N)
int getNodeId() const
Return the unique node id.
static bool classof(const SDNode *N)
bool hasNoSignedWrap() const
pointer operator*() const
void setTruncatingStore(bool Truncating)
static bool isConstantSplat(SDValue Op, APInt &SplatVal)
mmo_iterator memoperands_begin() const
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID for this memory operation.
These are IR-level optimization flags that may be propagated to SDNodes.
Represents a use of a SDNode.
void dumpr() const
SDNode * operator*() const
Retrieve a pointer to the current user node.
ConstantSDNode * isConstOrConstSplat(SDValue N, bool AllowUndefs=false)
Returns the SDNode if it is a constant splat BuildVector or constant int.
const MachinePointerInfo & getPointerInfo() const
static bool classof(const SDNode *N)
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:321
const SDValue & getValue() const
bool operator!=(const use_iterator &x) const
Node - This class is used to maintain the singly linked bucket list in a folding set.
Definition: FoldingSet.h:135
bool operator!=(const SDValue &O) const
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
This base class is used to represent MLOAD and MSTORE nodes.
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
bool isZero() const
Return true if the value is positive or negative zero.
Definition: Constants.h:305
static bool hasOneUse(unsigned Reg, MachineInstr *Def, MachineRegisterInfo &MRI, MachineDominatorTree &MDT, LiveIntervals &LIS)
static bool classof(const SDNode *N)
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition: ISDOpcodes.h:642
bool isNaN() const
Return true if the value is a NaN.
Definition: Constants.h:314
static NodeRef getEntryNode(SDNode *N)
const NodeList & List
Definition: RDFGraph.cpp:201
static SimpleType getSimplifiedValue(SDValue &Val)
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
const ConstantInt * getConstantIntValue() const
const Value * getValue() const
Return the contained Value.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Definition: Constants.h:192
bool isInfinity() const
Return true if the value is infinity.
Definition: Constants.h:311
An SDNode that holds an arbitrary LLVM IR Value.
EVT getValueType() const
Convenience function for get().getValueType().
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:332
uint32_t Size
Definition: Profile.cpp:46
X = STRICT_FP_ROUND(Y, TRUNC) - Rounding &#39;Y&#39; from a larger floating point type down to the precision ...
Definition: ISDOpcodes.h:318
const SDValue & getBasePtr() const
bool operator<(const SDValue &V) const
Convenience function for get().operator<.
bool isNON_EXTLoad(const SDNode *N)
Returns true if the specified node is a non-extending load.
SDValue peekThroughExtractSubvectors(SDValue V)
Return the non-extracted vector source operand of V if it exists.
unsigned getOpcode() const
SDValue getValue(unsigned R) const
bool isInfinity() const
Return true if the value is an infinity.
This class is used to represent an MSCATTER node.
static ChildIteratorType child_begin(NodeRef N)
SDLoc(const SDValue V)
const MachinePointerInfo & getPointerInfo() const
MachineConstantPoolValue * getMachineCPVal() const
MaskedGatherScatterSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class is used to form a handle around another node that is persistent and is updated across invo...
unsigned getReg() const
std::iterator< std::forward_iterator_tag, SDUse, ptrdiff_t >::pointer pointer
bool isAllOnesConstant(SDValue V)
Returns true if V is an integer constant with all bits set.
This class is used to represent an MLOAD node.
MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO)
bool isPredecessorOf(const SDNode *N) const
Return true if this node is a predecessor of N.
unsigned getRawSubclassData() const
Return the SubclassData value, without HasDebugValue.
aarch64 promote const
ArrayRef< int > getMask() const
int64_t getOffset() const
For normal values, this is a byte offset added to the base address.
unsigned getOperand() const
LLVM Value Representation.
Definition: Value.h:72
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
unsigned getResNo() const
get the index which selects a specific result in the SDNode
static bool isEqual(const SDValue &LHS, const SDValue &RHS)
static SDNodeIterator end(const SDNode *N)
const MDNode * getRanges() const
Returns the Ranges that describes the dereference.
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID for this memory operation.
AtomicOrdering getFailureOrdering() const
For cmpxchg atomic operations, return the atomic ordering requirements when store does not occur...
MemSDNodeBitfields MemSDNodeBits
bool isTruncatingStore() const
Return true if the op does a truncation before store.
bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
void setDebugLoc(DebugLoc dl)
Set source location info.
This class is used to represent an MGATHER node.
bool hasNoUnsignedWrap() const
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E&#39;s largest value.
Definition: BitmaskEnum.h:80
PREFETCH - This corresponds to a prefetch intrinsic.
Definition: ISDOpcodes.h:807
void setHasDebugValue(bool b)
bool isNonTemporal() const
LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl, SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT, MachineMemOperand *MMO)
bool isUndef() const
Return true if the type of the node type undefined.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
SDNodeFlags()
Default constructor turns off all optimization flags.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX)
bool hasAllowReassociation() const
print Print MemDeps of function
SDLoc(const Instruction *I, int Order)
const APFloat & getValueAPF() const
static bool classof(const SDNode *N)
bool hasNoInfs() const
ISD::LoadExtType getExtensionType() const
static bool isSplat(ArrayRef< Value *> VL)
bool operator!=(const SDNodeIterator &x) const
static constexpr size_t getMaxNumOperands()
Return the maximum number of operands that a SDNode can hold.
bool operator==(uint64_t V1, const APInt &V2)
Definition: APInt.h:1966
unsigned getNumOperands() const
bool isStrictFPOpcode()
Test if this node is a strict floating point pseudo-op.
const SDValue & getOperand(unsigned i) const
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
Definition: Constants.h:156
OUTCHAIN = ATOMIC_STORE(INCHAIN, ptr, val) This corresponds to "store atomic" instruction.
Definition: ISDOpcodes.h:820
SDNode * getUser()
This returns the SDNode that contains this Use.
MaskedLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, ISD::LoadExtType ETy, bool IsExpanding, EVT MemVT, MachineMemOperand *MMO)
uint64_t getZExtValue() const
bool hasPredecessor(const SDNode *N) const
Return true if N is a predecessor of this node.
const APInt & getConstantOperandAPInt(unsigned Num) const
Helper method returns the APInt of a ConstantSDNode operand.
AtomicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTL, EVT MemVT, MachineMemOperand *MMO)
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
int64_t getFrameIndex() const
MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemoryVT, MachineMemOperand *MMO)
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
Definition: ISDOpcodes.h:816
const SDValue & getBasePtr() const
const SDValue & getMask() const
unsigned getIROrder() const
MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO)
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:163
void refineAlignment(const MachineMemOperand *NewMMO)
Update this MemSDNode&#39;s MachineMemOperand information to reflect the alignment of NewMMO...
bool hasTrivialDestructor() const
Check whether this has a trivial destructor.
Definition: DebugLoc.h:69
MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO)
MemIndexedMode
MemIndexedMode enum - This enum defines the load / store indexed addressing modes.
Definition: ISDOpcodes.h:950
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:763
This class is used to represent ISD::LOAD nodes.