LLVM  6.0.0svn
SelectionDAGNodes.h
Go to the documentation of this file.
1 //===- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the SDNode class and derived classes, which are used to
11 // represent the nodes and operations present in a SelectionDAG. These nodes
12 // and operations are machine code level operations, with some similarities to
13 // the GCC RTL representation.
14 //
15 // Clients should include the SelectionDAG.h file instead of this file directly.
16 //
17 //===----------------------------------------------------------------------===//
18 
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
21 
22 #include "llvm/ADT/APFloat.h"
23 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/ADT/BitVector.h"
25 #include "llvm/ADT/FoldingSet.h"
26 #include "llvm/ADT/GraphTraits.h"
27 #include "llvm/ADT/SmallPtrSet.h"
28 #include "llvm/ADT/SmallVector.h"
29 #include "llvm/ADT/ilist_node.h"
30 #include "llvm/ADT/iterator.h"
36 #include "llvm/IR/Constants.h"
37 #include "llvm/IR/DebugLoc.h"
38 #include "llvm/IR/Instruction.h"
39 #include "llvm/IR/Instructions.h"
40 #include "llvm/IR/Metadata.h"
41 #include "llvm/Support/AlignOf.h"
43 #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 bool isTargetMemoryOpcode() const;
187  inline bool isTargetOpcode() const;
188  inline bool isMachineOpcode() const;
189  inline bool isUndef() const;
190  inline unsigned getMachineOpcode() const;
191  inline const DebugLoc &getDebugLoc() const;
192  inline void dump() const;
193  inline void dumpr() const;
194 
195  /// Return true if this operand (which must be a chain) reaches the
196  /// specified operand without crossing any side-effecting instructions.
197  /// In practice, this looks through token factors and non-volatile loads.
198  /// In order to remain efficient, this only
199  /// looks a couple of nodes in, it does not do an exhaustive search.
200  bool reachesChainWithoutSideEffects(SDValue Dest,
201  unsigned Depth = 2) const;
202 
203  /// Return true if there are no nodes using value ResNo of Node.
204  inline bool use_empty() const;
205 
206  /// Return true if there is exactly one node using value ResNo of Node.
207  inline bool hasOneUse() const;
208 };
209 
210 template<> struct DenseMapInfo<SDValue> {
211  static inline SDValue getEmptyKey() {
212  SDValue V;
213  V.ResNo = -1U;
214  return V;
215  }
216 
217  static inline SDValue getTombstoneKey() {
218  SDValue V;
219  V.ResNo = -2U;
220  return V;
221  }
222 
223  static unsigned getHashValue(const SDValue &Val) {
224  return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
225  (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
226  }
227 
228  static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
229  return LHS == RHS;
230  }
231 };
232 template <> struct isPodLike<SDValue> { static const bool value = true; };
233 
234 /// Allow casting operators to work directly on
235 /// SDValues as if they were SDNode*'s.
236 template<> struct simplify_type<SDValue> {
237  using SimpleType = SDNode *;
238 
240  return Val.getNode();
241  }
242 };
243 template<> struct simplify_type<const SDValue> {
244  using SimpleType = /*const*/ SDNode *;
245 
246  static SimpleType getSimplifiedValue(const SDValue &Val) {
247  return Val.getNode();
248  }
249 };
250 
251 /// Represents a use of a SDNode. This class holds an SDValue,
252 /// which records the SDNode being used and the result number, a
253 /// pointer to the SDNode using the value, and Next and Prev pointers,
254 /// which link together all the uses of an SDNode.
255 ///
256 class SDUse {
257  /// Val - The value being used.
258  SDValue Val;
259  /// User - The user of this value.
260  SDNode *User = nullptr;
261  /// Prev, Next - Pointers to the uses list of the SDNode referred by
262  /// this operand.
263  SDUse **Prev = nullptr;
264  SDUse *Next = nullptr;
265 
266 public:
267  SDUse() = default;
268  SDUse(const SDUse &U) = delete;
269  SDUse &operator=(const SDUse &) = delete;
270 
271  /// Normally SDUse will just implicitly convert to an SDValue that it holds.
272  operator const SDValue&() const { return Val; }
273 
274  /// If implicit conversion to SDValue doesn't work, the get() method returns
275  /// the SDValue.
276  const SDValue &get() const { return Val; }
277 
278  /// This returns the SDNode that contains this Use.
279  SDNode *getUser() { return User; }
280 
281  /// Get the next SDUse in the use list.
282  SDUse *getNext() const { return Next; }
283 
284  /// Convenience function for get().getNode().
285  SDNode *getNode() const { return Val.getNode(); }
286  /// Convenience function for get().getResNo().
287  unsigned getResNo() const { return Val.getResNo(); }
288  /// Convenience function for get().getValueType().
289  EVT getValueType() const { return Val.getValueType(); }
290 
291  /// Convenience function for get().operator==
292  bool operator==(const SDValue &V) const {
293  return Val == V;
294  }
295 
296  /// Convenience function for get().operator!=
297  bool operator!=(const SDValue &V) const {
298  return Val != V;
299  }
300 
301  /// Convenience function for get().operator<
302  bool operator<(const SDValue &V) const {
303  return Val < V;
304  }
305 
306 private:
307  friend class SelectionDAG;
308  friend class SDNode;
309  // TODO: unfriend HandleSDNode once we fix its operand handling.
310  friend class HandleSDNode;
311 
312  void setUser(SDNode *p) { User = p; }
313 
314  /// Remove this use from its existing use list, assign it the
315  /// given value, and add it to the new value's node's use list.
316  inline void set(const SDValue &V);
317  /// Like set, but only supports initializing a newly-allocated
318  /// SDUse with a non-null value.
319  inline void setInitial(const SDValue &V);
320  /// Like set, but only sets the Node portion of the value,
321  /// leaving the ResNo portion unmodified.
322  inline void setNode(SDNode *N);
323 
324  void addToList(SDUse **List) {
325  Next = *List;
326  if (Next) Next->Prev = &Next;
327  Prev = List;
328  *List = this;
329  }
330 
331  void removeFromList() {
332  *Prev = Next;
333  if (Next) Next->Prev = Prev;
334  }
335 };
336 
337 /// simplify_type specializations - Allow casting operators to work directly on
338 /// SDValues as if they were SDNode*'s.
339 template<> struct simplify_type<SDUse> {
340  using SimpleType = SDNode *;
341 
343  return Val.getNode();
344  }
345 };
346 
347 /// These are IR-level optimization flags that may be propagated to SDNodes.
348 /// TODO: This data structure should be shared by the IR optimizer and the
349 /// the backend.
350 struct SDNodeFlags {
351 private:
352  // This bit is used to determine if the flags are in a defined state.
353  // Flag bits can only be masked out during intersection if the masking flags
354  // are defined.
355  bool AnyDefined : 1;
356 
357  bool NoUnsignedWrap : 1;
358  bool NoSignedWrap : 1;
359  bool Exact : 1;
360  bool UnsafeAlgebra : 1;
361  bool NoNaNs : 1;
362  bool NoInfs : 1;
363  bool NoSignedZeros : 1;
364  bool AllowReciprocal : 1;
365  bool VectorReduction : 1;
366  bool AllowContract : 1;
367 
368 public:
369  /// Default constructor turns off all optimization flags.
371  : AnyDefined(false), NoUnsignedWrap(false), NoSignedWrap(false),
372  Exact(false), UnsafeAlgebra(false), NoNaNs(false), NoInfs(false),
373  NoSignedZeros(false), AllowReciprocal(false), VectorReduction(false),
374  AllowContract(false) {}
375 
376  /// Sets the state of the flags to the defined state.
377  void setDefined() { AnyDefined = true; }
378  /// Returns true if the flags are in a defined state.
379  bool isDefined() const { return AnyDefined; }
380 
381  // These are mutators for each flag.
382  void setNoUnsignedWrap(bool b) {
383  setDefined();
384  NoUnsignedWrap = b;
385  }
386  void setNoSignedWrap(bool b) {
387  setDefined();
388  NoSignedWrap = b;
389  }
390  void setExact(bool b) {
391  setDefined();
392  Exact = b;
393  }
394  void setUnsafeAlgebra(bool b) {
395  setDefined();
396  UnsafeAlgebra = b;
397  }
398  void setNoNaNs(bool b) {
399  setDefined();
400  NoNaNs = b;
401  }
402  void setNoInfs(bool b) {
403  setDefined();
404  NoInfs = b;
405  }
406  void setNoSignedZeros(bool b) {
407  setDefined();
408  NoSignedZeros = b;
409  }
410  void setAllowReciprocal(bool b) {
411  setDefined();
412  AllowReciprocal = b;
413  }
414  void setVectorReduction(bool b) {
415  setDefined();
416  VectorReduction = b;
417  }
418  void setAllowContract(bool b) {
419  setDefined();
420  AllowContract = b;
421  }
422 
423  // These are accessors for each flag.
424  bool hasNoUnsignedWrap() const { return NoUnsignedWrap; }
425  bool hasNoSignedWrap() const { return NoSignedWrap; }
426  bool hasExact() const { return Exact; }
427  bool hasUnsafeAlgebra() const { return UnsafeAlgebra; }
428  bool hasNoNaNs() const { return NoNaNs; }
429  bool hasNoInfs() const { return NoInfs; }
430  bool hasNoSignedZeros() const { return NoSignedZeros; }
431  bool hasAllowReciprocal() const { return AllowReciprocal; }
432  bool hasVectorReduction() const { return VectorReduction; }
433  bool hasAllowContract() const { return AllowContract; }
434 
435  /// Clear any flags in this flag set that aren't also set in Flags.
436  /// If the given Flags are undefined then don't do anything.
438  if (!Flags.isDefined())
439  return;
440  NoUnsignedWrap &= Flags.NoUnsignedWrap;
441  NoSignedWrap &= Flags.NoSignedWrap;
442  Exact &= Flags.Exact;
443  UnsafeAlgebra &= Flags.UnsafeAlgebra;
444  NoNaNs &= Flags.NoNaNs;
445  NoInfs &= Flags.NoInfs;
446  NoSignedZeros &= Flags.NoSignedZeros;
447  AllowReciprocal &= Flags.AllowReciprocal;
448  VectorReduction &= Flags.VectorReduction;
449  AllowContract &= Flags.AllowContract;
450  }
451 };
452 
453 /// Represents one node in the SelectionDAG.
454 ///
455 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
456 private:
457  /// The operation that this node performs.
458  int16_t NodeType;
459 
460 protected:
461  // We define a set of mini-helper classes to help us interpret the bits in our
462  // SubclassData. These are designed to fit within a uint16_t so they pack
463  // with NodeType.
464 
466  friend class SDNode;
467  friend class MemIntrinsicSDNode;
468  friend class MemSDNode;
469 
470  uint16_t HasDebugValue : 1;
471  uint16_t IsMemIntrinsic : 1;
472  };
473  enum { NumSDNodeBits = 2 };
474 
476  friend class ConstantSDNode;
477 
478  uint16_t : NumSDNodeBits;
479 
480  uint16_t IsOpaque : 1;
481  };
482 
484  friend class MemSDNode;
485  friend class MemIntrinsicSDNode;
486  friend class AtomicSDNode;
487 
488  uint16_t : NumSDNodeBits;
489 
490  uint16_t IsVolatile : 1;
491  uint16_t IsNonTemporal : 1;
492  uint16_t IsDereferenceable : 1;
493  uint16_t IsInvariant : 1;
494  };
495  enum { NumMemSDNodeBits = NumSDNodeBits + 4 };
496 
498  friend class LSBaseSDNode;
499 
500  uint16_t : NumMemSDNodeBits;
501 
502  uint16_t AddressingMode : 3; // enum ISD::MemIndexedMode
503  };
504  enum { NumLSBaseSDNodeBits = NumMemSDNodeBits + 3 };
505 
507  friend class LoadSDNode;
508  friend class MaskedLoadSDNode;
509 
510  uint16_t : NumLSBaseSDNodeBits;
511 
512  uint16_t ExtTy : 2; // enum ISD::LoadExtType
513  uint16_t IsExpanding : 1;
514  };
515 
517  friend class StoreSDNode;
518  friend class MaskedStoreSDNode;
519 
520  uint16_t : NumLSBaseSDNodeBits;
521 
522  uint16_t IsTruncating : 1;
523  uint16_t IsCompressing : 1;
524  };
525 
526  union {
527  char RawSDNodeBits[sizeof(uint16_t)];
534  };
535 
536  // RawSDNodeBits must cover the entirety of the union. This means that all of
537  // the union's members must have size <= RawSDNodeBits. We write the RHS as
538  // "2" instead of sizeof(RawSDNodeBits) because MSVC can't handle the latter.
539  static_assert(sizeof(SDNodeBitfields) <= 2, "field too wide");
540  static_assert(sizeof(ConstantSDNodeBitfields) <= 2, "field too wide");
541  static_assert(sizeof(MemSDNodeBitfields) <= 2, "field too wide");
542  static_assert(sizeof(LSBaseSDNodeBitfields) <= 2, "field too wide");
543  static_assert(sizeof(LoadSDNodeBitfields) <= 4, "field too wide");
544  static_assert(sizeof(StoreSDNodeBitfields) <= 2, "field too wide");
545 
546 private:
547  friend class SelectionDAG;
548  // TODO: unfriend HandleSDNode once we fix its operand handling.
549  friend class HandleSDNode;
550 
551  /// Unique id per SDNode in the DAG.
552  int NodeId = -1;
553 
554  /// The values that are used by this operation.
555  SDUse *OperandList = nullptr;
556 
557  /// The types of the values this node defines. SDNode's may
558  /// define multiple values simultaneously.
559  const EVT *ValueList;
560 
561  /// List of uses for this SDNode.
562  SDUse *UseList = nullptr;
563 
564  /// The number of entries in the Operand/Value list.
565  unsigned short NumOperands = 0;
566  unsigned short NumValues;
567 
568  // The ordering of the SDNodes. It roughly corresponds to the ordering of the
569  // original LLVM instructions.
570  // This is used for turning off scheduling, because we'll forgo
571  // the normal scheduling algorithms and output the instructions according to
572  // this ordering.
573  unsigned IROrder;
574 
575  /// Source line information.
576  DebugLoc debugLoc;
577 
578  /// Return a pointer to the specified value type.
579  static const EVT *getValueTypeList(EVT VT);
580 
582 
583 public:
584  /// Unique and persistent id per SDNode in the DAG.
585  /// Used for debug printing.
586  uint16_t PersistentId;
587 
588  //===--------------------------------------------------------------------===//
589  // Accessors
590  //
591 
592  /// Return the SelectionDAG opcode value for this node. For
593  /// pre-isel nodes (those for which isMachineOpcode returns false), these
594  /// are the opcode values in the ISD and <target>ISD namespaces. For
595  /// post-isel opcodes, see getMachineOpcode.
596  unsigned getOpcode() const { return (unsigned short)NodeType; }
597 
598  /// Test if this node has a target-specific opcode (in the
599  /// <target>ISD namespace).
600  bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
601 
602  /// Test if this node has a target-specific
603  /// memory-referencing opcode (in the <target>ISD namespace and
604  /// greater than FIRST_TARGET_MEMORY_OPCODE).
605  bool isTargetMemoryOpcode() const {
606  return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
607  }
608 
609  /// Return true if the type of the node type undefined.
610  bool isUndef() const { return NodeType == ISD::UNDEF; }
611 
612  /// Test if this node is a memory intrinsic (with valid pointer information).
613  /// INTRINSIC_W_CHAIN and INTRINSIC_VOID nodes are sometimes created for
614  /// non-memory intrinsics (with chains) that are not really instances of
615  /// MemSDNode. For such nodes, we need some extra state to determine the
616  /// proper classof relationship.
617  bool isMemIntrinsic() const {
618  return (NodeType == ISD::INTRINSIC_W_CHAIN ||
619  NodeType == ISD::INTRINSIC_VOID) &&
620  SDNodeBits.IsMemIntrinsic;
621  }
622 
623  /// Test if this node is a strict floating point pseudo-op.
625  switch (NodeType) {
626  default:
627  return false;
628  case ISD::STRICT_FADD:
629  case ISD::STRICT_FSUB:
630  case ISD::STRICT_FMUL:
631  case ISD::STRICT_FDIV:
632  case ISD::STRICT_FREM:
633  case ISD::STRICT_FSQRT:
634  case ISD::STRICT_FPOW:
635  case ISD::STRICT_FPOWI:
636  case ISD::STRICT_FSIN:
637  case ISD::STRICT_FCOS:
638  case ISD::STRICT_FEXP:
639  case ISD::STRICT_FEXP2:
640  case ISD::STRICT_FLOG:
641  case ISD::STRICT_FLOG10:
642  case ISD::STRICT_FLOG2:
643  case ISD::STRICT_FRINT:
645  return true;
646  }
647  }
648 
649  /// Test if this node has a post-isel opcode, directly
650  /// corresponding to a MachineInstr opcode.
651  bool isMachineOpcode() const { return NodeType < 0; }
652 
653  /// This may only be called if isMachineOpcode returns
654  /// true. It returns the MachineInstr opcode value that the node's opcode
655  /// corresponds to.
656  unsigned getMachineOpcode() const {
657  assert(isMachineOpcode() && "Not a MachineInstr opcode!");
658  return ~NodeType;
659  }
660 
661  bool getHasDebugValue() const { return SDNodeBits.HasDebugValue; }
662  void setHasDebugValue(bool b) { SDNodeBits.HasDebugValue = b; }
663 
664  /// Return true if there are no uses of this node.
665  bool use_empty() const { return UseList == nullptr; }
666 
667  /// Return true if there is exactly one use of this node.
668  bool hasOneUse() const {
669  return !use_empty() && std::next(use_begin()) == use_end();
670  }
671 
672  /// Return the number of uses of this node. This method takes
673  /// time proportional to the number of uses.
674  size_t use_size() const { return std::distance(use_begin(), use_end()); }
675 
676  /// Return the unique node id.
677  int getNodeId() const { return NodeId; }
678 
679  /// Set unique node id.
680  void setNodeId(int Id) { NodeId = Id; }
681 
682  /// Return the node ordering.
683  unsigned getIROrder() const { return IROrder; }
684 
685  /// Set the node ordering.
686  void setIROrder(unsigned Order) { IROrder = Order; }
687 
688  /// Return the source location info.
689  const DebugLoc &getDebugLoc() const { return debugLoc; }
690 
691  /// Set source location info. Try to avoid this, putting
692  /// it in the constructor is preferable.
693  void setDebugLoc(DebugLoc dl) { debugLoc = std::move(dl); }
694 
695  /// This class provides iterator support for SDUse
696  /// operands that use a specific SDNode.
698  : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
699  friend class SDNode;
700 
701  SDUse *Op = nullptr;
702 
703  explicit use_iterator(SDUse *op) : Op(op) {}
704 
705  public:
706  using reference = std::iterator<std::forward_iterator_tag,
708  using pointer = std::iterator<std::forward_iterator_tag,
710 
711  use_iterator() = default;
712  use_iterator(const use_iterator &I) : Op(I.Op) {}
713 
714  bool operator==(const use_iterator &x) const {
715  return Op == x.Op;
716  }
717  bool operator!=(const use_iterator &x) const {
718  return !operator==(x);
719  }
720 
721  /// Return true if this iterator is at the end of uses list.
722  bool atEnd() const { return Op == nullptr; }
723 
724  // Iterator traversal: forward iteration only.
725  use_iterator &operator++() { // Preincrement
726  assert(Op && "Cannot increment end iterator!");
727  Op = Op->getNext();
728  return *this;
729  }
730 
731  use_iterator operator++(int) { // Postincrement
732  use_iterator tmp = *this; ++*this; return tmp;
733  }
734 
735  /// Retrieve a pointer to the current user node.
736  SDNode *operator*() const {
737  assert(Op && "Cannot dereference end iterator!");
738  return Op->getUser();
739  }
740 
741  SDNode *operator->() const { return operator*(); }
742 
743  SDUse &getUse() const { return *Op; }
744 
745  /// Retrieve the operand # of this use in its user.
746  unsigned getOperandNo() const {
747  assert(Op && "Cannot dereference end iterator!");
748  return (unsigned)(Op - Op->getUser()->OperandList);
749  }
750  };
751 
752  /// Provide iteration support to walk over all uses of an SDNode.
754  return use_iterator(UseList);
755  }
756 
757  static use_iterator use_end() { return use_iterator(nullptr); }
758 
760  return make_range(use_begin(), use_end());
761  }
763  return make_range(use_begin(), use_end());
764  }
765 
766  /// Return true if there are exactly NUSES uses of the indicated value.
767  /// This method ignores uses of other values defined by this operation.
768  bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
769 
770  /// Return true if there are any use of the indicated value.
771  /// This method ignores uses of other values defined by this operation.
772  bool hasAnyUseOfValue(unsigned Value) const;
773 
774  /// Return true if this node is the only use of N.
775  bool isOnlyUserOf(const SDNode *N) const;
776 
777  /// Return true if this node is an operand of N.
778  bool isOperandOf(const SDNode *N) const;
779 
780  /// Return true if this node is a predecessor of N.
781  /// NOTE: Implemented on top of hasPredecessor and every bit as
782  /// expensive. Use carefully.
783  bool isPredecessorOf(const SDNode *N) const {
784  return N->hasPredecessor(this);
785  }
786 
787  /// Return true if N is a predecessor of this node.
788  /// N is either an operand of this node, or can be reached by recursively
789  /// traversing up the operands.
790  /// NOTE: This is an expensive method. Use it carefully.
791  bool hasPredecessor(const SDNode *N) const;
792 
793  /// Returns true if N is a predecessor of any node in Worklist. This
794  /// helper keeps Visited and Worklist sets externally to allow unions
795  /// searches to be performed in parallel, caching of results across
796  /// queries and incremental addition to Worklist. Stops early if N is
797  /// found but will resume. Remember to clear Visited and Worklists
798  /// if DAG changes.
799  static bool hasPredecessorHelper(const SDNode *N,
802  if (Visited.count(N))
803  return true;
804  while (!Worklist.empty()) {
805  const SDNode *M = Worklist.pop_back_val();
806  bool Found = false;
807  for (const SDValue &OpV : M->op_values()) {
808  SDNode *Op = OpV.getNode();
809  if (Visited.insert(Op).second)
810  Worklist.push_back(Op);
811  if (Op == N)
812  Found = true;
813  }
814  if (Found)
815  return true;
816  }
817  return false;
818  }
819 
820  /// Return true if all the users of N are contained in Nodes.
821  /// NOTE: Requires at least one match, but doesn't require them all.
822  static bool areOnlyUsersOf(ArrayRef<const SDNode *> Nodes, const SDNode *N);
823 
824  /// Return the number of values used by this operation.
825  unsigned getNumOperands() const { return NumOperands; }
826 
827  /// Helper method returns the integer value of a ConstantSDNode operand.
828  inline uint64_t getConstantOperandVal(unsigned Num) const;
829 
830  const SDValue &getOperand(unsigned Num) const {
831  assert(Num < NumOperands && "Invalid child # of SDNode!");
832  return OperandList[Num];
833  }
834 
835  using op_iterator = SDUse *;
836 
837  op_iterator op_begin() const { return OperandList; }
838  op_iterator op_end() const { return OperandList+NumOperands; }
839  ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
840 
841  /// Iterator for directly iterating over the operand SDValue's.
843  : iterator_adaptor_base<value_op_iterator, op_iterator,
844  std::random_access_iterator_tag, SDValue,
845  ptrdiff_t, value_op_iterator *,
846  value_op_iterator *> {
847  explicit value_op_iterator(SDUse *U = nullptr)
848  : iterator_adaptor_base(U) {}
849 
850  const SDValue &operator*() const { return I->get(); }
851  };
852 
854  return make_range(value_op_iterator(op_begin()),
855  value_op_iterator(op_end()));
856  }
857 
858  SDVTList getVTList() const {
859  SDVTList X = { ValueList, NumValues };
860  return X;
861  }
862 
863  /// If this node has a glue operand, return the node
864  /// to which the glue operand points. Otherwise return NULL.
865  SDNode *getGluedNode() const {
866  if (getNumOperands() != 0 &&
867  getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
868  return getOperand(getNumOperands()-1).getNode();
869  return nullptr;
870  }
871 
872  /// If this node has a glue value with a user, return
873  /// the user (there is at most one). Otherwise return NULL.
874  SDNode *getGluedUser() const {
875  for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
876  if (UI.getUse().get().getValueType() == MVT::Glue)
877  return *UI;
878  return nullptr;
879  }
880 
881  const SDNodeFlags getFlags() const { return Flags; }
882  void setFlags(SDNodeFlags NewFlags) { Flags = NewFlags; }
883 
884  /// Clear any flags in this node that aren't also set in Flags.
885  /// If Flags is not in a defined state then this has no effect.
886  void intersectFlagsWith(const SDNodeFlags Flags);
887 
888  /// Return the number of values defined/returned by this operator.
889  unsigned getNumValues() const { return NumValues; }
890 
891  /// Return the type of a specified result.
892  EVT getValueType(unsigned ResNo) const {
893  assert(ResNo < NumValues && "Illegal result number!");
894  return ValueList[ResNo];
895  }
896 
897  /// Return the type of a specified result as a simple type.
898  MVT getSimpleValueType(unsigned ResNo) const {
899  return getValueType(ResNo).getSimpleVT();
900  }
901 
902  /// Returns MVT::getSizeInBits(getValueType(ResNo)).
903  unsigned getValueSizeInBits(unsigned ResNo) const {
904  return getValueType(ResNo).getSizeInBits();
905  }
906 
907  using value_iterator = const EVT *;
908 
909  value_iterator value_begin() const { return ValueList; }
910  value_iterator value_end() const { return ValueList+NumValues; }
911 
912  /// Return the opcode of this operation for printing.
913  std::string getOperationName(const SelectionDAG *G = nullptr) const;
914  static const char* getIndexedModeName(ISD::MemIndexedMode AM);
915  void print_types(raw_ostream &OS, const SelectionDAG *G) const;
916  void print_details(raw_ostream &OS, const SelectionDAG *G) const;
917  void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
918  void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
919 
920  /// Print a SelectionDAG node and all children down to
921  /// the leaves. The given SelectionDAG allows target-specific nodes
922  /// to be printed in human-readable form. Unlike printr, this will
923  /// print the whole DAG, including children that appear multiple
924  /// times.
925  ///
926  void printrFull(raw_ostream &O, const SelectionDAG *G = nullptr) const;
927 
928  /// Print a SelectionDAG node and children up to
929  /// depth "depth." The given SelectionDAG allows target-specific
930  /// nodes to be printed in human-readable form. Unlike printr, this
931  /// will print children that appear multiple times wherever they are
932  /// used.
933  ///
934  void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
935  unsigned depth = 100) const;
936 
937  /// Dump this node, for debugging.
938  void dump() const;
939 
940  /// Dump (recursively) this node and its use-def subgraph.
941  void dumpr() const;
942 
943  /// Dump this node, for debugging.
944  /// The given SelectionDAG allows target-specific nodes to be printed
945  /// in human-readable form.
946  void dump(const SelectionDAG *G) const;
947 
948  /// Dump (recursively) this node and its use-def subgraph.
949  /// The given SelectionDAG allows target-specific nodes to be printed
950  /// in human-readable form.
951  void dumpr(const SelectionDAG *G) const;
952 
953  /// printrFull to dbgs(). The given SelectionDAG allows
954  /// target-specific nodes to be printed in human-readable form.
955  /// Unlike dumpr, this will print the whole DAG, including children
956  /// that appear multiple times.
957  void dumprFull(const SelectionDAG *G = nullptr) const;
958 
959  /// printrWithDepth to dbgs(). The given
960  /// SelectionDAG allows target-specific nodes to be printed in
961  /// human-readable form. Unlike dumpr, this will print children
962  /// that appear multiple times wherever they are used.
963  ///
964  void dumprWithDepth(const SelectionDAG *G = nullptr,
965  unsigned depth = 100) const;
966 
967  /// Gather unique data for the node.
968  void Profile(FoldingSetNodeID &ID) const;
969 
970  /// This method should only be used by the SDUse class.
971  void addUse(SDUse &U) { U.addToList(&UseList); }
972 
973 protected:
974  static SDVTList getSDVTList(EVT VT) {
975  SDVTList Ret = { getValueTypeList(VT), 1 };
976  return Ret;
977  }
978 
979  /// Create an SDNode.
980  ///
981  /// SDNodes are created without any operands, and never own the operand
982  /// storage. To add operands, see SelectionDAG::createOperands.
983  SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
984  : NodeType(Opc), ValueList(VTs.VTs), NumValues(VTs.NumVTs),
985  IROrder(Order), debugLoc(std::move(dl)) {
986  memset(&RawSDNodeBits, 0, sizeof(RawSDNodeBits));
987  assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
988  assert(NumValues == VTs.NumVTs &&
989  "NumValues wasn't wide enough for its operands!");
990  }
991 
992  /// Release the operands and set this node to have zero operands.
993  void DropOperands();
994 };
995 
996 /// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
997 /// into SDNode creation functions.
998 /// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
999 /// from the original Instruction, and IROrder is the ordinal position of
1000 /// the instruction.
1001 /// When an SDNode is created after the DAG is being built, both DebugLoc and
1002 /// the IROrder are propagated from the original SDNode.
1003 /// So SDLoc class provides two constructors besides the default one, one to
1004 /// be used by the DAGBuilder, the other to be used by others.
1005 class SDLoc {
1006 private:
1007  DebugLoc DL;
1008  int IROrder = 0;
1009 
1010 public:
1011  SDLoc() = default;
1012  SDLoc(const SDNode *N) : DL(N->getDebugLoc()), IROrder(N->getIROrder()) {}
1013  SDLoc(const SDValue V) : SDLoc(V.getNode()) {}
1014  SDLoc(const Instruction *I, int Order) : IROrder(Order) {
1015  assert(Order >= 0 && "bad IROrder");
1016  if (I)
1017  DL = I->getDebugLoc();
1018  }
1019 
1020  unsigned getIROrder() const { return IROrder; }
1021  const DebugLoc &getDebugLoc() const { return DL; }
1022 };
1023 
1024 // Define inline functions from the SDValue class.
1025 
1026 inline SDValue::SDValue(SDNode *node, unsigned resno)
1027  : Node(node), ResNo(resno) {
1028  // Explicitly check for !ResNo to avoid use-after-free, because there are
1029  // callers that use SDValue(N, 0) with a deleted N to indicate successful
1030  // combines.
1031  assert((!Node || !ResNo || ResNo < Node->getNumValues()) &&
1032  "Invalid result number for the given node!");
1033  assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
1034 }
1035 
1036 inline unsigned SDValue::getOpcode() const {
1037  return Node->getOpcode();
1038 }
1039 
1040 inline EVT SDValue::getValueType() const {
1041  return Node->getValueType(ResNo);
1042 }
1043 
1044 inline unsigned SDValue::getNumOperands() const {
1045  return Node->getNumOperands();
1046 }
1047 
1048 inline const SDValue &SDValue::getOperand(unsigned i) const {
1049  return Node->getOperand(i);
1050 }
1051 
1052 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1053  return Node->getConstantOperandVal(i);
1054 }
1055 
1056 inline bool SDValue::isTargetOpcode() const {
1057  return Node->isTargetOpcode();
1058 }
1059 
1060 inline bool SDValue::isTargetMemoryOpcode() const {
1061  return Node->isTargetMemoryOpcode();
1062 }
1063 
1064 inline bool SDValue::isMachineOpcode() const {
1065  return Node->isMachineOpcode();
1066 }
1067 
1068 inline unsigned SDValue::getMachineOpcode() const {
1069  return Node->getMachineOpcode();
1070 }
1071 
1072 inline bool SDValue::isUndef() const {
1073  return Node->isUndef();
1074 }
1075 
1076 inline bool SDValue::use_empty() const {
1077  return !Node->hasAnyUseOfValue(ResNo);
1078 }
1079 
1080 inline bool SDValue::hasOneUse() const {
1081  return Node->hasNUsesOfValue(1, ResNo);
1082 }
1083 
1084 inline const DebugLoc &SDValue::getDebugLoc() const {
1085  return Node->getDebugLoc();
1086 }
1087 
1088 inline void SDValue::dump() const {
1089  return Node->dump();
1090 }
1091 
1092 inline void SDValue::dumpr() const {
1093  return Node->dumpr();
1094 }
1095 
1096 // Define inline functions from the SDUse class.
1097 
1098 inline void SDUse::set(const SDValue &V) {
1099  if (Val.getNode()) removeFromList();
1100  Val = V;
1101  if (V.getNode()) V.getNode()->addUse(*this);
1102 }
1103 
1104 inline void SDUse::setInitial(const SDValue &V) {
1105  Val = V;
1106  V.getNode()->addUse(*this);
1107 }
1108 
1109 inline void SDUse::setNode(SDNode *N) {
1110  if (Val.getNode()) removeFromList();
1111  Val.setNode(N);
1112  if (N) N->addUse(*this);
1113 }
1114 
1115 /// This class is used to form a handle around another node that
1116 /// is persistent and is updated across invocations of replaceAllUsesWith on its
1117 /// operand. This node should be directly created by end-users and not added to
1118 /// the AllNodes list.
1119 class HandleSDNode : public SDNode {
1120  SDUse Op;
1121 
1122 public:
1124  : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1125  // HandleSDNodes are never inserted into the DAG, so they won't be
1126  // auto-numbered. Use ID 65535 as a sentinel.
1127  PersistentId = 0xffff;
1128 
1129  // Manually set up the operand list. This node type is special in that it's
1130  // always stack allocated and SelectionDAG does not manage its operands.
1131  // TODO: This should either (a) not be in the SDNode hierarchy, or (b) not
1132  // be so special.
1133  Op.setUser(this);
1134  Op.setInitial(X);
1135  NumOperands = 1;
1136  OperandList = &Op;
1137  }
1138  ~HandleSDNode();
1139 
1140  const SDValue &getValue() const { return Op; }
1141 };
1142 
1143 class AddrSpaceCastSDNode : public SDNode {
1144 private:
1145  unsigned SrcAddrSpace;
1146  unsigned DestAddrSpace;
1147 
1148 public:
1149  AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, EVT VT,
1150  unsigned SrcAS, unsigned DestAS);
1151 
1152  unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1153  unsigned getDestAddressSpace() const { return DestAddrSpace; }
1154 
1155  static bool classof(const SDNode *N) {
1156  return N->getOpcode() == ISD::ADDRSPACECAST;
1157  }
1158 };
1159 
1160 /// This is an abstract virtual class for memory operations.
1161 class MemSDNode : public SDNode {
1162 private:
1163  // VT of in-memory value.
1164  EVT MemoryVT;
1165 
1166 protected:
1167  /// Memory reference information.
1169 
1170 public:
1171  MemSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs,
1172  EVT MemoryVT, MachineMemOperand *MMO);
1173 
1174  bool readMem() const { return MMO->isLoad(); }
1175  bool writeMem() const { return MMO->isStore(); }
1176 
1177  /// Returns alignment and volatility of the memory access
1178  unsigned getOriginalAlignment() const {
1179  return MMO->getBaseAlignment();
1180  }
1181  unsigned getAlignment() const {
1182  return MMO->getAlignment();
1183  }
1184 
1185  /// Return the SubclassData value, without HasDebugValue. This contains an
1186  /// encoding of the volatile flag, as well as bits used by subclasses. This
1187  /// function should only be used to compute a FoldingSetNodeID value.
1188  /// The HasDebugValue bit is masked out because CSE map needs to match
1189  /// nodes with debug info with nodes without debug info.
1190  unsigned getRawSubclassData() const {
1191  uint16_t Data;
1192  union {
1193  char RawSDNodeBits[sizeof(uint16_t)];
1194  SDNodeBitfields SDNodeBits;
1195  };
1196  memcpy(&RawSDNodeBits, &this->RawSDNodeBits, sizeof(this->RawSDNodeBits));
1197  SDNodeBits.HasDebugValue = 0;
1198  memcpy(&Data, &RawSDNodeBits, sizeof(RawSDNodeBits));
1199  return Data;
1200  }
1201 
1202  bool isVolatile() const { return MemSDNodeBits.IsVolatile; }
1203  bool isNonTemporal() const { return MemSDNodeBits.IsNonTemporal; }
1204  bool isDereferenceable() const { return MemSDNodeBits.IsDereferenceable; }
1205  bool isInvariant() const { return MemSDNodeBits.IsInvariant; }
1206 
1207  // Returns the offset from the location of the access.
1208  int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1209 
1210  /// Returns the AA info that describes the dereference.
1211  AAMDNodes getAAInfo() const { return MMO->getAAInfo(); }
1212 
1213  /// Returns the Ranges that describes the dereference.
1214  const MDNode *getRanges() const { return MMO->getRanges(); }
1215 
1216  /// Returns the synchronization scope ID for this memory operation.
1217  SyncScope::ID getSyncScopeID() const { return MMO->getSyncScopeID(); }
1218 
1219  /// Return the atomic ordering requirements for this memory operation. For
1220  /// cmpxchg atomic operations, return the atomic ordering requirements when
1221  /// store occurs.
1222  AtomicOrdering getOrdering() const { return MMO->getOrdering(); }
1223 
1224  /// Return the type of the in-memory value.
1225  EVT getMemoryVT() const { return MemoryVT; }
1226 
1227  /// Return a MachineMemOperand object describing the memory
1228  /// reference performed by operation.
1229  MachineMemOperand *getMemOperand() const { return MMO; }
1230 
1232  return MMO->getPointerInfo();
1233  }
1234 
1235  /// Return the address space for the associated pointer
1236  unsigned getAddressSpace() const {
1237  return getPointerInfo().getAddrSpace();
1238  }
1239 
1240  /// Update this MemSDNode's MachineMemOperand information
1241  /// to reflect the alignment of NewMMO, if it has a greater alignment.
1242  /// This must only be used when the new alignment applies to all users of
1243  /// this MachineMemOperand.
1244  void refineAlignment(const MachineMemOperand *NewMMO) {
1245  MMO->refineAlignment(NewMMO);
1246  }
1247 
1248  const SDValue &getChain() const { return getOperand(0); }
1249  const SDValue &getBasePtr() const {
1250  return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1251  }
1252 
1253  // Methods to support isa and dyn_cast
1254  static bool classof(const SDNode *N) {
1255  // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1256  // with either an intrinsic or a target opcode.
1257  return N->getOpcode() == ISD::LOAD ||
1258  N->getOpcode() == ISD::STORE ||
1259  N->getOpcode() == ISD::PREFETCH ||
1260  N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1262  N->getOpcode() == ISD::ATOMIC_SWAP ||
1263  N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1264  N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1265  N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1266  N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1267  N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1268  N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1269  N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1270  N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1271  N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1272  N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1273  N->getOpcode() == ISD::ATOMIC_LOAD ||
1274  N->getOpcode() == ISD::ATOMIC_STORE ||
1275  N->getOpcode() == ISD::MLOAD ||
1276  N->getOpcode() == ISD::MSTORE ||
1277  N->getOpcode() == ISD::MGATHER ||
1278  N->getOpcode() == ISD::MSCATTER ||
1279  N->isMemIntrinsic() ||
1280  N->isTargetMemoryOpcode();
1281  }
1282 };
1283 
1284 /// This is an SDNode representing atomic operations.
1285 class AtomicSDNode : public MemSDNode {
1286 public:
1287  AtomicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTL,
1288  EVT MemVT, MachineMemOperand *MMO)
1289  : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {}
1290 
1291  const SDValue &getBasePtr() const { return getOperand(1); }
1292  const SDValue &getVal() const { return getOperand(2); }
1293 
1294  /// Returns true if this SDNode represents cmpxchg atomic operation, false
1295  /// otherwise.
1296  bool isCompareAndSwap() const {
1297  unsigned Op = getOpcode();
1298  return Op == ISD::ATOMIC_CMP_SWAP ||
1300  }
1301 
1302  /// For cmpxchg atomic operations, return the atomic ordering requirements
1303  /// when store does not occur.
1305  assert(isCompareAndSwap() && "Must be cmpxchg operation");
1306  return MMO->getFailureOrdering();
1307  }
1308 
1309  // Methods to support isa and dyn_cast
1310  static bool classof(const SDNode *N) {
1311  return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1313  N->getOpcode() == ISD::ATOMIC_SWAP ||
1314  N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1315  N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1316  N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1317  N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1318  N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1319  N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1320  N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1321  N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1322  N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1323  N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1324  N->getOpcode() == ISD::ATOMIC_LOAD ||
1325  N->getOpcode() == ISD::ATOMIC_STORE;
1326  }
1327 };
1328 
1329 /// This SDNode is used for target intrinsics that touch
1330 /// memory and need an associated MachineMemOperand. Its opcode may be
1331 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1332 /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1334 public:
1335  MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl,
1336  SDVTList VTs, EVT MemoryVT, MachineMemOperand *MMO)
1337  : MemSDNode(Opc, Order, dl, VTs, MemoryVT, MMO) {
1338  SDNodeBits.IsMemIntrinsic = true;
1339  }
1340 
1341  // Methods to support isa and dyn_cast
1342  static bool classof(const SDNode *N) {
1343  // We lower some target intrinsics to their target opcode
1344  // early a node with a target opcode can be of this class
1345  return N->isMemIntrinsic() ||
1346  N->getOpcode() == ISD::PREFETCH ||
1347  N->isTargetMemoryOpcode();
1348  }
1349 };
1350 
1351 /// This SDNode is used to implement the code generator
1352 /// support for the llvm IR shufflevector instruction. It combines elements
1353 /// from two input vectors into a new input vector, with the selection and
1354 /// ordering of elements determined by an array of integers, referred to as
1355 /// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1356 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1357 /// An index of -1 is treated as undef, such that the code generator may put
1358 /// any value in the corresponding element of the result.
1359 class ShuffleVectorSDNode : public SDNode {
1360  // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1361  // is freed when the SelectionDAG object is destroyed.
1362  const int *Mask;
1363 
1364 protected:
1365  friend class SelectionDAG;
1366 
1367  ShuffleVectorSDNode(EVT VT, unsigned Order, const DebugLoc &dl, const int *M)
1368  : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {}
1369 
1370 public:
1372  EVT VT = getValueType(0);
1373  return makeArrayRef(Mask, VT.getVectorNumElements());
1374  }
1375 
1376  int getMaskElt(unsigned Idx) const {
1377  assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1378  return Mask[Idx];
1379  }
1380 
1381  bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1382 
1383  int getSplatIndex() const {
1384  assert(isSplat() && "Cannot get splat index for non-splat!");
1385  EVT VT = getValueType(0);
1386  for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
1387  if (Mask[i] >= 0)
1388  return Mask[i];
1389  }
1390  llvm_unreachable("Splat with all undef indices?");
1391  }
1392 
1393  static bool isSplatMask(const int *Mask, EVT VT);
1394 
1395  /// Change values in a shuffle permute mask assuming
1396  /// the two vector operands have swapped position.
1397  static void commuteMask(MutableArrayRef<int> Mask) {
1398  unsigned NumElems = Mask.size();
1399  for (unsigned i = 0; i != NumElems; ++i) {
1400  int idx = Mask[i];
1401  if (idx < 0)
1402  continue;
1403  else if (idx < (int)NumElems)
1404  Mask[i] = idx + NumElems;
1405  else
1406  Mask[i] = idx - NumElems;
1407  }
1408  }
1409 
1410  static bool classof(const SDNode *N) {
1411  return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1412  }
1413 };
1414 
1415 class ConstantSDNode : public SDNode {
1416  friend class SelectionDAG;
1417 
1418  const ConstantInt *Value;
1419 
1420  ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val,
1421  const DebugLoc &DL, EVT VT)
1422  : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, 0, DL,
1423  getSDVTList(VT)),
1424  Value(val) {
1425  ConstantSDNodeBits.IsOpaque = isOpaque;
1426  }
1427 
1428 public:
1429  const ConstantInt *getConstantIntValue() const { return Value; }
1430  const APInt &getAPIntValue() const { return Value->getValue(); }
1431  uint64_t getZExtValue() const { return Value->getZExtValue(); }
1432  int64_t getSExtValue() const { return Value->getSExtValue(); }
1433 
1434  bool isOne() const { return Value->isOne(); }
1435  bool isNullValue() const { return Value->isZero(); }
1436  bool isAllOnesValue() const { return Value->isMinusOne(); }
1437 
1438  bool isOpaque() const { return ConstantSDNodeBits.IsOpaque; }
1439 
1440  static bool classof(const SDNode *N) {
1441  return N->getOpcode() == ISD::Constant ||
1443  }
1444 };
1445 
1446 uint64_t SDNode::getConstantOperandVal(unsigned Num) const {
1447  return cast<ConstantSDNode>(getOperand(Num))->getZExtValue();
1448 }
1449 
1450 class ConstantFPSDNode : public SDNode {
1451  friend class SelectionDAG;
1452 
1453  const ConstantFP *Value;
1454 
1455  ConstantFPSDNode(bool isTarget, const ConstantFP *val, const DebugLoc &DL,
1456  EVT VT)
1457  : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 0, DL,
1458  getSDVTList(VT)),
1459  Value(val) {}
1460 
1461 public:
1462  const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1463  const ConstantFP *getConstantFPValue() const { return Value; }
1464 
1465  /// Return true if the value is positive or negative zero.
1466  bool isZero() const { return Value->isZero(); }
1467 
1468  /// Return true if the value is a NaN.
1469  bool isNaN() const { return Value->isNaN(); }
1470 
1471  /// Return true if the value is an infinity
1472  bool isInfinity() const { return Value->isInfinity(); }
1473 
1474  /// Return true if the value is negative.
1475  bool isNegative() const { return Value->isNegative(); }
1476 
1477  /// We don't rely on operator== working on double values, as
1478  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1479  /// As such, this method can be used to do an exact bit-for-bit comparison of
1480  /// two floating point values.
1481 
1482  /// We leave the version with the double argument here because it's just so
1483  /// convenient to write "2.0" and the like. Without this function we'd
1484  /// have to duplicate its logic everywhere it's called.
1485  bool isExactlyValue(double V) const {
1486  bool ignored;
1487  APFloat Tmp(V);
1488  Tmp.convert(Value->getValueAPF().getSemantics(),
1489  APFloat::rmNearestTiesToEven, &ignored);
1490  return isExactlyValue(Tmp);
1491  }
1492  bool isExactlyValue(const APFloat& V) const;
1493 
1494  static bool isValueValidForType(EVT VT, const APFloat& Val);
1495 
1496  static bool classof(const SDNode *N) {
1497  return N->getOpcode() == ISD::ConstantFP ||
1499  }
1500 };
1501 
1502 /// Returns true if \p V is a constant integer zero.
1503 bool isNullConstant(SDValue V);
1504 
1505 /// Returns true if \p V is an FP constant with a value of positive zero.
1506 bool isNullFPConstant(SDValue V);
1507 
1508 /// Returns true if \p V is an integer constant with all bits set.
1509 bool isAllOnesConstant(SDValue V);
1510 
1511 /// Returns true if \p V is a constant integer one.
1512 bool isOneConstant(SDValue V);
1513 
1514 /// Returns true if \p V is a bitwise not operation. Assumes that an all ones
1515 /// constant is canonicalized to be operand 1.
1516 bool isBitwiseNot(SDValue V);
1517 
1518 /// Returns the SDNode if it is a constant splat BuildVector or constant int.
1520 
1521 /// Returns the SDNode if it is a constant splat BuildVector or constant float.
1523 
1524 class GlobalAddressSDNode : public SDNode {
1525  friend class SelectionDAG;
1526 
1527  const GlobalValue *TheGlobal;
1528  int64_t Offset;
1529  unsigned char TargetFlags;
1530 
1531  GlobalAddressSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL,
1532  const GlobalValue *GA, EVT VT, int64_t o,
1533  unsigned char TargetFlags);
1534 
1535 public:
1536  const GlobalValue *getGlobal() const { return TheGlobal; }
1537  int64_t getOffset() const { return Offset; }
1538  unsigned char getTargetFlags() const { return TargetFlags; }
1539  // Return the address space this GlobalAddress belongs to.
1540  unsigned getAddressSpace() const;
1541 
1542  static bool classof(const SDNode *N) {
1543  return N->getOpcode() == ISD::GlobalAddress ||
1545  N->getOpcode() == ISD::GlobalTLSAddress ||
1547  }
1548 };
1549 
1550 class FrameIndexSDNode : public SDNode {
1551  friend class SelectionDAG;
1552 
1553  int FI;
1554 
1555  FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1556  : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1557  0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1558  }
1559 
1560 public:
1561  int getIndex() const { return FI; }
1562 
1563  static bool classof(const SDNode *N) {
1564  return N->getOpcode() == ISD::FrameIndex ||
1566  }
1567 };
1568 
1569 class JumpTableSDNode : public SDNode {
1570  friend class SelectionDAG;
1571 
1572  int JTI;
1573  unsigned char TargetFlags;
1574 
1575  JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1576  : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1577  0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1578  }
1579 
1580 public:
1581  int getIndex() const { return JTI; }
1582  unsigned char getTargetFlags() const { return TargetFlags; }
1583 
1584  static bool classof(const SDNode *N) {
1585  return N->getOpcode() == ISD::JumpTable ||
1587  }
1588 };
1589 
1590 class ConstantPoolSDNode : public SDNode {
1591  friend class SelectionDAG;
1592 
1593  union {
1596  } Val;
1597  int Offset; // It's a MachineConstantPoolValue if top bit is set.
1598  unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
1599  unsigned char TargetFlags;
1600 
1601  ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1602  unsigned Align, unsigned char TF)
1603  : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1604  DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1605  TargetFlags(TF) {
1606  assert(Offset >= 0 && "Offset is too large");
1607  Val.ConstVal = c;
1608  }
1609 
1610  ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1611  EVT VT, int o, unsigned Align, unsigned char TF)
1613  DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1614  TargetFlags(TF) {
1615  assert(Offset >= 0 && "Offset is too large");
1616  Val.MachineCPVal = v;
1617  Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1618  }
1619 
1620 public:
1622  return Offset < 0;
1623  }
1624 
1625  const Constant *getConstVal() const {
1626  assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1627  return Val.ConstVal;
1628  }
1629 
1631  assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1632  return Val.MachineCPVal;
1633  }
1634 
1635  int getOffset() const {
1636  return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1637  }
1638 
1639  // Return the alignment of this constant pool object, which is either 0 (for
1640  // default alignment) or the desired value.
1641  unsigned getAlignment() const { return Alignment; }
1642  unsigned char getTargetFlags() const { return TargetFlags; }
1643 
1644  Type *getType() const;
1645 
1646  static bool classof(const SDNode *N) {
1647  return N->getOpcode() == ISD::ConstantPool ||
1649  }
1650 };
1651 
1652 /// Completely target-dependent object reference.
1653 class TargetIndexSDNode : public SDNode {
1654  friend class SelectionDAG;
1655 
1656  unsigned char TargetFlags;
1657  int Index;
1658  int64_t Offset;
1659 
1660 public:
1661  TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1662  : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
1663  TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1664 
1665  unsigned char getTargetFlags() const { return TargetFlags; }
1666  int getIndex() const { return Index; }
1667  int64_t getOffset() const { return Offset; }
1668 
1669  static bool classof(const SDNode *N) {
1670  return N->getOpcode() == ISD::TargetIndex;
1671  }
1672 };
1673 
1674 class BasicBlockSDNode : public SDNode {
1675  friend class SelectionDAG;
1676 
1677  MachineBasicBlock *MBB;
1678 
1679  /// Debug info is meaningful and potentially useful here, but we create
1680  /// blocks out of order when they're jumped to, which makes it a bit
1681  /// harder. Let's see if we need it first.
1682  explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1683  : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
1684  {}
1685 
1686 public:
1687  MachineBasicBlock *getBasicBlock() const { return MBB; }
1688 
1689  static bool classof(const SDNode *N) {
1690  return N->getOpcode() == ISD::BasicBlock;
1691  }
1692 };
1693 
1694 /// A "pseudo-class" with methods for operating on BUILD_VECTORs.
1695 class BuildVectorSDNode : public SDNode {
1696 public:
1697  // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1698  explicit BuildVectorSDNode() = delete;
1699 
1700  /// Check if this is a constant splat, and if so, find the
1701  /// smallest element size that splats the vector. If MinSplatBits is
1702  /// nonzero, the element size must be at least that large. Note that the
1703  /// splat element may be the entire vector (i.e., a one element vector).
1704  /// Returns the splat element value in SplatValue. Any undefined bits in
1705  /// that value are zero, and the corresponding bits in the SplatUndef mask
1706  /// are set. The SplatBitSize value is set to the splat element size in
1707  /// bits. HasAnyUndefs is set to true if any bits in the vector are
1708  /// undefined. isBigEndian describes the endianness of the target.
1709  bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1710  unsigned &SplatBitSize, bool &HasAnyUndefs,
1711  unsigned MinSplatBits = 0,
1712  bool isBigEndian = false) const;
1713 
1714  /// \brief Returns the splatted value or a null value if this is not a splat.
1715  ///
1716  /// If passed a non-null UndefElements bitvector, it will resize it to match
1717  /// the vector width and set the bits where elements are undef.
1718  SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
1719 
1720  /// \brief Returns the splatted constant or null if this is not a constant
1721  /// splat.
1722  ///
1723  /// If passed a non-null UndefElements bitvector, it will resize it to match
1724  /// the vector width and set the bits where elements are undef.
1725  ConstantSDNode *
1726  getConstantSplatNode(BitVector *UndefElements = nullptr) const;
1727 
1728  /// \brief Returns the splatted constant FP or null if this is not a constant
1729  /// FP splat.
1730  ///
1731  /// If passed a non-null UndefElements bitvector, it will resize it to match
1732  /// the vector width and set the bits where elements are undef.
1734  getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
1735 
1736  /// \brief If this is a constant FP splat and the splatted constant FP is an
1737  /// exact power or 2, return the log base 2 integer value. Otherwise,
1738  /// return -1.
1739  ///
1740  /// The BitWidth specifies the necessary bit precision.
1741  int32_t getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements,
1742  uint32_t BitWidth) const;
1743 
1744  bool isConstant() const;
1745 
1746  static bool classof(const SDNode *N) {
1747  return N->getOpcode() == ISD::BUILD_VECTOR;
1748  }
1749 };
1750 
1751 /// An SDNode that holds an arbitrary LLVM IR Value. This is
1752 /// used when the SelectionDAG needs to make a simple reference to something
1753 /// in the LLVM IR representation.
1754 ///
1755 class SrcValueSDNode : public SDNode {
1756  friend class SelectionDAG;
1757 
1758  const Value *V;
1759 
1760  /// Create a SrcValue for a general value.
1761  explicit SrcValueSDNode(const Value *v)
1762  : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1763 
1764 public:
1765  /// Return the contained Value.
1766  const Value *getValue() const { return V; }
1767 
1768  static bool classof(const SDNode *N) {
1769  return N->getOpcode() == ISD::SRCVALUE;
1770  }
1771 };
1772 
1773 class MDNodeSDNode : public SDNode {
1774  friend class SelectionDAG;
1775 
1776  const MDNode *MD;
1777 
1778  explicit MDNodeSDNode(const MDNode *md)
1779  : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
1780  {}
1781 
1782 public:
1783  const MDNode *getMD() const { return MD; }
1784 
1785  static bool classof(const SDNode *N) {
1786  return N->getOpcode() == ISD::MDNODE_SDNODE;
1787  }
1788 };
1789 
1790 class RegisterSDNode : public SDNode {
1791  friend class SelectionDAG;
1792 
1793  unsigned Reg;
1794 
1795  RegisterSDNode(unsigned reg, EVT VT)
1796  : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {}
1797 
1798 public:
1799  unsigned getReg() const { return Reg; }
1800 
1801  static bool classof(const SDNode *N) {
1802  return N->getOpcode() == ISD::Register;
1803  }
1804 };
1805 
1806 class RegisterMaskSDNode : public SDNode {
1807  friend class SelectionDAG;
1808 
1809  // The memory for RegMask is not owned by the node.
1810  const uint32_t *RegMask;
1811 
1812  RegisterMaskSDNode(const uint32_t *mask)
1813  : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
1814  RegMask(mask) {}
1815 
1816 public:
1817  const uint32_t *getRegMask() const { return RegMask; }
1818 
1819  static bool classof(const SDNode *N) {
1820  return N->getOpcode() == ISD::RegisterMask;
1821  }
1822 };
1823 
1824 class BlockAddressSDNode : public SDNode {
1825  friend class SelectionDAG;
1826 
1827  const BlockAddress *BA;
1828  int64_t Offset;
1829  unsigned char TargetFlags;
1830 
1831  BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1832  int64_t o, unsigned char Flags)
1833  : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
1834  BA(ba), Offset(o), TargetFlags(Flags) {}
1835 
1836 public:
1837  const BlockAddress *getBlockAddress() const { return BA; }
1838  int64_t getOffset() const { return Offset; }
1839  unsigned char getTargetFlags() const { return TargetFlags; }
1840 
1841  static bool classof(const SDNode *N) {
1842  return N->getOpcode() == ISD::BlockAddress ||
1844  }
1845 };
1846 
1847 class EHLabelSDNode : public SDNode {
1848  friend class SelectionDAG;
1849 
1850  MCSymbol *Label;
1851 
1852  EHLabelSDNode(unsigned Order, const DebugLoc &dl, MCSymbol *L)
1853  : SDNode(ISD::EH_LABEL, Order, dl, getSDVTList(MVT::Other)), Label(L) {}
1854 
1855 public:
1856  MCSymbol *getLabel() const { return Label; }
1857 
1858  static bool classof(const SDNode *N) {
1859  return N->getOpcode() == ISD::EH_LABEL;
1860  }
1861 };
1862 
1864  friend class SelectionDAG;
1865 
1866  const char *Symbol;
1867  unsigned char TargetFlags;
1868 
1869  ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1870  : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1871  0, DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {}
1872 
1873 public:
1874  const char *getSymbol() const { return Symbol; }
1875  unsigned char getTargetFlags() const { return TargetFlags; }
1876 
1877  static bool classof(const SDNode *N) {
1878  return N->getOpcode() == ISD::ExternalSymbol ||
1880  }
1881 };
1882 
1883 class MCSymbolSDNode : public SDNode {
1884  friend class SelectionDAG;
1885 
1886  MCSymbol *Symbol;
1887 
1888  MCSymbolSDNode(MCSymbol *Symbol, EVT VT)
1889  : SDNode(ISD::MCSymbol, 0, DebugLoc(), getSDVTList(VT)), Symbol(Symbol) {}
1890 
1891 public:
1892  MCSymbol *getMCSymbol() const { return Symbol; }
1893 
1894  static bool classof(const SDNode *N) {
1895  return N->getOpcode() == ISD::MCSymbol;
1896  }
1897 };
1898 
1899 class CondCodeSDNode : public SDNode {
1900  friend class SelectionDAG;
1901 
1902  ISD::CondCode Condition;
1903 
1904  explicit CondCodeSDNode(ISD::CondCode Cond)
1905  : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1906  Condition(Cond) {}
1907 
1908 public:
1909  ISD::CondCode get() const { return Condition; }
1910 
1911  static bool classof(const SDNode *N) {
1912  return N->getOpcode() == ISD::CONDCODE;
1913  }
1914 };
1915 
1916 /// This class is used to represent EVT's, which are used
1917 /// to parameterize some operations.
1918 class VTSDNode : public SDNode {
1919  friend class SelectionDAG;
1920 
1921  EVT ValueType;
1922 
1923  explicit VTSDNode(EVT VT)
1924  : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1925  ValueType(VT) {}
1926 
1927 public:
1928  EVT getVT() const { return ValueType; }
1929 
1930  static bool classof(const SDNode *N) {
1931  return N->getOpcode() == ISD::VALUETYPE;
1932  }
1933 };
1934 
1935 /// Base class for LoadSDNode and StoreSDNode
1936 class LSBaseSDNode : public MemSDNode {
1937 public:
1938  LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl,
1939  SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
1940  MachineMemOperand *MMO)
1941  : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
1942  LSBaseSDNodeBits.AddressingMode = AM;
1943  assert(getAddressingMode() == AM && "Value truncated");
1944  }
1945 
1946  const SDValue &getOffset() const {
1947  return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1948  }
1949 
1950  /// Return the addressing mode for this load or store:
1951  /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
1953  return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
1954  }
1955 
1956  /// Return true if this is a pre/post inc/dec load/store.
1957  bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
1958 
1959  /// Return true if this is NOT a pre/post inc/dec load/store.
1960  bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
1961 
1962  static bool classof(const SDNode *N) {
1963  return N->getOpcode() == ISD::LOAD ||
1964  N->getOpcode() == ISD::STORE;
1965  }
1966 };
1967 
1968 /// This class is used to represent ISD::LOAD nodes.
1969 class LoadSDNode : public LSBaseSDNode {
1970  friend class SelectionDAG;
1971 
1972  LoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
1973  ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
1974  MachineMemOperand *MMO)
1975  : LSBaseSDNode(ISD::LOAD, Order, dl, VTs, AM, MemVT, MMO) {
1976  LoadSDNodeBits.ExtTy = ETy;
1977  assert(readMem() && "Load MachineMemOperand is not a load!");
1978  assert(!writeMem() && "Load MachineMemOperand is a store!");
1979  }
1980 
1981 public:
1982  /// Return whether this is a plain node,
1983  /// or one of the varieties of value-extending loads.
1985  return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
1986  }
1987 
1988  const SDValue &getBasePtr() const { return getOperand(1); }
1989  const SDValue &getOffset() const { return getOperand(2); }
1990 
1991  static bool classof(const SDNode *N) {
1992  return N->getOpcode() == ISD::LOAD;
1993  }
1994 };
1995 
1996 /// This class is used to represent ISD::STORE nodes.
1997 class StoreSDNode : public LSBaseSDNode {
1998  friend class SelectionDAG;
1999 
2000  StoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2001  ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
2002  MachineMemOperand *MMO)
2003  : LSBaseSDNode(ISD::STORE, Order, dl, VTs, AM, MemVT, MMO) {
2004  StoreSDNodeBits.IsTruncating = isTrunc;
2005  assert(!readMem() && "Store MachineMemOperand is a load!");
2006  assert(writeMem() && "Store MachineMemOperand is not a store!");
2007  }
2008 
2009 public:
2010  /// Return true if the op does a truncation before store.
2011  /// For integers this is the same as doing a TRUNCATE and storing the result.
2012  /// For floats, it is the same as doing an FP_ROUND and storing the result.
2013  bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2014 
2015  const SDValue &getValue() const { return getOperand(1); }
2016  const SDValue &getBasePtr() const { return getOperand(2); }
2017  const SDValue &getOffset() const { return getOperand(3); }
2018 
2019  static bool classof(const SDNode *N) {
2020  return N->getOpcode() == ISD::STORE;
2021  }
2022 };
2023 
2024 /// This base class is used to represent MLOAD and MSTORE nodes
2026 public:
2027  friend class SelectionDAG;
2028 
2029  MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order,
2030  const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2031  MachineMemOperand *MMO)
2032  : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2033 
2034  // In the both nodes address is Op1, mask is Op2:
2035  // MaskedLoadSDNode (Chain, ptr, mask, src0), src0 is a passthru value
2036  // MaskedStoreSDNode (Chain, ptr, mask, data)
2037  // Mask is a vector of i1 elements
2038  const SDValue &getBasePtr() const { return getOperand(1); }
2039  const SDValue &getMask() const { return getOperand(2); }
2040 
2041  static bool classof(const SDNode *N) {
2042  return N->getOpcode() == ISD::MLOAD ||
2043  N->getOpcode() == ISD::MSTORE;
2044  }
2045 };
2046 
2047 /// This class is used to represent an MLOAD node
2049 public:
2050  friend class SelectionDAG;
2051 
2052  MaskedLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2053  ISD::LoadExtType ETy, bool IsExpanding, EVT MemVT,
2054  MachineMemOperand *MMO)
2055  : MaskedLoadStoreSDNode(ISD::MLOAD, Order, dl, VTs, MemVT, MMO) {
2056  LoadSDNodeBits.ExtTy = ETy;
2057  LoadSDNodeBits.IsExpanding = IsExpanding;
2058  }
2059 
2061  return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2062  }
2063 
2064  const SDValue &getSrc0() const { return getOperand(3); }
2065  static bool classof(const SDNode *N) {
2066  return N->getOpcode() == ISD::MLOAD;
2067  }
2068 
2069  bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
2070 };
2071 
2072 /// This class is used to represent an MSTORE node
2074 public:
2075  friend class SelectionDAG;
2076 
2077  MaskedStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2078  bool isTrunc, bool isCompressing, EVT MemVT,
2079  MachineMemOperand *MMO)
2080  : MaskedLoadStoreSDNode(ISD::MSTORE, Order, dl, VTs, MemVT, MMO) {
2081  StoreSDNodeBits.IsTruncating = isTrunc;
2082  StoreSDNodeBits.IsCompressing = isCompressing;
2083  }
2084 
2085  /// Return true if the op does a truncation before store.
2086  /// For integers this is the same as doing a TRUNCATE and storing the result.
2087  /// For floats, it is the same as doing an FP_ROUND and storing the result.
2088  bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2089 
2090  /// Returns true if the op does a compression to the vector before storing.
2091  /// The node contiguously stores the active elements (integers or floats)
2092  /// in src (those with their respective bit set in writemask k) to unaligned
2093  /// memory at base_addr.
2094  bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
2095 
2096  const SDValue &getValue() const { return getOperand(3); }
2097 
2098  static bool classof(const SDNode *N) {
2099  return N->getOpcode() == ISD::MSTORE;
2100  }
2101 };
2102 
2103 /// This is a base class used to represent
2104 /// MGATHER and MSCATTER nodes
2105 ///
2107 public:
2108  friend class SelectionDAG;
2109 
2110  MaskedGatherScatterSDNode(unsigned NodeTy, unsigned Order,
2111  const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2112  MachineMemOperand *MMO)
2113  : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2114 
2115  // In the both nodes address is Op1, mask is Op2:
2116  // MaskedGatherSDNode (Chain, src0, mask, base, index), src0 is a passthru value
2117  // MaskedScatterSDNode (Chain, value, mask, base, index)
2118  // Mask is a vector of i1 elements
2119  const SDValue &getBasePtr() const { return getOperand(3); }
2120  const SDValue &getIndex() const { return getOperand(4); }
2121  const SDValue &getMask() const { return getOperand(2); }
2122  const SDValue &getValue() const { return getOperand(1); }
2123 
2124  static bool classof(const SDNode *N) {
2125  return N->getOpcode() == ISD::MGATHER ||
2126  N->getOpcode() == ISD::MSCATTER;
2127  }
2128 };
2129 
2130 /// This class is used to represent an MGATHER node
2131 ///
2133 public:
2134  friend class SelectionDAG;
2135 
2136  MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2137  EVT MemVT, MachineMemOperand *MMO)
2138  : MaskedGatherScatterSDNode(ISD::MGATHER, Order, dl, VTs, MemVT, MMO) {}
2139 
2140  static bool classof(const SDNode *N) {
2141  return N->getOpcode() == ISD::MGATHER;
2142  }
2143 };
2144 
2145 /// This class is used to represent an MSCATTER node
2146 ///
2148 public:
2149  friend class SelectionDAG;
2150 
2151  MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2152  EVT MemVT, MachineMemOperand *MMO)
2153  : MaskedGatherScatterSDNode(ISD::MSCATTER, Order, dl, VTs, MemVT, MMO) {}
2154 
2155  static bool classof(const SDNode *N) {
2156  return N->getOpcode() == ISD::MSCATTER;
2157  }
2158 };
2159 
2160 /// An SDNode that represents everything that will be needed
2161 /// to construct a MachineInstr. These nodes are created during the
2162 /// instruction selection proper phase.
2163 class MachineSDNode : public SDNode {
2164 public:
2166 
2167 private:
2168  friend class SelectionDAG;
2169 
2170  MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL, SDVTList VTs)
2171  : SDNode(Opc, Order, DL, VTs) {}
2172 
2173  /// Memory reference descriptions for this instruction.
2174  mmo_iterator MemRefs = nullptr;
2175  mmo_iterator MemRefsEnd = nullptr;
2176 
2177 public:
2178  mmo_iterator memoperands_begin() const { return MemRefs; }
2179  mmo_iterator memoperands_end() const { return MemRefsEnd; }
2180  bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
2181 
2182  /// Assign this MachineSDNodes's memory reference descriptor
2183  /// list. This does not transfer ownership.
2184  void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
2185  for (mmo_iterator MMI = NewMemRefs, MME = NewMemRefsEnd; MMI != MME; ++MMI)
2186  assert(*MMI && "Null mem ref detected!");
2187  MemRefs = NewMemRefs;
2188  MemRefsEnd = NewMemRefsEnd;
2189  }
2190 
2191  static bool classof(const SDNode *N) {
2192  return N->isMachineOpcode();
2193  }
2194 };
2195 
2196 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
2197  SDNode, ptrdiff_t> {
2198  const SDNode *Node;
2199  unsigned Operand;
2200 
2201  SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2202 
2203 public:
2204  bool operator==(const SDNodeIterator& x) const {
2205  return Operand == x.Operand;
2206  }
2207  bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2208 
2209  pointer operator*() const {
2210  return Node->getOperand(Operand).getNode();
2211  }
2212  pointer operator->() const { return operator*(); }
2213 
2214  SDNodeIterator& operator++() { // Preincrement
2215  ++Operand;
2216  return *this;
2217  }
2218  SDNodeIterator operator++(int) { // Postincrement
2219  SDNodeIterator tmp = *this; ++*this; return tmp;
2220  }
2221  size_t operator-(SDNodeIterator Other) const {
2222  assert(Node == Other.Node &&
2223  "Cannot compare iterators of two different nodes!");
2224  return Operand - Other.Operand;
2225  }
2226 
2227  static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
2228  static SDNodeIterator end (const SDNode *N) {
2229  return SDNodeIterator(N, N->getNumOperands());
2230  }
2231 
2232  unsigned getOperand() const { return Operand; }
2233  const SDNode *getNode() const { return Node; }
2234 };
2235 
2236 template <> struct GraphTraits<SDNode*> {
2237  using NodeRef = SDNode *;
2239 
2240  static NodeRef getEntryNode(SDNode *N) { return N; }
2241 
2243  return SDNodeIterator::begin(N);
2244  }
2245 
2247  return SDNodeIterator::end(N);
2248  }
2249 };
2250 
2251 /// A representation of the largest SDNode, for use in sizeof().
2252 ///
2253 /// This needs to be a union because the largest node differs on 32 bit systems
2254 /// with 4 and 8 byte pointer alignment, respectively.
2258 
2259 /// The SDNode class with the greatest alignment requirement.
2261 
2262 namespace ISD {
2263 
2264  /// Returns true if the specified node is a non-extending and unindexed load.
2265  inline bool isNormalLoad(const SDNode *N) {
2266  const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2267  return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2269  }
2270 
2271  /// Returns true if the specified node is a non-extending load.
2272  inline bool isNON_EXTLoad(const SDNode *N) {
2273  return isa<LoadSDNode>(N) &&
2274  cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2275  }
2276 
2277  /// Returns true if the specified node is a EXTLOAD.
2278  inline bool isEXTLoad(const SDNode *N) {
2279  return isa<LoadSDNode>(N) &&
2280  cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2281  }
2282 
2283  /// Returns true if the specified node is a SEXTLOAD.
2284  inline bool isSEXTLoad(const SDNode *N) {
2285  return isa<LoadSDNode>(N) &&
2286  cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2287  }
2288 
2289  /// Returns true if the specified node is a ZEXTLOAD.
2290  inline bool isZEXTLoad(const SDNode *N) {
2291  return isa<LoadSDNode>(N) &&
2292  cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2293  }
2294 
2295  /// Returns true if the specified node is an unindexed load.
2296  inline bool isUNINDEXEDLoad(const SDNode *N) {
2297  return isa<LoadSDNode>(N) &&
2298  cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2299  }
2300 
2301  /// Returns true if the specified node is a non-truncating
2302  /// and unindexed store.
2303  inline bool isNormalStore(const SDNode *N) {
2304  const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2305  return St && !St->isTruncatingStore() &&
2307  }
2308 
2309  /// Returns true if the specified node is a non-truncating store.
2310  inline bool isNON_TRUNCStore(const SDNode *N) {
2311  return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2312  }
2313 
2314  /// Returns true if the specified node is a truncating store.
2315  inline bool isTRUNCStore(const SDNode *N) {
2316  return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2317  }
2318 
2319  /// Returns true if the specified node is an unindexed store.
2320  inline bool isUNINDEXEDStore(const SDNode *N) {
2321  return isa<StoreSDNode>(N) &&
2322  cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2323  }
2324 
2325 } // end namespace ISD
2326 
2327 } // end namespace llvm
2328 
2329 #endif // LLVM_CODEGEN_SELECTIONDAGNODES_H
bool isMachineConstantPoolEntry() const
Iterator for directly iterating over the operand SDValue&#39;s.
void setAllowReciprocal(bool b)
bool isInvariant() const
BUILTIN_OP_END - This must be the last enum value in this list.
Definition: ISDOpcodes.h:827
EVT getValueType() const
Return the ValueType of the referenced return value.
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
Constrained versions of libm-equivalent floating point intrinsics.
Definition: ISDOpcodes.h:271
This SDNode is used for target intrinsics that touch memory and need an associated MachineMemOperand...
const GlobalValue * getGlobal() const
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
bool isBuildVectorOfConstantSDNodes(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR node of all ConstantSDNode or undef...
static bool classof(const SDNode *N)
bool isIndexed() const
Return true if this is a pre/post inc/dec load/store.
Atomic ordering constants.
unsigned char getTargetFlags() const
MDNODE_SDNODE - This is a node that holdes an MDNode*, which is used to reference metadata in the IR...
Definition: ISDOpcodes.h:696
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
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:60
bool isCompareAndSwap() const
Returns true if this SDNode represents cmpxchg atomic operation, false otherwise. ...
void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd)
Assign this MachineSDNodes&#39;s memory reference descriptor list.
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:341
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Definition: ValueTypes.h:260
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
MCSymbol * getLabel() const
const SDValue & getVal() const
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
constexpr char IsVolatile[]
Key for Kernel::Arg::Metadata::mIsVolatile.
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
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:253
const SDValue & getBasePtr() const
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
Completely target-dependent object reference.
const SDValue & getBasePtr() const
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:131
unsigned getAlignment() const
bool operator==(const use_iterator &x) const
unsigned getValueSizeInBits(unsigned ResNo) const
Returns MVT::getSizeInBits(getValueType(ResNo)).
bool isBitwiseNot(SDValue V)
Returns true if V is a bitwise not operation.
Val, Success, OUTCHAIN = ATOMIC_CMP_SWAP_WITH_SUCCESS(INCHAIN, ptr, cmp, swap) N.b.
Definition: ISDOpcodes.h:762
Constrained versions of the binary floating point operators.
Definition: ISDOpcodes.h:265
SDLoc(const SDNode *N)
A debug info location.
Definition: DebugLoc.h:34
Metadata node.
Definition: Metadata.h:862
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
const fltSemantics & getSemantics() const
Definition: APFloat.h:1140
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.
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:39
const SDValue & getValue() const
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)
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
Definition: ISDOpcodes.h:159
bool isTruncatingStore() const
Return true if the op does a truncation before store.
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:345
unsigned char getTargetFlags() const
static SDVTList getSDVTList(EVT VT)
void setNoSignedWrap(bool b)
The address of a basic block.
Definition: Constants.h:813
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:920
std::iterator< std::forward_iterator_tag, SDUse, ptrdiff_t >::reference reference
static bool classof(const SDNode *N)
void setVectorReduction(bool b)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
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...
bool hasUnsafeAlgebra() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
const MDNode * getMD() 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.
Reg
All possible values of the reg field in the ModR/M byte.
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:770
const SDValue & getValue() const
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:695
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:2070
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:201
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:292
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
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition: APFloat.cpp:4441
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)
bool isNegative() const
Return true if the sign bit is set.
Definition: Constants.h:300
static SimpleType getSimplifiedValue(const SDValue &Val)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
static bool classof(const SDNode *N)
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:138
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:209
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
Definition: ISDOpcodes.h:909
op_iterator op_begin() const
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification, or lowering of the constant.
Definition: ISDOpcodes.h:125
MachineConstantPoolValue * MachineCPVal
ArrayRef< SDUse > ops() const
void setIROrder(unsigned Order)
Set the node ordering.
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:178
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:301
bool isOneConstant(SDValue V)
Returns true if V is a constant integer one.
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:311
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:166
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:149
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:291
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:59
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
bool hasAnyUseOfValue(unsigned Value) const
Return true if there are any use of the indicated value.
bool isMachineOpcode() const
CRTP base class for adapting an iterator to a different type.
Definition: iterator.h:208
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:273
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
This is an important base class in LLVM.
Definition: Constant.h:42
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:884
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:264
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:372
unsigned char getTargetFlags() const
This is a base class used to represent MGATHER and MSCATTER nodes.
unsigned char getTargetFlags() const
const SDValue & getOffset() const
unsigned getDestAddressSpace() const
bool isTargetMemoryOpcode() const
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:144
static bool classof(const SDNode *N)
SDNodeIterator & operator++()
SDNodeIterator operator++(int)
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:383
unsigned getOriginalAlignment() const
Returns alignment and volatility of the memory access.
bool hasNUsesOfValue(unsigned NUses, unsigned Value) const
Return true if there are exactly NUSES uses of the indicated value.
void setAllowContract(bool b)
static bool classof(const SDNode *N)
static bool classof(const SDNode *N)
ConstantSDNode * isConstOrConstSplat(SDValue V)
Returns the SDNode if it is a constant splat BuildVector or constant int.
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo...
Definition: ISDOpcodes.h:756
unsigned char getTargetFlags() const
static bool hasPredecessorHelper(const SDNode *N, SmallPtrSetImpl< const SDNode *> &Visited, SmallVectorImpl< const SDNode *> &Worklist)
Returns true if N is a predecessor of any node in Worklist.
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:34
static bool classof(const SDNode *N)
MaskedGatherScatterSDNode(unsigned NodeTy, unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO)
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)
const SDValue & getSrc0() const
static bool classof(const SDNode *N)
bool isVolatile() const
This class contains a discriminated union of information about pointers in memory operands...
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.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
HANDLENODE node - Used as a handle for various purposes.
Definition: ISDOpcodes.h:710
uint64_t getAlignment() const
Return the minimum known alignment in bytes of the actual memory reference.
const SDValue & getMask() const
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
Definition: ISDOpcodes.h:638
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.
uint32_t NodeId
Definition: RDFGraph.h:263
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:294
bool use_empty() const
Return true if there are no uses of this node.
SDNode * getNode() const
Convenience function for get().getNode().
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void dump() const
Dump this node, for debugging.
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)
isPodLike - This is a type trait that is used to determine whether a given type can be copied around ...
Definition: ArrayRef.h:530
bool memoperands_empty() const
void setNoUnsignedWrap(bool b)
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
void setNode(SDNode *N)
set the SDNode
use_iterator(const use_iterator &I)
TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:209
void setDefined()
Sets the state of the flags to the defined state.
ADDRSPACECAST - This operator converts between pointers of different address spaces.
Definition: ISDOpcodes.h:548
value_iterator value_begin() const
static bool classof(const SDNode *N)
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:206
An SDNode that represents everything that will be needed to construct a MachineInstr.
const SDValue & getOffset() const
Promote Memory to Register
Definition: Mem2Reg.cpp:101
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:642
const size_t N
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:385
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...
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:834
void setNoNaNs(bool b)
Represents one node in the SelectionDAG.
bool readMem() const
bool operator==(const SDNodeIterator &x) const
unsigned char getTargetFlags() const
static bool classof(const SDNode *N)
bool isDereferenceable() const
size_t use_size() const
Return the number of uses of this node.
A range adaptor for a pair of iterators.
EVT getMemoryVT() const
Return the type of the in-memory value.
Class for arbitrary precision integers.
Definition: APInt.h:69
bool isBuildVectorOfConstantFPSDNodes(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR node of all ConstantFPSDNode or undef...
iterator_range< use_iterator > uses()
A "pseudo-class" with methods for operating on BUILD_VECTORs.
static use_iterator use_end()
bool isNullFPConstant(SDValue V)
Returns true if V is an FP constant with a value of positive zero.
pointer operator->() const
This union template exposes a suitably aligned and sized character array member which can hold elemen...
Definition: AlignOf.h:138
unsigned getOperandNo() const
Retrieve the operand # of this use in its user.
iterator_range< use_iterator > uses() const
const uint32_t * getRegMask() const
int getMaskElt(unsigned Idx) const
size_t operator-(SDNodeIterator Other) const
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
static std::vector< std::string > Flags
Definition: FlagsTest.cpp:8
mmo_iterator memoperands_begin() const
ConstantFPSDNode * isConstOrConstSplatFP(SDValue V)
Returns the SDNode if it is a constant splat BuildVector or constant float.
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:280
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:139
bool operator!=(const SDValue &O) const
This base class is used to represent MLOAD and MSTORE nodes.
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:61
bool isZero() const
Return true if the value is positive or negative zero.
Definition: Constants.h:297
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition: ISDOpcodes.h:580
bool isNaN() const
Return true if the value is a NaN.
Definition: Constants.h:306
static NodeRef getEntryNode(SDNode *N)
const NodeList & List
Definition: RDFGraph.cpp:205
static SimpleType getSimplifiedValue(SDValue &Val)
#define I(x, y, z)
Definition: MD5.cpp:58
const ConstantInt * getConstantIntValue() const
const Value * getValue() const
Return the contained Value.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Definition: Constants.h:193
bool isInfinity() const
Return true if the value is infinity.
Definition: Constants.h:303
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:323
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.
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)
void setUnsafeAlgebra(bool b)
const MachinePointerInfo & getPointerInfo() const
MachineConstantPoolValue * getMachineCPVal() const
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.
void dumpr() const
Dump (recursively) this node and its use-def subgraph.
This class is used to represent an MLOAD node.
MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO)
bool isPredecessorOf(const SDNode *N) const
Return true if this node is a predecessor of N.
unsigned getRawSubclassData() const
Return the SubclassData value, without HasDebugValue.
aarch64 promote const
ArrayRef< int > getMask() const
int64_t getOffset() const
For normal values, this is a byte offset added to the base address.
unsigned getOperand() const
LLVM Value Representation.
Definition: Value.h: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:81
PREFETCH - This corresponds to a prefetch intrinsic.
Definition: ISDOpcodes.h:736
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:44
SDNodeFlags()
Default constructor turns off all optimization flags.
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
bool operator==(uint64_t V1, const APInt &V2)
Definition: APInt.h:1946
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:157
OUTCHAIN = ATOMIC_STORE(INCHAIN, ptr, val) This corresponds to "store atomic" instruction.
Definition: ISDOpcodes.h:749
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.
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...
MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemoryVT, MachineMemOperand *MMO)
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
Definition: ISDOpcodes.h:745
const SDValue & getBasePtr() const
const SDValue & getMask() const
unsigned getIROrder() const
MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT MemVT, MachineMemOperand *MMO)
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:70
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:864
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:692
This class is used to represent ISD::LOAD nodes.