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/BitVector.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/STLExtras.h"
26 #include "llvm/ADT/SmallPtrSet.h"
27 #include "llvm/ADT/SmallVector.h"
28 #include "llvm/ADT/ilist_node.h"
29 #include "llvm/ADT/iterator_range.h"
30 #include "llvm/CodeGen/ISDOpcodes.h"
31 #include "llvm/CodeGen/MachineMemOperand.h"
32 #include "llvm/CodeGen/ValueTypes.h"
33 #include "llvm/IR/Constants.h"
34 #include "llvm/IR/DebugLoc.h"
35 #include "llvm/IR/Instructions.h"
36 #include "llvm/Support/DataTypes.h"
37 #include "llvm/Support/MathExtras.h"
44 class MachineBasicBlock;
45 class MachineConstantPoolValue;
49 template <typename T> struct DenseMapInfo;
50 template <typename T> struct simplify_type;
51 template <typename T> struct ilist_traits;
53 /// isBinOpWithFlags - Returns true if the opcode is a binary operation
55 static bool isBinOpWithFlags(unsigned Opcode) {
71 void checkForCycles(const SDNode *N, const SelectionDAG *DAG = nullptr,
74 /// SDVTList - This represents a list of ValueType's that has been intern'd by
75 /// a SelectionDAG. Instances of this simple value class are returned by
76 /// SelectionDAG::getVTList(...).
86 /// isBuildVectorAllOnes - Return true if the specified node is a
87 /// BUILD_VECTOR where all of the elements are ~0 or undef.
88 bool isBuildVectorAllOnes(const SDNode *N);
90 /// isBuildVectorAllZeros - Return true if the specified node is a
91 /// BUILD_VECTOR where all of the elements are 0 or undef.
92 bool isBuildVectorAllZeros(const SDNode *N);
94 /// \brief Return true if the specified node is a BUILD_VECTOR node of
95 /// all ConstantSDNode or undef.
96 bool isBuildVectorOfConstantSDNodes(const SDNode *N);
98 /// isScalarToVector - Return true if the specified node is a
99 /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
100 /// element is not an undef.
101 bool isScalarToVector(const SDNode *N);
103 /// allOperandsUndef - Return true if the node has at least one operand
104 /// and all operands of the specified node are ISD::UNDEF.
105 bool allOperandsUndef(const SDNode *N);
106 } // end llvm:ISD namespace
108 //===----------------------------------------------------------------------===//
109 /// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
110 /// values as the result of a computation. Many nodes return multiple values,
111 /// from loads (which define a token and a return value) to ADDC (which returns
112 /// a result and a carry value), to calls (which may return an arbitrary number
115 /// As such, each use of a SelectionDAG computation must indicate the node that
116 /// computes it as well as which return value to use from that node. This pair
117 /// of information is represented with the SDValue value type.
120 friend struct DenseMapInfo<SDValue>;
122 SDNode *Node; // The node defining the value we are using.
123 unsigned ResNo; // Which return value of the node we are using.
125 SDValue() : Node(nullptr), ResNo(0) {}
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 // isOperandOf - Return true if this node is an operand of N.
157 bool isOperandOf(SDNode *N) const;
159 /// getValueType - Return the ValueType of the referenced return value.
161 inline EVT getValueType() const;
163 /// Return the simple ValueType of the referenced return value.
164 MVT getSimpleValueType() const {
165 return getValueType().getSimpleVT();
168 /// getValueSizeInBits - Returns the size of the value in bits.
170 unsigned getValueSizeInBits() const {
171 return getValueType().getSizeInBits();
174 unsigned getScalarValueSizeInBits() const {
175 return getValueType().getScalarType().getSizeInBits();
178 // Forwarding methods - These forward to the corresponding methods in SDNode.
179 inline unsigned getOpcode() const;
180 inline unsigned getNumOperands() const;
181 inline const SDValue &getOperand(unsigned i) const;
182 inline uint64_t getConstantOperandVal(unsigned i) const;
183 inline bool isTargetMemoryOpcode() const;
184 inline bool isTargetOpcode() const;
185 inline bool isMachineOpcode() const;
186 inline unsigned getMachineOpcode() const;
187 inline const DebugLoc &getDebugLoc() const;
188 inline void dump() const;
189 inline void dumpr() const;
191 /// reachesChainWithoutSideEffects - Return true if this operand (which must
192 /// be a chain) reaches the specified operand without crossing any
193 /// side-effecting instructions. In practice, this looks through token
194 /// factors and non-volatile loads. In order to remain efficient, this only
195 /// looks a couple of nodes in, it does not do an exhaustive search.
196 bool reachesChainWithoutSideEffects(SDValue Dest,
197 unsigned Depth = 2) const;
199 /// use_empty - Return true if there are no nodes using value ResNo
202 inline bool use_empty() const;
204 /// hasOneUse - Return true if there is exactly one node using value
207 inline bool hasOneUse() const;
211 template<> struct DenseMapInfo<SDValue> {
212 static inline SDValue getEmptyKey() {
217 static inline SDValue getTombstoneKey() {
222 static unsigned getHashValue(const SDValue &Val) {
223 return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
224 (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
226 static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
230 template <> struct isPodLike<SDValue> { static const bool value = true; };
233 /// simplify_type specializations - Allow casting operators to work directly on
234 /// SDValues as if they were SDNode*'s.
235 template<> struct simplify_type<SDValue> {
236 typedef SDNode* SimpleType;
237 static SimpleType getSimplifiedValue(SDValue &Val) {
238 return Val.getNode();
241 template<> struct simplify_type<const SDValue> {
242 typedef /*const*/ SDNode* SimpleType;
243 static SimpleType getSimplifiedValue(const SDValue &Val) {
244 return Val.getNode();
248 /// SDUse - Represents a use of a SDNode. This class holds an SDValue,
249 /// which records the SDNode being used and the result number, a
250 /// pointer to the SDNode using the value, and Next and Prev pointers,
251 /// which link together all the uses of an SDNode.
254 /// Val - The value being used.
256 /// User - The user of this value.
258 /// Prev, Next - Pointers to the uses list of the SDNode referred by
262 SDUse(const SDUse &U) = delete;
263 void operator=(const SDUse &U) = delete;
266 SDUse() : Val(), User(nullptr), Prev(nullptr), Next(nullptr) {}
268 /// Normally SDUse will just implicitly convert to an SDValue that it holds.
269 operator const SDValue&() const { return Val; }
271 /// If implicit conversion to SDValue doesn't work, the get() method returns
273 const SDValue &get() const { return Val; }
275 /// getUser - This returns the SDNode that contains this Use.
276 SDNode *getUser() { return User; }
278 /// getNext - Get the next SDUse in the use list.
279 SDUse *getNext() const { return Next; }
281 /// getNode - Convenience function for get().getNode().
282 SDNode *getNode() const { return Val.getNode(); }
283 /// getResNo - Convenience function for get().getResNo().
284 unsigned getResNo() const { return Val.getResNo(); }
285 /// getValueType - Convenience function for get().getValueType().
286 EVT getValueType() const { return Val.getValueType(); }
288 /// operator== - Convenience function for get().operator==
289 bool operator==(const SDValue &V) const {
293 /// operator!= - Convenience function for get().operator!=
294 bool operator!=(const SDValue &V) const {
298 /// operator< - Convenience function for get().operator<
299 bool operator<(const SDValue &V) const {
304 friend class SelectionDAG;
307 void setUser(SDNode *p) { User = p; }
309 /// set - Remove this use from its existing use list, assign it the
310 /// given value, and add it to the new value's node's use list.
311 inline void set(const SDValue &V);
312 /// setInitial - like set, but only supports initializing a newly-allocated
313 /// SDUse with a non-null value.
314 inline void setInitial(const SDValue &V);
315 /// setNode - like set, but only sets the Node portion of the value,
316 /// leaving the ResNo portion unmodified.
317 inline void setNode(SDNode *N);
319 void addToList(SDUse **List) {
321 if (Next) Next->Prev = &Next;
326 void removeFromList() {
328 if (Next) Next->Prev = Prev;
332 /// simplify_type specializations - Allow casting operators to work directly on
333 /// SDValues as if they were SDNode*'s.
334 template<> struct simplify_type<SDUse> {
335 typedef SDNode* SimpleType;
336 static SimpleType getSimplifiedValue(SDUse &Val) {
337 return Val.getNode();
342 /// SDNode - Represents one node in the SelectionDAG.
344 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
346 /// NodeType - The operation that this node performs.
350 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
351 /// then they will be delete[]'d when the node is destroyed.
352 uint16_t OperandsNeedDelete : 1;
354 /// HasDebugValue - This tracks whether this node has one or more dbg_value
355 /// nodes corresponding to it.
356 uint16_t HasDebugValue : 1;
359 /// SubclassData - This member is defined by this class, but is not used for
360 /// anything. Subclasses can use it to hold whatever state they find useful.
361 /// This field is initialized to zero by the ctor.
362 uint16_t SubclassData : 14;
365 /// NodeId - Unique id per SDNode in the DAG.
368 /// OperandList - The values that are used by this operation.
372 /// ValueList - The types of the values this node defines. SDNode's may
373 /// define multiple values simultaneously.
374 const EVT *ValueList;
376 /// UseList - List of uses for this SDNode.
379 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
380 unsigned short NumOperands, NumValues;
382 /// debugLoc - source line information.
385 // The ordering of the SDNodes. It roughly corresponds to the ordering of the
386 // original LLVM instructions.
387 // This is used for turning off scheduling, because we'll forgo
388 // the normal scheduling algorithms and output the instructions according to
392 /// getValueTypeList - Return a pointer to the specified value type.
393 static const EVT *getValueTypeList(EVT VT);
395 friend class SelectionDAG;
396 friend struct ilist_traits<SDNode>;
399 //===--------------------------------------------------------------------===//
403 /// getOpcode - Return the SelectionDAG opcode value for this node. For
404 /// pre-isel nodes (those for which isMachineOpcode returns false), these
405 /// are the opcode values in the ISD and <target>ISD namespaces. For
406 /// post-isel opcodes, see getMachineOpcode.
407 unsigned getOpcode() const { return (unsigned short)NodeType; }
409 /// isTargetOpcode - Test if this node has a target-specific opcode (in the
410 /// \<target\>ISD namespace).
411 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
413 /// isTargetMemoryOpcode - Test if this node has a target-specific
414 /// memory-referencing opcode (in the \<target\>ISD namespace and
415 /// greater than FIRST_TARGET_MEMORY_OPCODE).
416 bool isTargetMemoryOpcode() const {
417 return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
420 /// Test if this node is a memory intrinsic (with valid pointer information).
421 /// INTRINSIC_W_CHAIN and INTRINSIC_VOID nodes are sometimes created for
422 /// non-memory intrinsics (with chains) that are not really instances of
423 /// MemSDNode. For such nodes, we need some extra state to determine the
424 /// proper classof relationship.
425 bool isMemIntrinsic() const {
426 return (NodeType == ISD::INTRINSIC_W_CHAIN ||
427 NodeType == ISD::INTRINSIC_VOID) && ((SubclassData >> 13) & 1);
430 /// isMachineOpcode - Test if this node has a post-isel opcode, directly
431 /// corresponding to a MachineInstr opcode.
432 bool isMachineOpcode() const { return NodeType < 0; }
434 /// getMachineOpcode - This may only be called if isMachineOpcode returns
435 /// true. It returns the MachineInstr opcode value that the node's opcode
437 unsigned getMachineOpcode() const {
438 assert(isMachineOpcode() && "Not a MachineInstr opcode!");
442 /// getHasDebugValue - get this bit.
443 bool getHasDebugValue() const { return HasDebugValue; }
445 /// setHasDebugValue - set this bit.
446 void setHasDebugValue(bool b) { HasDebugValue = b; }
448 /// use_empty - Return true if there are no uses of this node.
450 bool use_empty() const { return UseList == nullptr; }
452 /// hasOneUse - Return true if there is exactly one use of this node.
454 bool hasOneUse() const {
455 return !use_empty() && std::next(use_begin()) == use_end();
458 /// use_size - Return the number of uses of this node. This method takes
459 /// time proportional to the number of uses.
461 size_t use_size() const { return std::distance(use_begin(), use_end()); }
463 /// getNodeId - Return the unique node id.
465 int getNodeId() const { return NodeId; }
467 /// setNodeId - Set unique node id.
468 void setNodeId(int Id) { NodeId = Id; }
470 /// getIROrder - Return the node ordering.
472 unsigned getIROrder() const { return IROrder; }
474 /// setIROrder - Set the node ordering.
476 void setIROrder(unsigned Order) { IROrder = Order; }
478 /// getDebugLoc - Return the source location info.
479 const DebugLoc &getDebugLoc() const { return debugLoc; }
481 /// setDebugLoc - Set source location info. Try to avoid this, putting
482 /// it in the constructor is preferable.
483 void setDebugLoc(DebugLoc dl) { debugLoc = std::move(dl); }
485 /// use_iterator - This class provides iterator support for SDUse
486 /// operands that use a specific SDNode.
488 : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
490 explicit use_iterator(SDUse *op) : Op(op) {
494 typedef std::iterator<std::forward_iterator_tag,
495 SDUse, ptrdiff_t>::reference reference;
496 typedef std::iterator<std::forward_iterator_tag,
497 SDUse, ptrdiff_t>::pointer pointer;
499 use_iterator(const use_iterator &I) : Op(I.Op) {}
500 use_iterator() : Op(nullptr) {}
502 bool operator==(const use_iterator &x) const {
505 bool operator!=(const use_iterator &x) const {
506 return !operator==(x);
509 /// atEnd - return true if this iterator is at the end of uses list.
510 bool atEnd() const { return Op == nullptr; }
512 // Iterator traversal: forward iteration only.
513 use_iterator &operator++() { // Preincrement
514 assert(Op && "Cannot increment end iterator!");
519 use_iterator operator++(int) { // Postincrement
520 use_iterator tmp = *this; ++*this; return tmp;
523 /// Retrieve a pointer to the current user node.
524 SDNode *operator*() const {
525 assert(Op && "Cannot dereference end iterator!");
526 return Op->getUser();
529 SDNode *operator->() const { return operator*(); }
531 SDUse &getUse() const { return *Op; }
533 /// getOperandNo - Retrieve the operand # of this use in its user.
535 unsigned getOperandNo() const {
536 assert(Op && "Cannot dereference end iterator!");
537 return (unsigned)(Op - Op->getUser()->OperandList);
541 /// use_begin/use_end - Provide iteration support to walk over all uses
544 use_iterator use_begin() const {
545 return use_iterator(UseList);
548 static use_iterator use_end() { return use_iterator(nullptr); }
550 inline iterator_range<use_iterator> uses() {
551 return iterator_range<use_iterator>(use_begin(), use_end());
553 inline iterator_range<use_iterator> uses() const {
554 return iterator_range<use_iterator>(use_begin(), use_end());
557 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
558 /// indicated value. This method ignores uses of other values defined by this
560 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
562 /// hasAnyUseOfValue - Return true if there are any use of the indicated
563 /// value. This method ignores uses of other values defined by this operation.
564 bool hasAnyUseOfValue(unsigned Value) const;
566 /// isOnlyUserOf - Return true if this node is the only use of N.
568 bool isOnlyUserOf(SDNode *N) const;
570 /// isOperandOf - Return true if this node is an operand of N.
572 bool isOperandOf(SDNode *N) const;
574 /// isPredecessorOf - Return true if this node is a predecessor of N.
575 /// NOTE: Implemented on top of hasPredecessor and every bit as
576 /// expensive. Use carefully.
577 bool isPredecessorOf(const SDNode *N) const {
578 return N->hasPredecessor(this);
581 /// hasPredecessor - Return true if N is a predecessor of this node.
582 /// N is either an operand of this node, or can be reached by recursively
583 /// traversing up the operands.
584 /// NOTE: This is an expensive method. Use it carefully.
585 bool hasPredecessor(const SDNode *N) const;
587 /// hasPredecesorHelper - Return true if N is a predecessor of this node.
588 /// N is either an operand of this node, or can be reached by recursively
589 /// traversing up the operands.
590 /// In this helper the Visited and worklist sets are held externally to
591 /// cache predecessors over multiple invocations. If you want to test for
592 /// multiple predecessors this method is preferable to multiple calls to
593 /// hasPredecessor. Be sure to clear Visited and Worklist if the DAG
595 /// NOTE: This is still very expensive. Use carefully.
596 bool hasPredecessorHelper(const SDNode *N,
597 SmallPtrSetImpl<const SDNode *> &Visited,
598 SmallVectorImpl<const SDNode *> &Worklist) const;
600 /// getNumOperands - Return the number of values used by this operation.
602 unsigned getNumOperands() const { return NumOperands; }
604 /// getConstantOperandVal - Helper method returns the integer value of a
605 /// ConstantSDNode operand.
606 uint64_t getConstantOperandVal(unsigned Num) const;
608 const SDValue &getOperand(unsigned Num) const {
609 assert(Num < NumOperands && "Invalid child # of SDNode!");
610 return OperandList[Num];
613 typedef SDUse* op_iterator;
614 op_iterator op_begin() const { return OperandList; }
615 op_iterator op_end() const { return OperandList+NumOperands; }
616 ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
618 SDVTList getVTList() const {
619 SDVTList X = { ValueList, NumValues };
623 /// getGluedNode - If this node has a glue operand, return the node
624 /// to which the glue operand points. Otherwise return NULL.
625 SDNode *getGluedNode() const {
626 if (getNumOperands() != 0 &&
627 getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
628 return getOperand(getNumOperands()-1).getNode();
632 // If this is a pseudo op, like copyfromreg, look to see if there is a
633 // real target node glued to it. If so, return the target node.
634 const SDNode *getGluedMachineNode() const {
635 const SDNode *FoundNode = this;
637 // Climb up glue edges until a machine-opcode node is found, or the
638 // end of the chain is reached.
639 while (!FoundNode->isMachineOpcode()) {
640 const SDNode *N = FoundNode->getGluedNode();
648 /// getGluedUser - If this node has a glue value with a user, return
649 /// the user (there is at most one). Otherwise return NULL.
650 SDNode *getGluedUser() const {
651 for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
652 if (UI.getUse().get().getValueType() == MVT::Glue)
657 /// getNumValues - Return the number of values defined/returned by this
660 unsigned getNumValues() const { return NumValues; }
662 /// getValueType - Return the type of a specified result.
664 EVT getValueType(unsigned ResNo) const {
665 assert(ResNo < NumValues && "Illegal result number!");
666 return ValueList[ResNo];
669 /// Return the type of a specified result as a simple type.
671 MVT getSimpleValueType(unsigned ResNo) const {
672 return getValueType(ResNo).getSimpleVT();
675 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
677 unsigned getValueSizeInBits(unsigned ResNo) const {
678 return getValueType(ResNo).getSizeInBits();
681 typedef const EVT* value_iterator;
682 value_iterator value_begin() const { return ValueList; }
683 value_iterator value_end() const { return ValueList+NumValues; }
685 /// getOperationName - Return the opcode of this operation for printing.
687 std::string getOperationName(const SelectionDAG *G = nullptr) const;
688 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
689 void print_types(raw_ostream &OS, const SelectionDAG *G) const;
690 void print_details(raw_ostream &OS, const SelectionDAG *G) const;
691 void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
692 void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
694 /// printrFull - Print a SelectionDAG node and all children down to
695 /// the leaves. The given SelectionDAG allows target-specific nodes
696 /// to be printed in human-readable form. Unlike printr, this will
697 /// print the whole DAG, including children that appear multiple
700 void printrFull(raw_ostream &O, const SelectionDAG *G = nullptr) const;
702 /// printrWithDepth - Print a SelectionDAG node and children up to
703 /// depth "depth." The given SelectionDAG allows target-specific
704 /// nodes to be printed in human-readable form. Unlike printr, this
705 /// will print children that appear multiple times wherever they are
708 void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
709 unsigned depth = 100) const;
712 /// dump - Dump this node, for debugging.
715 /// dumpr - Dump (recursively) this node and its use-def subgraph.
718 /// dump - Dump this node, for debugging.
719 /// The given SelectionDAG allows target-specific nodes to be printed
720 /// in human-readable form.
721 void dump(const SelectionDAG *G) const;
723 /// dumpr - Dump (recursively) this node and its use-def subgraph.
724 /// The given SelectionDAG allows target-specific nodes to be printed
725 /// in human-readable form.
726 void dumpr(const SelectionDAG *G) const;
728 /// dumprFull - printrFull to dbgs(). The given SelectionDAG allows
729 /// target-specific nodes to be printed in human-readable form.
730 /// Unlike dumpr, this will print the whole DAG, including children
731 /// that appear multiple times.
733 void dumprFull(const SelectionDAG *G = nullptr) const;
735 /// dumprWithDepth - printrWithDepth to dbgs(). The given
736 /// SelectionDAG allows target-specific nodes to be printed in
737 /// human-readable form. Unlike dumpr, this will print children
738 /// that appear multiple times wherever they are used.
740 void dumprWithDepth(const SelectionDAG *G = nullptr,
741 unsigned depth = 100) const;
743 /// Profile - Gather unique data for the node.
745 void Profile(FoldingSetNodeID &ID) const;
747 /// addUse - This method should only be used by the SDUse class.
749 void addUse(SDUse &U) { U.addToList(&UseList); }
752 static SDVTList getSDVTList(EVT VT) {
753 SDVTList Ret = { getValueTypeList(VT), 1 };
757 SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
758 ArrayRef<SDValue> Ops)
759 : NodeType(Opc), OperandsNeedDelete(true), HasDebugValue(false),
760 SubclassData(0), NodeId(-1),
761 OperandList(Ops.size() ? new SDUse[Ops.size()] : nullptr),
762 ValueList(VTs.VTs), UseList(nullptr), NumOperands(Ops.size()),
763 NumValues(VTs.NumVTs), debugLoc(std::move(dl)), IROrder(Order) {
764 assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
765 assert(NumOperands == Ops.size() &&
766 "NumOperands wasn't wide enough for its operands!");
767 assert(NumValues == VTs.NumVTs &&
768 "NumValues wasn't wide enough for its operands!");
769 for (unsigned i = 0; i != Ops.size(); ++i) {
770 assert(OperandList && "no operands available");
771 OperandList[i].setUser(this);
772 OperandList[i].setInitial(Ops[i]);
774 checkForCycles(this);
777 /// This constructor adds no operands itself; operands can be
778 /// set later with InitOperands.
779 SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
780 : NodeType(Opc), OperandsNeedDelete(false), HasDebugValue(false),
781 SubclassData(0), NodeId(-1), OperandList(nullptr), ValueList(VTs.VTs),
782 UseList(nullptr), NumOperands(0), NumValues(VTs.NumVTs),
783 debugLoc(std::move(dl)), IROrder(Order) {
784 assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
785 assert(NumValues == VTs.NumVTs &&
786 "NumValues wasn't wide enough for its operands!");
789 /// InitOperands - Initialize the operands list of this with 1 operand.
790 void InitOperands(SDUse *Ops, const SDValue &Op0) {
791 Ops[0].setUser(this);
792 Ops[0].setInitial(Op0);
795 checkForCycles(this);
798 /// InitOperands - Initialize the operands list of this with 2 operands.
799 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1) {
800 Ops[0].setUser(this);
801 Ops[0].setInitial(Op0);
802 Ops[1].setUser(this);
803 Ops[1].setInitial(Op1);
806 checkForCycles(this);
809 /// InitOperands - Initialize the operands list of this with 3 operands.
810 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
811 const SDValue &Op2) {
812 Ops[0].setUser(this);
813 Ops[0].setInitial(Op0);
814 Ops[1].setUser(this);
815 Ops[1].setInitial(Op1);
816 Ops[2].setUser(this);
817 Ops[2].setInitial(Op2);
820 checkForCycles(this);
823 /// InitOperands - Initialize the operands list of this with 4 operands.
824 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
825 const SDValue &Op2, const SDValue &Op3) {
826 Ops[0].setUser(this);
827 Ops[0].setInitial(Op0);
828 Ops[1].setUser(this);
829 Ops[1].setInitial(Op1);
830 Ops[2].setUser(this);
831 Ops[2].setInitial(Op2);
832 Ops[3].setUser(this);
833 Ops[3].setInitial(Op3);
836 checkForCycles(this);
839 /// InitOperands - Initialize the operands list of this with N operands.
840 void InitOperands(SDUse *Ops, const SDValue *Vals, unsigned N) {
841 for (unsigned i = 0; i != N; ++i) {
842 Ops[i].setUser(this);
843 Ops[i].setInitial(Vals[i]);
846 assert(NumOperands == N &&
847 "NumOperands wasn't wide enough for its operands!");
849 checkForCycles(this);
852 /// DropOperands - Release the operands and set this node to have
857 /// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
858 /// into SDNode creation functions.
859 /// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
860 /// from the original Instruction, and IROrder is the ordinal position of
862 /// When an SDNode is created after the DAG is being built, both DebugLoc and
863 /// the IROrder are propagated from the original SDNode.
864 /// So SDLoc class provides two constructors besides the default one, one to
865 /// be used by the DAGBuilder, the other to be used by others.
868 // Ptr could be used for either Instruction* or SDNode*. It is used for
869 // Instruction* if IROrder is not -1.
874 SDLoc() : Ptr(nullptr), IROrder(0) {}
875 SDLoc(const SDNode *N) : Ptr(N), IROrder(-1) {
876 assert(N && "null SDNode");
878 SDLoc(const SDValue V) : Ptr(V.getNode()), IROrder(-1) {
879 assert(Ptr && "null SDNode");
881 SDLoc(const Instruction *I, int Order) : Ptr(I), IROrder(Order) {
882 assert(Order >= 0 && "bad IROrder");
884 unsigned getIROrder() {
885 if (IROrder >= 0 || Ptr == nullptr) {
886 return (unsigned)IROrder;
888 const SDNode *N = (const SDNode*)(Ptr);
889 return N->getIROrder();
891 DebugLoc getDebugLoc() {
896 const Instruction *I = (const Instruction*)(Ptr);
897 return I->getDebugLoc();
899 const SDNode *N = (const SDNode*)(Ptr);
900 return N->getDebugLoc();
905 // Define inline functions from the SDValue class.
907 inline SDValue::SDValue(SDNode *node, unsigned resno)
908 : Node(node), ResNo(resno) {
909 assert((!Node || ResNo < Node->getNumValues()) &&
910 "Invalid result number for the given node!");
911 assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
914 inline unsigned SDValue::getOpcode() const {
915 return Node->getOpcode();
917 inline EVT SDValue::getValueType() const {
918 return Node->getValueType(ResNo);
920 inline unsigned SDValue::getNumOperands() const {
921 return Node->getNumOperands();
923 inline const SDValue &SDValue::getOperand(unsigned i) const {
924 return Node->getOperand(i);
926 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
927 return Node->getConstantOperandVal(i);
929 inline bool SDValue::isTargetOpcode() const {
930 return Node->isTargetOpcode();
932 inline bool SDValue::isTargetMemoryOpcode() const {
933 return Node->isTargetMemoryOpcode();
935 inline bool SDValue::isMachineOpcode() const {
936 return Node->isMachineOpcode();
938 inline unsigned SDValue::getMachineOpcode() const {
939 return Node->getMachineOpcode();
941 inline bool SDValue::use_empty() const {
942 return !Node->hasAnyUseOfValue(ResNo);
944 inline bool SDValue::hasOneUse() const {
945 return Node->hasNUsesOfValue(1, ResNo);
947 inline const DebugLoc &SDValue::getDebugLoc() const {
948 return Node->getDebugLoc();
950 inline void SDValue::dump() const {
953 inline void SDValue::dumpr() const {
954 return Node->dumpr();
956 // Define inline functions from the SDUse class.
958 inline void SDUse::set(const SDValue &V) {
959 if (Val.getNode()) removeFromList();
961 if (V.getNode()) V.getNode()->addUse(*this);
964 inline void SDUse::setInitial(const SDValue &V) {
966 V.getNode()->addUse(*this);
969 inline void SDUse::setNode(SDNode *N) {
970 if (Val.getNode()) removeFromList();
972 if (N) N->addUse(*this);
975 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
976 /// to allow co-allocation of node operands with the node itself.
977 class UnarySDNode : public SDNode {
980 UnarySDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
982 : SDNode(Opc, Order, dl, VTs) {
983 InitOperands(&Op, X);
987 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
988 /// to allow co-allocation of node operands with the node itself.
989 class BinarySDNode : public SDNode {
992 BinarySDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
993 SDValue X, SDValue Y)
994 : SDNode(Opc, Order, dl, VTs) {
995 InitOperands(Ops, X, Y);
999 /// BinaryWithFlagsSDNode - This class is an extension of BinarySDNode
1000 /// used from those opcodes that have associated extra flags.
1001 class BinaryWithFlagsSDNode : public BinarySDNode {
1002 enum { NUW = (1 << 0), NSW = (1 << 1), EXACT = (1 << 2) };
1005 BinaryWithFlagsSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1006 SDValue X, SDValue Y)
1007 : BinarySDNode(Opc, Order, dl, VTs, X, Y) {}
1008 /// getRawSubclassData - Return the SubclassData value, which contains an
1009 /// encoding of the flags.
1010 /// This function should be used to add subclass data to the NodeID value.
1011 unsigned getRawSubclassData() const { return SubclassData; }
1012 void setHasNoUnsignedWrap(bool b) {
1013 SubclassData = (SubclassData & ~NUW) | (b ? NUW : 0);
1015 void setHasNoSignedWrap(bool b) {
1016 SubclassData = (SubclassData & ~NSW) | (b ? NSW : 0);
1018 void setIsExact(bool b) {
1019 SubclassData = (SubclassData & ~EXACT) | (b ? EXACT : 0);
1021 bool hasNoUnsignedWrap() const { return SubclassData & NUW; }
1022 bool hasNoSignedWrap() const { return SubclassData & NSW; }
1023 bool isExact() const { return SubclassData & EXACT; }
1024 static bool classof(const SDNode *N) {
1025 return isBinOpWithFlags(N->getOpcode());
1029 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1030 /// to allow co-allocation of node operands with the node itself.
1031 class TernarySDNode : public SDNode {
1034 TernarySDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1035 SDValue X, SDValue Y, SDValue Z)
1036 : SDNode(Opc, Order, dl, VTs) {
1037 InitOperands(Ops, X, Y, Z);
1042 /// HandleSDNode - This class is used to form a handle around another node that
1043 /// is persistent and is updated across invocations of replaceAllUsesWith on its
1044 /// operand. This node should be directly created by end-users and not added to
1045 /// the AllNodes list.
1046 class HandleSDNode : public SDNode {
1049 explicit HandleSDNode(SDValue X)
1050 : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1051 InitOperands(&Op, X);
1054 const SDValue &getValue() const { return Op; }
1057 class AddrSpaceCastSDNode : public UnarySDNode {
1059 unsigned SrcAddrSpace;
1060 unsigned DestAddrSpace;
1063 AddrSpaceCastSDNode(unsigned Order, DebugLoc dl, EVT VT, SDValue X,
1064 unsigned SrcAS, unsigned DestAS);
1066 unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1067 unsigned getDestAddressSpace() const { return DestAddrSpace; }
1069 static bool classof(const SDNode *N) {
1070 return N->getOpcode() == ISD::ADDRSPACECAST;
1074 /// Abstact virtual class for operations for memory operations
1075 class MemSDNode : public SDNode {
1077 // MemoryVT - VT of in-memory value.
1081 /// MMO - Memory reference information.
1082 MachineMemOperand *MMO;
1085 MemSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1086 EVT MemoryVT, MachineMemOperand *MMO);
1088 MemSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1089 ArrayRef<SDValue> Ops, EVT MemoryVT, MachineMemOperand *MMO);
1091 bool readMem() const { return MMO->isLoad(); }
1092 bool writeMem() const { return MMO->isStore(); }
1094 /// Returns alignment and volatility of the memory access
1095 unsigned getOriginalAlignment() const {
1096 return MMO->getBaseAlignment();
1098 unsigned getAlignment() const {
1099 return MMO->getAlignment();
1102 /// getRawSubclassData - Return the SubclassData value, which contains an
1103 /// encoding of the volatile flag, as well as bits used by subclasses. This
1104 /// function should only be used to compute a FoldingSetNodeID value.
1105 unsigned getRawSubclassData() const {
1106 return SubclassData;
1109 // We access subclass data here so that we can check consistency
1110 // with MachineMemOperand information.
1111 bool isVolatile() const { return (SubclassData >> 5) & 1; }
1112 bool isNonTemporal() const { return (SubclassData >> 6) & 1; }
1113 bool isInvariant() const { return (SubclassData >> 7) & 1; }
1115 AtomicOrdering getOrdering() const {
1116 return AtomicOrdering((SubclassData >> 8) & 15);
1118 SynchronizationScope getSynchScope() const {
1119 return SynchronizationScope((SubclassData >> 12) & 1);
1122 // Returns the offset from the location of the access.
1123 int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1125 /// Returns the AA info that describes the dereference.
1126 AAMDNodes getAAInfo() const { return MMO->getAAInfo(); }
1128 /// Returns the Ranges that describes the dereference.
1129 const MDNode *getRanges() const { return MMO->getRanges(); }
1131 /// getMemoryVT - Return the type of the in-memory value.
1132 EVT getMemoryVT() const { return MemoryVT; }
1134 /// getMemOperand - Return a MachineMemOperand object describing the memory
1135 /// reference performed by operation.
1136 MachineMemOperand *getMemOperand() const { return MMO; }
1138 const MachinePointerInfo &getPointerInfo() const {
1139 return MMO->getPointerInfo();
1142 /// getAddressSpace - Return the address space for the associated pointer
1143 unsigned getAddressSpace() const {
1144 return getPointerInfo().getAddrSpace();
1147 /// refineAlignment - Update this MemSDNode's MachineMemOperand information
1148 /// to reflect the alignment of NewMMO, if it has a greater alignment.
1149 /// This must only be used when the new alignment applies to all users of
1150 /// this MachineMemOperand.
1151 void refineAlignment(const MachineMemOperand *NewMMO) {
1152 MMO->refineAlignment(NewMMO);
1155 const SDValue &getChain() const { return getOperand(0); }
1156 const SDValue &getBasePtr() const {
1157 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1160 // Methods to support isa and dyn_cast
1161 static bool classof(const SDNode *N) {
1162 // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1163 // with either an intrinsic or a target opcode.
1164 return N->getOpcode() == ISD::LOAD ||
1165 N->getOpcode() == ISD::STORE ||
1166 N->getOpcode() == ISD::PREFETCH ||
1167 N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1168 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1169 N->getOpcode() == ISD::ATOMIC_SWAP ||
1170 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1171 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1172 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1173 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1174 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1175 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1176 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1177 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1178 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1179 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1180 N->getOpcode() == ISD::ATOMIC_LOAD ||
1181 N->getOpcode() == ISD::ATOMIC_STORE ||
1182 N->getOpcode() == ISD::MLOAD ||
1183 N->getOpcode() == ISD::MSTORE ||
1184 N->isMemIntrinsic() ||
1185 N->isTargetMemoryOpcode();
1189 /// AtomicSDNode - A SDNode reprenting atomic operations.
1191 class AtomicSDNode : public MemSDNode {
1194 /// For cmpxchg instructions, the ordering requirements when a store does not
1196 AtomicOrdering FailureOrdering;
1198 void InitAtomic(AtomicOrdering SuccessOrdering,
1199 AtomicOrdering FailureOrdering,
1200 SynchronizationScope SynchScope) {
1201 // This must match encodeMemSDNodeFlags() in SelectionDAG.cpp.
1202 assert((SuccessOrdering & 15) == SuccessOrdering &&
1203 "Ordering may not require more than 4 bits!");
1204 assert((FailureOrdering & 15) == FailureOrdering &&
1205 "Ordering may not require more than 4 bits!");
1206 assert((SynchScope & 1) == SynchScope &&
1207 "SynchScope may not require more than 1 bit!");
1208 SubclassData |= SuccessOrdering << 8;
1209 SubclassData |= SynchScope << 12;
1210 this->FailureOrdering = FailureOrdering;
1211 assert(getSuccessOrdering() == SuccessOrdering &&
1212 "Ordering encoding error!");
1213 assert(getFailureOrdering() == FailureOrdering &&
1214 "Ordering encoding error!");
1215 assert(getSynchScope() == SynchScope && "Synch-scope encoding error!");
1219 // Opc: opcode for atomic
1220 // VTL: value type list
1221 // Chain: memory chain for operaand
1222 // Ptr: address to update as a SDValue
1223 // Cmp: compare value
1225 // SrcVal: address to update as a Value (used for MemOperand)
1226 // Align: alignment of memory
1227 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
1228 EVT MemVT, SDValue Chain, SDValue Ptr, SDValue Cmp, SDValue Swp,
1229 MachineMemOperand *MMO, AtomicOrdering Ordering,
1230 SynchronizationScope SynchScope)
1231 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1232 InitAtomic(Ordering, Ordering, SynchScope);
1233 InitOperands(Ops, Chain, Ptr, Cmp, Swp);
1235 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
1237 SDValue Chain, SDValue Ptr,
1238 SDValue Val, MachineMemOperand *MMO,
1239 AtomicOrdering Ordering, SynchronizationScope SynchScope)
1240 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1241 InitAtomic(Ordering, Ordering, SynchScope);
1242 InitOperands(Ops, Chain, Ptr, Val);
1244 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
1246 SDValue Chain, SDValue Ptr,
1247 MachineMemOperand *MMO,
1248 AtomicOrdering Ordering, SynchronizationScope SynchScope)
1249 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1250 InitAtomic(Ordering, Ordering, SynchScope);
1251 InitOperands(Ops, Chain, Ptr);
1253 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL, EVT MemVT,
1254 const SDValue* AllOps, SDUse *DynOps, unsigned NumOps,
1255 MachineMemOperand *MMO,
1256 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
1257 SynchronizationScope SynchScope)
1258 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1259 InitAtomic(SuccessOrdering, FailureOrdering, SynchScope);
1260 assert((DynOps || NumOps <= array_lengthof(Ops)) &&
1261 "Too many ops for internal storage!");
1262 InitOperands(DynOps ? DynOps : Ops, AllOps, NumOps);
1265 const SDValue &getBasePtr() const { return getOperand(1); }
1266 const SDValue &getVal() const { return getOperand(2); }
1268 AtomicOrdering getSuccessOrdering() const {
1269 return getOrdering();
1272 // Not quite enough room in SubclassData for everything, so failure gets its
1274 AtomicOrdering getFailureOrdering() const {
1275 return FailureOrdering;
1278 bool isCompareAndSwap() const {
1279 unsigned Op = getOpcode();
1280 return Op == ISD::ATOMIC_CMP_SWAP || Op == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS;
1283 // Methods to support isa and dyn_cast
1284 static bool classof(const SDNode *N) {
1285 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1286 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1287 N->getOpcode() == ISD::ATOMIC_SWAP ||
1288 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1289 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1290 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1291 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1292 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1293 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1294 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1295 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1296 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1297 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1298 N->getOpcode() == ISD::ATOMIC_LOAD ||
1299 N->getOpcode() == ISD::ATOMIC_STORE;
1303 /// MemIntrinsicSDNode - This SDNode is used for target intrinsics that touch
1304 /// memory and need an associated MachineMemOperand. Its opcode may be
1305 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1306 /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1307 class MemIntrinsicSDNode : public MemSDNode {
1309 MemIntrinsicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1310 ArrayRef<SDValue> Ops, EVT MemoryVT,
1311 MachineMemOperand *MMO)
1312 : MemSDNode(Opc, Order, dl, VTs, Ops, MemoryVT, MMO) {
1313 SubclassData |= 1u << 13;
1316 // Methods to support isa and dyn_cast
1317 static bool classof(const SDNode *N) {
1318 // We lower some target intrinsics to their target opcode
1319 // early a node with a target opcode can be of this class
1320 return N->isMemIntrinsic() ||
1321 N->getOpcode() == ISD::PREFETCH ||
1322 N->isTargetMemoryOpcode();
1326 /// ShuffleVectorSDNode - This SDNode is used to implement the code generator
1327 /// support for the llvm IR shufflevector instruction. It combines elements
1328 /// from two input vectors into a new input vector, with the selection and
1329 /// ordering of elements determined by an array of integers, referred to as
1330 /// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1331 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1332 /// An index of -1 is treated as undef, such that the code generator may put
1333 /// any value in the corresponding element of the result.
1334 class ShuffleVectorSDNode : public SDNode {
1337 // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1338 // is freed when the SelectionDAG object is destroyed.
1341 friend class SelectionDAG;
1342 ShuffleVectorSDNode(EVT VT, unsigned Order, DebugLoc dl, SDValue N1,
1343 SDValue N2, const int *M)
1344 : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {
1345 InitOperands(Ops, N1, N2);
1349 ArrayRef<int> getMask() const {
1350 EVT VT = getValueType(0);
1351 return makeArrayRef(Mask, VT.getVectorNumElements());
1353 int getMaskElt(unsigned Idx) const {
1354 assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1358 bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1359 int getSplatIndex() const {
1360 assert(isSplat() && "Cannot get splat index for non-splat!");
1361 EVT VT = getValueType(0);
1362 for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
1366 llvm_unreachable("Splat with all undef indices?");
1368 static bool isSplatMask(const int *Mask, EVT VT);
1370 static bool classof(const SDNode *N) {
1371 return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1375 class ConstantSDNode : public SDNode {
1376 const ConstantInt *Value;
1377 friend class SelectionDAG;
1378 ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val, EVT VT)
1379 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant,
1380 0, DebugLoc(), getSDVTList(VT)), Value(val) {
1381 SubclassData |= (uint16_t)isOpaque;
1385 const ConstantInt *getConstantIntValue() const { return Value; }
1386 const APInt &getAPIntValue() const { return Value->getValue(); }
1387 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1388 int64_t getSExtValue() const { return Value->getSExtValue(); }
1390 bool isOne() const { return Value->isOne(); }
1391 bool isNullValue() const { return Value->isNullValue(); }
1392 bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1394 bool isOpaque() const { return SubclassData & 1; }
1396 static bool classof(const SDNode *N) {
1397 return N->getOpcode() == ISD::Constant ||
1398 N->getOpcode() == ISD::TargetConstant;
1402 class ConstantFPSDNode : public SDNode {
1403 const ConstantFP *Value;
1404 friend class SelectionDAG;
1405 ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1406 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1407 0, DebugLoc(), getSDVTList(VT)), Value(val) {
1411 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1412 const ConstantFP *getConstantFPValue() const { return Value; }
1414 /// isZero - Return true if the value is positive or negative zero.
1415 bool isZero() const { return Value->isZero(); }
1417 /// isNaN - Return true if the value is a NaN.
1418 bool isNaN() const { return Value->isNaN(); }
1420 /// isInfinity - Return true if the value is an infinity
1421 bool isInfinity() const { return Value->isInfinity(); }
1423 /// isNegative - Return true if the value is negative.
1424 bool isNegative() const { return Value->isNegative(); }
1426 /// isExactlyValue - We don't rely on operator== working on double values, as
1427 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1428 /// As such, this method can be used to do an exact bit-for-bit comparison of
1429 /// two floating point values.
1431 /// We leave the version with the double argument here because it's just so
1432 /// convenient to write "2.0" and the like. Without this function we'd
1433 /// have to duplicate its logic everywhere it's called.
1434 bool isExactlyValue(double V) const {
1437 Tmp.convert(Value->getValueAPF().getSemantics(),
1438 APFloat::rmNearestTiesToEven, &ignored);
1439 return isExactlyValue(Tmp);
1441 bool isExactlyValue(const APFloat& V) const;
1443 static bool isValueValidForType(EVT VT, const APFloat& Val);
1445 static bool classof(const SDNode *N) {
1446 return N->getOpcode() == ISD::ConstantFP ||
1447 N->getOpcode() == ISD::TargetConstantFP;
1451 class GlobalAddressSDNode : public SDNode {
1452 const GlobalValue *TheGlobal;
1454 unsigned char TargetFlags;
1455 friend class SelectionDAG;
1456 GlobalAddressSDNode(unsigned Opc, unsigned Order, DebugLoc DL,
1457 const GlobalValue *GA, EVT VT, int64_t o,
1458 unsigned char TargetFlags);
1461 const GlobalValue *getGlobal() const { return TheGlobal; }
1462 int64_t getOffset() const { return Offset; }
1463 unsigned char getTargetFlags() const { return TargetFlags; }
1464 // Return the address space this GlobalAddress belongs to.
1465 unsigned getAddressSpace() const;
1467 static bool classof(const SDNode *N) {
1468 return N->getOpcode() == ISD::GlobalAddress ||
1469 N->getOpcode() == ISD::TargetGlobalAddress ||
1470 N->getOpcode() == ISD::GlobalTLSAddress ||
1471 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1475 class FrameIndexSDNode : public SDNode {
1477 friend class SelectionDAG;
1478 FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1479 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1480 0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1484 int getIndex() const { return FI; }
1486 static bool classof(const SDNode *N) {
1487 return N->getOpcode() == ISD::FrameIndex ||
1488 N->getOpcode() == ISD::TargetFrameIndex;
1492 class JumpTableSDNode : public SDNode {
1494 unsigned char TargetFlags;
1495 friend class SelectionDAG;
1496 JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1497 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1498 0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1502 int getIndex() const { return JTI; }
1503 unsigned char getTargetFlags() const { return TargetFlags; }
1505 static bool classof(const SDNode *N) {
1506 return N->getOpcode() == ISD::JumpTable ||
1507 N->getOpcode() == ISD::TargetJumpTable;
1511 class ConstantPoolSDNode : public SDNode {
1513 const Constant *ConstVal;
1514 MachineConstantPoolValue *MachineCPVal;
1516 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1517 unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
1518 unsigned char TargetFlags;
1519 friend class SelectionDAG;
1520 ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1521 unsigned Align, unsigned char TF)
1522 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1523 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1525 assert(Offset >= 0 && "Offset is too large");
1528 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1529 EVT VT, int o, unsigned Align, unsigned char TF)
1530 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1531 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1533 assert(Offset >= 0 && "Offset is too large");
1534 Val.MachineCPVal = v;
1535 Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1539 bool isMachineConstantPoolEntry() const {
1543 const Constant *getConstVal() const {
1544 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1545 return Val.ConstVal;
1548 MachineConstantPoolValue *getMachineCPVal() const {
1549 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1550 return Val.MachineCPVal;
1553 int getOffset() const {
1554 return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1557 // Return the alignment of this constant pool object, which is either 0 (for
1558 // default alignment) or the desired value.
1559 unsigned getAlignment() const { return Alignment; }
1560 unsigned char getTargetFlags() const { return TargetFlags; }
1562 Type *getType() const;
1564 static bool classof(const SDNode *N) {
1565 return N->getOpcode() == ISD::ConstantPool ||
1566 N->getOpcode() == ISD::TargetConstantPool;
1570 /// Completely target-dependent object reference.
1571 class TargetIndexSDNode : public SDNode {
1572 unsigned char TargetFlags;
1575 friend class SelectionDAG;
1578 TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1579 : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
1580 TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1583 unsigned char getTargetFlags() const { return TargetFlags; }
1584 int getIndex() const { return Index; }
1585 int64_t getOffset() const { return Offset; }
1587 static bool classof(const SDNode *N) {
1588 return N->getOpcode() == ISD::TargetIndex;
1592 class BasicBlockSDNode : public SDNode {
1593 MachineBasicBlock *MBB;
1594 friend class SelectionDAG;
1595 /// Debug info is meaningful and potentially useful here, but we create
1596 /// blocks out of order when they're jumped to, which makes it a bit
1597 /// harder. Let's see if we need it first.
1598 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1599 : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
1603 MachineBasicBlock *getBasicBlock() const { return MBB; }
1605 static bool classof(const SDNode *N) {
1606 return N->getOpcode() == ISD::BasicBlock;
1610 /// BuildVectorSDNode - A "pseudo-class" with methods for operating on
1612 class BuildVectorSDNode : public SDNode {
1613 // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1614 explicit BuildVectorSDNode() = delete;
1616 /// isConstantSplat - Check if this is a constant splat, and if so, find the
1617 /// smallest element size that splats the vector. If MinSplatBits is
1618 /// nonzero, the element size must be at least that large. Note that the
1619 /// splat element may be the entire vector (i.e., a one element vector).
1620 /// Returns the splat element value in SplatValue. Any undefined bits in
1621 /// that value are zero, and the corresponding bits in the SplatUndef mask
1622 /// are set. The SplatBitSize value is set to the splat element size in
1623 /// bits. HasAnyUndefs is set to true if any bits in the vector are
1624 /// undefined. isBigEndian describes the endianness of the target.
1625 bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1626 unsigned &SplatBitSize, bool &HasAnyUndefs,
1627 unsigned MinSplatBits = 0,
1628 bool isBigEndian = false) const;
1630 /// \brief Returns the splatted value or a null value if this is not a splat.
1632 /// If passed a non-null UndefElements bitvector, it will resize it to match
1633 /// the vector width and set the bits where elements are undef.
1634 SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
1636 /// \brief Returns the splatted constant or null if this is not a constant
1639 /// If passed a non-null UndefElements bitvector, it will resize it to match
1640 /// the vector width and set the bits where elements are undef.
1642 getConstantSplatNode(BitVector *UndefElements = nullptr) const;
1644 /// \brief Returns the splatted constant FP or null if this is not a constant
1647 /// If passed a non-null UndefElements bitvector, it will resize it to match
1648 /// the vector width and set the bits where elements are undef.
1650 getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
1652 bool isConstant() const;
1654 static inline bool classof(const SDNode *N) {
1655 return N->getOpcode() == ISD::BUILD_VECTOR;
1659 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1660 /// used when the SelectionDAG needs to make a simple reference to something
1661 /// in the LLVM IR representation.
1663 class SrcValueSDNode : public SDNode {
1665 friend class SelectionDAG;
1666 /// Create a SrcValue for a general value.
1667 explicit SrcValueSDNode(const Value *v)
1668 : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1671 /// getValue - return the contained Value.
1672 const Value *getValue() const { return V; }
1674 static bool classof(const SDNode *N) {
1675 return N->getOpcode() == ISD::SRCVALUE;
1679 class MDNodeSDNode : public SDNode {
1681 friend class SelectionDAG;
1682 explicit MDNodeSDNode(const MDNode *md)
1683 : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
1687 const MDNode *getMD() const { return MD; }
1689 static bool classof(const SDNode *N) {
1690 return N->getOpcode() == ISD::MDNODE_SDNODE;
1694 class RegisterSDNode : public SDNode {
1696 friend class SelectionDAG;
1697 RegisterSDNode(unsigned reg, EVT VT)
1698 : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {
1702 unsigned getReg() const { return Reg; }
1704 static bool classof(const SDNode *N) {
1705 return N->getOpcode() == ISD::Register;
1709 class RegisterMaskSDNode : public SDNode {
1710 // The memory for RegMask is not owned by the node.
1711 const uint32_t *RegMask;
1712 friend class SelectionDAG;
1713 RegisterMaskSDNode(const uint32_t *mask)
1714 : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
1718 const uint32_t *getRegMask() const { return RegMask; }
1720 static bool classof(const SDNode *N) {
1721 return N->getOpcode() == ISD::RegisterMask;
1725 class BlockAddressSDNode : public SDNode {
1726 const BlockAddress *BA;
1728 unsigned char TargetFlags;
1729 friend class SelectionDAG;
1730 BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1731 int64_t o, unsigned char Flags)
1732 : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
1733 BA(ba), Offset(o), TargetFlags(Flags) {
1736 const BlockAddress *getBlockAddress() const { return BA; }
1737 int64_t getOffset() const { return Offset; }
1738 unsigned char getTargetFlags() const { return TargetFlags; }
1740 static bool classof(const SDNode *N) {
1741 return N->getOpcode() == ISD::BlockAddress ||
1742 N->getOpcode() == ISD::TargetBlockAddress;
1746 class EHLabelSDNode : public SDNode {
1749 friend class SelectionDAG;
1750 EHLabelSDNode(unsigned Order, DebugLoc dl, SDValue ch, MCSymbol *L)
1751 : SDNode(ISD::EH_LABEL, Order, dl, getSDVTList(MVT::Other)), Label(L) {
1752 InitOperands(&Chain, ch);
1755 MCSymbol *getLabel() const { return Label; }
1757 static bool classof(const SDNode *N) {
1758 return N->getOpcode() == ISD::EH_LABEL;
1762 class ExternalSymbolSDNode : public SDNode {
1764 unsigned char TargetFlags;
1766 friend class SelectionDAG;
1767 ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1768 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1769 0, DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {
1773 const char *getSymbol() const { return Symbol; }
1774 unsigned char getTargetFlags() const { return TargetFlags; }
1776 static bool classof(const SDNode *N) {
1777 return N->getOpcode() == ISD::ExternalSymbol ||
1778 N->getOpcode() == ISD::TargetExternalSymbol;
1782 class CondCodeSDNode : public SDNode {
1783 ISD::CondCode Condition;
1784 friend class SelectionDAG;
1785 explicit CondCodeSDNode(ISD::CondCode Cond)
1786 : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1791 ISD::CondCode get() const { return Condition; }
1793 static bool classof(const SDNode *N) {
1794 return N->getOpcode() == ISD::CONDCODE;
1798 /// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
1799 /// future and most targets don't support it.
1800 class CvtRndSatSDNode : public SDNode {
1801 ISD::CvtCode CvtCode;
1802 friend class SelectionDAG;
1803 explicit CvtRndSatSDNode(EVT VT, unsigned Order, DebugLoc dl,
1804 ArrayRef<SDValue> Ops, ISD::CvtCode Code)
1805 : SDNode(ISD::CONVERT_RNDSAT, Order, dl, getSDVTList(VT), Ops),
1807 assert(Ops.size() == 5 && "wrong number of operations");
1810 ISD::CvtCode getCvtCode() const { return CvtCode; }
1812 static bool classof(const SDNode *N) {
1813 return N->getOpcode() == ISD::CONVERT_RNDSAT;
1817 /// VTSDNode - This class is used to represent EVT's, which are used
1818 /// to parameterize some operations.
1819 class VTSDNode : public SDNode {
1821 friend class SelectionDAG;
1822 explicit VTSDNode(EVT VT)
1823 : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1828 EVT getVT() const { return ValueType; }
1830 static bool classof(const SDNode *N) {
1831 return N->getOpcode() == ISD::VALUETYPE;
1835 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1837 class LSBaseSDNode : public MemSDNode {
1838 //! Operand array for load and store
1840 \note Moving this array to the base class captures more
1841 common functionality shared between LoadSDNode and
1846 LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, DebugLoc dl,
1847 SDValue *Operands, unsigned numOperands,
1848 SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
1849 MachineMemOperand *MMO)
1850 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
1851 SubclassData |= AM << 2;
1852 assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
1853 InitOperands(Ops, Operands, numOperands);
1854 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1855 "Only indexed loads and stores have a non-undef offset operand");
1858 const SDValue &getOffset() const {
1859 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1862 /// getAddressingMode - Return the addressing mode for this load or store:
1863 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
1864 ISD::MemIndexedMode getAddressingMode() const {
1865 return ISD::MemIndexedMode((SubclassData >> 2) & 7);
1868 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1869 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
1871 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1872 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
1874 static bool classof(const SDNode *N) {
1875 return N->getOpcode() == ISD::LOAD ||
1876 N->getOpcode() == ISD::STORE;
1880 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1882 class LoadSDNode : public LSBaseSDNode {
1883 friend class SelectionDAG;
1884 LoadSDNode(SDValue *ChainPtrOff, unsigned Order, DebugLoc dl, SDVTList VTs,
1885 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
1886 MachineMemOperand *MMO)
1887 : LSBaseSDNode(ISD::LOAD, Order, dl, ChainPtrOff, 3, VTs, AM, MemVT, MMO) {
1888 SubclassData |= (unsigned short)ETy;
1889 assert(getExtensionType() == ETy && "LoadExtType encoding error!");
1890 assert(readMem() && "Load MachineMemOperand is not a load!");
1891 assert(!writeMem() && "Load MachineMemOperand is a store!");
1895 /// getExtensionType - Return whether this is a plain node,
1896 /// or one of the varieties of value-extending loads.
1897 ISD::LoadExtType getExtensionType() const {
1898 return ISD::LoadExtType(SubclassData & 3);
1901 const SDValue &getBasePtr() const { return getOperand(1); }
1902 const SDValue &getOffset() const { return getOperand(2); }
1904 static bool classof(const SDNode *N) {
1905 return N->getOpcode() == ISD::LOAD;
1909 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1911 class StoreSDNode : public LSBaseSDNode {
1912 friend class SelectionDAG;
1913 StoreSDNode(SDValue *ChainValuePtrOff, unsigned Order, DebugLoc dl,
1914 SDVTList VTs, ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
1915 MachineMemOperand *MMO)
1916 : LSBaseSDNode(ISD::STORE, Order, dl, ChainValuePtrOff, 4,
1917 VTs, AM, MemVT, MMO) {
1918 SubclassData |= (unsigned short)isTrunc;
1919 assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
1920 assert(!readMem() && "Store MachineMemOperand is a load!");
1921 assert(writeMem() && "Store MachineMemOperand is not a store!");
1925 /// isTruncatingStore - Return true if the op does a truncation before store.
1926 /// For integers this is the same as doing a TRUNCATE and storing the result.
1927 /// For floats, it is the same as doing an FP_ROUND and storing the result.
1928 bool isTruncatingStore() const { return SubclassData & 1; }
1930 const SDValue &getValue() const { return getOperand(1); }
1931 const SDValue &getBasePtr() const { return getOperand(2); }
1932 const SDValue &getOffset() const { return getOperand(3); }
1934 static bool classof(const SDNode *N) {
1935 return N->getOpcode() == ISD::STORE;
1939 /// MaskedLoadStoreSDNode - This is a base class is used to represent MLOAD and
1942 class MaskedLoadStoreSDNode : public MemSDNode {
1946 friend class SelectionDAG;
1947 MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order, DebugLoc dl,
1948 SDValue *Operands, unsigned numOperands,
1949 SDVTList VTs, EVT MemVT, MachineMemOperand *MMO)
1950 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
1951 InitOperands(Ops, Operands, numOperands);
1954 // In the both nodes address is Op1, mask is Op2:
1955 // MaskedLoadSDNode (Chain, ptr, mask, src0), src0 is a passthru value
1956 // MaskedStoreSDNode (Chain, ptr, mask, data)
1957 // Mask is a vector of i1 elements
1958 const SDValue &getBasePtr() const { return getOperand(1); }
1959 const SDValue &getMask() const { return getOperand(2); }
1961 static bool classof(const SDNode *N) {
1962 return N->getOpcode() == ISD::MLOAD ||
1963 N->getOpcode() == ISD::MSTORE;
1967 /// MaskedLoadSDNode - This class is used to represent an MLOAD node
1969 class MaskedLoadSDNode : public MaskedLoadStoreSDNode {
1971 friend class SelectionDAG;
1972 MaskedLoadSDNode(unsigned Order, DebugLoc dl, SDValue *Operands,
1973 unsigned numOperands, SDVTList VTs, ISD::LoadExtType ETy,
1974 EVT MemVT, MachineMemOperand *MMO)
1975 : MaskedLoadStoreSDNode(ISD::MLOAD, Order, dl, Operands, numOperands,
1977 SubclassData |= (unsigned short)ETy;
1980 ISD::LoadExtType getExtensionType() const {
1981 return ISD::LoadExtType(SubclassData & 3);
1983 const SDValue &getSrc0() const { return getOperand(3); }
1984 static bool classof(const SDNode *N) {
1985 return N->getOpcode() == ISD::MLOAD;
1989 /// MaskedStoreSDNode - This class is used to represent an MSTORE node
1991 class MaskedStoreSDNode : public MaskedLoadStoreSDNode {
1994 friend class SelectionDAG;
1995 MaskedStoreSDNode(unsigned Order, DebugLoc dl, SDValue *Operands,
1996 unsigned numOperands, SDVTList VTs, bool isTrunc, EVT MemVT,
1997 MachineMemOperand *MMO)
1998 : MaskedLoadStoreSDNode(ISD::MSTORE, Order, dl, Operands, numOperands,
2000 SubclassData |= (unsigned short)isTrunc;
2002 /// isTruncatingStore - Return true if the op does a truncation before store.
2003 /// For integers this is the same as doing a TRUNCATE and storing the result.
2004 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2005 bool isTruncatingStore() const { return SubclassData & 1; }
2007 const SDValue &getValue() const { return getOperand(3); }
2009 static bool classof(const SDNode *N) {
2010 return N->getOpcode() == ISD::MSTORE;
2014 /// MachineSDNode - An SDNode that represents everything that will be needed
2015 /// to construct a MachineInstr. These nodes are created during the
2016 /// instruction selection proper phase.
2018 class MachineSDNode : public SDNode {
2020 typedef MachineMemOperand **mmo_iterator;
2023 friend class SelectionDAG;
2024 MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc DL, SDVTList VTs)
2025 : SDNode(Opc, Order, DL, VTs), MemRefs(nullptr), MemRefsEnd(nullptr) {}
2027 /// LocalOperands - Operands for this instruction, if they fit here. If
2028 /// they don't, this field is unused.
2029 SDUse LocalOperands[4];
2031 /// MemRefs - Memory reference descriptions for this instruction.
2032 mmo_iterator MemRefs;
2033 mmo_iterator MemRefsEnd;
2036 mmo_iterator memoperands_begin() const { return MemRefs; }
2037 mmo_iterator memoperands_end() const { return MemRefsEnd; }
2038 bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
2040 /// setMemRefs - Assign this MachineSDNodes's memory reference descriptor
2041 /// list. This does not transfer ownership.
2042 void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
2043 for (mmo_iterator MMI = NewMemRefs, MME = NewMemRefsEnd; MMI != MME; ++MMI)
2044 assert(*MMI && "Null mem ref detected!");
2045 MemRefs = NewMemRefs;
2046 MemRefsEnd = NewMemRefsEnd;
2049 static bool classof(const SDNode *N) {
2050 return N->isMachineOpcode();
2054 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
2055 SDNode, ptrdiff_t> {
2059 SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2061 bool operator==(const SDNodeIterator& x) const {
2062 return Operand == x.Operand;
2064 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2066 pointer operator*() const {
2067 return Node->getOperand(Operand).getNode();
2069 pointer operator->() const { return operator*(); }
2071 SDNodeIterator& operator++() { // Preincrement
2075 SDNodeIterator operator++(int) { // Postincrement
2076 SDNodeIterator tmp = *this; ++*this; return tmp;
2078 size_t operator-(SDNodeIterator Other) const {
2079 assert(Node == Other.Node &&
2080 "Cannot compare iterators of two different nodes!");
2081 return Operand - Other.Operand;
2084 static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
2085 static SDNodeIterator end (const SDNode *N) {
2086 return SDNodeIterator(N, N->getNumOperands());
2089 unsigned getOperand() const { return Operand; }
2090 const SDNode *getNode() const { return Node; }
2093 template <> struct GraphTraits<SDNode*> {
2094 typedef SDNode NodeType;
2095 typedef SDNodeIterator ChildIteratorType;
2096 static inline NodeType *getEntryNode(SDNode *N) { return N; }
2097 static inline ChildIteratorType child_begin(NodeType *N) {
2098 return SDNodeIterator::begin(N);
2100 static inline ChildIteratorType child_end(NodeType *N) {
2101 return SDNodeIterator::end(N);
2105 /// LargestSDNode - The largest SDNode class.
2107 typedef AtomicSDNode LargestSDNode;
2109 /// MostAlignedSDNode - The SDNode class with the greatest alignment
2112 typedef GlobalAddressSDNode MostAlignedSDNode;
2115 /// isNormalLoad - Returns true if the specified node is a non-extending
2116 /// and unindexed load.
2117 inline bool isNormalLoad(const SDNode *N) {
2118 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2119 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2120 Ld->getAddressingMode() == ISD::UNINDEXED;
2123 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2125 inline bool isNON_EXTLoad(const SDNode *N) {
2126 return isa<LoadSDNode>(N) &&
2127 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2130 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2132 inline bool isEXTLoad(const SDNode *N) {
2133 return isa<LoadSDNode>(N) &&
2134 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2137 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2139 inline bool isSEXTLoad(const SDNode *N) {
2140 return isa<LoadSDNode>(N) &&
2141 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2144 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2146 inline bool isZEXTLoad(const SDNode *N) {
2147 return isa<LoadSDNode>(N) &&
2148 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2151 /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
2153 inline bool isUNINDEXEDLoad(const SDNode *N) {
2154 return isa<LoadSDNode>(N) &&
2155 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2158 /// isNormalStore - Returns true if the specified node is a non-truncating
2159 /// and unindexed store.
2160 inline bool isNormalStore(const SDNode *N) {
2161 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2162 return St && !St->isTruncatingStore() &&
2163 St->getAddressingMode() == ISD::UNINDEXED;
2166 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2168 inline bool isNON_TRUNCStore(const SDNode *N) {
2169 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2172 /// isTRUNCStore - Returns true if the specified node is a truncating
2174 inline bool isTRUNCStore(const SDNode *N) {
2175 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2178 /// isUNINDEXEDStore - Returns true if the specified node is an
2179 /// unindexed store.
2180 inline bool isUNINDEXEDStore(const SDNode *N) {
2181 return isa<StoreSDNode>(N) &&
2182 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2186 } // end llvm namespace