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 // This bit is used to determine if the flags are in a defined state.
345 // Flag bits can only be masked out during intersection if the masking flags
349 bool NoUnsignedWrap : 1;
350 bool NoSignedWrap : 1;
352 bool UnsafeAlgebra : 1;
355 bool NoSignedZeros : 1;
356 bool AllowReciprocal : 1;
357 bool VectorReduction : 1;
358 bool AllowContract : 1;
361 /// Default constructor turns off all optimization flags.
363 : AnyDefined(false), NoUnsignedWrap(false), NoSignedWrap(false),
364 Exact(false), UnsafeAlgebra(false), NoNaNs(false), NoInfs(false),
365 NoSignedZeros(false), AllowReciprocal(false), VectorReduction(false),
366 AllowContract(false) {}
368 /// Sets the state of the flags to the defined state.
369 void setDefined() { AnyDefined = true; }
370 /// Returns true if the flags are in a defined state.
371 bool isDefined() const { return AnyDefined; }
373 // These are mutators for each flag.
374 void setNoUnsignedWrap(bool b) {
378 void setNoSignedWrap(bool b) {
382 void setExact(bool b) {
386 void setUnsafeAlgebra(bool b) {
390 void setNoNaNs(bool b) {
394 void setNoInfs(bool b) {
398 void setNoSignedZeros(bool b) {
402 void setAllowReciprocal(bool b) {
406 void setVectorReduction(bool b) {
410 void setAllowContract(bool b) {
415 // These are accessors for each flag.
416 bool hasNoUnsignedWrap() const { return NoUnsignedWrap; }
417 bool hasNoSignedWrap() const { return NoSignedWrap; }
418 bool hasExact() const { return Exact; }
419 bool hasUnsafeAlgebra() const { return UnsafeAlgebra; }
420 bool hasNoNaNs() const { return NoNaNs; }
421 bool hasNoInfs() const { return NoInfs; }
422 bool hasNoSignedZeros() const { return NoSignedZeros; }
423 bool hasAllowReciprocal() const { return AllowReciprocal; }
424 bool hasVectorReduction() const { return VectorReduction; }
425 bool hasAllowContract() const { return AllowContract; }
427 /// Clear any flags in this flag set that aren't also set in Flags.
428 /// If the given Flags are undefined then don't do anything.
429 void intersectWith(const SDNodeFlags Flags) {
430 if (!Flags.isDefined())
432 NoUnsignedWrap &= Flags.NoUnsignedWrap;
433 NoSignedWrap &= Flags.NoSignedWrap;
434 Exact &= Flags.Exact;
435 UnsafeAlgebra &= Flags.UnsafeAlgebra;
436 NoNaNs &= Flags.NoNaNs;
437 NoInfs &= Flags.NoInfs;
438 NoSignedZeros &= Flags.NoSignedZeros;
439 AllowReciprocal &= Flags.AllowReciprocal;
440 VectorReduction &= Flags.VectorReduction;
441 AllowContract &= Flags.AllowContract;
445 /// Represents one node in the SelectionDAG.
447 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
449 /// The operation that this node performs.
453 // We define a set of mini-helper classes to help us interpret the bits in our
454 // SubclassData. These are designed to fit within a uint16_t so they pack
457 class SDNodeBitfields {
459 friend class MemIntrinsicSDNode;
460 friend class MemSDNode;
462 uint16_t HasDebugValue : 1;
463 uint16_t IsMemIntrinsic : 1;
465 enum { NumSDNodeBits = 2 };
467 class ConstantSDNodeBitfields {
468 friend class ConstantSDNode;
470 uint16_t : NumSDNodeBits;
472 uint16_t IsOpaque : 1;
475 class MemSDNodeBitfields {
476 friend class MemSDNode;
477 friend class MemIntrinsicSDNode;
478 friend class AtomicSDNode;
480 uint16_t : NumSDNodeBits;
482 uint16_t IsVolatile : 1;
483 uint16_t IsNonTemporal : 1;
484 uint16_t IsDereferenceable : 1;
485 uint16_t IsInvariant : 1;
487 enum { NumMemSDNodeBits = NumSDNodeBits + 4 };
489 class LSBaseSDNodeBitfields {
490 friend class LSBaseSDNode;
492 uint16_t : NumMemSDNodeBits;
494 uint16_t AddressingMode : 3; // enum ISD::MemIndexedMode
496 enum { NumLSBaseSDNodeBits = NumMemSDNodeBits + 3 };
498 class LoadSDNodeBitfields {
499 friend class LoadSDNode;
500 friend class MaskedLoadSDNode;
502 uint16_t : NumLSBaseSDNodeBits;
504 uint16_t ExtTy : 2; // enum ISD::LoadExtType
505 uint16_t IsExpanding : 1;
508 class StoreSDNodeBitfields {
509 friend class StoreSDNode;
510 friend class MaskedStoreSDNode;
512 uint16_t : NumLSBaseSDNodeBits;
514 uint16_t IsTruncating : 1;
515 uint16_t IsCompressing : 1;
519 char RawSDNodeBits[sizeof(uint16_t)];
520 SDNodeBitfields SDNodeBits;
521 ConstantSDNodeBitfields ConstantSDNodeBits;
522 MemSDNodeBitfields MemSDNodeBits;
523 LSBaseSDNodeBitfields LSBaseSDNodeBits;
524 LoadSDNodeBitfields LoadSDNodeBits;
525 StoreSDNodeBitfields StoreSDNodeBits;
528 // RawSDNodeBits must cover the entirety of the union. This means that all of
529 // the union's members must have size <= RawSDNodeBits. We write the RHS as
530 // "2" instead of sizeof(RawSDNodeBits) because MSVC can't handle the latter.
531 static_assert(sizeof(SDNodeBitfields) <= 2, "field too wide");
532 static_assert(sizeof(ConstantSDNodeBitfields) <= 2, "field too wide");
533 static_assert(sizeof(MemSDNodeBitfields) <= 2, "field too wide");
534 static_assert(sizeof(LSBaseSDNodeBitfields) <= 2, "field too wide");
535 static_assert(sizeof(LoadSDNodeBitfields) <= 4, "field too wide");
536 static_assert(sizeof(StoreSDNodeBitfields) <= 2, "field too wide");
539 friend class SelectionDAG;
540 // TODO: unfriend HandleSDNode once we fix its operand handling.
541 friend class HandleSDNode;
543 /// Unique id per SDNode in the DAG.
546 /// The values that are used by this operation.
547 SDUse *OperandList = nullptr;
549 /// The types of the values this node defines. SDNode's may
550 /// define multiple values simultaneously.
551 const EVT *ValueList;
553 /// List of uses for this SDNode.
554 SDUse *UseList = nullptr;
556 /// The number of entries in the Operand/Value list.
557 unsigned short NumOperands = 0;
558 unsigned short NumValues;
560 // The ordering of the SDNodes. It roughly corresponds to the ordering of the
561 // original LLVM instructions.
562 // This is used for turning off scheduling, because we'll forgo
563 // the normal scheduling algorithms and output the instructions according to
567 /// Source line information.
570 /// Return a pointer to the specified value type.
571 static const EVT *getValueTypeList(EVT VT);
576 /// Unique and persistent id per SDNode in the DAG.
577 /// Used for debug printing.
578 uint16_t PersistentId;
580 //===--------------------------------------------------------------------===//
584 /// Return the SelectionDAG opcode value for this node. For
585 /// pre-isel nodes (those for which isMachineOpcode returns false), these
586 /// are the opcode values in the ISD and <target>ISD namespaces. For
587 /// post-isel opcodes, see getMachineOpcode.
588 unsigned getOpcode() const { return (unsigned short)NodeType; }
590 /// Test if this node has a target-specific opcode (in the
591 /// \<target\>ISD namespace).
592 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
594 /// Test if this node has a target-specific
595 /// memory-referencing opcode (in the \<target\>ISD namespace and
596 /// greater than FIRST_TARGET_MEMORY_OPCODE).
597 bool isTargetMemoryOpcode() const {
598 return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
601 /// Return true if the type of the node type undefined.
602 bool isUndef() const { return NodeType == ISD::UNDEF; }
604 /// Test if this node is a memory intrinsic (with valid pointer information).
605 /// INTRINSIC_W_CHAIN and INTRINSIC_VOID nodes are sometimes created for
606 /// non-memory intrinsics (with chains) that are not really instances of
607 /// MemSDNode. For such nodes, we need some extra state to determine the
608 /// proper classof relationship.
609 bool isMemIntrinsic() const {
610 return (NodeType == ISD::INTRINSIC_W_CHAIN ||
611 NodeType == ISD::INTRINSIC_VOID) &&
612 SDNodeBits.IsMemIntrinsic;
615 /// Test if this node has a post-isel opcode, directly
616 /// corresponding to a MachineInstr opcode.
617 bool isMachineOpcode() const { return NodeType < 0; }
619 /// This may only be called if isMachineOpcode returns
620 /// true. It returns the MachineInstr opcode value that the node's opcode
622 unsigned getMachineOpcode() const {
623 assert(isMachineOpcode() && "Not a MachineInstr opcode!");
627 bool getHasDebugValue() const { return SDNodeBits.HasDebugValue; }
628 void setHasDebugValue(bool b) { SDNodeBits.HasDebugValue = b; }
630 /// Return true if there are no uses of this node.
631 bool use_empty() const { return UseList == nullptr; }
633 /// Return true if there is exactly one use of this node.
634 bool hasOneUse() const {
635 return !use_empty() && std::next(use_begin()) == use_end();
638 /// Return the number of uses of this node. This method takes
639 /// time proportional to the number of uses.
640 size_t use_size() const { return std::distance(use_begin(), use_end()); }
642 /// Return the unique node id.
643 int getNodeId() const { return NodeId; }
645 /// Set unique node id.
646 void setNodeId(int Id) { NodeId = Id; }
648 /// Return the node ordering.
649 unsigned getIROrder() const { return IROrder; }
651 /// Set the node ordering.
652 void setIROrder(unsigned Order) { IROrder = Order; }
654 /// Return the source location info.
655 const DebugLoc &getDebugLoc() const { return debugLoc; }
657 /// Set source location info. Try to avoid this, putting
658 /// it in the constructor is preferable.
659 void setDebugLoc(DebugLoc dl) { debugLoc = std::move(dl); }
661 /// This class provides iterator support for SDUse
662 /// operands that use a specific SDNode.
664 : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
669 explicit use_iterator(SDUse *op) : Op(op) {}
672 typedef std::iterator<std::forward_iterator_tag,
673 SDUse, ptrdiff_t>::reference reference;
674 typedef std::iterator<std::forward_iterator_tag,
675 SDUse, ptrdiff_t>::pointer pointer;
677 use_iterator() = default;
678 use_iterator(const use_iterator &I) : Op(I.Op) {}
680 bool operator==(const use_iterator &x) const {
683 bool operator!=(const use_iterator &x) const {
684 return !operator==(x);
687 /// Return true if this iterator is at the end of uses list.
688 bool atEnd() const { return Op == nullptr; }
690 // Iterator traversal: forward iteration only.
691 use_iterator &operator++() { // Preincrement
692 assert(Op && "Cannot increment end iterator!");
697 use_iterator operator++(int) { // Postincrement
698 use_iterator tmp = *this; ++*this; return tmp;
701 /// Retrieve a pointer to the current user node.
702 SDNode *operator*() const {
703 assert(Op && "Cannot dereference end iterator!");
704 return Op->getUser();
707 SDNode *operator->() const { return operator*(); }
709 SDUse &getUse() const { return *Op; }
711 /// Retrieve the operand # of this use in its user.
712 unsigned getOperandNo() const {
713 assert(Op && "Cannot dereference end iterator!");
714 return (unsigned)(Op - Op->getUser()->OperandList);
718 /// Provide iteration support to walk over all uses of an SDNode.
719 use_iterator use_begin() const {
720 return use_iterator(UseList);
723 static use_iterator use_end() { return use_iterator(nullptr); }
725 inline iterator_range<use_iterator> uses() {
726 return make_range(use_begin(), use_end());
728 inline iterator_range<use_iterator> uses() const {
729 return make_range(use_begin(), use_end());
732 /// Return true if there are exactly NUSES uses of the indicated value.
733 /// This method ignores uses of other values defined by this operation.
734 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
736 /// Return true if there are any use of the indicated value.
737 /// This method ignores uses of other values defined by this operation.
738 bool hasAnyUseOfValue(unsigned Value) const;
740 /// Return true if this node is the only use of N.
741 bool isOnlyUserOf(const SDNode *N) const;
743 /// Return true if this node is an operand of N.
744 bool isOperandOf(const SDNode *N) const;
746 /// Return true if this node is a predecessor of N.
747 /// NOTE: Implemented on top of hasPredecessor and every bit as
748 /// expensive. Use carefully.
749 bool isPredecessorOf(const SDNode *N) const {
750 return N->hasPredecessor(this);
753 /// Return true if N is a predecessor of this node.
754 /// N is either an operand of this node, or can be reached by recursively
755 /// traversing up the operands.
756 /// NOTE: This is an expensive method. Use it carefully.
757 bool hasPredecessor(const SDNode *N) const;
759 /// Returns true if N is a predecessor of any node in Worklist. This
760 /// helper keeps Visited and Worklist sets externally to allow unions
761 /// searches to be performed in parallel, caching of results across
762 /// queries and incremental addition to Worklist. Stops early if N is
763 /// found but will resume. Remember to clear Visited and Worklists
765 static bool hasPredecessorHelper(const SDNode *N,
766 SmallPtrSetImpl<const SDNode *> &Visited,
767 SmallVectorImpl<const SDNode *> &Worklist) {
768 if (Visited.count(N))
770 while (!Worklist.empty()) {
771 const SDNode *M = Worklist.pop_back_val();
773 for (const SDValue &OpV : M->op_values()) {
774 SDNode *Op = OpV.getNode();
775 if (Visited.insert(Op).second)
776 Worklist.push_back(Op);
786 /// Return true if all the users of N are contained in Nodes.
787 /// NOTE: Requires at least one match, but doesn't require them all.
788 static bool areOnlyUsersOf(ArrayRef<const SDNode *> Nodes, const SDNode *N);
790 /// Return the number of values used by this operation.
791 unsigned getNumOperands() const { return NumOperands; }
793 /// Helper method returns the integer value of a ConstantSDNode operand.
794 inline uint64_t getConstantOperandVal(unsigned Num) const;
796 const SDValue &getOperand(unsigned Num) const {
797 assert(Num < NumOperands && "Invalid child # of SDNode!");
798 return OperandList[Num];
801 typedef SDUse* op_iterator;
803 op_iterator op_begin() const { return OperandList; }
804 op_iterator op_end() const { return OperandList+NumOperands; }
805 ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
807 /// Iterator for directly iterating over the operand SDValue's.
808 struct value_op_iterator
809 : iterator_adaptor_base<value_op_iterator, op_iterator,
810 std::random_access_iterator_tag, SDValue,
811 ptrdiff_t, value_op_iterator *,
812 value_op_iterator *> {
813 explicit value_op_iterator(SDUse *U = nullptr)
814 : iterator_adaptor_base(U) {}
816 const SDValue &operator*() const { return I->get(); }
819 iterator_range<value_op_iterator> op_values() const {
820 return make_range(value_op_iterator(op_begin()),
821 value_op_iterator(op_end()));
824 SDVTList getVTList() const {
825 SDVTList X = { ValueList, NumValues };
829 /// If this node has a glue operand, return the node
830 /// to which the glue operand points. Otherwise return NULL.
831 SDNode *getGluedNode() const {
832 if (getNumOperands() != 0 &&
833 getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
834 return getOperand(getNumOperands()-1).getNode();
838 /// If this node has a glue value with a user, return
839 /// the user (there is at most one). Otherwise return NULL.
840 SDNode *getGluedUser() const {
841 for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
842 if (UI.getUse().get().getValueType() == MVT::Glue)
847 const SDNodeFlags getFlags() const { return Flags; }
848 void setFlags(SDNodeFlags NewFlags) { Flags = NewFlags; }
850 /// Clear any flags in this node that aren't also set in Flags.
851 /// If Flags is not in a defined state then this has no effect.
852 void intersectFlagsWith(const SDNodeFlags Flags);
854 /// Return the number of values defined/returned by this operator.
855 unsigned getNumValues() const { return NumValues; }
857 /// Return the type of a specified result.
858 EVT getValueType(unsigned ResNo) const {
859 assert(ResNo < NumValues && "Illegal result number!");
860 return ValueList[ResNo];
863 /// Return the type of a specified result as a simple type.
864 MVT getSimpleValueType(unsigned ResNo) const {
865 return getValueType(ResNo).getSimpleVT();
868 /// Returns MVT::getSizeInBits(getValueType(ResNo)).
869 unsigned getValueSizeInBits(unsigned ResNo) const {
870 return getValueType(ResNo).getSizeInBits();
873 typedef const EVT* value_iterator;
874 value_iterator value_begin() const { return ValueList; }
875 value_iterator value_end() const { return ValueList+NumValues; }
877 /// Return the opcode of this operation for printing.
878 std::string getOperationName(const SelectionDAG *G = nullptr) const;
879 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
880 void print_types(raw_ostream &OS, const SelectionDAG *G) const;
881 void print_details(raw_ostream &OS, const SelectionDAG *G) const;
882 void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
883 void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
885 /// Print a SelectionDAG node and all children down to
886 /// the leaves. The given SelectionDAG allows target-specific nodes
887 /// to be printed in human-readable form. Unlike printr, this will
888 /// print the whole DAG, including children that appear multiple
891 void printrFull(raw_ostream &O, const SelectionDAG *G = nullptr) const;
893 /// Print a SelectionDAG node and children up to
894 /// depth "depth." The given SelectionDAG allows target-specific
895 /// nodes to be printed in human-readable form. Unlike printr, this
896 /// will print children that appear multiple times wherever they are
899 void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
900 unsigned depth = 100) const;
902 /// Dump this node, for debugging.
905 /// Dump (recursively) this node and its use-def subgraph.
908 /// Dump this node, for debugging.
909 /// The given SelectionDAG allows target-specific nodes to be printed
910 /// in human-readable form.
911 void dump(const SelectionDAG *G) const;
913 /// Dump (recursively) this node and its use-def subgraph.
914 /// The given SelectionDAG allows target-specific nodes to be printed
915 /// in human-readable form.
916 void dumpr(const SelectionDAG *G) const;
918 /// printrFull to dbgs(). The given SelectionDAG allows
919 /// target-specific nodes to be printed in human-readable form.
920 /// Unlike dumpr, this will print the whole DAG, including children
921 /// that appear multiple times.
922 void dumprFull(const SelectionDAG *G = nullptr) const;
924 /// printrWithDepth to dbgs(). The given
925 /// SelectionDAG allows target-specific nodes to be printed in
926 /// human-readable form. Unlike dumpr, this will print children
927 /// that appear multiple times wherever they are used.
929 void dumprWithDepth(const SelectionDAG *G = nullptr,
930 unsigned depth = 100) const;
932 /// Gather unique data for the node.
933 void Profile(FoldingSetNodeID &ID) const;
935 /// This method should only be used by the SDUse class.
936 void addUse(SDUse &U) { U.addToList(&UseList); }
939 static SDVTList getSDVTList(EVT VT) {
940 SDVTList Ret = { getValueTypeList(VT), 1 };
944 /// Create an SDNode.
946 /// SDNodes are created without any operands, and never own the operand
947 /// storage. To add operands, see SelectionDAG::createOperands.
948 SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
949 : NodeType(Opc), ValueList(VTs.VTs), NumValues(VTs.NumVTs),
950 IROrder(Order), debugLoc(std::move(dl)) {
951 memset(&RawSDNodeBits, 0, sizeof(RawSDNodeBits));
952 assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
953 assert(NumValues == VTs.NumVTs &&
954 "NumValues wasn't wide enough for its operands!");
957 /// Release the operands and set this node to have zero operands.
961 /// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
962 /// into SDNode creation functions.
963 /// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
964 /// from the original Instruction, and IROrder is the ordinal position of
966 /// When an SDNode is created after the DAG is being built, both DebugLoc and
967 /// the IROrder are propagated from the original SDNode.
968 /// So SDLoc class provides two constructors besides the default one, one to
969 /// be used by the DAGBuilder, the other to be used by others.
977 SDLoc(const SDNode *N) : DL(N->getDebugLoc()), IROrder(N->getIROrder()) {}
978 SDLoc(const SDValue V) : SDLoc(V.getNode()) {}
979 SDLoc(const Instruction *I, int Order) : IROrder(Order) {
980 assert(Order >= 0 && "bad IROrder");
982 DL = I->getDebugLoc();
985 unsigned getIROrder() const { return IROrder; }
986 const DebugLoc &getDebugLoc() const { return DL; }
989 // Define inline functions from the SDValue class.
991 inline SDValue::SDValue(SDNode *node, unsigned resno)
992 : Node(node), ResNo(resno) {
993 // Explicitly check for !ResNo to avoid use-after-free, because there are
994 // callers that use SDValue(N, 0) with a deleted N to indicate successful
996 assert((!Node || !ResNo || ResNo < Node->getNumValues()) &&
997 "Invalid result number for the given node!");
998 assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
1001 inline unsigned SDValue::getOpcode() const {
1002 return Node->getOpcode();
1005 inline EVT SDValue::getValueType() const {
1006 return Node->getValueType(ResNo);
1009 inline unsigned SDValue::getNumOperands() const {
1010 return Node->getNumOperands();
1013 inline const SDValue &SDValue::getOperand(unsigned i) const {
1014 return Node->getOperand(i);
1017 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1018 return Node->getConstantOperandVal(i);
1021 inline bool SDValue::isTargetOpcode() const {
1022 return Node->isTargetOpcode();
1025 inline bool SDValue::isTargetMemoryOpcode() const {
1026 return Node->isTargetMemoryOpcode();
1029 inline bool SDValue::isMachineOpcode() const {
1030 return Node->isMachineOpcode();
1033 inline unsigned SDValue::getMachineOpcode() const {
1034 return Node->getMachineOpcode();
1037 inline bool SDValue::isUndef() const {
1038 return Node->isUndef();
1041 inline bool SDValue::use_empty() const {
1042 return !Node->hasAnyUseOfValue(ResNo);
1045 inline bool SDValue::hasOneUse() const {
1046 return Node->hasNUsesOfValue(1, ResNo);
1049 inline const DebugLoc &SDValue::getDebugLoc() const {
1050 return Node->getDebugLoc();
1053 inline void SDValue::dump() const {
1054 return Node->dump();
1057 inline void SDValue::dumpr() const {
1058 return Node->dumpr();
1061 // Define inline functions from the SDUse class.
1063 inline void SDUse::set(const SDValue &V) {
1064 if (Val.getNode()) removeFromList();
1066 if (V.getNode()) V.getNode()->addUse(*this);
1069 inline void SDUse::setInitial(const SDValue &V) {
1071 V.getNode()->addUse(*this);
1074 inline void SDUse::setNode(SDNode *N) {
1075 if (Val.getNode()) removeFromList();
1077 if (N) N->addUse(*this);
1080 /// This class is used to form a handle around another node that
1081 /// is persistent and is updated across invocations of replaceAllUsesWith on its
1082 /// operand. This node should be directly created by end-users and not added to
1083 /// the AllNodes list.
1084 class HandleSDNode : public SDNode {
1088 explicit HandleSDNode(SDValue X)
1089 : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1090 // HandleSDNodes are never inserted into the DAG, so they won't be
1091 // auto-numbered. Use ID 65535 as a sentinel.
1092 PersistentId = 0xffff;
1094 // Manually set up the operand list. This node type is special in that it's
1095 // always stack allocated and SelectionDAG does not manage its operands.
1096 // TODO: This should either (a) not be in the SDNode hierarchy, or (b) not
1105 const SDValue &getValue() const { return Op; }
1108 class AddrSpaceCastSDNode : public SDNode {
1110 unsigned SrcAddrSpace;
1111 unsigned DestAddrSpace;
1114 AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, EVT VT,
1115 unsigned SrcAS, unsigned DestAS);
1117 unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1118 unsigned getDestAddressSpace() const { return DestAddrSpace; }
1120 static bool classof(const SDNode *N) {
1121 return N->getOpcode() == ISD::ADDRSPACECAST;
1125 /// This is an abstract virtual class for memory operations.
1126 class MemSDNode : public SDNode {
1128 // VT of in-memory value.
1132 /// Memory reference information.
1133 MachineMemOperand *MMO;
1136 MemSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs,
1137 EVT MemoryVT, MachineMemOperand *MMO);
1139 bool readMem() const { return MMO->isLoad(); }
1140 bool writeMem() const { return MMO->isStore(); }
1142 /// Returns alignment and volatility of the memory access
1143 unsigned getOriginalAlignment() const {
1144 return MMO->getBaseAlignment();
1146 unsigned getAlignment() const {
1147 return MMO->getAlignment();
1150 /// Return the SubclassData value, without HasDebugValue. This contains an
1151 /// encoding of the volatile flag, as well as bits used by subclasses. This
1152 /// function should only be used to compute a FoldingSetNodeID value.
1153 /// The HasDebugValue bit is masked out because CSE map needs to match
1154 /// nodes with debug info with nodes without debug info.
1155 unsigned getRawSubclassData() const {
1158 char RawSDNodeBits[sizeof(uint16_t)];
1159 SDNodeBitfields SDNodeBits;
1161 memcpy(&RawSDNodeBits, &this->RawSDNodeBits, sizeof(this->RawSDNodeBits));
1162 SDNodeBits.HasDebugValue = 0;
1163 memcpy(&Data, &RawSDNodeBits, sizeof(RawSDNodeBits));
1167 bool isVolatile() const { return MemSDNodeBits.IsVolatile; }
1168 bool isNonTemporal() const { return MemSDNodeBits.IsNonTemporal; }
1169 bool isDereferenceable() const { return MemSDNodeBits.IsDereferenceable; }
1170 bool isInvariant() const { return MemSDNodeBits.IsInvariant; }
1172 // Returns the offset from the location of the access.
1173 int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1175 /// Returns the AA info that describes the dereference.
1176 AAMDNodes getAAInfo() const { return MMO->getAAInfo(); }
1178 /// Returns the Ranges that describes the dereference.
1179 const MDNode *getRanges() const { return MMO->getRanges(); }
1181 /// Return the synchronization scope for this memory operation.
1182 SynchronizationScope getSynchScope() const { return MMO->getSynchScope(); }
1184 /// Return the atomic ordering requirements for this memory operation. For
1185 /// cmpxchg atomic operations, return the atomic ordering requirements when
1187 AtomicOrdering getOrdering() const { return MMO->getOrdering(); }
1189 /// Return the type of the in-memory value.
1190 EVT getMemoryVT() const { return MemoryVT; }
1192 /// Return a MachineMemOperand object describing the memory
1193 /// reference performed by operation.
1194 MachineMemOperand *getMemOperand() const { return MMO; }
1196 const MachinePointerInfo &getPointerInfo() const {
1197 return MMO->getPointerInfo();
1200 /// Return the address space for the associated pointer
1201 unsigned getAddressSpace() const {
1202 return getPointerInfo().getAddrSpace();
1205 /// Update this MemSDNode's MachineMemOperand information
1206 /// to reflect the alignment of NewMMO, if it has a greater alignment.
1207 /// This must only be used when the new alignment applies to all users of
1208 /// this MachineMemOperand.
1209 void refineAlignment(const MachineMemOperand *NewMMO) {
1210 MMO->refineAlignment(NewMMO);
1213 const SDValue &getChain() const { return getOperand(0); }
1214 const SDValue &getBasePtr() const {
1215 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1218 // Methods to support isa and dyn_cast
1219 static bool classof(const SDNode *N) {
1220 // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1221 // with either an intrinsic or a target opcode.
1222 return N->getOpcode() == ISD::LOAD ||
1223 N->getOpcode() == ISD::STORE ||
1224 N->getOpcode() == ISD::PREFETCH ||
1225 N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1226 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1227 N->getOpcode() == ISD::ATOMIC_SWAP ||
1228 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1229 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1230 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1231 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1232 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1233 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1234 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1235 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1236 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1237 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1238 N->getOpcode() == ISD::ATOMIC_LOAD ||
1239 N->getOpcode() == ISD::ATOMIC_STORE ||
1240 N->getOpcode() == ISD::MLOAD ||
1241 N->getOpcode() == ISD::MSTORE ||
1242 N->getOpcode() == ISD::MGATHER ||
1243 N->getOpcode() == ISD::MSCATTER ||
1244 N->isMemIntrinsic() ||
1245 N->isTargetMemoryOpcode();
1249 /// This is an SDNode representing atomic operations.
1250 class AtomicSDNode : public MemSDNode {
1252 AtomicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTL,
1253 EVT MemVT, MachineMemOperand *MMO)
1254 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {}
1256 const SDValue &getBasePtr() const { return getOperand(1); }
1257 const SDValue &getVal() const { return getOperand(2); }
1259 /// Returns true if this SDNode represents cmpxchg atomic operation, false
1261 bool isCompareAndSwap() const {
1262 unsigned Op = getOpcode();
1263 return Op == ISD::ATOMIC_CMP_SWAP ||
1264 Op == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS;
1267 /// For cmpxchg atomic operations, return the atomic ordering requirements
1268 /// when store does not occur.
1269 AtomicOrdering getFailureOrdering() const {
1270 assert(isCompareAndSwap() && "Must be cmpxchg operation");
1271 return MMO->getFailureOrdering();
1274 // Methods to support isa and dyn_cast
1275 static bool classof(const SDNode *N) {
1276 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1277 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1278 N->getOpcode() == ISD::ATOMIC_SWAP ||
1279 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1280 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1281 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1282 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1283 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1284 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1285 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1286 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1287 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1288 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1289 N->getOpcode() == ISD::ATOMIC_LOAD ||
1290 N->getOpcode() == ISD::ATOMIC_STORE;
1294 /// This SDNode is used for target intrinsics that touch
1295 /// memory and need an associated MachineMemOperand. Its opcode may be
1296 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1297 /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1298 class MemIntrinsicSDNode : public MemSDNode {
1300 MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl,
1301 SDVTList VTs, EVT MemoryVT, MachineMemOperand *MMO)
1302 : MemSDNode(Opc, Order, dl, VTs, MemoryVT, MMO) {
1303 SDNodeBits.IsMemIntrinsic = true;
1306 // Methods to support isa and dyn_cast
1307 static bool classof(const SDNode *N) {
1308 // We lower some target intrinsics to their target opcode
1309 // early a node with a target opcode can be of this class
1310 return N->isMemIntrinsic() ||
1311 N->getOpcode() == ISD::PREFETCH ||
1312 N->isTargetMemoryOpcode();
1316 /// This SDNode is used to implement the code generator
1317 /// support for the llvm IR shufflevector instruction. It combines elements
1318 /// from two input vectors into a new input vector, with the selection and
1319 /// ordering of elements determined by an array of integers, referred to as
1320 /// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1321 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1322 /// An index of -1 is treated as undef, such that the code generator may put
1323 /// any value in the corresponding element of the result.
1324 class ShuffleVectorSDNode : public SDNode {
1325 // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1326 // is freed when the SelectionDAG object is destroyed.
1330 friend class SelectionDAG;
1332 ShuffleVectorSDNode(EVT VT, unsigned Order, const DebugLoc &dl, const int *M)
1333 : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {}
1336 ArrayRef<int> getMask() const {
1337 EVT VT = getValueType(0);
1338 return makeArrayRef(Mask, VT.getVectorNumElements());
1341 int getMaskElt(unsigned Idx) const {
1342 assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1346 bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1348 int getSplatIndex() const {
1349 assert(isSplat() && "Cannot get splat index for non-splat!");
1350 EVT VT = getValueType(0);
1351 for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
1355 llvm_unreachable("Splat with all undef indices?");
1358 static bool isSplatMask(const int *Mask, EVT VT);
1360 /// Change values in a shuffle permute mask assuming
1361 /// the two vector operands have swapped position.
1362 static void commuteMask(MutableArrayRef<int> Mask) {
1363 unsigned NumElems = Mask.size();
1364 for (unsigned i = 0; i != NumElems; ++i) {
1368 else if (idx < (int)NumElems)
1369 Mask[i] = idx + NumElems;
1371 Mask[i] = idx - NumElems;
1375 static bool classof(const SDNode *N) {
1376 return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1380 class ConstantSDNode : public SDNode {
1381 friend class SelectionDAG;
1383 const ConstantInt *Value;
1385 ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val,
1386 const DebugLoc &DL, EVT VT)
1387 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, 0, DL,
1390 ConstantSDNodeBits.IsOpaque = isOpaque;
1394 const ConstantInt *getConstantIntValue() const { return Value; }
1395 const APInt &getAPIntValue() const { return Value->getValue(); }
1396 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1397 int64_t getSExtValue() const { return Value->getSExtValue(); }
1399 bool isOne() const { return Value->isOne(); }
1400 bool isNullValue() const { return Value->isNullValue(); }
1401 bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1403 bool isOpaque() const { return ConstantSDNodeBits.IsOpaque; }
1405 static bool classof(const SDNode *N) {
1406 return N->getOpcode() == ISD::Constant ||
1407 N->getOpcode() == ISD::TargetConstant;
1411 uint64_t SDNode::getConstantOperandVal(unsigned Num) const {
1412 return cast<ConstantSDNode>(getOperand(Num))->getZExtValue();
1415 class ConstantFPSDNode : public SDNode {
1416 friend class SelectionDAG;
1418 const ConstantFP *Value;
1420 ConstantFPSDNode(bool isTarget, const ConstantFP *val, const DebugLoc &DL,
1422 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 0, DL,
1427 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1428 const ConstantFP *getConstantFPValue() const { return Value; }
1430 /// Return true if the value is positive or negative zero.
1431 bool isZero() const { return Value->isZero(); }
1433 /// Return true if the value is a NaN.
1434 bool isNaN() const { return Value->isNaN(); }
1436 /// Return true if the value is an infinity
1437 bool isInfinity() const { return Value->isInfinity(); }
1439 /// Return true if the value is negative.
1440 bool isNegative() const { return Value->isNegative(); }
1442 /// We don't rely on operator== working on double values, as
1443 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1444 /// As such, this method can be used to do an exact bit-for-bit comparison of
1445 /// two floating point values.
1447 /// We leave the version with the double argument here because it's just so
1448 /// convenient to write "2.0" and the like. Without this function we'd
1449 /// have to duplicate its logic everywhere it's called.
1450 bool isExactlyValue(double V) const {
1453 Tmp.convert(Value->getValueAPF().getSemantics(),
1454 APFloat::rmNearestTiesToEven, &ignored);
1455 return isExactlyValue(Tmp);
1457 bool isExactlyValue(const APFloat& V) const;
1459 static bool isValueValidForType(EVT VT, const APFloat& Val);
1461 static bool classof(const SDNode *N) {
1462 return N->getOpcode() == ISD::ConstantFP ||
1463 N->getOpcode() == ISD::TargetConstantFP;
1467 /// Returns true if \p V is a constant integer zero.
1468 bool isNullConstant(SDValue V);
1470 /// Returns true if \p V is an FP constant with a value of positive zero.
1471 bool isNullFPConstant(SDValue V);
1473 /// Returns true if \p V is an integer constant with all bits set.
1474 bool isAllOnesConstant(SDValue V);
1476 /// Returns true if \p V is a constant integer one.
1477 bool isOneConstant(SDValue V);
1479 /// Returns true if \p V is a bitwise not operation. Assumes that an all ones
1480 /// constant is canonicalized to be operand 1.
1481 bool isBitwiseNot(SDValue V);
1483 /// Returns the SDNode if it is a constant splat BuildVector or constant int.
1484 ConstantSDNode *isConstOrConstSplat(SDValue V);
1486 /// Returns the SDNode if it is a constant splat BuildVector or constant float.
1487 ConstantFPSDNode *isConstOrConstSplatFP(SDValue V);
1489 class GlobalAddressSDNode : public SDNode {
1490 friend class SelectionDAG;
1492 const GlobalValue *TheGlobal;
1494 unsigned char TargetFlags;
1496 GlobalAddressSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL,
1497 const GlobalValue *GA, EVT VT, int64_t o,
1498 unsigned char TargetFlags);
1501 const GlobalValue *getGlobal() const { return TheGlobal; }
1502 int64_t getOffset() const { return Offset; }
1503 unsigned char getTargetFlags() const { return TargetFlags; }
1504 // Return the address space this GlobalAddress belongs to.
1505 unsigned getAddressSpace() const;
1507 static bool classof(const SDNode *N) {
1508 return N->getOpcode() == ISD::GlobalAddress ||
1509 N->getOpcode() == ISD::TargetGlobalAddress ||
1510 N->getOpcode() == ISD::GlobalTLSAddress ||
1511 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1515 class FrameIndexSDNode : public SDNode {
1516 friend class SelectionDAG;
1520 FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1521 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1522 0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1526 int getIndex() const { return FI; }
1528 static bool classof(const SDNode *N) {
1529 return N->getOpcode() == ISD::FrameIndex ||
1530 N->getOpcode() == ISD::TargetFrameIndex;
1534 class JumpTableSDNode : public SDNode {
1535 friend class SelectionDAG;
1538 unsigned char TargetFlags;
1540 JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1541 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1542 0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1546 int getIndex() const { return JTI; }
1547 unsigned char getTargetFlags() const { return TargetFlags; }
1549 static bool classof(const SDNode *N) {
1550 return N->getOpcode() == ISD::JumpTable ||
1551 N->getOpcode() == ISD::TargetJumpTable;
1555 class ConstantPoolSDNode : public SDNode {
1556 friend class SelectionDAG;
1559 const Constant *ConstVal;
1560 MachineConstantPoolValue *MachineCPVal;
1562 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1563 unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
1564 unsigned char TargetFlags;
1566 ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1567 unsigned Align, unsigned char TF)
1568 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1569 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1571 assert(Offset >= 0 && "Offset is too large");
1575 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1576 EVT VT, int o, unsigned Align, unsigned char TF)
1577 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1578 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1580 assert(Offset >= 0 && "Offset is too large");
1581 Val.MachineCPVal = v;
1582 Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1586 bool isMachineConstantPoolEntry() const {
1590 const Constant *getConstVal() const {
1591 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1592 return Val.ConstVal;
1595 MachineConstantPoolValue *getMachineCPVal() const {
1596 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1597 return Val.MachineCPVal;
1600 int getOffset() const {
1601 return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1604 // Return the alignment of this constant pool object, which is either 0 (for
1605 // default alignment) or the desired value.
1606 unsigned getAlignment() const { return Alignment; }
1607 unsigned char getTargetFlags() const { return TargetFlags; }
1609 Type *getType() const;
1611 static bool classof(const SDNode *N) {
1612 return N->getOpcode() == ISD::ConstantPool ||
1613 N->getOpcode() == ISD::TargetConstantPool;
1617 /// Completely target-dependent object reference.
1618 class TargetIndexSDNode : public SDNode {
1619 friend class SelectionDAG;
1621 unsigned char TargetFlags;
1626 TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1627 : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
1628 TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1630 unsigned char getTargetFlags() const { return TargetFlags; }
1631 int getIndex() const { return Index; }
1632 int64_t getOffset() const { return Offset; }
1634 static bool classof(const SDNode *N) {
1635 return N->getOpcode() == ISD::TargetIndex;
1639 class BasicBlockSDNode : public SDNode {
1640 friend class SelectionDAG;
1642 MachineBasicBlock *MBB;
1644 /// Debug info is meaningful and potentially useful here, but we create
1645 /// blocks out of order when they're jumped to, which makes it a bit
1646 /// harder. Let's see if we need it first.
1647 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1648 : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
1652 MachineBasicBlock *getBasicBlock() const { return MBB; }
1654 static bool classof(const SDNode *N) {
1655 return N->getOpcode() == ISD::BasicBlock;
1659 /// A "pseudo-class" with methods for operating on BUILD_VECTORs.
1660 class BuildVectorSDNode : public SDNode {
1662 // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1663 explicit BuildVectorSDNode() = delete;
1665 /// Check if this is a constant splat, and if so, find the
1666 /// smallest element size that splats the vector. If MinSplatBits is
1667 /// nonzero, the element size must be at least that large. Note that the
1668 /// splat element may be the entire vector (i.e., a one element vector).
1669 /// Returns the splat element value in SplatValue. Any undefined bits in
1670 /// that value are zero, and the corresponding bits in the SplatUndef mask
1671 /// are set. The SplatBitSize value is set to the splat element size in
1672 /// bits. HasAnyUndefs is set to true if any bits in the vector are
1673 /// undefined. isBigEndian describes the endianness of the target.
1674 bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1675 unsigned &SplatBitSize, bool &HasAnyUndefs,
1676 unsigned MinSplatBits = 0,
1677 bool isBigEndian = false) const;
1679 /// \brief Returns the splatted value or a null value if this is not a splat.
1681 /// If passed a non-null UndefElements bitvector, it will resize it to match
1682 /// the vector width and set the bits where elements are undef.
1683 SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
1685 /// \brief Returns the splatted constant 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 getConstantSplatNode(BitVector *UndefElements = nullptr) const;
1693 /// \brief Returns the splatted constant FP or null if this is not a constant
1696 /// If passed a non-null UndefElements bitvector, it will resize it to match
1697 /// the vector width and set the bits where elements are undef.
1699 getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
1701 /// \brief If this is a constant FP splat and the splatted constant FP is an
1702 /// exact power or 2, return the log base 2 integer value. Otherwise,
1705 /// The BitWidth specifies the necessary bit precision.
1706 int32_t getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements,
1707 uint32_t BitWidth) const;
1709 bool isConstant() const;
1711 static inline bool classof(const SDNode *N) {
1712 return N->getOpcode() == ISD::BUILD_VECTOR;
1716 /// An SDNode that holds an arbitrary LLVM IR Value. This is
1717 /// used when the SelectionDAG needs to make a simple reference to something
1718 /// in the LLVM IR representation.
1720 class SrcValueSDNode : public SDNode {
1721 friend class SelectionDAG;
1725 /// Create a SrcValue for a general value.
1726 explicit SrcValueSDNode(const Value *v)
1727 : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1730 /// Return the contained Value.
1731 const Value *getValue() const { return V; }
1733 static bool classof(const SDNode *N) {
1734 return N->getOpcode() == ISD::SRCVALUE;
1738 class MDNodeSDNode : public SDNode {
1739 friend class SelectionDAG;
1743 explicit MDNodeSDNode(const MDNode *md)
1744 : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
1748 const MDNode *getMD() const { return MD; }
1750 static bool classof(const SDNode *N) {
1751 return N->getOpcode() == ISD::MDNODE_SDNODE;
1755 class RegisterSDNode : public SDNode {
1756 friend class SelectionDAG;
1760 RegisterSDNode(unsigned reg, EVT VT)
1761 : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {}
1764 unsigned getReg() const { return Reg; }
1766 static bool classof(const SDNode *N) {
1767 return N->getOpcode() == ISD::Register;
1771 class RegisterMaskSDNode : public SDNode {
1772 friend class SelectionDAG;
1774 // The memory for RegMask is not owned by the node.
1775 const uint32_t *RegMask;
1777 RegisterMaskSDNode(const uint32_t *mask)
1778 : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
1782 const uint32_t *getRegMask() const { return RegMask; }
1784 static bool classof(const SDNode *N) {
1785 return N->getOpcode() == ISD::RegisterMask;
1789 class BlockAddressSDNode : public SDNode {
1790 friend class SelectionDAG;
1792 const BlockAddress *BA;
1794 unsigned char TargetFlags;
1796 BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1797 int64_t o, unsigned char Flags)
1798 : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
1799 BA(ba), Offset(o), TargetFlags(Flags) {
1803 const BlockAddress *getBlockAddress() const { return BA; }
1804 int64_t getOffset() const { return Offset; }
1805 unsigned char getTargetFlags() const { return TargetFlags; }
1807 static bool classof(const SDNode *N) {
1808 return N->getOpcode() == ISD::BlockAddress ||
1809 N->getOpcode() == ISD::TargetBlockAddress;
1813 class EHLabelSDNode : public SDNode {
1814 friend class SelectionDAG;
1818 EHLabelSDNode(unsigned Order, const DebugLoc &dl, MCSymbol *L)
1819 : SDNode(ISD::EH_LABEL, Order, dl, getSDVTList(MVT::Other)), Label(L) {}
1822 MCSymbol *getLabel() const { return Label; }
1824 static bool classof(const SDNode *N) {
1825 return N->getOpcode() == ISD::EH_LABEL;
1829 class ExternalSymbolSDNode : public SDNode {
1830 friend class SelectionDAG;
1833 unsigned char TargetFlags;
1835 ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1836 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1837 0, DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {}
1840 const char *getSymbol() const { return Symbol; }
1841 unsigned char getTargetFlags() const { return TargetFlags; }
1843 static bool classof(const SDNode *N) {
1844 return N->getOpcode() == ISD::ExternalSymbol ||
1845 N->getOpcode() == ISD::TargetExternalSymbol;
1849 class MCSymbolSDNode : public SDNode {
1850 friend class SelectionDAG;
1854 MCSymbolSDNode(MCSymbol *Symbol, EVT VT)
1855 : SDNode(ISD::MCSymbol, 0, DebugLoc(), getSDVTList(VT)), Symbol(Symbol) {}
1858 MCSymbol *getMCSymbol() const { return Symbol; }
1860 static bool classof(const SDNode *N) {
1861 return N->getOpcode() == ISD::MCSymbol;
1865 class CondCodeSDNode : public SDNode {
1866 friend class SelectionDAG;
1868 ISD::CondCode Condition;
1870 explicit CondCodeSDNode(ISD::CondCode Cond)
1871 : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1875 ISD::CondCode get() const { return Condition; }
1877 static bool classof(const SDNode *N) {
1878 return N->getOpcode() == ISD::CONDCODE;
1882 /// This class is used to represent EVT's, which are used
1883 /// to parameterize some operations.
1884 class VTSDNode : public SDNode {
1885 friend class SelectionDAG;
1889 explicit VTSDNode(EVT VT)
1890 : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1894 EVT getVT() const { return ValueType; }
1896 static bool classof(const SDNode *N) {
1897 return N->getOpcode() == ISD::VALUETYPE;
1901 /// Base class for LoadSDNode and StoreSDNode
1902 class LSBaseSDNode : public MemSDNode {
1904 LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl,
1905 SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
1906 MachineMemOperand *MMO)
1907 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
1908 LSBaseSDNodeBits.AddressingMode = AM;
1909 assert(getAddressingMode() == AM && "Value truncated");
1912 const SDValue &getOffset() const {
1913 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1916 /// Return the addressing mode for this load or store:
1917 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
1918 ISD::MemIndexedMode getAddressingMode() const {
1919 return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
1922 /// Return true if this is a pre/post inc/dec load/store.
1923 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
1925 /// Return true if this is NOT a pre/post inc/dec load/store.
1926 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
1928 static bool classof(const SDNode *N) {
1929 return N->getOpcode() == ISD::LOAD ||
1930 N->getOpcode() == ISD::STORE;
1934 /// This class is used to represent ISD::LOAD nodes.
1935 class LoadSDNode : public LSBaseSDNode {
1936 friend class SelectionDAG;
1938 LoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
1939 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
1940 MachineMemOperand *MMO)
1941 : LSBaseSDNode(ISD::LOAD, Order, dl, VTs, AM, MemVT, MMO) {
1942 LoadSDNodeBits.ExtTy = ETy;
1943 assert(readMem() && "Load MachineMemOperand is not a load!");
1944 assert(!writeMem() && "Load MachineMemOperand is a store!");
1948 /// Return whether this is a plain node,
1949 /// or one of the varieties of value-extending loads.
1950 ISD::LoadExtType getExtensionType() const {
1951 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
1954 const SDValue &getBasePtr() const { return getOperand(1); }
1955 const SDValue &getOffset() const { return getOperand(2); }
1957 static bool classof(const SDNode *N) {
1958 return N->getOpcode() == ISD::LOAD;
1962 /// This class is used to represent ISD::STORE nodes.
1963 class StoreSDNode : public LSBaseSDNode {
1964 friend class SelectionDAG;
1966 StoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
1967 ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
1968 MachineMemOperand *MMO)
1969 : LSBaseSDNode(ISD::STORE, Order, dl, VTs, AM, MemVT, MMO) {
1970 StoreSDNodeBits.IsTruncating = isTrunc;
1971 assert(!readMem() && "Store MachineMemOperand is a load!");
1972 assert(writeMem() && "Store MachineMemOperand is not a store!");
1976 /// Return true if the op does a truncation before store.
1977 /// For integers this is the same as doing a TRUNCATE and storing the result.
1978 /// For floats, it is the same as doing an FP_ROUND and storing the result.
1979 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
1981 const SDValue &getValue() const { return getOperand(1); }
1982 const SDValue &getBasePtr() const { return getOperand(2); }
1983 const SDValue &getOffset() const { return getOperand(3); }
1985 static bool classof(const SDNode *N) {
1986 return N->getOpcode() == ISD::STORE;
1990 /// This base class is used to represent MLOAD and MSTORE nodes
1991 class MaskedLoadStoreSDNode : public MemSDNode {
1993 friend class SelectionDAG;
1995 MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order,
1996 const DebugLoc &dl, SDVTList VTs, EVT MemVT,
1997 MachineMemOperand *MMO)
1998 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2000 // In the both nodes address is Op1, mask is Op2:
2001 // MaskedLoadSDNode (Chain, ptr, mask, src0), src0 is a passthru value
2002 // MaskedStoreSDNode (Chain, ptr, mask, data)
2003 // Mask is a vector of i1 elements
2004 const SDValue &getBasePtr() const { return getOperand(1); }
2005 const SDValue &getMask() const { return getOperand(2); }
2007 static bool classof(const SDNode *N) {
2008 return N->getOpcode() == ISD::MLOAD ||
2009 N->getOpcode() == ISD::MSTORE;
2013 /// This class is used to represent an MLOAD node
2014 class MaskedLoadSDNode : public MaskedLoadStoreSDNode {
2016 friend class SelectionDAG;
2018 MaskedLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2019 ISD::LoadExtType ETy, bool IsExpanding, EVT MemVT,
2020 MachineMemOperand *MMO)
2021 : MaskedLoadStoreSDNode(ISD::MLOAD, Order, dl, VTs, MemVT, MMO) {
2022 LoadSDNodeBits.ExtTy = ETy;
2023 LoadSDNodeBits.IsExpanding = IsExpanding;
2026 ISD::LoadExtType getExtensionType() const {
2027 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2030 const SDValue &getSrc0() const { return getOperand(3); }
2031 static bool classof(const SDNode *N) {
2032 return N->getOpcode() == ISD::MLOAD;
2035 bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
2038 /// This class is used to represent an MSTORE node
2039 class MaskedStoreSDNode : public MaskedLoadStoreSDNode {
2041 friend class SelectionDAG;
2043 MaskedStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2044 bool isTrunc, bool isCompressing, EVT MemVT,
2045 MachineMemOperand *MMO)
2046 : MaskedLoadStoreSDNode(ISD::MSTORE, Order, dl, VTs, MemVT, MMO) {
2047 StoreSDNodeBits.IsTruncating = isTrunc;
2048 StoreSDNodeBits.IsCompressing = isCompressing;
2051 /// Return true if the op does a truncation before store.
2052 /// For integers this is the same as doing a TRUNCATE and storing the result.
2053 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2054 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2056 /// Returns true if the op does a compression to the vector before storing.
2057 /// The node contiguously stores the active elements (integers or floats)
2058 /// in src (those with their respective bit set in writemask k) to unaligned
2059 /// memory at base_addr.
2060 bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
2062 const SDValue &getValue() const { return getOperand(3); }
2064 static bool classof(const SDNode *N) {
2065 return N->getOpcode() == ISD::MSTORE;
2069 /// This is a base class used to represent
2070 /// MGATHER and MSCATTER nodes
2072 class MaskedGatherScatterSDNode : public MemSDNode {
2074 friend class SelectionDAG;
2076 MaskedGatherScatterSDNode(ISD::NodeType NodeTy, unsigned Order,
2077 const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2078 MachineMemOperand *MMO)
2079 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2081 // In the both nodes address is Op1, mask is Op2:
2082 // MaskedGatherSDNode (Chain, src0, mask, base, index), src0 is a passthru value
2083 // MaskedScatterSDNode (Chain, value, mask, base, index)
2084 // Mask is a vector of i1 elements
2085 const SDValue &getBasePtr() const { return getOperand(3); }
2086 const SDValue &getIndex() const { return getOperand(4); }
2087 const SDValue &getMask() const { return getOperand(2); }
2088 const SDValue &getValue() const { return getOperand(1); }
2090 static bool classof(const SDNode *N) {
2091 return N->getOpcode() == ISD::MGATHER ||
2092 N->getOpcode() == ISD::MSCATTER;
2096 /// This class is used to represent an MGATHER node
2098 class MaskedGatherSDNode : public MaskedGatherScatterSDNode {
2100 friend class SelectionDAG;
2102 MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2103 EVT MemVT, MachineMemOperand *MMO)
2104 : MaskedGatherScatterSDNode(ISD::MGATHER, Order, dl, VTs, MemVT, MMO) {}
2106 static bool classof(const SDNode *N) {
2107 return N->getOpcode() == ISD::MGATHER;
2111 /// This class is used to represent an MSCATTER node
2113 class MaskedScatterSDNode : public MaskedGatherScatterSDNode {
2115 friend class SelectionDAG;
2117 MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2118 EVT MemVT, MachineMemOperand *MMO)
2119 : MaskedGatherScatterSDNode(ISD::MSCATTER, Order, dl, VTs, MemVT, MMO) {}
2121 static bool classof(const SDNode *N) {
2122 return N->getOpcode() == ISD::MSCATTER;
2126 /// An SDNode that represents everything that will be needed
2127 /// to construct a MachineInstr. These nodes are created during the
2128 /// instruction selection proper phase.
2129 class MachineSDNode : public SDNode {
2131 typedef MachineMemOperand **mmo_iterator;
2134 friend class SelectionDAG;
2136 MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL, SDVTList VTs)
2137 : SDNode(Opc, Order, DL, VTs) {}
2139 /// Memory reference descriptions for this instruction.
2140 mmo_iterator MemRefs = nullptr;
2141 mmo_iterator MemRefsEnd = nullptr;
2144 mmo_iterator memoperands_begin() const { return MemRefs; }
2145 mmo_iterator memoperands_end() const { return MemRefsEnd; }
2146 bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
2148 /// Assign this MachineSDNodes's memory reference descriptor
2149 /// list. This does not transfer ownership.
2150 void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
2151 for (mmo_iterator MMI = NewMemRefs, MME = NewMemRefsEnd; MMI != MME; ++MMI)
2152 assert(*MMI && "Null mem ref detected!");
2153 MemRefs = NewMemRefs;
2154 MemRefsEnd = NewMemRefsEnd;
2157 static bool classof(const SDNode *N) {
2158 return N->isMachineOpcode();
2162 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
2163 SDNode, ptrdiff_t> {
2167 SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2170 bool operator==(const SDNodeIterator& x) const {
2171 return Operand == x.Operand;
2173 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2175 pointer operator*() const {
2176 return Node->getOperand(Operand).getNode();
2178 pointer operator->() const { return operator*(); }
2180 SDNodeIterator& operator++() { // Preincrement
2184 SDNodeIterator operator++(int) { // Postincrement
2185 SDNodeIterator tmp = *this; ++*this; return tmp;
2187 size_t operator-(SDNodeIterator Other) const {
2188 assert(Node == Other.Node &&
2189 "Cannot compare iterators of two different nodes!");
2190 return Operand - Other.Operand;
2193 static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
2194 static SDNodeIterator end (const SDNode *N) {
2195 return SDNodeIterator(N, N->getNumOperands());
2198 unsigned getOperand() const { return Operand; }
2199 const SDNode *getNode() const { return Node; }
2202 template <> struct GraphTraits<SDNode*> {
2203 typedef SDNode *NodeRef;
2204 typedef SDNodeIterator ChildIteratorType;
2206 static NodeRef getEntryNode(SDNode *N) { return N; }
2208 static ChildIteratorType child_begin(NodeRef N) {
2209 return SDNodeIterator::begin(N);
2212 static ChildIteratorType child_end(NodeRef N) {
2213 return SDNodeIterator::end(N);
2217 /// A representation of the largest SDNode, for use in sizeof().
2219 /// This needs to be a union because the largest node differs on 32 bit systems
2220 /// with 4 and 8 byte pointer alignment, respectively.
2221 typedef AlignedCharArrayUnion<AtomicSDNode, TargetIndexSDNode,
2222 BlockAddressSDNode, GlobalAddressSDNode>
2225 /// The SDNode class with the greatest alignment requirement.
2226 typedef GlobalAddressSDNode MostAlignedSDNode;
2230 /// Returns true if the specified node is a non-extending and unindexed load.
2231 inline bool isNormalLoad(const SDNode *N) {
2232 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2233 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2234 Ld->getAddressingMode() == ISD::UNINDEXED;
2237 /// Returns true if the specified node is a non-extending load.
2238 inline bool isNON_EXTLoad(const SDNode *N) {
2239 return isa<LoadSDNode>(N) &&
2240 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2243 /// Returns true if the specified node is a EXTLOAD.
2244 inline bool isEXTLoad(const SDNode *N) {
2245 return isa<LoadSDNode>(N) &&
2246 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2249 /// Returns true if the specified node is a SEXTLOAD.
2250 inline bool isSEXTLoad(const SDNode *N) {
2251 return isa<LoadSDNode>(N) &&
2252 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2255 /// Returns true if the specified node is a ZEXTLOAD.
2256 inline bool isZEXTLoad(const SDNode *N) {
2257 return isa<LoadSDNode>(N) &&
2258 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2261 /// Returns true if the specified node is an unindexed load.
2262 inline bool isUNINDEXEDLoad(const SDNode *N) {
2263 return isa<LoadSDNode>(N) &&
2264 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2267 /// Returns true if the specified node is a non-truncating
2268 /// and unindexed store.
2269 inline bool isNormalStore(const SDNode *N) {
2270 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2271 return St && !St->isTruncatingStore() &&
2272 St->getAddressingMode() == ISD::UNINDEXED;
2275 /// Returns true if the specified node is a non-truncating store.
2276 inline bool isNON_TRUNCStore(const SDNode *N) {
2277 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2280 /// Returns true if the specified node is a truncating store.
2281 inline bool isTRUNCStore(const SDNode *N) {
2282 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2285 /// Returns true if the specified node is an unindexed store.
2286 inline bool isUNINDEXEDStore(const SDNode *N) {
2287 return isa<StoreSDNode>(N) &&
2288 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2291 } // end namespace ISD
2293 } // end namespace llvm
2295 #endif // LLVM_CODEGEN_SELECTIONDAGNODES_H