LLVM  10.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  // We assume instructions do not raise floating-point exceptions by default,
372  // and only those marked explicitly may do so. We could choose to represent
373  // this via a positive "FPExcept" flags like on the MI level, but having a
374  // negative "NoFPExcept" flag here (that defaults to true) makes the flag
375  // intersection logic more straightforward.
376  bool NoFPExcept : 1;
377 
378 public:
379  /// Default constructor turns off all optimization flags.
381  : AnyDefined(false), NoUnsignedWrap(false), NoSignedWrap(false),
382  Exact(false), NoNaNs(false), NoInfs(false),
383  NoSignedZeros(false), AllowReciprocal(false), VectorReduction(false),
384  AllowContract(false), ApproximateFuncs(false),
385  AllowReassociation(false), NoFPExcept(true) {}
386 
387  /// Propagate the fast-math-flags from an IR FPMathOperator.
388  void copyFMF(const FPMathOperator &FPMO) {
389  setNoNaNs(FPMO.hasNoNaNs());
390  setNoInfs(FPMO.hasNoInfs());
391  setNoSignedZeros(FPMO.hasNoSignedZeros());
392  setAllowReciprocal(FPMO.hasAllowReciprocal());
393  setAllowContract(FPMO.hasAllowContract());
394  setApproximateFuncs(FPMO.hasApproxFunc());
395  setAllowReassociation(FPMO.hasAllowReassoc());
396  }
397 
398  /// Sets the state of the flags to the defined state.
399  void setDefined() { AnyDefined = true; }
400  /// Returns true if the flags are in a defined state.
401  bool isDefined() const { return AnyDefined; }
402 
403  // These are mutators for each flag.
404  void setNoUnsignedWrap(bool b) {
405  setDefined();
406  NoUnsignedWrap = b;
407  }
408  void setNoSignedWrap(bool b) {
409  setDefined();
410  NoSignedWrap = b;
411  }
412  void setExact(bool b) {
413  setDefined();
414  Exact = b;
415  }
416  void setNoNaNs(bool b) {
417  setDefined();
418  NoNaNs = b;
419  }
420  void setNoInfs(bool b) {
421  setDefined();
422  NoInfs = b;
423  }
424  void setNoSignedZeros(bool b) {
425  setDefined();
426  NoSignedZeros = b;
427  }
428  void setAllowReciprocal(bool b) {
429  setDefined();
430  AllowReciprocal = b;
431  }
432  void setVectorReduction(bool b) {
433  setDefined();
434  VectorReduction = b;
435  }
436  void setAllowContract(bool b) {
437  setDefined();
438  AllowContract = b;
439  }
440  void setApproximateFuncs(bool b) {
441  setDefined();
442  ApproximateFuncs = b;
443  }
444  void setAllowReassociation(bool b) {
445  setDefined();
446  AllowReassociation = b;
447  }
448  void setFPExcept(bool b) {
449  setDefined();
450  NoFPExcept = !b;
451  }
452 
453  // These are accessors for each flag.
454  bool hasNoUnsignedWrap() const { return NoUnsignedWrap; }
455  bool hasNoSignedWrap() const { return NoSignedWrap; }
456  bool hasExact() const { return Exact; }
457  bool hasNoNaNs() const { return NoNaNs; }
458  bool hasNoInfs() const { return NoInfs; }
459  bool hasNoSignedZeros() const { return NoSignedZeros; }
460  bool hasAllowReciprocal() const { return AllowReciprocal; }
461  bool hasVectorReduction() const { return VectorReduction; }
462  bool hasAllowContract() const { return AllowContract; }
463  bool hasApproximateFuncs() const { return ApproximateFuncs; }
464  bool hasAllowReassociation() const { return AllowReassociation; }
465  bool hasFPExcept() const { return !NoFPExcept; }
466 
467  bool isFast() const {
468  return NoSignedZeros && AllowReciprocal && NoNaNs && NoInfs && NoFPExcept &&
469  AllowContract && ApproximateFuncs && AllowReassociation;
470  }
471 
472  /// Clear any flags in this flag set that aren't also set in Flags.
473  /// If the given Flags are undefined then don't do anything.
474  void intersectWith(const SDNodeFlags Flags) {
475  if (!Flags.isDefined())
476  return;
477  NoUnsignedWrap &= Flags.NoUnsignedWrap;
478  NoSignedWrap &= Flags.NoSignedWrap;
479  Exact &= Flags.Exact;
480  NoNaNs &= Flags.NoNaNs;
481  NoInfs &= Flags.NoInfs;
482  NoSignedZeros &= Flags.NoSignedZeros;
483  AllowReciprocal &= Flags.AllowReciprocal;
484  VectorReduction &= Flags.VectorReduction;
485  AllowContract &= Flags.AllowContract;
486  ApproximateFuncs &= Flags.ApproximateFuncs;
487  AllowReassociation &= Flags.AllowReassociation;
488  NoFPExcept &= Flags.NoFPExcept;
489  }
490 };
491 
492 /// Represents one node in the SelectionDAG.
493 ///
494 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
495 private:
496  /// The operation that this node performs.
497  int16_t NodeType;
498 
499 protected:
500  // We define a set of mini-helper classes to help us interpret the bits in our
501  // SubclassData. These are designed to fit within a uint16_t so they pack
502  // with NodeType.
503 
504 #if defined(_AIX) && (!defined(__GNUC__) || defined(__ibmxl__))
505 // Except for GCC; by default, AIX compilers store bit-fields in 4-byte words
506 // and give the `pack` pragma push semantics.
507 #define BEGIN_TWO_BYTE_PACK() _Pragma("pack(2)")
508 #define END_TWO_BYTE_PACK() _Pragma("pack(pop)")
509 #else
510 #define BEGIN_TWO_BYTE_PACK()
511 #define END_TWO_BYTE_PACK()
512 #endif
513 
516  friend class SDNode;
517  friend class MemIntrinsicSDNode;
518  friend class MemSDNode;
519  friend class SelectionDAG;
520 
521  uint16_t HasDebugValue : 1;
522  uint16_t IsMemIntrinsic : 1;
523  uint16_t IsDivergent : 1;
524  };
525  enum { NumSDNodeBits = 3 };
526 
528  friend class ConstantSDNode;
529 
530  uint16_t : NumSDNodeBits;
531 
532  uint16_t IsOpaque : 1;
533  };
534 
536  friend class MemSDNode;
537  friend class MemIntrinsicSDNode;
538  friend class AtomicSDNode;
539 
540  uint16_t : NumSDNodeBits;
541 
542  uint16_t IsVolatile : 1;
543  uint16_t IsNonTemporal : 1;
544  uint16_t IsDereferenceable : 1;
545  uint16_t IsInvariant : 1;
546  };
547  enum { NumMemSDNodeBits = NumSDNodeBits + 4 };
548 
550  friend class LSBaseSDNode;
552 
553  uint16_t : NumMemSDNodeBits;
554 
555  // This storage is shared between disparate class hierarchies to hold an
556  // enumeration specific to the class hierarchy in use.
557  // LSBaseSDNode => enum ISD::MemIndexedMode
558  // MaskedGatherScatterSDNode => enum ISD::MemIndexType
559  uint16_t AddressingMode : 3;
560  };
561  enum { NumLSBaseSDNodeBits = NumMemSDNodeBits + 3 };
562 
564  friend class LoadSDNode;
565  friend class MaskedLoadSDNode;
566 
567  uint16_t : NumLSBaseSDNodeBits;
568 
569  uint16_t ExtTy : 2; // enum ISD::LoadExtType
570  uint16_t IsExpanding : 1;
571  };
572 
574  friend class StoreSDNode;
575  friend class MaskedStoreSDNode;
576 
577  uint16_t : NumLSBaseSDNodeBits;
578 
579  uint16_t IsTruncating : 1;
580  uint16_t IsCompressing : 1;
581  };
582 
583  union {
584  char RawSDNodeBits[sizeof(uint16_t)];
591  };
593 #undef BEGIN_TWO_BYTE_PACK
594 #undef END_TWO_BYTE_PACK
595 
596  // RawSDNodeBits must cover the entirety of the union. This means that all of
597  // the union's members must have size <= RawSDNodeBits. We write the RHS as
598  // "2" instead of sizeof(RawSDNodeBits) because MSVC can't handle the latter.
599  static_assert(sizeof(SDNodeBitfields) <= 2, "field too wide");
600  static_assert(sizeof(ConstantSDNodeBitfields) <= 2, "field too wide");
601  static_assert(sizeof(MemSDNodeBitfields) <= 2, "field too wide");
602  static_assert(sizeof(LSBaseSDNodeBitfields) <= 2, "field too wide");
603  static_assert(sizeof(LoadSDNodeBitfields) <= 2, "field too wide");
604  static_assert(sizeof(StoreSDNodeBitfields) <= 2, "field too wide");
605 
606 private:
607  friend class SelectionDAG;
608  // TODO: unfriend HandleSDNode once we fix its operand handling.
609  friend class HandleSDNode;
610 
611  /// Unique id per SDNode in the DAG.
612  int NodeId = -1;
613 
614  /// The values that are used by this operation.
615  SDUse *OperandList = nullptr;
616 
617  /// The types of the values this node defines. SDNode's may
618  /// define multiple values simultaneously.
619  const EVT *ValueList;
620 
621  /// List of uses for this SDNode.
622  SDUse *UseList = nullptr;
623 
624  /// The number of entries in the Operand/Value list.
625  unsigned short NumOperands = 0;
626  unsigned short NumValues;
627 
628  // The ordering of the SDNodes. It roughly corresponds to the ordering of the
629  // original LLVM instructions.
630  // This is used for turning off scheduling, because we'll forgo
631  // the normal scheduling algorithms and output the instructions according to
632  // this ordering.
633  unsigned IROrder;
634 
635  /// Source line information.
636  DebugLoc debugLoc;
637 
638  /// Return a pointer to the specified value type.
639  static const EVT *getValueTypeList(EVT VT);
640 
641  SDNodeFlags Flags;
642 
643 public:
644  /// Unique and persistent id per SDNode in the DAG.
645  /// Used for debug printing.
646  uint16_t PersistentId;
647 
648  //===--------------------------------------------------------------------===//
649  // Accessors
650  //
651 
652  /// Return the SelectionDAG opcode value for this node. For
653  /// pre-isel nodes (those for which isMachineOpcode returns false), these
654  /// are the opcode values in the ISD and <target>ISD namespaces. For
655  /// post-isel opcodes, see getMachineOpcode.
656  unsigned getOpcode() const { return (unsigned short)NodeType; }
657 
658  /// Test if this node has a target-specific opcode (in the
659  /// <target>ISD namespace).
660  bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
661 
662  /// Test if this node has a target-specific
663  /// memory-referencing opcode (in the <target>ISD namespace and
664  /// greater than FIRST_TARGET_MEMORY_OPCODE).
665  bool isTargetMemoryOpcode() const {
666  return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
667  }
668 
669  /// Return true if the type of the node type undefined.
670  bool isUndef() const { return NodeType == ISD::UNDEF; }
671 
672  /// Test if this node is a memory intrinsic (with valid pointer information).
673  /// INTRINSIC_W_CHAIN and INTRINSIC_VOID nodes are sometimes created for
674  /// non-memory intrinsics (with chains) that are not really instances of
675  /// MemSDNode. For such nodes, we need some extra state to determine the
676  /// proper classof relationship.
677  bool isMemIntrinsic() const {
678  return (NodeType == ISD::INTRINSIC_W_CHAIN ||
679  NodeType == ISD::INTRINSIC_VOID) &&
680  SDNodeBits.IsMemIntrinsic;
681  }
682 
683  /// Test if this node is a strict floating point pseudo-op.
685  switch (NodeType) {
686  default:
687  return false;
688  case ISD::STRICT_FADD:
689  case ISD::STRICT_FSUB:
690  case ISD::STRICT_FMUL:
691  case ISD::STRICT_FDIV:
692  case ISD::STRICT_FREM:
693  case ISD::STRICT_FMA:
694  case ISD::STRICT_FSQRT:
695  case ISD::STRICT_FPOW:
696  case ISD::STRICT_FPOWI:
697  case ISD::STRICT_FSIN:
698  case ISD::STRICT_FCOS:
699  case ISD::STRICT_FEXP:
700  case ISD::STRICT_FEXP2:
701  case ISD::STRICT_FLOG:
702  case ISD::STRICT_FLOG10:
703  case ISD::STRICT_FLOG2:
704  case ISD::STRICT_FRINT:
706  case ISD::STRICT_FMAXNUM:
707  case ISD::STRICT_FMINNUM:
708  case ISD::STRICT_FCEIL:
709  case ISD::STRICT_FFLOOR:
710  case ISD::STRICT_FROUND:
711  case ISD::STRICT_FTRUNC:
714  return true;
715  }
716  }
717 
718  /// Test if this node has a post-isel opcode, directly
719  /// corresponding to a MachineInstr opcode.
720  bool isMachineOpcode() const { return NodeType < 0; }
721 
722  /// This may only be called if isMachineOpcode returns
723  /// true. It returns the MachineInstr opcode value that the node's opcode
724  /// corresponds to.
725  unsigned getMachineOpcode() const {
726  assert(isMachineOpcode() && "Not a MachineInstr opcode!");
727  return ~NodeType;
728  }
729 
730  bool getHasDebugValue() const { return SDNodeBits.HasDebugValue; }
731  void setHasDebugValue(bool b) { SDNodeBits.HasDebugValue = b; }
732 
733  bool isDivergent() const { return SDNodeBits.IsDivergent; }
734 
735  /// Return true if there are no uses of this node.
736  bool use_empty() const { return UseList == nullptr; }
737 
738  /// Return true if there is exactly one use of this node.
739  bool hasOneUse() const {
740  return !use_empty() && std::next(use_begin()) == use_end();
741  }
742 
743  /// Return the number of uses of this node. This method takes
744  /// time proportional to the number of uses.
745  size_t use_size() const { return std::distance(use_begin(), use_end()); }
746 
747  /// Return the unique node id.
748  int getNodeId() const { return NodeId; }
749 
750  /// Set unique node id.
751  void setNodeId(int Id) { NodeId = Id; }
752 
753  /// Return the node ordering.
754  unsigned getIROrder() const { return IROrder; }
755 
756  /// Set the node ordering.
757  void setIROrder(unsigned Order) { IROrder = Order; }
758 
759  /// Return the source location info.
760  const DebugLoc &getDebugLoc() const { return debugLoc; }
761 
762  /// Set source location info. Try to avoid this, putting
763  /// it in the constructor is preferable.
764  void setDebugLoc(DebugLoc dl) { debugLoc = std::move(dl); }
765 
766  /// This class provides iterator support for SDUse
767  /// operands that use a specific SDNode.
769  : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
770  friend class SDNode;
771 
772  SDUse *Op = nullptr;
773 
774  explicit use_iterator(SDUse *op) : Op(op) {}
775 
776  public:
777  using reference = std::iterator<std::forward_iterator_tag,
779  using pointer = std::iterator<std::forward_iterator_tag,
781 
782  use_iterator() = default;
783  use_iterator(const use_iterator &I) : Op(I.Op) {}
784 
785  bool operator==(const use_iterator &x) const {
786  return Op == x.Op;
787  }
788  bool operator!=(const use_iterator &x) const {
789  return !operator==(x);
790  }
791 
792  /// Return true if this iterator is at the end of uses list.
793  bool atEnd() const { return Op == nullptr; }
794 
795  // Iterator traversal: forward iteration only.
796  use_iterator &operator++() { // Preincrement
797  assert(Op && "Cannot increment end iterator!");
798  Op = Op->getNext();
799  return *this;
800  }
801 
802  use_iterator operator++(int) { // Postincrement
803  use_iterator tmp = *this; ++*this; return tmp;
804  }
805 
806  /// Retrieve a pointer to the current user node.
807  SDNode *operator*() const {
808  assert(Op && "Cannot dereference end iterator!");
809  return Op->getUser();
810  }
811 
812  SDNode *operator->() const { return operator*(); }
813 
814  SDUse &getUse() const { return *Op; }
815 
816  /// Retrieve the operand # of this use in its user.
817  unsigned getOperandNo() const {
818  assert(Op && "Cannot dereference end iterator!");
819  return (unsigned)(Op - Op->getUser()->OperandList);
820  }
821  };
822 
823  /// Provide iteration support to walk over all uses of an SDNode.
825  return use_iterator(UseList);
826  }
827 
828  static use_iterator use_end() { return use_iterator(nullptr); }
829 
831  return make_range(use_begin(), use_end());
832  }
834  return make_range(use_begin(), use_end());
835  }
836 
837  /// Return true if there are exactly NUSES uses of the indicated value.
838  /// This method ignores uses of other values defined by this operation.
839  bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
840 
841  /// Return true if there are any use of the indicated value.
842  /// This method ignores uses of other values defined by this operation.
843  bool hasAnyUseOfValue(unsigned Value) const;
844 
845  /// Return true if this node is the only use of N.
846  bool isOnlyUserOf(const SDNode *N) const;
847 
848  /// Return true if this node is an operand of N.
849  bool isOperandOf(const SDNode *N) const;
850 
851  /// Return true if this node is a predecessor of N.
852  /// NOTE: Implemented on top of hasPredecessor and every bit as
853  /// expensive. Use carefully.
854  bool isPredecessorOf(const SDNode *N) const {
855  return N->hasPredecessor(this);
856  }
857 
858  /// Return true if N is a predecessor of this node.
859  /// N is either an operand of this node, or can be reached by recursively
860  /// traversing up the operands.
861  /// NOTE: This is an expensive method. Use it carefully.
862  bool hasPredecessor(const SDNode *N) const;
863 
864  /// Returns true if N is a predecessor of any node in Worklist. This
865  /// helper keeps Visited and Worklist sets externally to allow unions
866  /// searches to be performed in parallel, caching of results across
867  /// queries and incremental addition to Worklist. Stops early if N is
868  /// found but will resume. Remember to clear Visited and Worklists
869  /// if DAG changes. MaxSteps gives a maximum number of nodes to visit before
870  /// giving up. The TopologicalPrune flag signals that positive NodeIds are
871  /// topologically ordered (Operands have strictly smaller node id) and search
872  /// can be pruned leveraging this.
873  static bool hasPredecessorHelper(const SDNode *N,
876  unsigned int MaxSteps = 0,
877  bool TopologicalPrune = false) {
878  SmallVector<const SDNode *, 8> DeferredNodes;
879  if (Visited.count(N))
880  return true;
881 
882  // Node Id's are assigned in three places: As a topological
883  // ordering (> 0), during legalization (results in values set to
884  // 0), new nodes (set to -1). If N has a topolgical id then we
885  // know that all nodes with ids smaller than it cannot be
886  // successors and we need not check them. Filter out all node
887  // that can't be matches. We add them to the worklist before exit
888  // in case of multiple calls. Note that during selection the topological id
889  // may be violated if a node's predecessor is selected before it. We mark
890  // this at selection negating the id of unselected successors and
891  // restricting topological pruning to positive ids.
892 
893  int NId = N->getNodeId();
894  // If we Invalidated the Id, reconstruct original NId.
895  if (NId < -1)
896  NId = -(NId + 1);
897 
898  bool Found = false;
899  while (!Worklist.empty()) {
900  const SDNode *M = Worklist.pop_back_val();
901  int MId = M->getNodeId();
902  if (TopologicalPrune && M->getOpcode() != ISD::TokenFactor && (NId > 0) &&
903  (MId > 0) && (MId < NId)) {
904  DeferredNodes.push_back(M);
905  continue;
906  }
907  for (const SDValue &OpV : M->op_values()) {
908  SDNode *Op = OpV.getNode();
909  if (Visited.insert(Op).second)
910  Worklist.push_back(Op);
911  if (Op == N)
912  Found = true;
913  }
914  if (Found)
915  break;
916  if (MaxSteps != 0 && Visited.size() >= MaxSteps)
917  break;
918  }
919  // Push deferred nodes back on worklist.
920  Worklist.append(DeferredNodes.begin(), DeferredNodes.end());
921  // If we bailed early, conservatively return found.
922  if (MaxSteps != 0 && Visited.size() >= MaxSteps)
923  return true;
924  return Found;
925  }
926 
927  /// Return true if all the users of N are contained in Nodes.
928  /// NOTE: Requires at least one match, but doesn't require them all.
929  static bool areOnlyUsersOf(ArrayRef<const SDNode *> Nodes, const SDNode *N);
930 
931  /// Return the number of values used by this operation.
932  unsigned getNumOperands() const { return NumOperands; }
933 
934  /// Return the maximum number of operands that a SDNode can hold.
935  static constexpr size_t getMaxNumOperands() {
937  }
938 
939  /// Helper method returns the integer value of a ConstantSDNode operand.
940  inline uint64_t getConstantOperandVal(unsigned Num) const;
941 
942  /// Helper method returns the APInt of a ConstantSDNode operand.
943  inline const APInt &getConstantOperandAPInt(unsigned Num) const;
944 
945  const SDValue &getOperand(unsigned Num) const {
946  assert(Num < NumOperands && "Invalid child # of SDNode!");
947  return OperandList[Num];
948  }
949 
950  using op_iterator = SDUse *;
951 
952  op_iterator op_begin() const { return OperandList; }
953  op_iterator op_end() const { return OperandList+NumOperands; }
954  ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
955 
956  /// Iterator for directly iterating over the operand SDValue's.
958  : iterator_adaptor_base<value_op_iterator, op_iterator,
959  std::random_access_iterator_tag, SDValue,
960  ptrdiff_t, value_op_iterator *,
961  value_op_iterator *> {
962  explicit value_op_iterator(SDUse *U = nullptr)
963  : iterator_adaptor_base(U) {}
964 
965  const SDValue &operator*() const { return I->get(); }
966  };
967 
969  return make_range(value_op_iterator(op_begin()),
970  value_op_iterator(op_end()));
971  }
972 
973  SDVTList getVTList() const {
974  SDVTList X = { ValueList, NumValues };
975  return X;
976  }
977 
978  /// If this node has a glue operand, return the node
979  /// to which the glue operand points. Otherwise return NULL.
980  SDNode *getGluedNode() const {
981  if (getNumOperands() != 0 &&
982  getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
983  return getOperand(getNumOperands()-1).getNode();
984  return nullptr;
985  }
986 
987  /// If this node has a glue value with a user, return
988  /// the user (there is at most one). Otherwise return NULL.
989  SDNode *getGluedUser() const {
990  for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
991  if (UI.getUse().get().getValueType() == MVT::Glue)
992  return *UI;
993  return nullptr;
994  }
995 
996  const SDNodeFlags getFlags() const { return Flags; }
997  void setFlags(SDNodeFlags NewFlags) { Flags = NewFlags; }
998  bool isFast() { return Flags.isFast(); }
999 
1000  /// Clear any flags in this node that aren't also set in Flags.
1001  /// If Flags is not in a defined state then this has no effect.
1002  void intersectFlagsWith(const SDNodeFlags Flags);
1003 
1004  /// Return the number of values defined/returned by this operator.
1005  unsigned getNumValues() const { return NumValues; }
1006 
1007  /// Return the type of a specified result.
1008  EVT getValueType(unsigned ResNo) const {
1009  assert(ResNo < NumValues && "Illegal result number!");
1010  return ValueList[ResNo];
1011  }
1012 
1013  /// Return the type of a specified result as a simple type.
1014  MVT getSimpleValueType(unsigned ResNo) const {
1015  return getValueType(ResNo).getSimpleVT();
1016  }
1017 
1018  /// Returns MVT::getSizeInBits(getValueType(ResNo)).
1019  unsigned getValueSizeInBits(unsigned ResNo) const {
1020  return getValueType(ResNo).getSizeInBits();
1021  }
1022 
1023  using value_iterator = const EVT *;
1024 
1025  value_iterator value_begin() const { return ValueList; }
1026  value_iterator value_end() const { return ValueList+NumValues; }
1027 
1028  /// Return the opcode of this operation for printing.
1029  std::string getOperationName(const SelectionDAG *G = nullptr) const;
1030  static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1031  void print_types(raw_ostream &OS, const SelectionDAG *G) const;
1032  void print_details(raw_ostream &OS, const SelectionDAG *G) const;
1033  void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
1034  void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
1035 
1036  /// Print a SelectionDAG node and all children down to
1037  /// the leaves. The given SelectionDAG allows target-specific nodes
1038  /// to be printed in human-readable form. Unlike printr, this will
1039  /// print the whole DAG, including children that appear multiple
1040  /// times.
1041  ///
1042  void printrFull(raw_ostream &O, const SelectionDAG *G = nullptr) const;
1043 
1044  /// Print a SelectionDAG node and children up to
1045  /// depth "depth." The given SelectionDAG allows target-specific
1046  /// nodes to be printed in human-readable form. Unlike printr, this
1047  /// will print children that appear multiple times wherever they are
1048  /// used.
1049  ///
1050  void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
1051  unsigned depth = 100) const;
1052 
1053  /// Dump this node, for debugging.
1054  void dump() const;
1055 
1056  /// Dump (recursively) this node and its use-def subgraph.
1057  void dumpr() const;
1058 
1059  /// Dump this node, for debugging.
1060  /// The given SelectionDAG allows target-specific nodes to be printed
1061  /// in human-readable form.
1062  void dump(const SelectionDAG *G) const;
1063 
1064  /// Dump (recursively) this node and its use-def subgraph.
1065  /// The given SelectionDAG allows target-specific nodes to be printed
1066  /// in human-readable form.
1067  void dumpr(const SelectionDAG *G) const;
1068 
1069  /// printrFull to dbgs(). The given SelectionDAG allows
1070  /// target-specific nodes to be printed in human-readable form.
1071  /// Unlike dumpr, this will print the whole DAG, including children
1072  /// that appear multiple times.
1073  void dumprFull(const SelectionDAG *G = nullptr) const;
1074 
1075  /// printrWithDepth to dbgs(). The given
1076  /// SelectionDAG allows target-specific nodes to be printed in
1077  /// human-readable form. Unlike dumpr, this will print children
1078  /// that appear multiple times wherever they are used.
1079  ///
1080  void dumprWithDepth(const SelectionDAG *G = nullptr,
1081  unsigned depth = 100) const;
1082 
1083  /// Gather unique data for the node.
1084  void Profile(FoldingSetNodeID &ID) const;
1085 
1086  /// This method should only be used by the SDUse class.
1087  void addUse(SDUse &U) { U.addToList(&UseList); }
1088 
1089 protected:
1090  static SDVTList getSDVTList(EVT VT) {
1091  SDVTList Ret = { getValueTypeList(VT), 1 };
1092  return Ret;
1093  }
1094 
1095  /// Create an SDNode.
1096  ///
1097  /// SDNodes are created without any operands, and never own the operand
1098  /// storage. To add operands, see SelectionDAG::createOperands.
1099  SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
1100  : NodeType(Opc), ValueList(VTs.VTs), NumValues(VTs.NumVTs),
1101  IROrder(Order), debugLoc(std::move(dl)) {
1102  memset(&RawSDNodeBits, 0, sizeof(RawSDNodeBits));
1103  assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
1104  assert(NumValues == VTs.NumVTs &&
1105  "NumValues wasn't wide enough for its operands!");
1106  }
1107 
1108  /// Release the operands and set this node to have zero operands.
1109  void DropOperands();
1110 };
1111 
1112 /// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
1113 /// into SDNode creation functions.
1114 /// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
1115 /// from the original Instruction, and IROrder is the ordinal position of
1116 /// the instruction.
1117 /// When an SDNode is created after the DAG is being built, both DebugLoc and
1118 /// the IROrder are propagated from the original SDNode.
1119 /// So SDLoc class provides two constructors besides the default one, one to
1120 /// be used by the DAGBuilder, the other to be used by others.
1121 class SDLoc {
1122 private:
1123  DebugLoc DL;
1124  int IROrder = 0;
1125 
1126 public:
1127  SDLoc() = default;
1128  SDLoc(const SDNode *N) : DL(N->getDebugLoc()), IROrder(N->getIROrder()) {}
1129  SDLoc(const SDValue V) : SDLoc(V.getNode()) {}
1130  SDLoc(const Instruction *I, int Order) : IROrder(Order) {
1131  assert(Order >= 0 && "bad IROrder");
1132  if (I)
1133  DL = I->getDebugLoc();
1134  }
1135 
1136  unsigned getIROrder() const { return IROrder; }
1137  const DebugLoc &getDebugLoc() const { return DL; }
1138 };
1139 
1140 // Define inline functions from the SDValue class.
1141 
1142 inline SDValue::SDValue(SDNode *node, unsigned resno)
1143  : Node(node), ResNo(resno) {
1144  // Explicitly check for !ResNo to avoid use-after-free, because there are
1145  // callers that use SDValue(N, 0) with a deleted N to indicate successful
1146  // combines.
1147  assert((!Node || !ResNo || ResNo < Node->getNumValues()) &&
1148  "Invalid result number for the given node!");
1149  assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
1150 }
1151 
1152 inline unsigned SDValue::getOpcode() const {
1153  return Node->getOpcode();
1154 }
1155 
1156 inline EVT SDValue::getValueType() const {
1157  return Node->getValueType(ResNo);
1158 }
1159 
1160 inline unsigned SDValue::getNumOperands() const {
1161  return Node->getNumOperands();
1162 }
1163 
1164 inline const SDValue &SDValue::getOperand(unsigned i) const {
1165  return Node->getOperand(i);
1166 }
1167 
1168 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1169  return Node->getConstantOperandVal(i);
1170 }
1171 
1172 inline const APInt &SDValue::getConstantOperandAPInt(unsigned i) const {
1173  return Node->getConstantOperandAPInt(i);
1174 }
1175 
1176 inline bool SDValue::isTargetOpcode() const {
1177  return Node->isTargetOpcode();
1178 }
1179 
1180 inline bool SDValue::isTargetMemoryOpcode() const {
1181  return Node->isTargetMemoryOpcode();
1182 }
1183 
1184 inline bool SDValue::isMachineOpcode() const {
1185  return Node->isMachineOpcode();
1186 }
1187 
1188 inline unsigned SDValue::getMachineOpcode() const {
1189  return Node->getMachineOpcode();
1190 }
1191 
1192 inline bool SDValue::isUndef() const {
1193  return Node->isUndef();
1194 }
1195 
1196 inline bool SDValue::use_empty() const {
1197  return !Node->hasAnyUseOfValue(ResNo);
1198 }
1199 
1200 inline bool SDValue::hasOneUse() const {
1201  return Node->hasNUsesOfValue(1, ResNo);
1202 }
1203 
1204 inline const DebugLoc &SDValue::getDebugLoc() const {
1205  return Node->getDebugLoc();
1206 }
1207 
1208 inline void SDValue::dump() const {
1209  return Node->dump();
1210 }
1211 
1212 inline void SDValue::dump(const SelectionDAG *G) const {
1213  return Node->dump(G);
1214 }
1215 
1216 inline void SDValue::dumpr() const {
1217  return Node->dumpr();
1218 }
1219 
1220 inline void SDValue::dumpr(const SelectionDAG *G) const {
1221  return Node->dumpr(G);
1222 }
1223 
1224 // Define inline functions from the SDUse class.
1225 
1226 inline void SDUse::set(const SDValue &V) {
1227  if (Val.getNode()) removeFromList();
1228  Val = V;
1229  if (V.getNode()) V.getNode()->addUse(*this);
1230 }
1231 
1232 inline void SDUse::setInitial(const SDValue &V) {
1233  Val = V;
1234  V.getNode()->addUse(*this);
1235 }
1236 
1237 inline void SDUse::setNode(SDNode *N) {
1238  if (Val.getNode()) removeFromList();
1239  Val.setNode(N);
1240  if (N) N->addUse(*this);
1241 }
1242 
1243 /// This class is used to form a handle around another node that
1244 /// is persistent and is updated across invocations of replaceAllUsesWith on its
1245 /// operand. This node should be directly created by end-users and not added to
1246 /// the AllNodes list.
1247 class HandleSDNode : public SDNode {
1248  SDUse Op;
1249 
1250 public:
1252  : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1253  // HandleSDNodes are never inserted into the DAG, so they won't be
1254  // auto-numbered. Use ID 65535 as a sentinel.
1255  PersistentId = 0xffff;
1256 
1257  // Manually set up the operand list. This node type is special in that it's
1258  // always stack allocated and SelectionDAG does not manage its operands.
1259  // TODO: This should either (a) not be in the SDNode hierarchy, or (b) not
1260  // be so special.
1261  Op.setUser(this);
1262  Op.setInitial(X);
1263  NumOperands = 1;
1264  OperandList = &Op;
1265  }
1266  ~HandleSDNode();
1267 
1268  const SDValue &getValue() const { return Op; }
1269 };
1270 
1271 class AddrSpaceCastSDNode : public SDNode {
1272 private:
1273  unsigned SrcAddrSpace;
1274  unsigned DestAddrSpace;
1275 
1276 public:
1277  AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, EVT VT,
1278  unsigned SrcAS, unsigned DestAS);
1279 
1280  unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1281  unsigned getDestAddressSpace() const { return DestAddrSpace; }
1282 
1283  static bool classof(const SDNode *N) {
1284  return N->getOpcode() == ISD::ADDRSPACECAST;
1285  }
1286 };
1287 
1288 /// This is an abstract virtual class for memory operations.
1289 class MemSDNode : public SDNode {
1290 private:
1291  // VT of in-memory value.
1292  EVT MemoryVT;
1293 
1294 protected:
1295  /// Memory reference information.
1297 
1298 public:
1299  MemSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs,
1300  EVT memvt, MachineMemOperand *MMO);
1301 
1302  bool readMem() const { return MMO->isLoad(); }
1303  bool writeMem() const { return MMO->isStore(); }
1304 
1305  /// Returns alignment and volatility of the memory access
1306  unsigned getOriginalAlignment() const {
1307  return MMO->getBaseAlignment();
1308  }
1309  unsigned getAlignment() const {
1310  return MMO->getAlignment();
1311  }
1312 
1313  /// Return the SubclassData value, without HasDebugValue. This contains an
1314  /// encoding of the volatile flag, as well as bits used by subclasses. This
1315  /// function should only be used to compute a FoldingSetNodeID value.
1316  /// The HasDebugValue bit is masked out because CSE map needs to match
1317  /// nodes with debug info with nodes without debug info. Same is about
1318  /// isDivergent bit.
1319  unsigned getRawSubclassData() const {
1320  uint16_t Data;
1321  union {
1322  char RawSDNodeBits[sizeof(uint16_t)];
1323  SDNodeBitfields SDNodeBits;
1324  };
1325  memcpy(&RawSDNodeBits, &this->RawSDNodeBits, sizeof(this->RawSDNodeBits));
1326  SDNodeBits.HasDebugValue = 0;
1327  SDNodeBits.IsDivergent = false;
1328  memcpy(&Data, &RawSDNodeBits, sizeof(RawSDNodeBits));
1329  return Data;
1330  }
1331 
1332  bool isVolatile() const { return MemSDNodeBits.IsVolatile; }
1333  bool isNonTemporal() const { return MemSDNodeBits.IsNonTemporal; }
1334  bool isDereferenceable() const { return MemSDNodeBits.IsDereferenceable; }
1335  bool isInvariant() const { return MemSDNodeBits.IsInvariant; }
1336 
1337  // Returns the offset from the location of the access.
1338  int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1339 
1340  /// Returns the AA info that describes the dereference.
1341  AAMDNodes getAAInfo() const { return MMO->getAAInfo(); }
1342 
1343  /// Returns the Ranges that describes the dereference.
1344  const MDNode *getRanges() const { return MMO->getRanges(); }
1345 
1346  /// Returns the synchronization scope ID for this memory operation.
1347  SyncScope::ID getSyncScopeID() const { return MMO->getSyncScopeID(); }
1348 
1349  /// Return the atomic ordering requirements for this memory operation. For
1350  /// cmpxchg atomic operations, return the atomic ordering requirements when
1351  /// store occurs.
1352  AtomicOrdering getOrdering() const { return MMO->getOrdering(); }
1353 
1354  /// Return true if the memory operation ordering is Unordered or higher.
1355  bool isAtomic() const { return MMO->isAtomic(); }
1356 
1357  /// Returns true if the memory operation doesn't imply any ordering
1358  /// constraints on surrounding memory operations beyond the normal memory
1359  /// aliasing rules.
1360  bool isUnordered() const { return MMO->isUnordered(); }
1361 
1362  /// Return the type of the in-memory value.
1363  EVT getMemoryVT() const { return MemoryVT; }
1364 
1365  /// Return a MachineMemOperand object describing the memory
1366  /// reference performed by operation.
1367  MachineMemOperand *getMemOperand() const { return MMO; }
1368 
1370  return MMO->getPointerInfo();
1371  }
1372 
1373  /// Return the address space for the associated pointer
1374  unsigned getAddressSpace() const {
1375  return getPointerInfo().getAddrSpace();
1376  }
1377 
1378  /// Update this MemSDNode's MachineMemOperand information
1379  /// to reflect the alignment of NewMMO, if it has a greater alignment.
1380  /// This must only be used when the new alignment applies to all users of
1381  /// this MachineMemOperand.
1382  void refineAlignment(const MachineMemOperand *NewMMO) {
1383  MMO->refineAlignment(NewMMO);
1384  }
1385 
1386  const SDValue &getChain() const { return getOperand(0); }
1387  const SDValue &getBasePtr() const {
1388  return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1389  }
1390 
1391  // Methods to support isa and dyn_cast
1392  static bool classof(const SDNode *N) {
1393  // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1394  // with either an intrinsic or a target opcode.
1395  return N->getOpcode() == ISD::LOAD ||
1396  N->getOpcode() == ISD::STORE ||
1397  N->getOpcode() == ISD::PREFETCH ||
1398  N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1400  N->getOpcode() == ISD::ATOMIC_SWAP ||
1401  N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1402  N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1403  N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1404  N->getOpcode() == ISD::ATOMIC_LOAD_CLR ||
1405  N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1406  N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1407  N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1408  N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1409  N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1410  N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1411  N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1412  N->getOpcode() == ISD::ATOMIC_LOAD_FADD ||
1413  N->getOpcode() == ISD::ATOMIC_LOAD_FSUB ||
1414  N->getOpcode() == ISD::ATOMIC_LOAD ||
1415  N->getOpcode() == ISD::ATOMIC_STORE ||
1416  N->getOpcode() == ISD::MLOAD ||
1417  N->getOpcode() == ISD::MSTORE ||
1418  N->getOpcode() == ISD::MGATHER ||
1419  N->getOpcode() == ISD::MSCATTER ||
1420  N->isMemIntrinsic() ||
1421  N->isTargetMemoryOpcode();
1422  }
1423 };
1424 
1425 /// This is an SDNode representing atomic operations.
1426 class AtomicSDNode : public MemSDNode {
1427 public:
1428  AtomicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTL,
1429  EVT MemVT, MachineMemOperand *MMO)
1430  : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1431  assert(((Opc != ISD::ATOMIC_LOAD && Opc != ISD::ATOMIC_STORE) ||
1432  MMO->isAtomic()) && "then why are we using an AtomicSDNode?");
1433  }
1434 
1435  const SDValue &getBasePtr() const { return getOperand(1); }
1436  const SDValue &getVal() const { return getOperand(2); }
1437 
1438  /// Returns true if this SDNode represents cmpxchg atomic operation, false
1439  /// otherwise.
1440  bool isCompareAndSwap() const {
1441  unsigned Op = getOpcode();
1442  return Op == ISD::ATOMIC_CMP_SWAP ||
1444  }
1445 
1446  /// For cmpxchg atomic operations, return the atomic ordering requirements
1447  /// when store does not occur.
1449  assert(isCompareAndSwap() && "Must be cmpxchg operation");
1450  return MMO->getFailureOrdering();
1451  }
1452 
1453  // Methods to support isa and dyn_cast
1454  static bool classof(const SDNode *N) {
1455  return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1457  N->getOpcode() == ISD::ATOMIC_SWAP ||
1458  N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1459  N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1460  N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1461  N->getOpcode() == ISD::ATOMIC_LOAD_CLR ||
1462  N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1463  N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1464  N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1465  N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1466  N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1467  N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1468  N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1469  N->getOpcode() == ISD::ATOMIC_LOAD_FADD ||
1470  N->getOpcode() == ISD::ATOMIC_LOAD_FSUB ||
1471  N->getOpcode() == ISD::ATOMIC_LOAD ||
1472  N->getOpcode() == ISD::ATOMIC_STORE;
1473  }
1474 };
1475 
1476 /// This SDNode is used for target intrinsics that touch
1477 /// memory and need an associated MachineMemOperand. Its opcode may be
1478 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1479 /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1481 public:
1482  MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl,
1483  SDVTList VTs, EVT MemoryVT, MachineMemOperand *MMO)
1484  : MemSDNode(Opc, Order, dl, VTs, MemoryVT, MMO) {
1485  SDNodeBits.IsMemIntrinsic = true;
1486  }
1487 
1488  // Methods to support isa and dyn_cast
1489  static bool classof(const SDNode *N) {
1490  // We lower some target intrinsics to their target opcode
1491  // early a node with a target opcode can be of this class
1492  return N->isMemIntrinsic() ||
1493  N->getOpcode() == ISD::PREFETCH ||
1494  N->isTargetMemoryOpcode();
1495  }
1496 };
1497 
1498 /// This SDNode is used to implement the code generator
1499 /// support for the llvm IR shufflevector instruction. It combines elements
1500 /// from two input vectors into a new input vector, with the selection and
1501 /// ordering of elements determined by an array of integers, referred to as
1502 /// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1503 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1504 /// An index of -1 is treated as undef, such that the code generator may put
1505 /// any value in the corresponding element of the result.
1506 class ShuffleVectorSDNode : public SDNode {
1507  // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1508  // is freed when the SelectionDAG object is destroyed.
1509  const int *Mask;
1510 
1511 protected:
1512  friend class SelectionDAG;
1513 
1514  ShuffleVectorSDNode(EVT VT, unsigned Order, const DebugLoc &dl, const int *M)
1515  : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {}
1516 
1517 public:
1519  EVT VT = getValueType(0);
1520  return makeArrayRef(Mask, VT.getVectorNumElements());
1521  }
1522 
1523  int getMaskElt(unsigned Idx) const {
1524  assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1525  return Mask[Idx];
1526  }
1527 
1528  bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1529 
1530  int getSplatIndex() const {
1531  assert(isSplat() && "Cannot get splat index for non-splat!");
1532  EVT VT = getValueType(0);
1533  for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i)
1534  if (Mask[i] >= 0)
1535  return Mask[i];
1536 
1537  // We can choose any index value here and be correct because all elements
1538  // are undefined. Return 0 for better potential for callers to simplify.
1539  return 0;
1540  }
1541 
1542  static bool isSplatMask(const int *Mask, EVT VT);
1543 
1544  /// Change values in a shuffle permute mask assuming
1545  /// the two vector operands have swapped position.
1546  static void commuteMask(MutableArrayRef<int> Mask) {
1547  unsigned NumElems = Mask.size();
1548  for (unsigned i = 0; i != NumElems; ++i) {
1549  int idx = Mask[i];
1550  if (idx < 0)
1551  continue;
1552  else if (idx < (int)NumElems)
1553  Mask[i] = idx + NumElems;
1554  else
1555  Mask[i] = idx - NumElems;
1556  }
1557  }
1558 
1559  static bool classof(const SDNode *N) {
1560  return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1561  }
1562 };
1563 
1564 class ConstantSDNode : public SDNode {
1565  friend class SelectionDAG;
1566 
1567  const ConstantInt *Value;
1568 
1569  ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val, EVT VT)
1570  : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, 0, DebugLoc(),
1571  getSDVTList(VT)),
1572  Value(val) {
1573  ConstantSDNodeBits.IsOpaque = isOpaque;
1574  }
1575 
1576 public:
1577  const ConstantInt *getConstantIntValue() const { return Value; }
1578  const APInt &getAPIntValue() const { return Value->getValue(); }
1579  uint64_t getZExtValue() const { return Value->getZExtValue(); }
1580  int64_t getSExtValue() const { return Value->getSExtValue(); }
1581  uint64_t getLimitedValue(uint64_t Limit = UINT64_MAX) {
1582  return Value->getLimitedValue(Limit);
1583  }
1584 
1585  bool isOne() const { return Value->isOne(); }
1586  bool isNullValue() const { return Value->isZero(); }
1587  bool isAllOnesValue() const { return Value->isMinusOne(); }
1588 
1589  bool isOpaque() const { return ConstantSDNodeBits.IsOpaque; }
1590 
1591  static bool classof(const SDNode *N) {
1592  return N->getOpcode() == ISD::Constant ||
1594  }
1595 };
1596 
1597 uint64_t SDNode::getConstantOperandVal(unsigned Num) const {
1598  return cast<ConstantSDNode>(getOperand(Num))->getZExtValue();
1599 }
1600 
1601 const APInt &SDNode::getConstantOperandAPInt(unsigned Num) const {
1602  return cast<ConstantSDNode>(getOperand(Num))->getAPIntValue();
1603 }
1604 
1605 class ConstantFPSDNode : public SDNode {
1606  friend class SelectionDAG;
1607 
1608  const ConstantFP *Value;
1609 
1610  ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1611  : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 0,
1612  DebugLoc(), getSDVTList(VT)),
1613  Value(val) {}
1614 
1615 public:
1616  const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1617  const ConstantFP *getConstantFPValue() const { return Value; }
1618 
1619  /// Return true if the value is positive or negative zero.
1620  bool isZero() const { return Value->isZero(); }
1621 
1622  /// Return true if the value is a NaN.
1623  bool isNaN() const { return Value->isNaN(); }
1624 
1625  /// Return true if the value is an infinity
1626  bool isInfinity() const { return Value->isInfinity(); }
1627 
1628  /// Return true if the value is negative.
1629  bool isNegative() const { return Value->isNegative(); }
1630 
1631  /// We don't rely on operator== working on double values, as
1632  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1633  /// As such, this method can be used to do an exact bit-for-bit comparison of
1634  /// two floating point values.
1635 
1636  /// We leave the version with the double argument here because it's just so
1637  /// convenient to write "2.0" and the like. Without this function we'd
1638  /// have to duplicate its logic everywhere it's called.
1639  bool isExactlyValue(double V) const {
1640  return Value->getValueAPF().isExactlyValue(V);
1641  }
1642  bool isExactlyValue(const APFloat& V) const;
1643 
1644  static bool isValueValidForType(EVT VT, const APFloat& Val);
1645 
1646  static bool classof(const SDNode *N) {
1647  return N->getOpcode() == ISD::ConstantFP ||
1649  }
1650 };
1651 
1652 /// Returns true if \p V is a constant integer zero.
1653 bool isNullConstant(SDValue V);
1654 
1655 /// Returns true if \p V is an FP constant with a value of positive zero.
1656 bool isNullFPConstant(SDValue V);
1657 
1658 /// Returns true if \p V is an integer constant with all bits set.
1659 bool isAllOnesConstant(SDValue V);
1660 
1661 /// Returns true if \p V is a constant integer one.
1662 bool isOneConstant(SDValue V);
1663 
1664 /// Return the non-bitcasted source operand of \p V if it exists.
1665 /// If \p V is not a bitcasted value, it is returned as-is.
1667 
1668 /// Return the non-bitcasted and one-use source operand of \p V if it exists.
1669 /// If \p V is not a bitcasted one-use value, it is returned as-is.
1671 
1672 /// Return the non-extracted vector source operand of \p V if it exists.
1673 /// If \p V is not an extracted subvector, it is returned as-is.
1675 
1676 /// Returns true if \p V is a bitwise not operation. Assumes that an all ones
1677 /// constant is canonicalized to be operand 1.
1678 bool isBitwiseNot(SDValue V, bool AllowUndefs = false);
1679 
1680 /// Returns the SDNode if it is a constant splat BuildVector or constant int.
1681 ConstantSDNode *isConstOrConstSplat(SDValue N, bool AllowUndefs = false,
1682  bool AllowTruncation = false);
1683 
1684 /// Returns the SDNode if it is a demanded constant splat BuildVector or
1685 /// constant int.
1686 ConstantSDNode *isConstOrConstSplat(SDValue N, const APInt &DemandedElts,
1687  bool AllowUndefs = false,
1688  bool AllowTruncation = false);
1689 
1690 /// Returns the SDNode if it is a constant splat BuildVector or constant float.
1691 ConstantFPSDNode *isConstOrConstSplatFP(SDValue N, bool AllowUndefs = false);
1692 
1693 /// Returns the SDNode if it is a demanded constant splat BuildVector or
1694 /// constant float.
1695 ConstantFPSDNode *isConstOrConstSplatFP(SDValue N, const APInt &DemandedElts,
1696  bool AllowUndefs = false);
1697 
1698 /// Return true if the value is a constant 0 integer or a splatted vector of
1699 /// a constant 0 integer (with no undefs by default).
1700 /// Build vector implicit truncation is not an issue for null values.
1701 bool isNullOrNullSplat(SDValue V, bool AllowUndefs = false);
1702 
1703 /// Return true if the value is a constant 1 integer or a splatted vector of a
1704 /// constant 1 integer (with no undefs).
1705 /// Does not permit build vector implicit truncation.
1706 bool isOneOrOneSplat(SDValue V);
1707 
1708 /// Return true if the value is a constant -1 integer or a splatted vector of a
1709 /// constant -1 integer (with no undefs).
1710 /// Does not permit build vector implicit truncation.
1712 
1713 class GlobalAddressSDNode : public SDNode {
1714  friend class SelectionDAG;
1715 
1716  const GlobalValue *TheGlobal;
1717  int64_t Offset;
1718  unsigned TargetFlags;
1719 
1720  GlobalAddressSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL,
1721  const GlobalValue *GA, EVT VT, int64_t o,
1722  unsigned TF);
1723 
1724 public:
1725  const GlobalValue *getGlobal() const { return TheGlobal; }
1726  int64_t getOffset() const { return Offset; }
1727  unsigned getTargetFlags() const { return TargetFlags; }
1728  // Return the address space this GlobalAddress belongs to.
1729  unsigned getAddressSpace() const;
1730 
1731  static bool classof(const SDNode *N) {
1732  return N->getOpcode() == ISD::GlobalAddress ||
1734  N->getOpcode() == ISD::GlobalTLSAddress ||
1736  }
1737 };
1738 
1739 class FrameIndexSDNode : public SDNode {
1740  friend class SelectionDAG;
1741 
1742  int FI;
1743 
1744  FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1745  : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1746  0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1747  }
1748 
1749 public:
1750  int getIndex() const { return FI; }
1751 
1752  static bool classof(const SDNode *N) {
1753  return N->getOpcode() == ISD::FrameIndex ||
1755  }
1756 };
1757 
1758 /// This SDNode is used for LIFETIME_START/LIFETIME_END values, which indicate
1759 /// the offet and size that are started/ended in the underlying FrameIndex.
1760 class LifetimeSDNode : public SDNode {
1761  friend class SelectionDAG;
1762  int64_t Size;
1763  int64_t Offset; // -1 if offset is unknown.
1764 
1765  LifetimeSDNode(unsigned Opcode, unsigned Order, const DebugLoc &dl,
1766  SDVTList VTs, int64_t Size, int64_t Offset)
1767  : SDNode(Opcode, Order, dl, VTs), Size(Size), Offset(Offset) {}
1768 public:
1769  int64_t getFrameIndex() const {
1770  return cast<FrameIndexSDNode>(getOperand(1))->getIndex();
1771  }
1772 
1773  bool hasOffset() const { return Offset >= 0; }
1774  int64_t getOffset() const {
1775  assert(hasOffset() && "offset is unknown");
1776  return Offset;
1777  }
1778  int64_t getSize() const {
1779  assert(hasOffset() && "offset is unknown");
1780  return Size;
1781  }
1782 
1783  // Methods to support isa and dyn_cast
1784  static bool classof(const SDNode *N) {
1785  return N->getOpcode() == ISD::LIFETIME_START ||
1786  N->getOpcode() == ISD::LIFETIME_END;
1787  }
1788 };
1789 
1790 class JumpTableSDNode : public SDNode {
1791  friend class SelectionDAG;
1792 
1793  int JTI;
1794  unsigned TargetFlags;
1795 
1796  JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned TF)
1797  : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1798  0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1799  }
1800 
1801 public:
1802  int getIndex() const { return JTI; }
1803  unsigned getTargetFlags() const { return TargetFlags; }
1804 
1805  static bool classof(const SDNode *N) {
1806  return N->getOpcode() == ISD::JumpTable ||
1808  }
1809 };
1810 
1811 class ConstantPoolSDNode : public SDNode {
1812  friend class SelectionDAG;
1813 
1814  union {
1817  } Val;
1818  int Offset; // It's a MachineConstantPoolValue if top bit is set.
1819  unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
1820  unsigned TargetFlags;
1821 
1822  ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1823  unsigned Align, unsigned TF)
1824  : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1825  DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1826  TargetFlags(TF) {
1827  assert(Offset >= 0 && "Offset is too large");
1828  Val.ConstVal = c;
1829  }
1830 
1831  ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1832  EVT VT, int o, unsigned Align, unsigned TF)
1834  DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1835  TargetFlags(TF) {
1836  assert(Offset >= 0 && "Offset is too large");
1837  Val.MachineCPVal = v;
1838  Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1839  }
1840 
1841 public:
1843  return Offset < 0;
1844  }
1845 
1846  const Constant *getConstVal() const {
1847  assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1848  return Val.ConstVal;
1849  }
1850 
1852  assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1853  return Val.MachineCPVal;
1854  }
1855 
1856  int getOffset() const {
1857  return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1858  }
1859 
1860  // Return the alignment of this constant pool object, which is either 0 (for
1861  // default alignment) or the desired value.
1862  unsigned getAlignment() const { return Alignment; }
1863  unsigned getTargetFlags() const { return TargetFlags; }
1864 
1865  Type *getType() const;
1866 
1867  static bool classof(const SDNode *N) {
1868  return N->getOpcode() == ISD::ConstantPool ||
1870  }
1871 };
1872 
1873 /// Completely target-dependent object reference.
1874 class TargetIndexSDNode : public SDNode {
1875  friend class SelectionDAG;
1876 
1877  unsigned TargetFlags;
1878  int Index;
1879  int64_t Offset;
1880 
1881 public:
1882  TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned TF)
1883  : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
1884  TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1885 
1886  unsigned getTargetFlags() const { return TargetFlags; }
1887  int getIndex() const { return Index; }
1888  int64_t getOffset() const { return Offset; }
1889 
1890  static bool classof(const SDNode *N) {
1891  return N->getOpcode() == ISD::TargetIndex;
1892  }
1893 };
1894 
1895 class BasicBlockSDNode : public SDNode {
1896  friend class SelectionDAG;
1897 
1898  MachineBasicBlock *MBB;
1899 
1900  /// Debug info is meaningful and potentially useful here, but we create
1901  /// blocks out of order when they're jumped to, which makes it a bit
1902  /// harder. Let's see if we need it first.
1903  explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1904  : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
1905  {}
1906 
1907 public:
1908  MachineBasicBlock *getBasicBlock() const { return MBB; }
1909 
1910  static bool classof(const SDNode *N) {
1911  return N->getOpcode() == ISD::BasicBlock;
1912  }
1913 };
1914 
1915 /// A "pseudo-class" with methods for operating on BUILD_VECTORs.
1916 class BuildVectorSDNode : public SDNode {
1917 public:
1918  // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1919  explicit BuildVectorSDNode() = delete;
1920 
1921  /// Check if this is a constant splat, and if so, find the
1922  /// smallest element size that splats the vector. If MinSplatBits is
1923  /// nonzero, the element size must be at least that large. Note that the
1924  /// splat element may be the entire vector (i.e., a one element vector).
1925  /// Returns the splat element value in SplatValue. Any undefined bits in
1926  /// that value are zero, and the corresponding bits in the SplatUndef mask
1927  /// are set. The SplatBitSize value is set to the splat element size in
1928  /// bits. HasAnyUndefs is set to true if any bits in the vector are
1929  /// undefined. isBigEndian describes the endianness of the target.
1930  bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1931  unsigned &SplatBitSize, bool &HasAnyUndefs,
1932  unsigned MinSplatBits = 0,
1933  bool isBigEndian = false) const;
1934 
1935  /// Returns the demanded splatted value or a null value if this is not a
1936  /// splat.
1937  ///
1938  /// The DemandedElts mask indicates the elements that must be in the splat.
1939  /// If passed a non-null UndefElements bitvector, it will resize it to match
1940  /// the vector width and set the bits where elements are undef.
1941  SDValue getSplatValue(const APInt &DemandedElts,
1942  BitVector *UndefElements = nullptr) const;
1943 
1944  /// Returns the splatted value or a null value if this is not a splat.
1945  ///
1946  /// If passed a non-null UndefElements bitvector, it will resize it to match
1947  /// the vector width and set the bits where elements are undef.
1948  SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
1949 
1950  /// Returns the demanded splatted constant or null if this is not a constant
1951  /// splat.
1952  ///
1953  /// The DemandedElts mask indicates the elements that must be in the splat.
1954  /// If passed a non-null UndefElements bitvector, it will resize it to match
1955  /// the vector width and set the bits where elements are undef.
1956  ConstantSDNode *
1957  getConstantSplatNode(const APInt &DemandedElts,
1958  BitVector *UndefElements = nullptr) const;
1959 
1960  /// Returns the splatted constant or null if this is not a constant
1961  /// splat.
1962  ///
1963  /// If passed a non-null UndefElements bitvector, it will resize it to match
1964  /// the vector width and set the bits where elements are undef.
1965  ConstantSDNode *
1966  getConstantSplatNode(BitVector *UndefElements = nullptr) const;
1967 
1968  /// Returns the demanded splatted constant FP or null if this is not a
1969  /// constant FP splat.
1970  ///
1971  /// The DemandedElts mask indicates the elements that must be in the splat.
1972  /// If passed a non-null UndefElements bitvector, it will resize it to match
1973  /// the vector width and set the bits where elements are undef.
1975  getConstantFPSplatNode(const APInt &DemandedElts,
1976  BitVector *UndefElements = nullptr) const;
1977 
1978  /// Returns the splatted constant FP or null if this is not a constant
1979  /// FP splat.
1980  ///
1981  /// If passed a non-null UndefElements bitvector, it will resize it to match
1982  /// the vector width and set the bits where elements are undef.
1984  getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
1985 
1986  /// If this is a constant FP splat and the splatted constant FP is an
1987  /// exact power or 2, return the log base 2 integer value. Otherwise,
1988  /// return -1.
1989  ///
1990  /// The BitWidth specifies the necessary bit precision.
1991  int32_t getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements,
1992  uint32_t BitWidth) const;
1993 
1994  bool isConstant() const;
1995 
1996  static bool classof(const SDNode *N) {
1997  return N->getOpcode() == ISD::BUILD_VECTOR;
1998  }
1999 };
2000 
2001 /// An SDNode that holds an arbitrary LLVM IR Value. This is
2002 /// used when the SelectionDAG needs to make a simple reference to something
2003 /// in the LLVM IR representation.
2004 ///
2005 class SrcValueSDNode : public SDNode {
2006  friend class SelectionDAG;
2007 
2008  const Value *V;
2009 
2010  /// Create a SrcValue for a general value.
2011  explicit SrcValueSDNode(const Value *v)
2012  : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
2013 
2014 public:
2015  /// Return the contained Value.
2016  const Value *getValue() const { return V; }
2017 
2018  static bool classof(const SDNode *N) {
2019  return N->getOpcode() == ISD::SRCVALUE;
2020  }
2021 };
2022 
2023 class MDNodeSDNode : public SDNode {
2024  friend class SelectionDAG;
2025 
2026  const MDNode *MD;
2027 
2028  explicit MDNodeSDNode(const MDNode *md)
2029  : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
2030  {}
2031 
2032 public:
2033  const MDNode *getMD() const { return MD; }
2034 
2035  static bool classof(const SDNode *N) {
2036  return N->getOpcode() == ISD::MDNODE_SDNODE;
2037  }
2038 };
2039 
2040 class RegisterSDNode : public SDNode {
2041  friend class SelectionDAG;
2042 
2043  unsigned Reg;
2044 
2045  RegisterSDNode(unsigned reg, EVT VT)
2046  : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {}
2047 
2048 public:
2049  unsigned getReg() const { return Reg; }
2050 
2051  static bool classof(const SDNode *N) {
2052  return N->getOpcode() == ISD::Register;
2053  }
2054 };
2055 
2056 class RegisterMaskSDNode : public SDNode {
2057  friend class SelectionDAG;
2058 
2059  // The memory for RegMask is not owned by the node.
2060  const uint32_t *RegMask;
2061 
2062  RegisterMaskSDNode(const uint32_t *mask)
2063  : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
2064  RegMask(mask) {}
2065 
2066 public:
2067  const uint32_t *getRegMask() const { return RegMask; }
2068 
2069  static bool classof(const SDNode *N) {
2070  return N->getOpcode() == ISD::RegisterMask;
2071  }
2072 };
2073 
2074 class BlockAddressSDNode : public SDNode {
2075  friend class SelectionDAG;
2076 
2077  const BlockAddress *BA;
2078  int64_t Offset;
2079  unsigned TargetFlags;
2080 
2081  BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
2082  int64_t o, unsigned Flags)
2083  : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
2084  BA(ba), Offset(o), TargetFlags(Flags) {}
2085 
2086 public:
2087  const BlockAddress *getBlockAddress() const { return BA; }
2088  int64_t getOffset() const { return Offset; }
2089  unsigned getTargetFlags() const { return TargetFlags; }
2090 
2091  static bool classof(const SDNode *N) {
2092  return N->getOpcode() == ISD::BlockAddress ||
2094  }
2095 };
2096 
2097 class LabelSDNode : public SDNode {
2098  friend class SelectionDAG;
2099 
2100  MCSymbol *Label;
2101 
2102  LabelSDNode(unsigned Opcode, unsigned Order, const DebugLoc &dl, MCSymbol *L)
2103  : SDNode(Opcode, Order, dl, getSDVTList(MVT::Other)), Label(L) {
2104  assert(LabelSDNode::classof(this) && "not a label opcode");
2105  }
2106 
2107 public:
2108  MCSymbol *getLabel() const { return Label; }
2109 
2110  static bool classof(const SDNode *N) {
2111  return N->getOpcode() == ISD::EH_LABEL ||
2113  }
2114 };
2115 
2117  friend class SelectionDAG;
2118 
2119  const char *Symbol;
2120  unsigned TargetFlags;
2121 
2122  ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned TF, EVT VT)
2123  : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol, 0,
2124  DebugLoc(), getSDVTList(VT)),
2125  Symbol(Sym), TargetFlags(TF) {}
2126 
2127 public:
2128  const char *getSymbol() const { return Symbol; }
2129  unsigned getTargetFlags() const { return TargetFlags; }
2130 
2131  static bool classof(const SDNode *N) {
2132  return N->getOpcode() == ISD::ExternalSymbol ||
2134  }
2135 };
2136 
2137 class MCSymbolSDNode : public SDNode {
2138  friend class SelectionDAG;
2139 
2140  MCSymbol *Symbol;
2141 
2142  MCSymbolSDNode(MCSymbol *Symbol, EVT VT)
2143  : SDNode(ISD::MCSymbol, 0, DebugLoc(), getSDVTList(VT)), Symbol(Symbol) {}
2144 
2145 public:
2146  MCSymbol *getMCSymbol() const { return Symbol; }
2147 
2148  static bool classof(const SDNode *N) {
2149  return N->getOpcode() == ISD::MCSymbol;
2150  }
2151 };
2152 
2153 class CondCodeSDNode : public SDNode {
2154  friend class SelectionDAG;
2155 
2156  ISD::CondCode Condition;
2157 
2158  explicit CondCodeSDNode(ISD::CondCode Cond)
2159  : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
2160  Condition(Cond) {}
2161 
2162 public:
2163  ISD::CondCode get() const { return Condition; }
2164 
2165  static bool classof(const SDNode *N) {
2166  return N->getOpcode() == ISD::CONDCODE;
2167  }
2168 };
2169 
2170 /// This class is used to represent EVT's, which are used
2171 /// to parameterize some operations.
2172 class VTSDNode : public SDNode {
2173  friend class SelectionDAG;
2174 
2175  EVT ValueType;
2176 
2177  explicit VTSDNode(EVT VT)
2178  : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
2179  ValueType(VT) {}
2180 
2181 public:
2182  EVT getVT() const { return ValueType; }
2183 
2184  static bool classof(const SDNode *N) {
2185  return N->getOpcode() == ISD::VALUETYPE;
2186  }
2187 };
2188 
2189 /// Base class for LoadSDNode and StoreSDNode
2190 class LSBaseSDNode : public MemSDNode {
2191 public:
2192  LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl,
2193  SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
2194  MachineMemOperand *MMO)
2195  : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
2196  LSBaseSDNodeBits.AddressingMode = AM;
2197  assert(getAddressingMode() == AM && "Value truncated");
2198  assert((!MMO->isAtomic() || MMO->isVolatile()) &&
2199  "use an AtomicSDNode instead for non-volatile atomics");
2200  }
2201 
2202  const SDValue &getOffset() const {
2203  return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2204  }
2205 
2206  /// Return the addressing mode for this load or store:
2207  /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2209  return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
2210  }
2211 
2212  /// Return true if this is a pre/post inc/dec load/store.
2213  bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2214 
2215  /// Return true if this is NOT a pre/post inc/dec load/store.
2216  bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2217 
2218  static bool classof(const SDNode *N) {
2219  return N->getOpcode() == ISD::LOAD ||
2220  N->getOpcode() == ISD::STORE;
2221  }
2222 };
2223 
2224 /// This class is used to represent ISD::LOAD nodes.
2225 class LoadSDNode : public LSBaseSDNode {
2226  friend class SelectionDAG;
2227 
2228  LoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2229  ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
2230  MachineMemOperand *MMO)
2231  : LSBaseSDNode(ISD::LOAD, Order, dl, VTs, AM, MemVT, MMO) {
2232  LoadSDNodeBits.ExtTy = ETy;
2233  assert(readMem() && "Load MachineMemOperand is not a load!");
2234  assert(!writeMem() && "Load MachineMemOperand is a store!");
2235  }
2236 
2237 public:
2238  /// Return whether this is a plain node,
2239  /// or one of the varieties of value-extending loads.
2241  return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2242  }
2243 
2244  const SDValue &getBasePtr() const { return getOperand(1); }
2245  const SDValue &getOffset() const { return getOperand(2); }
2246 
2247  static bool classof(const SDNode *N) {
2248  return N->getOpcode() == ISD::LOAD;
2249  }
2250 };
2251 
2252 /// This class is used to represent ISD::STORE nodes.
2253 class StoreSDNode : public LSBaseSDNode {
2254  friend class SelectionDAG;
2255 
2256  StoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2257  ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
2258  MachineMemOperand *MMO)
2259  : LSBaseSDNode(ISD::STORE, Order, dl, VTs, AM, MemVT, MMO) {
2260  StoreSDNodeBits.IsTruncating = isTrunc;
2261  assert(!readMem() && "Store MachineMemOperand is a load!");
2262  assert(writeMem() && "Store MachineMemOperand is not a store!");
2263  }
2264 
2265 public:
2266  /// Return true if the op does a truncation before store.
2267  /// For integers this is the same as doing a TRUNCATE and storing the result.
2268  /// For floats, it is the same as doing an FP_ROUND and storing the result.
2269  bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2270  void setTruncatingStore(bool Truncating) {
2271  StoreSDNodeBits.IsTruncating = Truncating;
2272  }
2273 
2274  const SDValue &getValue() const { return getOperand(1); }
2275  const SDValue &getBasePtr() const { return getOperand(2); }
2276  const SDValue &getOffset() const { return getOperand(3); }
2277 
2278  static bool classof(const SDNode *N) {
2279  return N->getOpcode() == ISD::STORE;
2280  }
2281 };
2282 
2283 /// This base class is used to represent MLOAD and MSTORE nodes
2285 public:
2286  friend class SelectionDAG;
2287 
2288  MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order,
2289  const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2290  MachineMemOperand *MMO)
2291  : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2292 
2293  // MaskedLoadSDNode (Chain, ptr, mask, passthru)
2294  // MaskedStoreSDNode (Chain, data, ptr, mask)
2295  // Mask is a vector of i1 elements
2296  const SDValue &getBasePtr() const {
2297  return getOperand(getOpcode() == ISD::MLOAD ? 1 : 2);
2298  }
2299  const SDValue &getMask() const {
2300  return getOperand(getOpcode() == ISD::MLOAD ? 2 : 3);
2301  }
2302 
2303  static bool classof(const SDNode *N) {
2304  return N->getOpcode() == ISD::MLOAD ||
2305  N->getOpcode() == ISD::MSTORE;
2306  }
2307 };
2308 
2309 /// This class is used to represent an MLOAD node
2311 public:
2312  friend class SelectionDAG;
2313 
2314  MaskedLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2315  ISD::LoadExtType ETy, bool IsExpanding, EVT MemVT,
2316  MachineMemOperand *MMO)
2317  : MaskedLoadStoreSDNode(ISD::MLOAD, Order, dl, VTs, MemVT, MMO) {
2318  LoadSDNodeBits.ExtTy = ETy;
2319  LoadSDNodeBits.IsExpanding = IsExpanding;
2320  }
2321 
2323  return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2324  }
2325 
2326  const SDValue &getBasePtr() const { return getOperand(1); }
2327  const SDValue &getMask() const { return getOperand(2); }
2328  const SDValue &getPassThru() const { return getOperand(3); }
2329 
2330  static bool classof(const SDNode *N) {
2331  return N->getOpcode() == ISD::MLOAD;
2332  }
2333 
2334  bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
2335 };
2336 
2337 /// This class is used to represent an MSTORE node
2339 public:
2340  friend class SelectionDAG;
2341 
2342  MaskedStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2343  bool isTrunc, bool isCompressing, EVT MemVT,
2344  MachineMemOperand *MMO)
2345  : MaskedLoadStoreSDNode(ISD::MSTORE, Order, dl, VTs, MemVT, MMO) {
2346  StoreSDNodeBits.IsTruncating = isTrunc;
2347  StoreSDNodeBits.IsCompressing = isCompressing;
2348  }
2349 
2350  /// Return true if the op does a truncation before store.
2351  /// For integers this is the same as doing a TRUNCATE and storing the result.
2352  /// For floats, it is the same as doing an FP_ROUND and storing the result.
2353  bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2354 
2355  /// Returns true if the op does a compression to the vector before storing.
2356  /// The node contiguously stores the active elements (integers or floats)
2357  /// in src (those with their respective bit set in writemask k) to unaligned
2358  /// memory at base_addr.
2359  bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
2360 
2361  const SDValue &getValue() const { return getOperand(1); }
2362  const SDValue &getBasePtr() const { return getOperand(2); }
2363  const SDValue &getMask() const { return getOperand(3); }
2364 
2365  static bool classof(const SDNode *N) {
2366  return N->getOpcode() == ISD::MSTORE;
2367  }
2368 };
2369 
2370 /// This is a base class used to represent
2371 /// MGATHER and MSCATTER nodes
2372 ///
2374 public:
2375  friend class SelectionDAG;
2376 
2378  const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2379  MachineMemOperand *MMO, ISD::MemIndexType IndexType)
2380  : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
2381  LSBaseSDNodeBits.AddressingMode = IndexType;
2382  assert(getIndexType() == IndexType && "Value truncated");
2383  }
2384 
2385  /// How is Index applied to BasePtr when computing addresses.
2387  return static_cast<ISD::MemIndexType>(LSBaseSDNodeBits.AddressingMode);
2388  }
2389  bool isIndexScaled() const {
2390  return (getIndexType() == ISD::SIGNED_SCALED) ||
2391  (getIndexType() == ISD::UNSIGNED_SCALED);
2392  }
2393  bool isIndexSigned() const {
2394  return (getIndexType() == ISD::SIGNED_SCALED) ||
2395  (getIndexType() == ISD::SIGNED_UNSCALED);
2396  }
2397 
2398  // In the both nodes address is Op1, mask is Op2:
2399  // MaskedGatherSDNode (Chain, passthru, mask, base, index, scale)
2400  // MaskedScatterSDNode (Chain, value, mask, base, index, scale)
2401  // Mask is a vector of i1 elements
2402  const SDValue &getBasePtr() const { return getOperand(3); }
2403  const SDValue &getIndex() const { return getOperand(4); }
2404  const SDValue &getMask() const { return getOperand(2); }
2405  const SDValue &getScale() const { return getOperand(5); }
2406 
2407  static bool classof(const SDNode *N) {
2408  return N->getOpcode() == ISD::MGATHER ||
2409  N->getOpcode() == ISD::MSCATTER;
2410  }
2411 };
2412 
2413 /// This class is used to represent an MGATHER node
2414 ///
2416 public:
2417  friend class SelectionDAG;
2418 
2419  MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2420  EVT MemVT, MachineMemOperand *MMO,
2421  ISD::MemIndexType IndexType)
2422  : MaskedGatherScatterSDNode(ISD::MGATHER, Order, dl, VTs, MemVT, MMO,
2423  IndexType) {}
2424 
2425  const SDValue &getPassThru() const { return getOperand(1); }
2426 
2427  static bool classof(const SDNode *N) {
2428  return N->getOpcode() == ISD::MGATHER;
2429  }
2430 };
2431 
2432 /// This class is used to represent an MSCATTER node
2433 ///
2435 public:
2436  friend class SelectionDAG;
2437 
2438  MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2439  EVT MemVT, MachineMemOperand *MMO,
2440  ISD::MemIndexType IndexType)
2441  : MaskedGatherScatterSDNode(ISD::MSCATTER, Order, dl, VTs, MemVT, MMO,
2442  IndexType) {}
2443 
2444  const SDValue &getValue() const { return getOperand(1); }
2445 
2446  static bool classof(const SDNode *N) {
2447  return N->getOpcode() == ISD::MSCATTER;
2448  }
2449 };
2450 
2451 /// An SDNode that represents everything that will be needed
2452 /// to construct a MachineInstr. These nodes are created during the
2453 /// instruction selection proper phase.
2454 ///
2455 /// Note that the only supported way to set the `memoperands` is by calling the
2456 /// `SelectionDAG::setNodeMemRefs` function as the memory management happens
2457 /// inside the DAG rather than in the node.
2458 class MachineSDNode : public SDNode {
2459 private:
2460  friend class SelectionDAG;
2461 
2462  MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL, SDVTList VTs)
2463  : SDNode(Opc, Order, DL, VTs) {}
2464 
2465  // We use a pointer union between a single `MachineMemOperand` pointer and
2466  // a pointer to an array of `MachineMemOperand` pointers. This is null when
2467  // the number of these is zero, the single pointer variant used when the
2468  // number is one, and the array is used for larger numbers.
2469  //
2470  // The array is allocated via the `SelectionDAG`'s allocator and so will
2471  // always live until the DAG is cleaned up and doesn't require ownership here.
2472  //
2473  // We can't use something simpler like `TinyPtrVector` here because `SDNode`
2474  // subclasses aren't managed in a conforming C++ manner. See the comments on
2475  // `SelectionDAG::MorphNodeTo` which details what all goes on, but the
2476  // constraint here is that these don't manage memory with their constructor or
2477  // destructor and can be initialized to a good state even if they start off
2478  // uninitialized.
2480 
2481  // Note that this could be folded into the above `MemRefs` member if doing so
2482  // is advantageous at some point. We don't need to store this in most cases.
2483  // However, at the moment this doesn't appear to make the allocation any
2484  // smaller and makes the code somewhat simpler to read.
2485  int NumMemRefs = 0;
2486 
2487 public:
2489 
2491  // Special case the common cases.
2492  if (NumMemRefs == 0)
2493  return {};
2494  if (NumMemRefs == 1)
2495  return makeArrayRef(MemRefs.getAddrOfPtr1(), 1);
2496 
2497  // Otherwise we have an actual array.
2498  return makeArrayRef(MemRefs.get<MachineMemOperand **>(), NumMemRefs);
2499  }
2500  mmo_iterator memoperands_begin() const { return memoperands().begin(); }
2501  mmo_iterator memoperands_end() const { return memoperands().end(); }
2502  bool memoperands_empty() const { return memoperands().empty(); }
2503 
2504  /// Clear out the memory reference descriptor list.
2505  void clearMemRefs() {
2506  MemRefs = nullptr;
2507  NumMemRefs = 0;
2508  }
2509 
2510  static bool classof(const SDNode *N) {
2511  return N->isMachineOpcode();
2512  }
2513 };
2514 
2515 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
2516  SDNode, ptrdiff_t> {
2517  const SDNode *Node;
2518  unsigned Operand;
2519 
2520  SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2521 
2522 public:
2523  bool operator==(const SDNodeIterator& x) const {
2524  return Operand == x.Operand;
2525  }
2526  bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2527 
2528  pointer operator*() const {
2529  return Node->getOperand(Operand).getNode();
2530  }
2531  pointer operator->() const { return operator*(); }
2532 
2533  SDNodeIterator& operator++() { // Preincrement
2534  ++Operand;
2535  return *this;
2536  }
2537  SDNodeIterator operator++(int) { // Postincrement
2538  SDNodeIterator tmp = *this; ++*this; return tmp;
2539  }
2540  size_t operator-(SDNodeIterator Other) const {
2541  assert(Node == Other.Node &&
2542  "Cannot compare iterators of two different nodes!");
2543  return Operand - Other.Operand;
2544  }
2545 
2546  static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
2547  static SDNodeIterator end (const SDNode *N) {
2548  return SDNodeIterator(N, N->getNumOperands());
2549  }
2550 
2551  unsigned getOperand() const { return Operand; }
2552  const SDNode *getNode() const { return Node; }
2553 };
2554 
2555 template <> struct GraphTraits<SDNode*> {
2556  using NodeRef = SDNode *;
2558 
2559  static NodeRef getEntryNode(SDNode *N) { return N; }
2560 
2562  return SDNodeIterator::begin(N);
2563  }
2564 
2566  return SDNodeIterator::end(N);
2567  }
2568 };
2569 
2570 /// A representation of the largest SDNode, for use in sizeof().
2571 ///
2572 /// This needs to be a union because the largest node differs on 32 bit systems
2573 /// with 4 and 8 byte pointer alignment, respectively.
2577 
2578 /// The SDNode class with the greatest alignment requirement.
2580 
2581 namespace ISD {
2582 
2583  /// Returns true if the specified node is a non-extending and unindexed load.
2584  inline bool isNormalLoad(const SDNode *N) {
2585  const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2586  return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2588  }
2589 
2590  /// Returns true if the specified node is a non-extending load.
2591  inline bool isNON_EXTLoad(const SDNode *N) {
2592  return isa<LoadSDNode>(N) &&
2593  cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2594  }
2595 
2596  /// Returns true if the specified node is a EXTLOAD.
2597  inline bool isEXTLoad(const SDNode *N) {
2598  return isa<LoadSDNode>(N) &&
2599  cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2600  }
2601 
2602  /// Returns true if the specified node is a SEXTLOAD.
2603  inline bool isSEXTLoad(const SDNode *N) {
2604  return isa<LoadSDNode>(N) &&
2605  cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2606  }
2607 
2608  /// Returns true if the specified node is a ZEXTLOAD.
2609  inline bool isZEXTLoad(const SDNode *N) {
2610  return isa<LoadSDNode>(N) &&
2611  cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2612  }
2613 
2614  /// Returns true if the specified node is an unindexed load.
2615  inline bool isUNINDEXEDLoad(const SDNode *N) {
2616  return isa<LoadSDNode>(N) &&
2617  cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2618  }
2619 
2620  /// Returns true if the specified node is a non-truncating
2621  /// and unindexed store.
2622  inline bool isNormalStore(const SDNode *N) {
2623  const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2624  return St && !St->isTruncatingStore() &&
2626  }
2627 
2628  /// Returns true if the specified node is a non-truncating store.
2629  inline bool isNON_TRUNCStore(const SDNode *N) {
2630  return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2631  }
2632 
2633  /// Returns true if the specified node is a truncating store.
2634  inline bool isTRUNCStore(const SDNode *N) {
2635  return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2636  }
2637 
2638  /// Returns true if the specified node is an unindexed store.
2639  inline bool isUNINDEXEDStore(const SDNode *N) {
2640  return isa<StoreSDNode>(N) &&
2641  cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2642  }
2643 
2644  /// Attempt to match a unary predicate against a scalar/splat constant or
2645  /// every element of a constant BUILD_VECTOR.
2646  /// If AllowUndef is true, then UNDEF elements will pass nullptr to Match.
2649  bool AllowUndefs = false);
2650 
2651  /// Attempt to match a binary predicate against a pair of scalar/splat
2652  /// constants or every element of a pair of constant BUILD_VECTORs.
2653  /// If AllowUndef is true, then UNDEF elements will pass nullptr to Match.
2654  /// If AllowTypeMismatch is true then RetType + ArgTypes don't need to match.
2655  bool matchBinaryPredicate(
2656  SDValue LHS, SDValue RHS,
2658  bool AllowUndefs = false, bool AllowTypeMismatch = false);
2659 } // end namespace ISD
2660 
2661 } // end namespace llvm
2662 
2663 #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
bool isUnordered() const
Returns true if this memory operation doesn&#39;t have any ordering constraints other than normal aliasin...
BUILTIN_OP_END - This must be the last enum value in this list.
Definition: ISDOpcodes.h:913
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:213
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.
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)).
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.
block Block Frequency true
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:198
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
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)
unsigned getTargetFlags() const
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)
ConstantSDNode * isConstOrConstSplat(SDValue N, bool AllowUndefs=false, bool AllowTruncation=false)
Returns the SDNode if it is a constant splat BuildVector or constant int.
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
MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexType IndexType)
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:877
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:2097
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
MemIndexType
MemIndexType enum - This enum defines how to interpret MGATHER/SCATTER&#39;s index parameter when calcula...
Definition: ISDOpcodes.h:968
unsigned getTargetFlags() const
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:1012
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
MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexType IndexType)
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:987
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)
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
This is a base class used to represent MGATHER and MSCATTER nodes.
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:1140
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)
unsigned getTargetFlags() const
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo...
Definition: ISDOpcodes.h:827
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.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:40
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)
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.
bool isAtomic() const
Return true if the memory operation ordering is Unordered or higher.
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:837
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
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
bool hasFPExcept() 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
unsigned getTargetFlags() const
void setNoNaNs(bool b)
Represents one node in the SelectionDAG.
bool isBitwiseNot(SDValue V, bool AllowUndefs=false)
Returns true if V is a bitwise not operation.
bool readMem() const
bool operator==(const SDNodeIterator &x) 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
A suitably aligned and sized character array member which can hold elements of any type...
Definition: AlignOf.h:48
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
bool matchBinaryPredicate(SDValue LHS, SDValue RHS, std::function< bool(ConstantSDNode *, ConstantSDNode *)> Match, bool AllowUndefs=false, bool AllowTypeMismatch=false)
Attempt to match a binary predicate against a pair of scalar/splat constants or every element of a pa...
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.
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
ISD::MemIndexType getIndexType() const
How is Index applied to BasePtr when computing addresses.
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
bool isUnordered() const
Returns true if the memory operation doesn&#39;t imply any ordering constraints on surrounding memory ope...
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.
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:73
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:1973
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)
TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned TF)
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
Definition: ISDOpcodes.h:816
const SDValue & getBasePtr() const
const SDValue & getMask() const
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
unsigned getIROrder() const
MaskedGatherScatterSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexType IndexType)
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:156
void setFPExcept(bool b)
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.