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