1 //===- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
15 // Clients should include the SelectionDAG.h file instead of this file directly.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
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"
29 #include "llvm/ADT/iterator_range.h"
30 #include "llvm/ADT/SmallPtrSet.h"
31 #include "llvm/ADT/SmallVector.h"
32 #include "llvm/CodeGen/ISDOpcodes.h"
33 #include "llvm/CodeGen/MachineMemOperand.h"
34 #include "llvm/CodeGen/MachineValueType.h"
35 #include "llvm/CodeGen/ValueTypes.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"
41 #include "llvm/Support/AtomicOrdering.h"
42 #include "llvm/Support/Casting.h"
43 #include "llvm/Support/ErrorHandling.h"
58 class MachineBasicBlock;
59 class MachineConstantPoolValue;
63 template <typename T> struct DenseMapInfo;
65 void checkForCycles(const SDNode *N, const SelectionDAG *DAG = nullptr,
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(...).
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);
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);
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);
93 /// Return true if the specified node is a BUILD_VECTOR node of all
94 /// ConstantSDNode or undef.
95 bool isBuildVectorOfConstantSDNodes(const SDNode *N);
97 /// Return true if the specified node is a BUILD_VECTOR node of all
98 /// ConstantFPSDNode or undef.
99 bool isBuildVectorOfConstantFPSDNodes(const SDNode *N);
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);
105 } // end namespace ISD
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
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.
119 friend struct DenseMapInfo<SDValue>;
121 SDNode *Node = nullptr; // The node defining the value we are using.
122 unsigned ResNo = 0; // Which return value of the node we are using.
126 SDValue(SDNode *node, unsigned resno);
128 /// get the index which selects a specific result in the SDNode
129 unsigned getResNo() const { return ResNo; }
131 /// get the SDNode which holds the desired result
132 SDNode *getNode() const { return Node; }
135 void setNode(SDNode *N) { Node = N; }
137 inline SDNode *operator->() const { return Node; }
139 bool operator==(const SDValue &O) const {
140 return Node == O.Node && ResNo == O.ResNo;
142 bool operator!=(const SDValue &O) const {
143 return !operator==(O);
145 bool operator<(const SDValue &O) const {
146 return std::tie(Node, ResNo) < std::tie(O.Node, O.ResNo);
148 explicit operator bool() const {
149 return Node != nullptr;
152 SDValue getValue(unsigned R) const {
153 return SDValue(Node, R);
156 /// Return true if this node is an operand of N.
157 bool isOperandOf(const SDNode *N) const;
159 /// Return the ValueType of the referenced return value.
160 inline EVT getValueType() const;
162 /// Return the simple ValueType of the referenced return value.
163 MVT getSimpleValueType() const {
164 return getValueType().getSimpleVT();
167 /// Returns the size of the value in bits.
168 unsigned getValueSizeInBits() const {
169 return getValueType().getSizeInBits();
172 unsigned getScalarValueSizeInBits() const {
173 return getValueType().getScalarType().getSizeInBits();
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;
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.
195 bool reachesChainWithoutSideEffects(SDValue Dest,
196 unsigned Depth = 2) const;
198 /// Return true if there are no nodes using value ResNo of Node.
199 inline bool use_empty() const;
201 /// Return true if there is exactly one node using value ResNo of Node.
202 inline bool hasOneUse() const;
205 template<> struct DenseMapInfo<SDValue> {
206 static inline SDValue getEmptyKey() {
212 static inline SDValue getTombstoneKey() {
218 static unsigned getHashValue(const SDValue &Val) {
219 return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
220 (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
223 static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
227 template <> struct isPodLike<SDValue> { static const bool value = true; };
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;
233 static SimpleType getSimplifiedValue(SDValue &Val) {
234 return Val.getNode();
237 template<> struct simplify_type<const SDValue> {
238 typedef /*const*/ SDNode* SimpleType;
239 static SimpleType getSimplifiedValue(const SDValue &Val) {
240 return Val.getNode();
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.
250 /// Val - The value being used.
252 /// User - The user of this value.
253 SDNode *User = nullptr;
254 /// Prev, Next - Pointers to the uses list of the SDNode referred by
256 SDUse **Prev = nullptr;
257 SDUse *Next = nullptr;
261 SDUse(const SDUse &U) = delete;
262 SDUse &operator=(const SDUse &) = delete;
264 /// Normally SDUse will just implicitly convert to an SDValue that it holds.
265 operator const SDValue&() const { return Val; }
267 /// If implicit conversion to SDValue doesn't work, the get() method returns
269 const SDValue &get() const { return Val; }
271 /// This returns the SDNode that contains this Use.
272 SDNode *getUser() { return User; }
274 /// Get the next SDUse in the use list.
275 SDUse *getNext() const { return Next; }
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(); }
284 /// Convenience function for get().operator==
285 bool operator==(const SDValue &V) const {
289 /// Convenience function for get().operator!=
290 bool operator!=(const SDValue &V) const {
294 /// Convenience function for get().operator<
295 bool operator<(const SDValue &V) const {
300 friend class SelectionDAG;
302 // TODO: unfriend HandleSDNode once we fix its operand handling.
303 friend class HandleSDNode;
305 void setUser(SDNode *p) { User = p; }
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);
317 void addToList(SDUse **List) {
319 if (Next) Next->Prev = &Next;
324 void removeFromList() {
326 if (Next) Next->Prev = Prev;
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;
334 static SimpleType getSimplifiedValue(SDUse &Val) {
335 return Val.getNode();
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
344 bool NoUnsignedWrap : 1;
345 bool NoSignedWrap : 1;
347 bool UnsafeAlgebra : 1;
350 bool NoSignedZeros : 1;
351 bool AllowReciprocal : 1;
352 bool VectorReduction : 1;
353 bool AllowContract : 1;
356 /// Default constructor turns off all optimization flags.
358 : NoUnsignedWrap(false), NoSignedWrap(false), Exact(false),
359 UnsafeAlgebra(false), NoNaNs(false), NoInfs(false),
360 NoSignedZeros(false), AllowReciprocal(false), VectorReduction(false),
361 AllowContract(false) {}
363 // These are mutators for each flag.
364 void setNoUnsignedWrap(bool b) { NoUnsignedWrap = b; }
365 void setNoSignedWrap(bool b) { NoSignedWrap = b; }
366 void setExact(bool b) { Exact = b; }
367 void setUnsafeAlgebra(bool b) { UnsafeAlgebra = b; }
368 void setNoNaNs(bool b) { NoNaNs = b; }
369 void setNoInfs(bool b) { NoInfs = b; }
370 void setNoSignedZeros(bool b) { NoSignedZeros = b; }
371 void setAllowReciprocal(bool b) { AllowReciprocal = b; }
372 void setVectorReduction(bool b) { VectorReduction = b; }
373 void setAllowContract(bool b) { AllowContract = b; }
375 // These are accessors for each flag.
376 bool hasNoUnsignedWrap() const { return NoUnsignedWrap; }
377 bool hasNoSignedWrap() const { return NoSignedWrap; }
378 bool hasExact() const { return Exact; }
379 bool hasUnsafeAlgebra() const { return UnsafeAlgebra; }
380 bool hasNoNaNs() const { return NoNaNs; }
381 bool hasNoInfs() const { return NoInfs; }
382 bool hasNoSignedZeros() const { return NoSignedZeros; }
383 bool hasAllowReciprocal() const { return AllowReciprocal; }
384 bool hasVectorReduction() const { return VectorReduction; }
385 bool hasAllowContract() const { return AllowContract; }
387 /// Clear any flags in this flag set that aren't also set in Flags.
388 void intersectWith(const SDNodeFlags *Flags) {
389 NoUnsignedWrap &= Flags->NoUnsignedWrap;
390 NoSignedWrap &= Flags->NoSignedWrap;
391 Exact &= Flags->Exact;
392 UnsafeAlgebra &= Flags->UnsafeAlgebra;
393 NoNaNs &= Flags->NoNaNs;
394 NoInfs &= Flags->NoInfs;
395 NoSignedZeros &= Flags->NoSignedZeros;
396 AllowReciprocal &= Flags->AllowReciprocal;
397 VectorReduction &= Flags->VectorReduction;
398 AllowContract &= Flags->AllowContract;
402 /// Represents one node in the SelectionDAG.
404 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
406 /// The operation that this node performs.
410 // We define a set of mini-helper classes to help us interpret the bits in our
411 // SubclassData. These are designed to fit within a uint16_t so they pack
414 class SDNodeBitfields {
416 friend class MemIntrinsicSDNode;
417 friend class MemSDNode;
419 uint16_t HasDebugValue : 1;
420 uint16_t IsMemIntrinsic : 1;
422 enum { NumSDNodeBits = 2 };
424 class ConstantSDNodeBitfields {
425 friend class ConstantSDNode;
427 uint16_t : NumSDNodeBits;
429 uint16_t IsOpaque : 1;
432 class MemSDNodeBitfields {
433 friend class MemSDNode;
434 friend class MemIntrinsicSDNode;
435 friend class AtomicSDNode;
437 uint16_t : NumSDNodeBits;
439 uint16_t IsVolatile : 1;
440 uint16_t IsNonTemporal : 1;
441 uint16_t IsDereferenceable : 1;
442 uint16_t IsInvariant : 1;
444 enum { NumMemSDNodeBits = NumSDNodeBits + 4 };
446 class LSBaseSDNodeBitfields {
447 friend class LSBaseSDNode;
449 uint16_t : NumMemSDNodeBits;
451 uint16_t AddressingMode : 3; // enum ISD::MemIndexedMode
453 enum { NumLSBaseSDNodeBits = NumMemSDNodeBits + 3 };
455 class LoadSDNodeBitfields {
456 friend class LoadSDNode;
457 friend class MaskedLoadSDNode;
459 uint16_t : NumLSBaseSDNodeBits;
461 uint16_t ExtTy : 2; // enum ISD::LoadExtType
462 uint16_t IsExpanding : 1;
465 class StoreSDNodeBitfields {
466 friend class StoreSDNode;
467 friend class MaskedStoreSDNode;
469 uint16_t : NumLSBaseSDNodeBits;
471 uint16_t IsTruncating : 1;
472 uint16_t IsCompressing : 1;
476 char RawSDNodeBits[sizeof(uint16_t)];
477 SDNodeBitfields SDNodeBits;
478 ConstantSDNodeBitfields ConstantSDNodeBits;
479 MemSDNodeBitfields MemSDNodeBits;
480 LSBaseSDNodeBitfields LSBaseSDNodeBits;
481 LoadSDNodeBitfields LoadSDNodeBits;
482 StoreSDNodeBitfields StoreSDNodeBits;
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");
496 friend class SelectionDAG;
497 // TODO: unfriend HandleSDNode once we fix its operand handling.
498 friend class HandleSDNode;
500 /// Unique id per SDNode in the DAG.
503 /// The values that are used by this operation.
504 SDUse *OperandList = nullptr;
506 /// The types of the values this node defines. SDNode's may
507 /// define multiple values simultaneously.
508 const EVT *ValueList;
510 /// List of uses for this SDNode.
511 SDUse *UseList = nullptr;
513 /// The number of entries in the Operand/Value list.
514 unsigned short NumOperands = 0;
515 unsigned short NumValues;
517 // The ordering of the SDNodes. It roughly corresponds to the ordering of the
518 // original LLVM instructions.
519 // This is used for turning off scheduling, because we'll forgo
520 // the normal scheduling algorithms and output the instructions according to
524 /// Source line information.
527 /// Return a pointer to the specified value type.
528 static const EVT *getValueTypeList(EVT VT);
531 /// Unique and persistent id per SDNode in the DAG.
532 /// Used for debug printing.
533 uint16_t PersistentId;
535 //===--------------------------------------------------------------------===//
539 /// Return the SelectionDAG opcode value for this node. For
540 /// pre-isel nodes (those for which isMachineOpcode returns false), these
541 /// are the opcode values in the ISD and <target>ISD namespaces. For
542 /// post-isel opcodes, see getMachineOpcode.
543 unsigned getOpcode() const { return (unsigned short)NodeType; }
545 /// Test if this node has a target-specific opcode (in the
546 /// \<target\>ISD namespace).
547 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
549 /// Test if this node has a target-specific
550 /// memory-referencing opcode (in the \<target\>ISD namespace and
551 /// greater than FIRST_TARGET_MEMORY_OPCODE).
552 bool isTargetMemoryOpcode() const {
553 return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
556 /// Return true if the type of the node type undefined.
557 bool isUndef() const { return NodeType == ISD::UNDEF; }
559 /// Test if this node is a memory intrinsic (with valid pointer information).
560 /// INTRINSIC_W_CHAIN and INTRINSIC_VOID nodes are sometimes created for
561 /// non-memory intrinsics (with chains) that are not really instances of
562 /// MemSDNode. For such nodes, we need some extra state to determine the
563 /// proper classof relationship.
564 bool isMemIntrinsic() const {
565 return (NodeType == ISD::INTRINSIC_W_CHAIN ||
566 NodeType == ISD::INTRINSIC_VOID) &&
567 SDNodeBits.IsMemIntrinsic;
570 /// Test if this node has a post-isel opcode, directly
571 /// corresponding to a MachineInstr opcode.
572 bool isMachineOpcode() const { return NodeType < 0; }
574 /// This may only be called if isMachineOpcode returns
575 /// true. It returns the MachineInstr opcode value that the node's opcode
577 unsigned getMachineOpcode() const {
578 assert(isMachineOpcode() && "Not a MachineInstr opcode!");
582 bool getHasDebugValue() const { return SDNodeBits.HasDebugValue; }
583 void setHasDebugValue(bool b) { SDNodeBits.HasDebugValue = b; }
585 /// Return true if there are no uses of this node.
586 bool use_empty() const { return UseList == nullptr; }
588 /// Return true if there is exactly one use of this node.
589 bool hasOneUse() const {
590 return !use_empty() && std::next(use_begin()) == use_end();
593 /// Return the number of uses of this node. This method takes
594 /// time proportional to the number of uses.
595 size_t use_size() const { return std::distance(use_begin(), use_end()); }
597 /// Return the unique node id.
598 int getNodeId() const { return NodeId; }
600 /// Set unique node id.
601 void setNodeId(int Id) { NodeId = Id; }
603 /// Return the node ordering.
604 unsigned getIROrder() const { return IROrder; }
606 /// Set the node ordering.
607 void setIROrder(unsigned Order) { IROrder = Order; }
609 /// Return the source location info.
610 const DebugLoc &getDebugLoc() const { return debugLoc; }
612 /// Set source location info. Try to avoid this, putting
613 /// it in the constructor is preferable.
614 void setDebugLoc(DebugLoc dl) { debugLoc = std::move(dl); }
616 /// This class provides iterator support for SDUse
617 /// operands that use a specific SDNode.
619 : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
624 explicit use_iterator(SDUse *op) : Op(op) {}
627 typedef std::iterator<std::forward_iterator_tag,
628 SDUse, ptrdiff_t>::reference reference;
629 typedef std::iterator<std::forward_iterator_tag,
630 SDUse, ptrdiff_t>::pointer pointer;
632 use_iterator() = default;
633 use_iterator(const use_iterator &I) : Op(I.Op) {}
635 bool operator==(const use_iterator &x) const {
638 bool operator!=(const use_iterator &x) const {
639 return !operator==(x);
642 /// Return true if this iterator is at the end of uses list.
643 bool atEnd() const { return Op == nullptr; }
645 // Iterator traversal: forward iteration only.
646 use_iterator &operator++() { // Preincrement
647 assert(Op && "Cannot increment end iterator!");
652 use_iterator operator++(int) { // Postincrement
653 use_iterator tmp = *this; ++*this; return tmp;
656 /// Retrieve a pointer to the current user node.
657 SDNode *operator*() const {
658 assert(Op && "Cannot dereference end iterator!");
659 return Op->getUser();
662 SDNode *operator->() const { return operator*(); }
664 SDUse &getUse() const { return *Op; }
666 /// Retrieve the operand # of this use in its user.
667 unsigned getOperandNo() const {
668 assert(Op && "Cannot dereference end iterator!");
669 return (unsigned)(Op - Op->getUser()->OperandList);
673 /// Provide iteration support to walk over all uses of an SDNode.
674 use_iterator use_begin() const {
675 return use_iterator(UseList);
678 static use_iterator use_end() { return use_iterator(nullptr); }
680 inline iterator_range<use_iterator> uses() {
681 return make_range(use_begin(), use_end());
683 inline iterator_range<use_iterator> uses() const {
684 return make_range(use_begin(), use_end());
687 /// Return true if there are exactly NUSES uses of the indicated value.
688 /// This method ignores uses of other values defined by this operation.
689 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
691 /// Return true if there are any use of the indicated value.
692 /// This method ignores uses of other values defined by this operation.
693 bool hasAnyUseOfValue(unsigned Value) const;
695 /// Return true if this node is the only use of N.
696 bool isOnlyUserOf(const SDNode *N) const;
698 /// Return true if this node is an operand of N.
699 bool isOperandOf(const SDNode *N) const;
701 /// Return true if this node is a predecessor of N.
702 /// NOTE: Implemented on top of hasPredecessor and every bit as
703 /// expensive. Use carefully.
704 bool isPredecessorOf(const SDNode *N) const {
705 return N->hasPredecessor(this);
708 /// Return true if N is a predecessor of this node.
709 /// N is either an operand of this node, or can be reached by recursively
710 /// traversing up the operands.
711 /// NOTE: This is an expensive method. Use it carefully.
712 bool hasPredecessor(const SDNode *N) const;
714 /// Returns true if N is a predecessor of any node in Worklist. This
715 /// helper keeps Visited and Worklist sets externally to allow unions
716 /// searches to be performed in parallel, caching of results across
717 /// queries and incremental addition to Worklist. Stops early if N is
718 /// found but will resume. Remember to clear Visited and Worklists
720 static bool hasPredecessorHelper(const SDNode *N,
721 SmallPtrSetImpl<const SDNode *> &Visited,
722 SmallVectorImpl<const SDNode *> &Worklist) {
723 if (Visited.count(N))
725 while (!Worklist.empty()) {
726 const SDNode *M = Worklist.pop_back_val();
728 for (const SDValue &OpV : M->op_values()) {
729 SDNode *Op = OpV.getNode();
730 if (Visited.insert(Op).second)
731 Worklist.push_back(Op);
741 /// Return true if all the users of N are contained in Nodes.
742 /// NOTE: Requires at least one match, but doesn't require them all.
743 static bool areOnlyUsersOf(ArrayRef<const SDNode *> Nodes, const SDNode *N);
745 /// Return the number of values used by this operation.
746 unsigned getNumOperands() const { return NumOperands; }
748 /// Helper method returns the integer value of a ConstantSDNode operand.
749 inline uint64_t getConstantOperandVal(unsigned Num) const;
751 const SDValue &getOperand(unsigned Num) const {
752 assert(Num < NumOperands && "Invalid child # of SDNode!");
753 return OperandList[Num];
756 typedef SDUse* op_iterator;
758 op_iterator op_begin() const { return OperandList; }
759 op_iterator op_end() const { return OperandList+NumOperands; }
760 ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
762 /// Iterator for directly iterating over the operand SDValue's.
763 struct value_op_iterator
764 : iterator_adaptor_base<value_op_iterator, op_iterator,
765 std::random_access_iterator_tag, SDValue,
766 ptrdiff_t, value_op_iterator *,
767 value_op_iterator *> {
768 explicit value_op_iterator(SDUse *U = nullptr)
769 : iterator_adaptor_base(U) {}
771 const SDValue &operator*() const { return I->get(); }
774 iterator_range<value_op_iterator> op_values() const {
775 return make_range(value_op_iterator(op_begin()),
776 value_op_iterator(op_end()));
779 SDVTList getVTList() const {
780 SDVTList X = { ValueList, NumValues };
784 /// If this node has a glue operand, return the node
785 /// to which the glue operand points. Otherwise return NULL.
786 SDNode *getGluedNode() const {
787 if (getNumOperands() != 0 &&
788 getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
789 return getOperand(getNumOperands()-1).getNode();
793 /// If this node has a glue value with a user, return
794 /// the user (there is at most one). Otherwise return NULL.
795 SDNode *getGluedUser() const {
796 for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
797 if (UI.getUse().get().getValueType() == MVT::Glue)
802 /// This could be defined as a virtual function and implemented more simply
803 /// and directly, but it is not to avoid creating a vtable for this class.
804 const SDNodeFlags *getFlags() const;
806 /// Clear any flags in this node that aren't also set in Flags.
807 void intersectFlagsWith(const SDNodeFlags *Flags);
809 /// Return the number of values defined/returned by this operator.
810 unsigned getNumValues() const { return NumValues; }
812 /// Return the type of a specified result.
813 EVT getValueType(unsigned ResNo) const {
814 assert(ResNo < NumValues && "Illegal result number!");
815 return ValueList[ResNo];
818 /// Return the type of a specified result as a simple type.
819 MVT getSimpleValueType(unsigned ResNo) const {
820 return getValueType(ResNo).getSimpleVT();
823 /// Returns MVT::getSizeInBits(getValueType(ResNo)).
824 unsigned getValueSizeInBits(unsigned ResNo) const {
825 return getValueType(ResNo).getSizeInBits();
828 typedef const EVT* value_iterator;
829 value_iterator value_begin() const { return ValueList; }
830 value_iterator value_end() const { return ValueList+NumValues; }
832 /// Return the opcode of this operation for printing.
833 std::string getOperationName(const SelectionDAG *G = nullptr) const;
834 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
835 void print_types(raw_ostream &OS, const SelectionDAG *G) const;
836 void print_details(raw_ostream &OS, const SelectionDAG *G) const;
837 void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
838 void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
840 /// Print a SelectionDAG node and all children down to
841 /// the leaves. The given SelectionDAG allows target-specific nodes
842 /// to be printed in human-readable form. Unlike printr, this will
843 /// print the whole DAG, including children that appear multiple
846 void printrFull(raw_ostream &O, const SelectionDAG *G = nullptr) const;
848 /// Print a SelectionDAG node and children up to
849 /// depth "depth." The given SelectionDAG allows target-specific
850 /// nodes to be printed in human-readable form. Unlike printr, this
851 /// will print children that appear multiple times wherever they are
854 void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
855 unsigned depth = 100) const;
857 /// Dump this node, for debugging.
860 /// Dump (recursively) this node and its use-def subgraph.
863 /// Dump this node, for debugging.
864 /// The given SelectionDAG allows target-specific nodes to be printed
865 /// in human-readable form.
866 void dump(const SelectionDAG *G) const;
868 /// Dump (recursively) this node and its use-def subgraph.
869 /// The given SelectionDAG allows target-specific nodes to be printed
870 /// in human-readable form.
871 void dumpr(const SelectionDAG *G) const;
873 /// printrFull to dbgs(). The given SelectionDAG allows
874 /// target-specific nodes to be printed in human-readable form.
875 /// Unlike dumpr, this will print the whole DAG, including children
876 /// that appear multiple times.
877 void dumprFull(const SelectionDAG *G = nullptr) const;
879 /// printrWithDepth to dbgs(). The given
880 /// SelectionDAG allows target-specific nodes to be printed in
881 /// human-readable form. Unlike dumpr, this will print children
882 /// that appear multiple times wherever they are used.
884 void dumprWithDepth(const SelectionDAG *G = nullptr,
885 unsigned depth = 100) const;
887 /// Gather unique data for the node.
888 void Profile(FoldingSetNodeID &ID) const;
890 /// This method should only be used by the SDUse class.
891 void addUse(SDUse &U) { U.addToList(&UseList); }
894 static SDVTList getSDVTList(EVT VT) {
895 SDVTList Ret = { getValueTypeList(VT), 1 };
899 /// Create an SDNode.
901 /// SDNodes are created without any operands, and never own the operand
902 /// storage. To add operands, see SelectionDAG::createOperands.
903 SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
904 : NodeType(Opc), ValueList(VTs.VTs), NumValues(VTs.NumVTs),
905 IROrder(Order), debugLoc(std::move(dl)) {
906 memset(&RawSDNodeBits, 0, sizeof(RawSDNodeBits));
907 assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
908 assert(NumValues == VTs.NumVTs &&
909 "NumValues wasn't wide enough for its operands!");
912 /// Release the operands and set this node to have zero operands.
916 /// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
917 /// into SDNode creation functions.
918 /// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
919 /// from the original Instruction, and IROrder is the ordinal position of
921 /// When an SDNode is created after the DAG is being built, both DebugLoc and
922 /// the IROrder are propagated from the original SDNode.
923 /// So SDLoc class provides two constructors besides the default one, one to
924 /// be used by the DAGBuilder, the other to be used by others.
932 SDLoc(const SDNode *N) : DL(N->getDebugLoc()), IROrder(N->getIROrder()) {}
933 SDLoc(const SDValue V) : SDLoc(V.getNode()) {}
934 SDLoc(const Instruction *I, int Order) : IROrder(Order) {
935 assert(Order >= 0 && "bad IROrder");
937 DL = I->getDebugLoc();
940 unsigned getIROrder() const { return IROrder; }
941 const DebugLoc &getDebugLoc() const { return DL; }
944 // Define inline functions from the SDValue class.
946 inline SDValue::SDValue(SDNode *node, unsigned resno)
947 : Node(node), ResNo(resno) {
948 // Explicitly check for !ResNo to avoid use-after-free, because there are
949 // callers that use SDValue(N, 0) with a deleted N to indicate successful
951 assert((!Node || !ResNo || ResNo < Node->getNumValues()) &&
952 "Invalid result number for the given node!");
953 assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
956 inline unsigned SDValue::getOpcode() const {
957 return Node->getOpcode();
960 inline EVT SDValue::getValueType() const {
961 return Node->getValueType(ResNo);
964 inline unsigned SDValue::getNumOperands() const {
965 return Node->getNumOperands();
968 inline const SDValue &SDValue::getOperand(unsigned i) const {
969 return Node->getOperand(i);
972 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
973 return Node->getConstantOperandVal(i);
976 inline bool SDValue::isTargetOpcode() const {
977 return Node->isTargetOpcode();
980 inline bool SDValue::isTargetMemoryOpcode() const {
981 return Node->isTargetMemoryOpcode();
984 inline bool SDValue::isMachineOpcode() const {
985 return Node->isMachineOpcode();
988 inline unsigned SDValue::getMachineOpcode() const {
989 return Node->getMachineOpcode();
992 inline bool SDValue::isUndef() const {
993 return Node->isUndef();
996 inline bool SDValue::use_empty() const {
997 return !Node->hasAnyUseOfValue(ResNo);
1000 inline bool SDValue::hasOneUse() const {
1001 return Node->hasNUsesOfValue(1, ResNo);
1004 inline const DebugLoc &SDValue::getDebugLoc() const {
1005 return Node->getDebugLoc();
1008 inline void SDValue::dump() const {
1009 return Node->dump();
1012 inline void SDValue::dumpr() const {
1013 return Node->dumpr();
1016 // Define inline functions from the SDUse class.
1018 inline void SDUse::set(const SDValue &V) {
1019 if (Val.getNode()) removeFromList();
1021 if (V.getNode()) V.getNode()->addUse(*this);
1024 inline void SDUse::setInitial(const SDValue &V) {
1026 V.getNode()->addUse(*this);
1029 inline void SDUse::setNode(SDNode *N) {
1030 if (Val.getNode()) removeFromList();
1032 if (N) N->addUse(*this);
1035 /// Returns true if the opcode is a binary operation with flags.
1036 static bool isBinOpWithFlags(unsigned Opcode) {
1057 /// This class is an extension of BinarySDNode
1058 /// used from those opcodes that have associated extra flags.
1059 class BinaryWithFlagsSDNode : public SDNode {
1063 BinaryWithFlagsSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl,
1064 SDVTList VTs, const SDNodeFlags &NodeFlags)
1065 : SDNode(Opc, Order, dl, VTs), Flags(NodeFlags) {}
1067 static bool classof(const SDNode *N) {
1068 return isBinOpWithFlags(N->getOpcode());
1072 /// This class is used to form a handle around another node that
1073 /// is persistent and is updated across invocations of replaceAllUsesWith on its
1074 /// operand. This node should be directly created by end-users and not added to
1075 /// the AllNodes list.
1076 class HandleSDNode : public SDNode {
1080 explicit HandleSDNode(SDValue X)
1081 : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1082 // HandleSDNodes are never inserted into the DAG, so they won't be
1083 // auto-numbered. Use ID 65535 as a sentinel.
1084 PersistentId = 0xffff;
1086 // Manually set up the operand list. This node type is special in that it's
1087 // always stack allocated and SelectionDAG does not manage its operands.
1088 // TODO: This should either (a) not be in the SDNode hierarchy, or (b) not
1097 const SDValue &getValue() const { return Op; }
1100 class AddrSpaceCastSDNode : public SDNode {
1102 unsigned SrcAddrSpace;
1103 unsigned DestAddrSpace;
1106 AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, EVT VT,
1107 unsigned SrcAS, unsigned DestAS);
1109 unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1110 unsigned getDestAddressSpace() const { return DestAddrSpace; }
1112 static bool classof(const SDNode *N) {
1113 return N->getOpcode() == ISD::ADDRSPACECAST;
1117 /// This is an abstract virtual class for memory operations.
1118 class MemSDNode : public SDNode {
1120 // VT of in-memory value.
1124 /// Memory reference information.
1125 MachineMemOperand *MMO;
1128 MemSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs,
1129 EVT MemoryVT, MachineMemOperand *MMO);
1131 bool readMem() const { return MMO->isLoad(); }
1132 bool writeMem() const { return MMO->isStore(); }
1134 /// Returns alignment and volatility of the memory access
1135 unsigned getOriginalAlignment() const {
1136 return MMO->getBaseAlignment();
1138 unsigned getAlignment() const {
1139 return MMO->getAlignment();
1142 /// Return the SubclassData value, without HasDebugValue. This contains an
1143 /// encoding of the volatile flag, as well as bits used by subclasses. This
1144 /// function should only be used to compute a FoldingSetNodeID value.
1145 /// The HasDebugValue bit is masked out because CSE map needs to match
1146 /// nodes with debug info with nodes without debug info.
1147 unsigned getRawSubclassData() const {
1150 char RawSDNodeBits[sizeof(uint16_t)];
1151 SDNodeBitfields SDNodeBits;
1153 memcpy(&RawSDNodeBits, &this->RawSDNodeBits, sizeof(this->RawSDNodeBits));
1154 SDNodeBits.HasDebugValue = 0;
1155 memcpy(&Data, &RawSDNodeBits, sizeof(RawSDNodeBits));
1159 bool isVolatile() const { return MemSDNodeBits.IsVolatile; }
1160 bool isNonTemporal() const { return MemSDNodeBits.IsNonTemporal; }
1161 bool isDereferenceable() const { return MemSDNodeBits.IsDereferenceable; }
1162 bool isInvariant() const { return MemSDNodeBits.IsInvariant; }
1164 // Returns the offset from the location of the access.
1165 int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1167 /// Returns the AA info that describes the dereference.
1168 AAMDNodes getAAInfo() const { return MMO->getAAInfo(); }
1170 /// Returns the Ranges that describes the dereference.
1171 const MDNode *getRanges() const { return MMO->getRanges(); }
1173 /// Return the synchronization scope for this memory operation.
1174 SynchronizationScope getSynchScope() const { return MMO->getSynchScope(); }
1176 /// Return the atomic ordering requirements for this memory operation. For
1177 /// cmpxchg atomic operations, return the atomic ordering requirements when
1179 AtomicOrdering getOrdering() const { return MMO->getOrdering(); }
1181 /// Return the type of the in-memory value.
1182 EVT getMemoryVT() const { return MemoryVT; }
1184 /// Return a MachineMemOperand object describing the memory
1185 /// reference performed by operation.
1186 MachineMemOperand *getMemOperand() const { return MMO; }
1188 const MachinePointerInfo &getPointerInfo() const {
1189 return MMO->getPointerInfo();
1192 /// Return the address space for the associated pointer
1193 unsigned getAddressSpace() const {
1194 return getPointerInfo().getAddrSpace();
1197 /// Update this MemSDNode's MachineMemOperand information
1198 /// to reflect the alignment of NewMMO, if it has a greater alignment.
1199 /// This must only be used when the new alignment applies to all users of
1200 /// this MachineMemOperand.
1201 void refineAlignment(const MachineMemOperand *NewMMO) {
1202 MMO->refineAlignment(NewMMO);
1205 const SDValue &getChain() const { return getOperand(0); }
1206 const SDValue &getBasePtr() const {
1207 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1210 // Methods to support isa and dyn_cast
1211 static bool classof(const SDNode *N) {
1212 // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1213 // with either an intrinsic or a target opcode.
1214 return N->getOpcode() == ISD::LOAD ||
1215 N->getOpcode() == ISD::STORE ||
1216 N->getOpcode() == ISD::PREFETCH ||
1217 N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1218 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1219 N->getOpcode() == ISD::ATOMIC_SWAP ||
1220 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1221 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1222 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1223 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1224 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1225 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1226 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1227 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1228 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1229 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1230 N->getOpcode() == ISD::ATOMIC_LOAD ||
1231 N->getOpcode() == ISD::ATOMIC_STORE ||
1232 N->getOpcode() == ISD::MLOAD ||
1233 N->getOpcode() == ISD::MSTORE ||
1234 N->getOpcode() == ISD::MGATHER ||
1235 N->getOpcode() == ISD::MSCATTER ||
1236 N->isMemIntrinsic() ||
1237 N->isTargetMemoryOpcode();
1241 /// This is an SDNode representing atomic operations.
1242 class AtomicSDNode : public MemSDNode {
1244 AtomicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTL,
1245 EVT MemVT, MachineMemOperand *MMO)
1246 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {}
1248 const SDValue &getBasePtr() const { return getOperand(1); }
1249 const SDValue &getVal() const { return getOperand(2); }
1251 /// Returns true if this SDNode represents cmpxchg atomic operation, false
1253 bool isCompareAndSwap() const {
1254 unsigned Op = getOpcode();
1255 return Op == ISD::ATOMIC_CMP_SWAP ||
1256 Op == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS;
1259 /// For cmpxchg atomic operations, return the atomic ordering requirements
1260 /// when store does not occur.
1261 AtomicOrdering getFailureOrdering() const {
1262 assert(isCompareAndSwap() && "Must be cmpxchg operation");
1263 return MMO->getFailureOrdering();
1266 // Methods to support isa and dyn_cast
1267 static bool classof(const SDNode *N) {
1268 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1269 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1270 N->getOpcode() == ISD::ATOMIC_SWAP ||
1271 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1272 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1273 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1274 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1275 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1276 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1277 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1278 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1279 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1280 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1281 N->getOpcode() == ISD::ATOMIC_LOAD ||
1282 N->getOpcode() == ISD::ATOMIC_STORE;
1286 /// This SDNode is used for target intrinsics that touch
1287 /// memory and need an associated MachineMemOperand. Its opcode may be
1288 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1289 /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1290 class MemIntrinsicSDNode : public MemSDNode {
1292 MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl,
1293 SDVTList VTs, EVT MemoryVT, MachineMemOperand *MMO)
1294 : MemSDNode(Opc, Order, dl, VTs, MemoryVT, MMO) {
1295 SDNodeBits.IsMemIntrinsic = true;
1298 // Methods to support isa and dyn_cast
1299 static bool classof(const SDNode *N) {
1300 // We lower some target intrinsics to their target opcode
1301 // early a node with a target opcode can be of this class
1302 return N->isMemIntrinsic() ||
1303 N->getOpcode() == ISD::PREFETCH ||
1304 N->isTargetMemoryOpcode();
1308 /// This SDNode is used to implement the code generator
1309 /// support for the llvm IR shufflevector instruction. It combines elements
1310 /// from two input vectors into a new input vector, with the selection and
1311 /// ordering of elements determined by an array of integers, referred to as
1312 /// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1313 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1314 /// An index of -1 is treated as undef, such that the code generator may put
1315 /// any value in the corresponding element of the result.
1316 class ShuffleVectorSDNode : public SDNode {
1317 // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1318 // is freed when the SelectionDAG object is destroyed.
1322 friend class SelectionDAG;
1324 ShuffleVectorSDNode(EVT VT, unsigned Order, const DebugLoc &dl, const int *M)
1325 : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {}
1328 ArrayRef<int> getMask() const {
1329 EVT VT = getValueType(0);
1330 return makeArrayRef(Mask, VT.getVectorNumElements());
1333 int getMaskElt(unsigned Idx) const {
1334 assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1338 bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1340 int getSplatIndex() const {
1341 assert(isSplat() && "Cannot get splat index for non-splat!");
1342 EVT VT = getValueType(0);
1343 for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
1347 llvm_unreachable("Splat with all undef indices?");
1350 static bool isSplatMask(const int *Mask, EVT VT);
1352 /// Change values in a shuffle permute mask assuming
1353 /// the two vector operands have swapped position.
1354 static void commuteMask(MutableArrayRef<int> Mask) {
1355 unsigned NumElems = Mask.size();
1356 for (unsigned i = 0; i != NumElems; ++i) {
1360 else if (idx < (int)NumElems)
1361 Mask[i] = idx + NumElems;
1363 Mask[i] = idx - NumElems;
1367 static bool classof(const SDNode *N) {
1368 return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1372 class ConstantSDNode : public SDNode {
1373 friend class SelectionDAG;
1375 const ConstantInt *Value;
1377 ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val,
1378 const DebugLoc &DL, EVT VT)
1379 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, 0, DL,
1382 ConstantSDNodeBits.IsOpaque = isOpaque;
1386 const ConstantInt *getConstantIntValue() const { return Value; }
1387 const APInt &getAPIntValue() const { return Value->getValue(); }
1388 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1389 int64_t getSExtValue() const { return Value->getSExtValue(); }
1391 bool isOne() const { return Value->isOne(); }
1392 bool isNullValue() const { return Value->isNullValue(); }
1393 bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1395 bool isOpaque() const { return ConstantSDNodeBits.IsOpaque; }
1397 static bool classof(const SDNode *N) {
1398 return N->getOpcode() == ISD::Constant ||
1399 N->getOpcode() == ISD::TargetConstant;
1403 uint64_t SDNode::getConstantOperandVal(unsigned Num) const {
1404 return cast<ConstantSDNode>(getOperand(Num))->getZExtValue();
1407 class ConstantFPSDNode : public SDNode {
1408 friend class SelectionDAG;
1410 const ConstantFP *Value;
1412 ConstantFPSDNode(bool isTarget, const ConstantFP *val, const DebugLoc &DL,
1414 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 0, DL,
1419 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1420 const ConstantFP *getConstantFPValue() const { return Value; }
1422 /// Return true if the value is positive or negative zero.
1423 bool isZero() const { return Value->isZero(); }
1425 /// Return true if the value is a NaN.
1426 bool isNaN() const { return Value->isNaN(); }
1428 /// Return true if the value is an infinity
1429 bool isInfinity() const { return Value->isInfinity(); }
1431 /// Return true if the value is negative.
1432 bool isNegative() const { return Value->isNegative(); }
1434 /// We don't rely on operator== working on double values, as
1435 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1436 /// As such, this method can be used to do an exact bit-for-bit comparison of
1437 /// two floating point values.
1439 /// We leave the version with the double argument here because it's just so
1440 /// convenient to write "2.0" and the like. Without this function we'd
1441 /// have to duplicate its logic everywhere it's called.
1442 bool isExactlyValue(double V) const {
1445 Tmp.convert(Value->getValueAPF().getSemantics(),
1446 APFloat::rmNearestTiesToEven, &ignored);
1447 return isExactlyValue(Tmp);
1449 bool isExactlyValue(const APFloat& V) const;
1451 static bool isValueValidForType(EVT VT, const APFloat& Val);
1453 static bool classof(const SDNode *N) {
1454 return N->getOpcode() == ISD::ConstantFP ||
1455 N->getOpcode() == ISD::TargetConstantFP;
1459 /// Returns true if \p V is a constant integer zero.
1460 bool isNullConstant(SDValue V);
1462 /// Returns true if \p V is an FP constant with a value of positive zero.
1463 bool isNullFPConstant(SDValue V);
1465 /// Returns true if \p V is an integer constant with all bits set.
1466 bool isAllOnesConstant(SDValue V);
1468 /// Returns true if \p V is a constant integer one.
1469 bool isOneConstant(SDValue V);
1471 /// Returns true if \p V is a bitwise not operation. Assumes that an all ones
1472 /// constant is canonicalized to be operand 1.
1473 bool isBitwiseNot(SDValue V);
1475 /// Returns the SDNode if it is a constant splat BuildVector or constant int.
1476 ConstantSDNode *isConstOrConstSplat(SDValue V);
1478 /// Returns the SDNode if it is a constant splat BuildVector or constant float.
1479 ConstantFPSDNode *isConstOrConstSplatFP(SDValue V);
1481 class GlobalAddressSDNode : public SDNode {
1482 friend class SelectionDAG;
1484 const GlobalValue *TheGlobal;
1486 unsigned char TargetFlags;
1488 GlobalAddressSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL,
1489 const GlobalValue *GA, EVT VT, int64_t o,
1490 unsigned char TargetFlags);
1493 const GlobalValue *getGlobal() const { return TheGlobal; }
1494 int64_t getOffset() const { return Offset; }
1495 unsigned char getTargetFlags() const { return TargetFlags; }
1496 // Return the address space this GlobalAddress belongs to.
1497 unsigned getAddressSpace() const;
1499 static bool classof(const SDNode *N) {
1500 return N->getOpcode() == ISD::GlobalAddress ||
1501 N->getOpcode() == ISD::TargetGlobalAddress ||
1502 N->getOpcode() == ISD::GlobalTLSAddress ||
1503 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1507 class FrameIndexSDNode : public SDNode {
1508 friend class SelectionDAG;
1512 FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1513 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1514 0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1518 int getIndex() const { return FI; }
1520 static bool classof(const SDNode *N) {
1521 return N->getOpcode() == ISD::FrameIndex ||
1522 N->getOpcode() == ISD::TargetFrameIndex;
1526 class JumpTableSDNode : public SDNode {
1527 friend class SelectionDAG;
1530 unsigned char TargetFlags;
1532 JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1533 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1534 0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1538 int getIndex() const { return JTI; }
1539 unsigned char getTargetFlags() const { return TargetFlags; }
1541 static bool classof(const SDNode *N) {
1542 return N->getOpcode() == ISD::JumpTable ||
1543 N->getOpcode() == ISD::TargetJumpTable;
1547 class ConstantPoolSDNode : public SDNode {
1548 friend class SelectionDAG;
1551 const Constant *ConstVal;
1552 MachineConstantPoolValue *MachineCPVal;
1554 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1555 unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
1556 unsigned char TargetFlags;
1558 ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1559 unsigned Align, unsigned char TF)
1560 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1561 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1563 assert(Offset >= 0 && "Offset is too large");
1567 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1568 EVT VT, int o, unsigned Align, unsigned char TF)
1569 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1570 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1572 assert(Offset >= 0 && "Offset is too large");
1573 Val.MachineCPVal = v;
1574 Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1578 bool isMachineConstantPoolEntry() const {
1582 const Constant *getConstVal() const {
1583 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1584 return Val.ConstVal;
1587 MachineConstantPoolValue *getMachineCPVal() const {
1588 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1589 return Val.MachineCPVal;
1592 int getOffset() const {
1593 return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1596 // Return the alignment of this constant pool object, which is either 0 (for
1597 // default alignment) or the desired value.
1598 unsigned getAlignment() const { return Alignment; }
1599 unsigned char getTargetFlags() const { return TargetFlags; }
1601 Type *getType() const;
1603 static bool classof(const SDNode *N) {
1604 return N->getOpcode() == ISD::ConstantPool ||
1605 N->getOpcode() == ISD::TargetConstantPool;
1609 /// Completely target-dependent object reference.
1610 class TargetIndexSDNode : public SDNode {
1611 friend class SelectionDAG;
1613 unsigned char TargetFlags;
1618 TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1619 : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
1620 TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1622 unsigned char getTargetFlags() const { return TargetFlags; }
1623 int getIndex() const { return Index; }
1624 int64_t getOffset() const { return Offset; }
1626 static bool classof(const SDNode *N) {
1627 return N->getOpcode() == ISD::TargetIndex;
1631 class BasicBlockSDNode : public SDNode {
1632 friend class SelectionDAG;
1634 MachineBasicBlock *MBB;
1636 /// Debug info is meaningful and potentially useful here, but we create
1637 /// blocks out of order when they're jumped to, which makes it a bit
1638 /// harder. Let's see if we need it first.
1639 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1640 : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
1644 MachineBasicBlock *getBasicBlock() const { return MBB; }
1646 static bool classof(const SDNode *N) {
1647 return N->getOpcode() == ISD::BasicBlock;
1651 /// A "pseudo-class" with methods for operating on BUILD_VECTORs.
1652 class BuildVectorSDNode : public SDNode {
1654 // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1655 explicit BuildVectorSDNode() = delete;
1657 /// Check if this is a constant splat, and if so, find the
1658 /// smallest element size that splats the vector. If MinSplatBits is
1659 /// nonzero, the element size must be at least that large. Note that the
1660 /// splat element may be the entire vector (i.e., a one element vector).
1661 /// Returns the splat element value in SplatValue. Any undefined bits in
1662 /// that value are zero, and the corresponding bits in the SplatUndef mask
1663 /// are set. The SplatBitSize value is set to the splat element size in
1664 /// bits. HasAnyUndefs is set to true if any bits in the vector are
1665 /// undefined. isBigEndian describes the endianness of the target.
1666 bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1667 unsigned &SplatBitSize, bool &HasAnyUndefs,
1668 unsigned MinSplatBits = 0,
1669 bool isBigEndian = false) const;
1671 /// \brief Returns the splatted value or a null value if this is not a splat.
1673 /// If passed a non-null UndefElements bitvector, it will resize it to match
1674 /// the vector width and set the bits where elements are undef.
1675 SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
1677 /// \brief Returns the splatted constant or null if this is not a constant
1680 /// If passed a non-null UndefElements bitvector, it will resize it to match
1681 /// the vector width and set the bits where elements are undef.
1683 getConstantSplatNode(BitVector *UndefElements = nullptr) const;
1685 /// \brief Returns the splatted constant FP or null if this is not a constant
1688 /// If passed a non-null UndefElements bitvector, it will resize it to match
1689 /// the vector width and set the bits where elements are undef.
1691 getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
1693 /// \brief If this is a constant FP splat and the splatted constant FP is an
1694 /// exact power or 2, return the log base 2 integer value. Otherwise,
1697 /// The BitWidth specifies the necessary bit precision.
1698 int32_t getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements,
1699 uint32_t BitWidth) const;
1701 bool isConstant() const;
1703 static inline bool classof(const SDNode *N) {
1704 return N->getOpcode() == ISD::BUILD_VECTOR;
1708 /// An SDNode that holds an arbitrary LLVM IR Value. This is
1709 /// used when the SelectionDAG needs to make a simple reference to something
1710 /// in the LLVM IR representation.
1712 class SrcValueSDNode : public SDNode {
1713 friend class SelectionDAG;
1717 /// Create a SrcValue for a general value.
1718 explicit SrcValueSDNode(const Value *v)
1719 : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1722 /// Return the contained Value.
1723 const Value *getValue() const { return V; }
1725 static bool classof(const SDNode *N) {
1726 return N->getOpcode() == ISD::SRCVALUE;
1730 class MDNodeSDNode : public SDNode {
1731 friend class SelectionDAG;
1735 explicit MDNodeSDNode(const MDNode *md)
1736 : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
1740 const MDNode *getMD() const { return MD; }
1742 static bool classof(const SDNode *N) {
1743 return N->getOpcode() == ISD::MDNODE_SDNODE;
1747 class RegisterSDNode : public SDNode {
1748 friend class SelectionDAG;
1752 RegisterSDNode(unsigned reg, EVT VT)
1753 : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {}
1756 unsigned getReg() const { return Reg; }
1758 static bool classof(const SDNode *N) {
1759 return N->getOpcode() == ISD::Register;
1763 class RegisterMaskSDNode : public SDNode {
1764 friend class SelectionDAG;
1766 // The memory for RegMask is not owned by the node.
1767 const uint32_t *RegMask;
1769 RegisterMaskSDNode(const uint32_t *mask)
1770 : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
1774 const uint32_t *getRegMask() const { return RegMask; }
1776 static bool classof(const SDNode *N) {
1777 return N->getOpcode() == ISD::RegisterMask;
1781 class BlockAddressSDNode : public SDNode {
1782 friend class SelectionDAG;
1784 const BlockAddress *BA;
1786 unsigned char TargetFlags;
1788 BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1789 int64_t o, unsigned char Flags)
1790 : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
1791 BA(ba), Offset(o), TargetFlags(Flags) {
1795 const BlockAddress *getBlockAddress() const { return BA; }
1796 int64_t getOffset() const { return Offset; }
1797 unsigned char getTargetFlags() const { return TargetFlags; }
1799 static bool classof(const SDNode *N) {
1800 return N->getOpcode() == ISD::BlockAddress ||
1801 N->getOpcode() == ISD::TargetBlockAddress;
1805 class EHLabelSDNode : public SDNode {
1806 friend class SelectionDAG;
1810 EHLabelSDNode(unsigned Order, const DebugLoc &dl, MCSymbol *L)
1811 : SDNode(ISD::EH_LABEL, Order, dl, getSDVTList(MVT::Other)), Label(L) {}
1814 MCSymbol *getLabel() const { return Label; }
1816 static bool classof(const SDNode *N) {
1817 return N->getOpcode() == ISD::EH_LABEL;
1821 class ExternalSymbolSDNode : public SDNode {
1822 friend class SelectionDAG;
1825 unsigned char TargetFlags;
1827 ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1828 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1829 0, DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {}
1832 const char *getSymbol() const { return Symbol; }
1833 unsigned char getTargetFlags() const { return TargetFlags; }
1835 static bool classof(const SDNode *N) {
1836 return N->getOpcode() == ISD::ExternalSymbol ||
1837 N->getOpcode() == ISD::TargetExternalSymbol;
1841 class MCSymbolSDNode : public SDNode {
1842 friend class SelectionDAG;
1846 MCSymbolSDNode(MCSymbol *Symbol, EVT VT)
1847 : SDNode(ISD::MCSymbol, 0, DebugLoc(), getSDVTList(VT)), Symbol(Symbol) {}
1850 MCSymbol *getMCSymbol() const { return Symbol; }
1852 static bool classof(const SDNode *N) {
1853 return N->getOpcode() == ISD::MCSymbol;
1857 class CondCodeSDNode : public SDNode {
1858 friend class SelectionDAG;
1860 ISD::CondCode Condition;
1862 explicit CondCodeSDNode(ISD::CondCode Cond)
1863 : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1867 ISD::CondCode get() const { return Condition; }
1869 static bool classof(const SDNode *N) {
1870 return N->getOpcode() == ISD::CONDCODE;
1874 /// This class is used to represent EVT's, which are used
1875 /// to parameterize some operations.
1876 class VTSDNode : public SDNode {
1877 friend class SelectionDAG;
1881 explicit VTSDNode(EVT VT)
1882 : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1886 EVT getVT() const { return ValueType; }
1888 static bool classof(const SDNode *N) {
1889 return N->getOpcode() == ISD::VALUETYPE;
1893 /// Base class for LoadSDNode and StoreSDNode
1894 class LSBaseSDNode : public MemSDNode {
1896 LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl,
1897 SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
1898 MachineMemOperand *MMO)
1899 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
1900 LSBaseSDNodeBits.AddressingMode = AM;
1901 assert(getAddressingMode() == AM && "Value truncated");
1904 const SDValue &getOffset() const {
1905 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1908 /// Return the addressing mode for this load or store:
1909 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
1910 ISD::MemIndexedMode getAddressingMode() const {
1911 return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
1914 /// Return true if this is a pre/post inc/dec load/store.
1915 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
1917 /// Return true if this is NOT a pre/post inc/dec load/store.
1918 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
1920 static bool classof(const SDNode *N) {
1921 return N->getOpcode() == ISD::LOAD ||
1922 N->getOpcode() == ISD::STORE;
1926 /// This class is used to represent ISD::LOAD nodes.
1927 class LoadSDNode : public LSBaseSDNode {
1928 friend class SelectionDAG;
1930 LoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
1931 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
1932 MachineMemOperand *MMO)
1933 : LSBaseSDNode(ISD::LOAD, Order, dl, VTs, AM, MemVT, MMO) {
1934 LoadSDNodeBits.ExtTy = ETy;
1935 assert(readMem() && "Load MachineMemOperand is not a load!");
1936 assert(!writeMem() && "Load MachineMemOperand is a store!");
1940 /// Return whether this is a plain node,
1941 /// or one of the varieties of value-extending loads.
1942 ISD::LoadExtType getExtensionType() const {
1943 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
1946 const SDValue &getBasePtr() const { return getOperand(1); }
1947 const SDValue &getOffset() const { return getOperand(2); }
1949 static bool classof(const SDNode *N) {
1950 return N->getOpcode() == ISD::LOAD;
1954 /// This class is used to represent ISD::STORE nodes.
1955 class StoreSDNode : public LSBaseSDNode {
1956 friend class SelectionDAG;
1958 StoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
1959 ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
1960 MachineMemOperand *MMO)
1961 : LSBaseSDNode(ISD::STORE, Order, dl, VTs, AM, MemVT, MMO) {
1962 StoreSDNodeBits.IsTruncating = isTrunc;
1963 assert(!readMem() && "Store MachineMemOperand is a load!");
1964 assert(writeMem() && "Store MachineMemOperand is not a store!");
1968 /// Return true if the op does a truncation before store.
1969 /// For integers this is the same as doing a TRUNCATE and storing the result.
1970 /// For floats, it is the same as doing an FP_ROUND and storing the result.
1971 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
1973 const SDValue &getValue() const { return getOperand(1); }
1974 const SDValue &getBasePtr() const { return getOperand(2); }
1975 const SDValue &getOffset() const { return getOperand(3); }
1977 static bool classof(const SDNode *N) {
1978 return N->getOpcode() == ISD::STORE;
1982 /// This base class is used to represent MLOAD and MSTORE nodes
1983 class MaskedLoadStoreSDNode : public MemSDNode {
1985 friend class SelectionDAG;
1987 MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order,
1988 const DebugLoc &dl, SDVTList VTs, EVT MemVT,
1989 MachineMemOperand *MMO)
1990 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
1992 // In the both nodes address is Op1, mask is Op2:
1993 // MaskedLoadSDNode (Chain, ptr, mask, src0), src0 is a passthru value
1994 // MaskedStoreSDNode (Chain, ptr, mask, data)
1995 // Mask is a vector of i1 elements
1996 const SDValue &getBasePtr() const { return getOperand(1); }
1997 const SDValue &getMask() const { return getOperand(2); }
1999 static bool classof(const SDNode *N) {
2000 return N->getOpcode() == ISD::MLOAD ||
2001 N->getOpcode() == ISD::MSTORE;
2005 /// This class is used to represent an MLOAD node
2006 class MaskedLoadSDNode : public MaskedLoadStoreSDNode {
2008 friend class SelectionDAG;
2010 MaskedLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2011 ISD::LoadExtType ETy, bool IsExpanding, EVT MemVT,
2012 MachineMemOperand *MMO)
2013 : MaskedLoadStoreSDNode(ISD::MLOAD, Order, dl, VTs, MemVT, MMO) {
2014 LoadSDNodeBits.ExtTy = ETy;
2015 LoadSDNodeBits.IsExpanding = IsExpanding;
2018 ISD::LoadExtType getExtensionType() const {
2019 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2022 const SDValue &getSrc0() const { return getOperand(3); }
2023 static bool classof(const SDNode *N) {
2024 return N->getOpcode() == ISD::MLOAD;
2027 bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
2030 /// This class is used to represent an MSTORE node
2031 class MaskedStoreSDNode : public MaskedLoadStoreSDNode {
2033 friend class SelectionDAG;
2035 MaskedStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2036 bool isTrunc, bool isCompressing, EVT MemVT,
2037 MachineMemOperand *MMO)
2038 : MaskedLoadStoreSDNode(ISD::MSTORE, Order, dl, VTs, MemVT, MMO) {
2039 StoreSDNodeBits.IsTruncating = isTrunc;
2040 StoreSDNodeBits.IsCompressing = isCompressing;
2043 /// Return true if the op does a truncation before store.
2044 /// For integers this is the same as doing a TRUNCATE and storing the result.
2045 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2046 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2048 /// Returns true if the op does a compression to the vector before storing.
2049 /// The node contiguously stores the active elements (integers or floats)
2050 /// in src (those with their respective bit set in writemask k) to unaligned
2051 /// memory at base_addr.
2052 bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
2054 const SDValue &getValue() const { return getOperand(3); }
2056 static bool classof(const SDNode *N) {
2057 return N->getOpcode() == ISD::MSTORE;
2061 /// This is a base class used to represent
2062 /// MGATHER and MSCATTER nodes
2064 class MaskedGatherScatterSDNode : public MemSDNode {
2066 friend class SelectionDAG;
2068 MaskedGatherScatterSDNode(ISD::NodeType NodeTy, unsigned Order,
2069 const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2070 MachineMemOperand *MMO)
2071 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2073 // In the both nodes address is Op1, mask is Op2:
2074 // MaskedGatherSDNode (Chain, src0, mask, base, index), src0 is a passthru value
2075 // MaskedScatterSDNode (Chain, value, mask, base, index)
2076 // Mask is a vector of i1 elements
2077 const SDValue &getBasePtr() const { return getOperand(3); }
2078 const SDValue &getIndex() const { return getOperand(4); }
2079 const SDValue &getMask() const { return getOperand(2); }
2080 const SDValue &getValue() const { return getOperand(1); }
2082 static bool classof(const SDNode *N) {
2083 return N->getOpcode() == ISD::MGATHER ||
2084 N->getOpcode() == ISD::MSCATTER;
2088 /// This class is used to represent an MGATHER node
2090 class MaskedGatherSDNode : public MaskedGatherScatterSDNode {
2092 friend class SelectionDAG;
2094 MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2095 EVT MemVT, MachineMemOperand *MMO)
2096 : MaskedGatherScatterSDNode(ISD::MGATHER, Order, dl, VTs, MemVT, MMO) {}
2098 static bool classof(const SDNode *N) {
2099 return N->getOpcode() == ISD::MGATHER;
2103 /// This class is used to represent an MSCATTER node
2105 class MaskedScatterSDNode : public MaskedGatherScatterSDNode {
2107 friend class SelectionDAG;
2109 MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2110 EVT MemVT, MachineMemOperand *MMO)
2111 : MaskedGatherScatterSDNode(ISD::MSCATTER, Order, dl, VTs, MemVT, MMO) {}
2113 static bool classof(const SDNode *N) {
2114 return N->getOpcode() == ISD::MSCATTER;
2118 /// An SDNode that represents everything that will be needed
2119 /// to construct a MachineInstr. These nodes are created during the
2120 /// instruction selection proper phase.
2121 class MachineSDNode : public SDNode {
2123 typedef MachineMemOperand **mmo_iterator;
2126 friend class SelectionDAG;
2128 MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL, SDVTList VTs)
2129 : SDNode(Opc, Order, DL, VTs) {}
2131 /// Memory reference descriptions for this instruction.
2132 mmo_iterator MemRefs = nullptr;
2133 mmo_iterator MemRefsEnd = nullptr;
2136 mmo_iterator memoperands_begin() const { return MemRefs; }
2137 mmo_iterator memoperands_end() const { return MemRefsEnd; }
2138 bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
2140 /// Assign this MachineSDNodes's memory reference descriptor
2141 /// list. This does not transfer ownership.
2142 void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
2143 for (mmo_iterator MMI = NewMemRefs, MME = NewMemRefsEnd; MMI != MME; ++MMI)
2144 assert(*MMI && "Null mem ref detected!");
2145 MemRefs = NewMemRefs;
2146 MemRefsEnd = NewMemRefsEnd;
2149 static bool classof(const SDNode *N) {
2150 return N->isMachineOpcode();
2154 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
2155 SDNode, ptrdiff_t> {
2159 SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2162 bool operator==(const SDNodeIterator& x) const {
2163 return Operand == x.Operand;
2165 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2167 pointer operator*() const {
2168 return Node->getOperand(Operand).getNode();
2170 pointer operator->() const { return operator*(); }
2172 SDNodeIterator& operator++() { // Preincrement
2176 SDNodeIterator operator++(int) { // Postincrement
2177 SDNodeIterator tmp = *this; ++*this; return tmp;
2179 size_t operator-(SDNodeIterator Other) const {
2180 assert(Node == Other.Node &&
2181 "Cannot compare iterators of two different nodes!");
2182 return Operand - Other.Operand;
2185 static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
2186 static SDNodeIterator end (const SDNode *N) {
2187 return SDNodeIterator(N, N->getNumOperands());
2190 unsigned getOperand() const { return Operand; }
2191 const SDNode *getNode() const { return Node; }
2194 template <> struct GraphTraits<SDNode*> {
2195 typedef SDNode *NodeRef;
2196 typedef SDNodeIterator ChildIteratorType;
2198 static NodeRef getEntryNode(SDNode *N) { return N; }
2200 static ChildIteratorType child_begin(NodeRef N) {
2201 return SDNodeIterator::begin(N);
2204 static ChildIteratorType child_end(NodeRef N) {
2205 return SDNodeIterator::end(N);
2209 /// A representation of the largest SDNode, for use in sizeof().
2211 /// This needs to be a union because the largest node differs on 32 bit systems
2212 /// with 4 and 8 byte pointer alignment, respectively.
2213 typedef AlignedCharArrayUnion<AtomicSDNode, TargetIndexSDNode,
2214 BlockAddressSDNode, GlobalAddressSDNode>
2217 /// The SDNode class with the greatest alignment requirement.
2218 typedef GlobalAddressSDNode MostAlignedSDNode;
2222 /// Returns true if the specified node is a non-extending and unindexed load.
2223 inline bool isNormalLoad(const SDNode *N) {
2224 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2225 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2226 Ld->getAddressingMode() == ISD::UNINDEXED;
2229 /// Returns true if the specified node is a non-extending load.
2230 inline bool isNON_EXTLoad(const SDNode *N) {
2231 return isa<LoadSDNode>(N) &&
2232 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2235 /// Returns true if the specified node is a EXTLOAD.
2236 inline bool isEXTLoad(const SDNode *N) {
2237 return isa<LoadSDNode>(N) &&
2238 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2241 /// Returns true if the specified node is a SEXTLOAD.
2242 inline bool isSEXTLoad(const SDNode *N) {
2243 return isa<LoadSDNode>(N) &&
2244 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2247 /// Returns true if the specified node is a ZEXTLOAD.
2248 inline bool isZEXTLoad(const SDNode *N) {
2249 return isa<LoadSDNode>(N) &&
2250 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2253 /// Returns true if the specified node is an unindexed load.
2254 inline bool isUNINDEXEDLoad(const SDNode *N) {
2255 return isa<LoadSDNode>(N) &&
2256 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2259 /// Returns true if the specified node is a non-truncating
2260 /// and unindexed store.
2261 inline bool isNormalStore(const SDNode *N) {
2262 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2263 return St && !St->isTruncatingStore() &&
2264 St->getAddressingMode() == ISD::UNINDEXED;
2267 /// Returns true if the specified node is a non-truncating store.
2268 inline bool isNON_TRUNCStore(const SDNode *N) {
2269 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2272 /// Returns true if the specified node is a truncating store.
2273 inline bool isTRUNCStore(const SDNode *N) {
2274 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2277 /// Returns true if the specified node is an unindexed store.
2278 inline bool isUNINDEXEDStore(const SDNode *N) {
2279 return isa<StoreSDNode>(N) &&
2280 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2283 } // end namespace ISD
2285 } // end namespace llvm
2287 #endif // LLVM_CODEGEN_SELECTIONDAGNODES_H