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 /// Returns true if the opcode is a binary operation with flags.
54 static bool isBinOpWithFlags(unsigned Opcode) {
70 void checkForCycles(const SDNode *N, const SelectionDAG *DAG = nullptr,
73 /// This represents a list of ValueType's that has been intern'd by
74 /// a SelectionDAG. Instances of this simple value class are returned by
75 /// SelectionDAG::getVTList(...).
85 /// Return true if the specified node is a
86 /// BUILD_VECTOR where all of the elements are ~0 or undef.
87 bool isBuildVectorAllOnes(const SDNode *N);
89 /// Return true if the specified node is a
90 /// BUILD_VECTOR where all of the elements are 0 or undef.
91 bool isBuildVectorAllZeros(const SDNode *N);
93 /// \brief Return true if the specified node is a BUILD_VECTOR node of
94 /// all ConstantSDNode or undef.
95 bool isBuildVectorOfConstantSDNodes(const SDNode *N);
97 /// Return true if the specified node is a
98 /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
99 /// element is not an undef.
100 bool isScalarToVector(const SDNode *N);
102 /// Return true if the node has at least one operand
103 /// and all operands of the specified node are ISD::UNDEF.
104 bool allOperandsUndef(const SDNode *N);
105 } // end llvm:ISD namespace
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; // The node defining the value we are using.
122 unsigned ResNo; // Which return value of the node we are using.
124 SDValue() : Node(nullptr), ResNo(0) {}
125 SDValue(SDNode *node, unsigned resno);
127 /// get the index which selects a specific result in the SDNode
128 unsigned getResNo() const { return ResNo; }
130 /// get the SDNode which holds the desired result
131 SDNode *getNode() const { return Node; }
134 void setNode(SDNode *N) { Node = N; }
136 inline SDNode *operator->() const { return Node; }
138 bool operator==(const SDValue &O) const {
139 return Node == O.Node && ResNo == O.ResNo;
141 bool operator!=(const SDValue &O) const {
142 return !operator==(O);
144 bool operator<(const SDValue &O) const {
145 return std::tie(Node, ResNo) < std::tie(O.Node, O.ResNo);
147 explicit operator bool() const {
148 return Node != nullptr;
151 SDValue getValue(unsigned R) const {
152 return SDValue(Node, R);
155 // Return true if this node is an operand of N.
156 bool isOperandOf(SDNode *N) const;
158 /// Return the ValueType of the referenced return value.
159 inline EVT getValueType() const;
161 /// Return the simple ValueType of the referenced return value.
162 MVT getSimpleValueType() const {
163 return getValueType().getSimpleVT();
166 /// Returns the size of the value in bits.
167 unsigned getValueSizeInBits() const {
168 return getValueType().getSizeInBits();
171 unsigned getScalarValueSizeInBits() const {
172 return getValueType().getScalarType().getSizeInBits();
175 // Forwarding methods - These forward to the corresponding methods in SDNode.
176 inline unsigned getOpcode() const;
177 inline unsigned getNumOperands() const;
178 inline const SDValue &getOperand(unsigned i) const;
179 inline uint64_t getConstantOperandVal(unsigned i) const;
180 inline bool isTargetMemoryOpcode() const;
181 inline bool isTargetOpcode() const;
182 inline bool isMachineOpcode() const;
183 inline unsigned getMachineOpcode() const;
184 inline const DebugLoc &getDebugLoc() const;
185 inline void dump() const;
186 inline void dumpr() const;
188 /// Return true if this operand (which must be a chain) reaches the
189 /// specified operand without crossing any side-effecting instructions.
190 /// In practice, this looks through token factors and non-volatile loads.
191 /// In order to remain efficient, this only
192 /// looks a couple of nodes in, it does not do an exhaustive search.
193 bool reachesChainWithoutSideEffects(SDValue Dest,
194 unsigned Depth = 2) const;
196 /// Return true if there are no nodes using value ResNo of Node.
197 inline bool use_empty() const;
199 /// Return true if there is exactly one node using value ResNo of Node.
200 inline bool hasOneUse() const;
204 template<> struct DenseMapInfo<SDValue> {
205 static inline SDValue getEmptyKey() {
210 static inline SDValue getTombstoneKey() {
215 static unsigned getHashValue(const SDValue &Val) {
216 return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
217 (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
219 static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
223 template <> struct isPodLike<SDValue> { static const bool value = true; };
226 /// Allow casting operators to work directly on
227 /// SDValues as if they were SDNode*'s.
228 template<> struct simplify_type<SDValue> {
229 typedef SDNode* SimpleType;
230 static SimpleType getSimplifiedValue(SDValue &Val) {
231 return Val.getNode();
234 template<> struct simplify_type<const SDValue> {
235 typedef /*const*/ SDNode* SimpleType;
236 static SimpleType getSimplifiedValue(const SDValue &Val) {
237 return Val.getNode();
241 /// Represents a use of a SDNode. This class holds an SDValue,
242 /// which records the SDNode being used and the result number, a
243 /// pointer to the SDNode using the value, and Next and Prev pointers,
244 /// which link together all the uses of an SDNode.
247 /// Val - The value being used.
249 /// User - The user of this value.
251 /// Prev, Next - Pointers to the uses list of the SDNode referred by
255 SDUse(const SDUse &U) = delete;
256 void operator=(const SDUse &U) = delete;
259 SDUse() : Val(), User(nullptr), Prev(nullptr), Next(nullptr) {}
261 /// Normally SDUse will just implicitly convert to an SDValue that it holds.
262 operator const SDValue&() const { return Val; }
264 /// If implicit conversion to SDValue doesn't work, the get() method returns
266 const SDValue &get() const { return Val; }
268 /// This returns the SDNode that contains this Use.
269 SDNode *getUser() { return User; }
271 /// Get the next SDUse in the use list.
272 SDUse *getNext() const { return Next; }
274 /// Convenience function for get().getNode().
275 SDNode *getNode() const { return Val.getNode(); }
276 /// Convenience function for get().getResNo().
277 unsigned getResNo() const { return Val.getResNo(); }
278 /// Convenience function for get().getValueType().
279 EVT getValueType() const { return Val.getValueType(); }
281 /// Convenience function for get().operator==
282 bool operator==(const SDValue &V) const {
286 /// Convenience function for get().operator!=
287 bool operator!=(const SDValue &V) const {
291 /// Convenience function for get().operator<
292 bool operator<(const SDValue &V) const {
297 friend class SelectionDAG;
300 void setUser(SDNode *p) { User = p; }
302 /// Remove this use from its existing use list, assign it the
303 /// given value, and add it to the new value's node's use list.
304 inline void set(const SDValue &V);
305 /// Like set, but only supports initializing a newly-allocated
306 /// SDUse with a non-null value.
307 inline void setInitial(const SDValue &V);
308 /// Like set, but only sets the Node portion of the value,
309 /// leaving the ResNo portion unmodified.
310 inline void setNode(SDNode *N);
312 void addToList(SDUse **List) {
314 if (Next) Next->Prev = &Next;
319 void removeFromList() {
321 if (Next) Next->Prev = Prev;
325 /// simplify_type specializations - Allow casting operators to work directly on
326 /// SDValues as if they were SDNode*'s.
327 template<> struct simplify_type<SDUse> {
328 typedef SDNode* SimpleType;
329 static SimpleType getSimplifiedValue(SDUse &Val) {
330 return Val.getNode();
335 /// Represents one node in the SelectionDAG.
337 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
339 /// The operation that this node performs.
342 /// This is true if OperandList was new[]'d. If true,
343 /// then they will be delete[]'d when the node is destroyed.
344 uint16_t OperandsNeedDelete : 1;
346 /// This tracks whether this node has one or more dbg_value
347 /// nodes corresponding to it.
348 uint16_t HasDebugValue : 1;
351 /// This member is defined by this class, but is not used for
352 /// anything. Subclasses can use it to hold whatever state they find useful.
353 /// This field is initialized to zero by the ctor.
354 uint16_t SubclassData : 14;
357 /// Unique id per SDNode in the DAG.
360 /// The values that are used by this operation.
363 /// The types of the values this node defines. SDNode's may
364 /// define multiple values simultaneously.
365 const EVT *ValueList;
367 /// List of uses for this SDNode.
370 /// The number of entries in the Operand/Value list.
371 unsigned short NumOperands, NumValues;
373 /// Source line information.
376 // The ordering of the SDNodes. It roughly corresponds to the ordering of the
377 // original LLVM instructions.
378 // This is used for turning off scheduling, because we'll forgo
379 // the normal scheduling algorithms and output the instructions according to
383 /// Return a pointer to the specified value type.
384 static const EVT *getValueTypeList(EVT VT);
386 friend class SelectionDAG;
387 friend struct ilist_traits<SDNode>;
390 //===--------------------------------------------------------------------===//
394 /// Return the SelectionDAG opcode value for this node. For
395 /// pre-isel nodes (those for which isMachineOpcode returns false), these
396 /// are the opcode values in the ISD and <target>ISD namespaces. For
397 /// post-isel opcodes, see getMachineOpcode.
398 unsigned getOpcode() const { return (unsigned short)NodeType; }
400 /// Test if this node has a target-specific opcode (in the
401 /// \<target\>ISD namespace).
402 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
404 /// Test if this node has a target-specific
405 /// memory-referencing opcode (in the \<target\>ISD namespace and
406 /// greater than FIRST_TARGET_MEMORY_OPCODE).
407 bool isTargetMemoryOpcode() const {
408 return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
411 /// Test if this node is a memory intrinsic (with valid pointer information).
412 /// INTRINSIC_W_CHAIN and INTRINSIC_VOID nodes are sometimes created for
413 /// non-memory intrinsics (with chains) that are not really instances of
414 /// MemSDNode. For such nodes, we need some extra state to determine the
415 /// proper classof relationship.
416 bool isMemIntrinsic() const {
417 return (NodeType == ISD::INTRINSIC_W_CHAIN ||
418 NodeType == ISD::INTRINSIC_VOID) && ((SubclassData >> 13) & 1);
421 /// Test if this node has a post-isel opcode, directly
422 /// corresponding to a MachineInstr opcode.
423 bool isMachineOpcode() const { return NodeType < 0; }
425 /// This may only be called if isMachineOpcode returns
426 /// true. It returns the MachineInstr opcode value that the node's opcode
428 unsigned getMachineOpcode() const {
429 assert(isMachineOpcode() && "Not a MachineInstr opcode!");
434 bool getHasDebugValue() const { return HasDebugValue; }
437 void setHasDebugValue(bool b) { HasDebugValue = b; }
439 /// Return true if there are no uses of this node.
440 bool use_empty() const { return UseList == nullptr; }
442 /// Return true if there is exactly one use of this node.
443 bool hasOneUse() const {
444 return !use_empty() && std::next(use_begin()) == use_end();
447 /// Return the number of uses of this node. This method takes
448 /// time proportional to the number of uses.
449 size_t use_size() const { return std::distance(use_begin(), use_end()); }
451 /// Return the unique node id.
452 int getNodeId() const { return NodeId; }
454 /// Set unique node id.
455 void setNodeId(int Id) { NodeId = Id; }
457 /// Return the node ordering.
458 unsigned getIROrder() const { return IROrder; }
460 /// Set the node ordering.
461 void setIROrder(unsigned Order) { IROrder = Order; }
463 /// Return the source location info.
464 const DebugLoc &getDebugLoc() const { return debugLoc; }
466 /// Set source location info. Try to avoid this, putting
467 /// it in the constructor is preferable.
468 void setDebugLoc(DebugLoc dl) { debugLoc = std::move(dl); }
470 /// This class provides iterator support for SDUse
471 /// operands that use a specific SDNode.
473 : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
475 explicit use_iterator(SDUse *op) : Op(op) {
479 typedef std::iterator<std::forward_iterator_tag,
480 SDUse, ptrdiff_t>::reference reference;
481 typedef std::iterator<std::forward_iterator_tag,
482 SDUse, ptrdiff_t>::pointer pointer;
484 use_iterator(const use_iterator &I) : Op(I.Op) {}
485 use_iterator() : Op(nullptr) {}
487 bool operator==(const use_iterator &x) const {
490 bool operator!=(const use_iterator &x) const {
491 return !operator==(x);
494 /// Return true if this iterator is at the end of uses list.
495 bool atEnd() const { return Op == nullptr; }
497 // Iterator traversal: forward iteration only.
498 use_iterator &operator++() { // Preincrement
499 assert(Op && "Cannot increment end iterator!");
504 use_iterator operator++(int) { // Postincrement
505 use_iterator tmp = *this; ++*this; return tmp;
508 /// Retrieve a pointer to the current user node.
509 SDNode *operator*() const {
510 assert(Op && "Cannot dereference end iterator!");
511 return Op->getUser();
514 SDNode *operator->() const { return operator*(); }
516 SDUse &getUse() const { return *Op; }
518 /// Retrieve the operand # of this use in its user.
519 unsigned getOperandNo() const {
520 assert(Op && "Cannot dereference end iterator!");
521 return (unsigned)(Op - Op->getUser()->OperandList);
525 /// Provide iteration support to walk over all uses of an SDNode.
526 use_iterator use_begin() const {
527 return use_iterator(UseList);
530 static use_iterator use_end() { return use_iterator(nullptr); }
532 inline iterator_range<use_iterator> uses() {
533 return iterator_range<use_iterator>(use_begin(), use_end());
535 inline iterator_range<use_iterator> uses() const {
536 return iterator_range<use_iterator>(use_begin(), use_end());
539 /// Return true if there are exactly NUSES uses of the indicated value.
540 /// This method ignores uses of other values defined by this operation.
541 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
543 /// Return true if there are any use of the indicated value.
544 /// This method ignores uses of other values defined by this operation.
545 bool hasAnyUseOfValue(unsigned Value) const;
547 /// Return true if this node is the only use of N.
548 bool isOnlyUserOf(SDNode *N) const;
550 /// Return true if this node is an operand of N.
551 bool isOperandOf(SDNode *N) const;
553 /// Return true if this node is a predecessor of N.
554 /// NOTE: Implemented on top of hasPredecessor and every bit as
555 /// expensive. Use carefully.
556 bool isPredecessorOf(const SDNode *N) const {
557 return N->hasPredecessor(this);
560 /// Return true if N is a predecessor of this node.
561 /// N is either an operand of this node, or can be reached by recursively
562 /// traversing up the operands.
563 /// NOTE: This is an expensive method. Use it carefully.
564 bool hasPredecessor(const SDNode *N) const;
566 /// Return true if N is a predecessor of this node.
567 /// N is either an operand of this node, or can be reached by recursively
568 /// traversing up the operands.
569 /// In this helper the Visited and worklist sets are held externally to
570 /// cache predecessors over multiple invocations. If you want to test for
571 /// multiple predecessors this method is preferable to multiple calls to
572 /// hasPredecessor. Be sure to clear Visited and Worklist if the DAG
574 /// NOTE: This is still very expensive. Use carefully.
575 bool hasPredecessorHelper(const SDNode *N,
576 SmallPtrSetImpl<const SDNode *> &Visited,
577 SmallVectorImpl<const SDNode *> &Worklist) const;
579 /// Return the number of values used by this operation.
580 unsigned getNumOperands() const { return NumOperands; }
582 /// Helper method returns the integer value of a ConstantSDNode operand.
583 uint64_t getConstantOperandVal(unsigned Num) const;
585 const SDValue &getOperand(unsigned Num) const {
586 assert(Num < NumOperands && "Invalid child # of SDNode!");
587 return OperandList[Num];
590 typedef SDUse* op_iterator;
591 op_iterator op_begin() const { return OperandList; }
592 op_iterator op_end() const { return OperandList+NumOperands; }
593 ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
595 SDVTList getVTList() const {
596 SDVTList X = { ValueList, NumValues };
600 /// If this node has a glue operand, return the node
601 /// to which the glue operand points. Otherwise return NULL.
602 SDNode *getGluedNode() const {
603 if (getNumOperands() != 0 &&
604 getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
605 return getOperand(getNumOperands()-1).getNode();
609 // If this is a pseudo op, like copyfromreg, look to see if there is a
610 // real target node glued to it. If so, return the target node.
611 const SDNode *getGluedMachineNode() const {
612 const SDNode *FoundNode = this;
614 // Climb up glue edges until a machine-opcode node is found, or the
615 // end of the chain is reached.
616 while (!FoundNode->isMachineOpcode()) {
617 const SDNode *N = FoundNode->getGluedNode();
625 /// If this node has a glue value with a user, return
626 /// the user (there is at most one). Otherwise return NULL.
627 SDNode *getGluedUser() const {
628 for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
629 if (UI.getUse().get().getValueType() == MVT::Glue)
634 /// Return the number of values defined/returned by this operator.
635 unsigned getNumValues() const { return NumValues; }
637 /// Return the type of a specified result.
638 EVT getValueType(unsigned ResNo) const {
639 assert(ResNo < NumValues && "Illegal result number!");
640 return ValueList[ResNo];
643 /// Return the type of a specified result as a simple type.
644 MVT getSimpleValueType(unsigned ResNo) const {
645 return getValueType(ResNo).getSimpleVT();
648 /// Returns MVT::getSizeInBits(getValueType(ResNo)).
649 unsigned getValueSizeInBits(unsigned ResNo) const {
650 return getValueType(ResNo).getSizeInBits();
653 typedef const EVT* value_iterator;
654 value_iterator value_begin() const { return ValueList; }
655 value_iterator value_end() const { return ValueList+NumValues; }
657 /// Return the opcode of this operation for printing.
658 std::string getOperationName(const SelectionDAG *G = nullptr) const;
659 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
660 void print_types(raw_ostream &OS, const SelectionDAG *G) const;
661 void print_details(raw_ostream &OS, const SelectionDAG *G) const;
662 void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
663 void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
665 /// Print a SelectionDAG node and all children down to
666 /// the leaves. The given SelectionDAG allows target-specific nodes
667 /// to be printed in human-readable form. Unlike printr, this will
668 /// print the whole DAG, including children that appear multiple
671 void printrFull(raw_ostream &O, const SelectionDAG *G = nullptr) const;
673 /// Print a SelectionDAG node and children up to
674 /// depth "depth." The given SelectionDAG allows target-specific
675 /// nodes to be printed in human-readable form. Unlike printr, this
676 /// will print children that appear multiple times wherever they are
679 void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
680 unsigned depth = 100) const;
683 /// Dump this node, for debugging.
686 /// Dump (recursively) this node and its use-def subgraph.
689 /// Dump this node, for debugging.
690 /// The given SelectionDAG allows target-specific nodes to be printed
691 /// in human-readable form.
692 void dump(const SelectionDAG *G) const;
694 /// Dump (recursively) this node and its use-def subgraph.
695 /// The given SelectionDAG allows target-specific nodes to be printed
696 /// in human-readable form.
697 void dumpr(const SelectionDAG *G) const;
699 /// printrFull to dbgs(). The given SelectionDAG allows
700 /// target-specific nodes to be printed in human-readable form.
701 /// Unlike dumpr, this will print the whole DAG, including children
702 /// that appear multiple times.
703 void dumprFull(const SelectionDAG *G = nullptr) const;
705 /// printrWithDepth to dbgs(). The given
706 /// SelectionDAG allows target-specific nodes to be printed in
707 /// human-readable form. Unlike dumpr, this will print children
708 /// that appear multiple times wherever they are used.
710 void dumprWithDepth(const SelectionDAG *G = nullptr,
711 unsigned depth = 100) const;
713 /// Gather unique data for the node.
714 void Profile(FoldingSetNodeID &ID) const;
716 /// This method should only be used by the SDUse class.
717 void addUse(SDUse &U) { U.addToList(&UseList); }
720 static SDVTList getSDVTList(EVT VT) {
721 SDVTList Ret = { getValueTypeList(VT), 1 };
725 SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
726 ArrayRef<SDValue> Ops)
727 : NodeType(Opc), OperandsNeedDelete(true), HasDebugValue(false),
728 SubclassData(0), NodeId(-1),
729 OperandList(Ops.size() ? new SDUse[Ops.size()] : nullptr),
730 ValueList(VTs.VTs), UseList(nullptr), NumOperands(Ops.size()),
731 NumValues(VTs.NumVTs), debugLoc(std::move(dl)), IROrder(Order) {
732 assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
733 assert(NumOperands == Ops.size() &&
734 "NumOperands wasn't wide enough for its operands!");
735 assert(NumValues == VTs.NumVTs &&
736 "NumValues wasn't wide enough for its operands!");
737 for (unsigned i = 0; i != Ops.size(); ++i) {
738 assert(OperandList && "no operands available");
739 OperandList[i].setUser(this);
740 OperandList[i].setInitial(Ops[i]);
742 checkForCycles(this);
745 /// This constructor adds no operands itself; operands can be
746 /// set later with InitOperands.
747 SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
748 : NodeType(Opc), OperandsNeedDelete(false), HasDebugValue(false),
749 SubclassData(0), NodeId(-1), OperandList(nullptr), ValueList(VTs.VTs),
750 UseList(nullptr), NumOperands(0), NumValues(VTs.NumVTs),
751 debugLoc(std::move(dl)), IROrder(Order) {
752 assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
753 assert(NumValues == VTs.NumVTs &&
754 "NumValues wasn't wide enough for its operands!");
757 /// Initialize the operands list of this with 1 operand.
758 void InitOperands(SDUse *Ops, const SDValue &Op0) {
759 Ops[0].setUser(this);
760 Ops[0].setInitial(Op0);
763 checkForCycles(this);
766 /// Initialize the operands list of this with 2 operands.
767 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1) {
768 Ops[0].setUser(this);
769 Ops[0].setInitial(Op0);
770 Ops[1].setUser(this);
771 Ops[1].setInitial(Op1);
774 checkForCycles(this);
777 /// Initialize the operands list of this with 3 operands.
778 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
779 const SDValue &Op2) {
780 Ops[0].setUser(this);
781 Ops[0].setInitial(Op0);
782 Ops[1].setUser(this);
783 Ops[1].setInitial(Op1);
784 Ops[2].setUser(this);
785 Ops[2].setInitial(Op2);
788 checkForCycles(this);
791 /// Initialize the operands list of this with 4 operands.
792 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
793 const SDValue &Op2, const SDValue &Op3) {
794 Ops[0].setUser(this);
795 Ops[0].setInitial(Op0);
796 Ops[1].setUser(this);
797 Ops[1].setInitial(Op1);
798 Ops[2].setUser(this);
799 Ops[2].setInitial(Op2);
800 Ops[3].setUser(this);
801 Ops[3].setInitial(Op3);
804 checkForCycles(this);
807 /// Initialize the operands list of this with N operands.
808 void InitOperands(SDUse *Ops, const SDValue *Vals, unsigned N) {
809 for (unsigned i = 0; i != N; ++i) {
810 Ops[i].setUser(this);
811 Ops[i].setInitial(Vals[i]);
814 assert(NumOperands == N &&
815 "NumOperands wasn't wide enough for its operands!");
817 checkForCycles(this);
820 /// Release the operands and set this node to have zero operands.
824 /// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
825 /// into SDNode creation functions.
826 /// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
827 /// from the original Instruction, and IROrder is the ordinal position of
829 /// When an SDNode is created after the DAG is being built, both DebugLoc and
830 /// the IROrder are propagated from the original SDNode.
831 /// So SDLoc class provides two constructors besides the default one, one to
832 /// be used by the DAGBuilder, the other to be used by others.
835 // Ptr could be used for either Instruction* or SDNode*. It is used for
836 // Instruction* if IROrder is not -1.
841 SDLoc() : Ptr(nullptr), IROrder(0) {}
842 SDLoc(const SDNode *N) : Ptr(N), IROrder(-1) {
843 assert(N && "null SDNode");
845 SDLoc(const SDValue V) : Ptr(V.getNode()), IROrder(-1) {
846 assert(Ptr && "null SDNode");
848 SDLoc(const Instruction *I, int Order) : Ptr(I), IROrder(Order) {
849 assert(Order >= 0 && "bad IROrder");
851 unsigned getIROrder() {
852 if (IROrder >= 0 || Ptr == nullptr) {
853 return (unsigned)IROrder;
855 const SDNode *N = (const SDNode*)(Ptr);
856 return N->getIROrder();
858 DebugLoc getDebugLoc() {
863 const Instruction *I = (const Instruction*)(Ptr);
864 return I->getDebugLoc();
866 const SDNode *N = (const SDNode*)(Ptr);
867 return N->getDebugLoc();
872 // Define inline functions from the SDValue class.
874 inline SDValue::SDValue(SDNode *node, unsigned resno)
875 : Node(node), ResNo(resno) {
876 assert((!Node || ResNo < Node->getNumValues()) &&
877 "Invalid result number for the given node!");
878 assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
881 inline unsigned SDValue::getOpcode() const {
882 return Node->getOpcode();
884 inline EVT SDValue::getValueType() const {
885 return Node->getValueType(ResNo);
887 inline unsigned SDValue::getNumOperands() const {
888 return Node->getNumOperands();
890 inline const SDValue &SDValue::getOperand(unsigned i) const {
891 return Node->getOperand(i);
893 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
894 return Node->getConstantOperandVal(i);
896 inline bool SDValue::isTargetOpcode() const {
897 return Node->isTargetOpcode();
899 inline bool SDValue::isTargetMemoryOpcode() const {
900 return Node->isTargetMemoryOpcode();
902 inline bool SDValue::isMachineOpcode() const {
903 return Node->isMachineOpcode();
905 inline unsigned SDValue::getMachineOpcode() const {
906 return Node->getMachineOpcode();
908 inline bool SDValue::use_empty() const {
909 return !Node->hasAnyUseOfValue(ResNo);
911 inline bool SDValue::hasOneUse() const {
912 return Node->hasNUsesOfValue(1, ResNo);
914 inline const DebugLoc &SDValue::getDebugLoc() const {
915 return Node->getDebugLoc();
917 inline void SDValue::dump() const {
920 inline void SDValue::dumpr() const {
921 return Node->dumpr();
923 // Define inline functions from the SDUse class.
925 inline void SDUse::set(const SDValue &V) {
926 if (Val.getNode()) removeFromList();
928 if (V.getNode()) V.getNode()->addUse(*this);
931 inline void SDUse::setInitial(const SDValue &V) {
933 V.getNode()->addUse(*this);
936 inline void SDUse::setNode(SDNode *N) {
937 if (Val.getNode()) removeFromList();
939 if (N) N->addUse(*this);
942 /// This class is used for single-operand SDNodes. This is solely
943 /// to allow co-allocation of node operands with the node itself.
944 class UnarySDNode : public SDNode {
947 UnarySDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
949 : SDNode(Opc, Order, dl, VTs) {
950 InitOperands(&Op, X);
954 /// This class is used for two-operand SDNodes. This is solely
955 /// to allow co-allocation of node operands with the node itself.
956 class BinarySDNode : public SDNode {
959 BinarySDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
960 SDValue X, SDValue Y)
961 : SDNode(Opc, Order, dl, VTs) {
962 InitOperands(Ops, X, Y);
966 /// This class is an extension of BinarySDNode
967 /// used from those opcodes that have associated extra flags.
968 class BinaryWithFlagsSDNode : public BinarySDNode {
969 enum { NUW = (1 << 0), NSW = (1 << 1), EXACT = (1 << 2) };
972 BinaryWithFlagsSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
973 SDValue X, SDValue Y)
974 : BinarySDNode(Opc, Order, dl, VTs, X, Y) {}
975 /// Return the SubclassData value, which contains an encoding of the flags.
976 /// This function should be used to add subclass data to the NodeID value.
977 unsigned getRawSubclassData() const { return SubclassData; }
978 void setHasNoUnsignedWrap(bool b) {
979 SubclassData = (SubclassData & ~NUW) | (b ? NUW : 0);
981 void setHasNoSignedWrap(bool b) {
982 SubclassData = (SubclassData & ~NSW) | (b ? NSW : 0);
984 void setIsExact(bool b) {
985 SubclassData = (SubclassData & ~EXACT) | (b ? EXACT : 0);
987 bool hasNoUnsignedWrap() const { return SubclassData & NUW; }
988 bool hasNoSignedWrap() const { return SubclassData & NSW; }
989 bool isExact() const { return SubclassData & EXACT; }
990 static bool classof(const SDNode *N) {
991 return isBinOpWithFlags(N->getOpcode());
995 /// This class is used for three-operand SDNodes. This is solely
996 /// to allow co-allocation of node operands with the node itself.
997 class TernarySDNode : public SDNode {
1000 TernarySDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1001 SDValue X, SDValue Y, SDValue Z)
1002 : SDNode(Opc, Order, dl, VTs) {
1003 InitOperands(Ops, X, Y, Z);
1008 /// This class is used to form a handle around another node that
1009 /// is persistent and is updated across invocations of replaceAllUsesWith on its
1010 /// operand. This node should be directly created by end-users and not added to
1011 /// the AllNodes list.
1012 class HandleSDNode : public SDNode {
1015 explicit HandleSDNode(SDValue X)
1016 : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1017 InitOperands(&Op, X);
1020 const SDValue &getValue() const { return Op; }
1023 class AddrSpaceCastSDNode : public UnarySDNode {
1025 unsigned SrcAddrSpace;
1026 unsigned DestAddrSpace;
1029 AddrSpaceCastSDNode(unsigned Order, DebugLoc dl, EVT VT, SDValue X,
1030 unsigned SrcAS, unsigned DestAS);
1032 unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1033 unsigned getDestAddressSpace() const { return DestAddrSpace; }
1035 static bool classof(const SDNode *N) {
1036 return N->getOpcode() == ISD::ADDRSPACECAST;
1040 /// Abstact virtual class for operations for memory operations
1041 class MemSDNode : public SDNode {
1043 // VT of in-memory value.
1047 /// Memory reference information.
1048 MachineMemOperand *MMO;
1051 MemSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1052 EVT MemoryVT, MachineMemOperand *MMO);
1054 MemSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1055 ArrayRef<SDValue> Ops, EVT MemoryVT, MachineMemOperand *MMO);
1057 bool readMem() const { return MMO->isLoad(); }
1058 bool writeMem() const { return MMO->isStore(); }
1060 /// Returns alignment and volatility of the memory access
1061 unsigned getOriginalAlignment() const {
1062 return MMO->getBaseAlignment();
1064 unsigned getAlignment() const {
1065 return MMO->getAlignment();
1068 /// Return the SubclassData value, which contains an
1069 /// encoding of the volatile flag, as well as bits used by subclasses. This
1070 /// function should only be used to compute a FoldingSetNodeID value.
1071 unsigned getRawSubclassData() const {
1072 return SubclassData;
1075 // We access subclass data here so that we can check consistency
1076 // with MachineMemOperand information.
1077 bool isVolatile() const { return (SubclassData >> 5) & 1; }
1078 bool isNonTemporal() const { return (SubclassData >> 6) & 1; }
1079 bool isInvariant() const { return (SubclassData >> 7) & 1; }
1081 AtomicOrdering getOrdering() const {
1082 return AtomicOrdering((SubclassData >> 8) & 15);
1084 SynchronizationScope getSynchScope() const {
1085 return SynchronizationScope((SubclassData >> 12) & 1);
1088 // Returns the offset from the location of the access.
1089 int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1091 /// Returns the AA info that describes the dereference.
1092 AAMDNodes getAAInfo() const { return MMO->getAAInfo(); }
1094 /// Returns the Ranges that describes the dereference.
1095 const MDNode *getRanges() const { return MMO->getRanges(); }
1097 /// Return the type of the in-memory value.
1098 EVT getMemoryVT() const { return MemoryVT; }
1100 /// Return a MachineMemOperand object describing the memory
1101 /// reference performed by operation.
1102 MachineMemOperand *getMemOperand() const { return MMO; }
1104 const MachinePointerInfo &getPointerInfo() const {
1105 return MMO->getPointerInfo();
1108 /// Return the address space for the associated pointer
1109 unsigned getAddressSpace() const {
1110 return getPointerInfo().getAddrSpace();
1113 /// Update this MemSDNode's MachineMemOperand information
1114 /// to reflect the alignment of NewMMO, if it has a greater alignment.
1115 /// This must only be used when the new alignment applies to all users of
1116 /// this MachineMemOperand.
1117 void refineAlignment(const MachineMemOperand *NewMMO) {
1118 MMO->refineAlignment(NewMMO);
1121 const SDValue &getChain() const { return getOperand(0); }
1122 const SDValue &getBasePtr() const {
1123 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1126 // Methods to support isa and dyn_cast
1127 static bool classof(const SDNode *N) {
1128 // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1129 // with either an intrinsic or a target opcode.
1130 return N->getOpcode() == ISD::LOAD ||
1131 N->getOpcode() == ISD::STORE ||
1132 N->getOpcode() == ISD::PREFETCH ||
1133 N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1134 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1135 N->getOpcode() == ISD::ATOMIC_SWAP ||
1136 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1137 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1138 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1139 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1140 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1141 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1142 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1143 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1144 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1145 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1146 N->getOpcode() == ISD::ATOMIC_LOAD ||
1147 N->getOpcode() == ISD::ATOMIC_STORE ||
1148 N->getOpcode() == ISD::MLOAD ||
1149 N->getOpcode() == ISD::MSTORE ||
1150 N->isMemIntrinsic() ||
1151 N->isTargetMemoryOpcode();
1155 /// A SDNode reprenting atomic operations.
1156 class AtomicSDNode : public MemSDNode {
1159 /// For cmpxchg instructions, the ordering requirements when a store does not
1161 AtomicOrdering FailureOrdering;
1163 void InitAtomic(AtomicOrdering SuccessOrdering,
1164 AtomicOrdering FailureOrdering,
1165 SynchronizationScope SynchScope) {
1166 // This must match encodeMemSDNodeFlags() in SelectionDAG.cpp.
1167 assert((SuccessOrdering & 15) == SuccessOrdering &&
1168 "Ordering may not require more than 4 bits!");
1169 assert((FailureOrdering & 15) == FailureOrdering &&
1170 "Ordering may not require more than 4 bits!");
1171 assert((SynchScope & 1) == SynchScope &&
1172 "SynchScope may not require more than 1 bit!");
1173 SubclassData |= SuccessOrdering << 8;
1174 SubclassData |= SynchScope << 12;
1175 this->FailureOrdering = FailureOrdering;
1176 assert(getSuccessOrdering() == SuccessOrdering &&
1177 "Ordering encoding error!");
1178 assert(getFailureOrdering() == FailureOrdering &&
1179 "Ordering encoding error!");
1180 assert(getSynchScope() == SynchScope && "Synch-scope encoding error!");
1184 // Opc: opcode for atomic
1185 // VTL: value type list
1186 // Chain: memory chain for operaand
1187 // Ptr: address to update as a SDValue
1188 // Cmp: compare value
1190 // SrcVal: address to update as a Value (used for MemOperand)
1191 // Align: alignment of memory
1192 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
1193 EVT MemVT, SDValue Chain, SDValue Ptr, SDValue Cmp, SDValue Swp,
1194 MachineMemOperand *MMO, AtomicOrdering Ordering,
1195 SynchronizationScope SynchScope)
1196 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1197 InitAtomic(Ordering, Ordering, SynchScope);
1198 InitOperands(Ops, Chain, Ptr, Cmp, Swp);
1200 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
1202 SDValue Chain, SDValue Ptr,
1203 SDValue Val, MachineMemOperand *MMO,
1204 AtomicOrdering Ordering, SynchronizationScope SynchScope)
1205 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1206 InitAtomic(Ordering, Ordering, SynchScope);
1207 InitOperands(Ops, Chain, Ptr, Val);
1209 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
1211 SDValue Chain, SDValue Ptr,
1212 MachineMemOperand *MMO,
1213 AtomicOrdering Ordering, SynchronizationScope SynchScope)
1214 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1215 InitAtomic(Ordering, Ordering, SynchScope);
1216 InitOperands(Ops, Chain, Ptr);
1218 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL, EVT MemVT,
1219 const SDValue* AllOps, SDUse *DynOps, unsigned NumOps,
1220 MachineMemOperand *MMO,
1221 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
1222 SynchronizationScope SynchScope)
1223 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1224 InitAtomic(SuccessOrdering, FailureOrdering, SynchScope);
1225 assert((DynOps || NumOps <= array_lengthof(Ops)) &&
1226 "Too many ops for internal storage!");
1227 InitOperands(DynOps ? DynOps : Ops, AllOps, NumOps);
1230 const SDValue &getBasePtr() const { return getOperand(1); }
1231 const SDValue &getVal() const { return getOperand(2); }
1233 AtomicOrdering getSuccessOrdering() const {
1234 return getOrdering();
1237 // Not quite enough room in SubclassData for everything, so failure gets its
1239 AtomicOrdering getFailureOrdering() const {
1240 return FailureOrdering;
1243 bool isCompareAndSwap() const {
1244 unsigned Op = getOpcode();
1245 return Op == ISD::ATOMIC_CMP_SWAP || Op == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS;
1248 // Methods to support isa and dyn_cast
1249 static bool classof(const SDNode *N) {
1250 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1251 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1252 N->getOpcode() == ISD::ATOMIC_SWAP ||
1253 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1254 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1255 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1256 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1257 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1258 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1259 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1260 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1261 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1262 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1263 N->getOpcode() == ISD::ATOMIC_LOAD ||
1264 N->getOpcode() == ISD::ATOMIC_STORE;
1268 /// This SDNode is used for target intrinsics that touch
1269 /// memory and need an associated MachineMemOperand. Its opcode may be
1270 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1271 /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1272 class MemIntrinsicSDNode : public MemSDNode {
1274 MemIntrinsicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1275 ArrayRef<SDValue> Ops, EVT MemoryVT,
1276 MachineMemOperand *MMO)
1277 : MemSDNode(Opc, Order, dl, VTs, Ops, MemoryVT, MMO) {
1278 SubclassData |= 1u << 13;
1281 // Methods to support isa and dyn_cast
1282 static bool classof(const SDNode *N) {
1283 // We lower some target intrinsics to their target opcode
1284 // early a node with a target opcode can be of this class
1285 return N->isMemIntrinsic() ||
1286 N->getOpcode() == ISD::PREFETCH ||
1287 N->isTargetMemoryOpcode();
1291 /// This SDNode is used to implement the code generator
1292 /// support for the llvm IR shufflevector instruction. It combines elements
1293 /// from two input vectors into a new input vector, with the selection and
1294 /// ordering of elements determined by an array of integers, referred to as
1295 /// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1296 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1297 /// An index of -1 is treated as undef, such that the code generator may put
1298 /// any value in the corresponding element of the result.
1299 class ShuffleVectorSDNode : public SDNode {
1302 // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1303 // is freed when the SelectionDAG object is destroyed.
1306 friend class SelectionDAG;
1307 ShuffleVectorSDNode(EVT VT, unsigned Order, DebugLoc dl, SDValue N1,
1308 SDValue N2, const int *M)
1309 : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {
1310 InitOperands(Ops, N1, N2);
1314 ArrayRef<int> getMask() const {
1315 EVT VT = getValueType(0);
1316 return makeArrayRef(Mask, VT.getVectorNumElements());
1318 int getMaskElt(unsigned Idx) const {
1319 assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1323 bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1324 int getSplatIndex() const {
1325 assert(isSplat() && "Cannot get splat index for non-splat!");
1326 EVT VT = getValueType(0);
1327 for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
1331 llvm_unreachable("Splat with all undef indices?");
1333 static bool isSplatMask(const int *Mask, EVT VT);
1335 /// Change values in a shuffle permute mask assuming
1336 /// the two vector operands have swapped position.
1337 static void commuteMask(SmallVectorImpl<int> &Mask) {
1338 unsigned NumElems = Mask.size();
1339 for (unsigned i = 0; i != NumElems; ++i) {
1343 else if (idx < (int)NumElems)
1344 Mask[i] = idx + NumElems;
1346 Mask[i] = idx - NumElems;
1350 static bool classof(const SDNode *N) {
1351 return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1355 class ConstantSDNode : public SDNode {
1356 const ConstantInt *Value;
1357 friend class SelectionDAG;
1358 ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val, EVT VT)
1359 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant,
1360 0, DebugLoc(), getSDVTList(VT)), Value(val) {
1361 SubclassData |= (uint16_t)isOpaque;
1365 const ConstantInt *getConstantIntValue() const { return Value; }
1366 const APInt &getAPIntValue() const { return Value->getValue(); }
1367 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1368 int64_t getSExtValue() const { return Value->getSExtValue(); }
1370 bool isOne() const { return Value->isOne(); }
1371 bool isNullValue() const { return Value->isNullValue(); }
1372 bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1374 bool isOpaque() const { return SubclassData & 1; }
1376 static bool classof(const SDNode *N) {
1377 return N->getOpcode() == ISD::Constant ||
1378 N->getOpcode() == ISD::TargetConstant;
1382 class ConstantFPSDNode : public SDNode {
1383 const ConstantFP *Value;
1384 friend class SelectionDAG;
1385 ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1386 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1387 0, DebugLoc(), getSDVTList(VT)), Value(val) {
1391 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1392 const ConstantFP *getConstantFPValue() const { return Value; }
1394 /// Return true if the value is positive or negative zero.
1395 bool isZero() const { return Value->isZero(); }
1397 /// Return true if the value is a NaN.
1398 bool isNaN() const { return Value->isNaN(); }
1400 /// Return true if the value is an infinity
1401 bool isInfinity() const { return Value->isInfinity(); }
1403 /// Return true if the value is negative.
1404 bool isNegative() const { return Value->isNegative(); }
1406 /// We don't rely on operator== working on double values, as
1407 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1408 /// As such, this method can be used to do an exact bit-for-bit comparison of
1409 /// two floating point values.
1411 /// We leave the version with the double argument here because it's just so
1412 /// convenient to write "2.0" and the like. Without this function we'd
1413 /// have to duplicate its logic everywhere it's called.
1414 bool isExactlyValue(double V) const {
1417 Tmp.convert(Value->getValueAPF().getSemantics(),
1418 APFloat::rmNearestTiesToEven, &ignored);
1419 return isExactlyValue(Tmp);
1421 bool isExactlyValue(const APFloat& V) const;
1423 static bool isValueValidForType(EVT VT, const APFloat& Val);
1425 static bool classof(const SDNode *N) {
1426 return N->getOpcode() == ISD::ConstantFP ||
1427 N->getOpcode() == ISD::TargetConstantFP;
1431 class GlobalAddressSDNode : public SDNode {
1432 const GlobalValue *TheGlobal;
1434 unsigned char TargetFlags;
1435 friend class SelectionDAG;
1436 GlobalAddressSDNode(unsigned Opc, unsigned Order, DebugLoc DL,
1437 const GlobalValue *GA, EVT VT, int64_t o,
1438 unsigned char TargetFlags);
1441 const GlobalValue *getGlobal() const { return TheGlobal; }
1442 int64_t getOffset() const { return Offset; }
1443 unsigned char getTargetFlags() const { return TargetFlags; }
1444 // Return the address space this GlobalAddress belongs to.
1445 unsigned getAddressSpace() const;
1447 static bool classof(const SDNode *N) {
1448 return N->getOpcode() == ISD::GlobalAddress ||
1449 N->getOpcode() == ISD::TargetGlobalAddress ||
1450 N->getOpcode() == ISD::GlobalTLSAddress ||
1451 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1455 class FrameIndexSDNode : public SDNode {
1457 friend class SelectionDAG;
1458 FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1459 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1460 0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1464 int getIndex() const { return FI; }
1466 static bool classof(const SDNode *N) {
1467 return N->getOpcode() == ISD::FrameIndex ||
1468 N->getOpcode() == ISD::TargetFrameIndex;
1472 class JumpTableSDNode : public SDNode {
1474 unsigned char TargetFlags;
1475 friend class SelectionDAG;
1476 JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1477 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1478 0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1482 int getIndex() const { return JTI; }
1483 unsigned char getTargetFlags() const { return TargetFlags; }
1485 static bool classof(const SDNode *N) {
1486 return N->getOpcode() == ISD::JumpTable ||
1487 N->getOpcode() == ISD::TargetJumpTable;
1491 class ConstantPoolSDNode : public SDNode {
1493 const Constant *ConstVal;
1494 MachineConstantPoolValue *MachineCPVal;
1496 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1497 unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
1498 unsigned char TargetFlags;
1499 friend class SelectionDAG;
1500 ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1501 unsigned Align, unsigned char TF)
1502 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1503 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1505 assert(Offset >= 0 && "Offset is too large");
1508 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1509 EVT VT, int o, unsigned Align, unsigned char TF)
1510 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1511 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1513 assert(Offset >= 0 && "Offset is too large");
1514 Val.MachineCPVal = v;
1515 Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1519 bool isMachineConstantPoolEntry() const {
1523 const Constant *getConstVal() const {
1524 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1525 return Val.ConstVal;
1528 MachineConstantPoolValue *getMachineCPVal() const {
1529 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1530 return Val.MachineCPVal;
1533 int getOffset() const {
1534 return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1537 // Return the alignment of this constant pool object, which is either 0 (for
1538 // default alignment) or the desired value.
1539 unsigned getAlignment() const { return Alignment; }
1540 unsigned char getTargetFlags() const { return TargetFlags; }
1542 Type *getType() const;
1544 static bool classof(const SDNode *N) {
1545 return N->getOpcode() == ISD::ConstantPool ||
1546 N->getOpcode() == ISD::TargetConstantPool;
1550 /// Completely target-dependent object reference.
1551 class TargetIndexSDNode : public SDNode {
1552 unsigned char TargetFlags;
1555 friend class SelectionDAG;
1558 TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1559 : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
1560 TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1563 unsigned char getTargetFlags() const { return TargetFlags; }
1564 int getIndex() const { return Index; }
1565 int64_t getOffset() const { return Offset; }
1567 static bool classof(const SDNode *N) {
1568 return N->getOpcode() == ISD::TargetIndex;
1572 class BasicBlockSDNode : public SDNode {
1573 MachineBasicBlock *MBB;
1574 friend class SelectionDAG;
1575 /// Debug info is meaningful and potentially useful here, but we create
1576 /// blocks out of order when they're jumped to, which makes it a bit
1577 /// harder. Let's see if we need it first.
1578 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1579 : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
1583 MachineBasicBlock *getBasicBlock() const { return MBB; }
1585 static bool classof(const SDNode *N) {
1586 return N->getOpcode() == ISD::BasicBlock;
1590 /// A "pseudo-class" with methods for operating on BUILD_VECTORs.
1591 class BuildVectorSDNode : public SDNode {
1592 // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1593 explicit BuildVectorSDNode() = delete;
1595 /// Check if this is a constant splat, and if so, find the
1596 /// smallest element size that splats the vector. If MinSplatBits is
1597 /// nonzero, the element size must be at least that large. Note that the
1598 /// splat element may be the entire vector (i.e., a one element vector).
1599 /// Returns the splat element value in SplatValue. Any undefined bits in
1600 /// that value are zero, and the corresponding bits in the SplatUndef mask
1601 /// are set. The SplatBitSize value is set to the splat element size in
1602 /// bits. HasAnyUndefs is set to true if any bits in the vector are
1603 /// undefined. isBigEndian describes the endianness of the target.
1604 bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1605 unsigned &SplatBitSize, bool &HasAnyUndefs,
1606 unsigned MinSplatBits = 0,
1607 bool isBigEndian = false) const;
1609 /// \brief Returns the splatted value or a null value if this is not a splat.
1611 /// If passed a non-null UndefElements bitvector, it will resize it to match
1612 /// the vector width and set the bits where elements are undef.
1613 SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
1615 /// \brief Returns the splatted constant or null if this is not a constant
1618 /// If passed a non-null UndefElements bitvector, it will resize it to match
1619 /// the vector width and set the bits where elements are undef.
1621 getConstantSplatNode(BitVector *UndefElements = nullptr) const;
1623 /// \brief Returns the splatted constant FP or null if this is not a constant
1626 /// If passed a non-null UndefElements bitvector, it will resize it to match
1627 /// the vector width and set the bits where elements are undef.
1629 getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
1631 bool isConstant() const;
1633 static inline bool classof(const SDNode *N) {
1634 return N->getOpcode() == ISD::BUILD_VECTOR;
1638 /// An SDNode that holds an arbitrary LLVM IR Value. This is
1639 /// used when the SelectionDAG needs to make a simple reference to something
1640 /// in the LLVM IR representation.
1642 class SrcValueSDNode : public SDNode {
1644 friend class SelectionDAG;
1645 /// Create a SrcValue for a general value.
1646 explicit SrcValueSDNode(const Value *v)
1647 : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1650 /// Return the contained Value.
1651 const Value *getValue() const { return V; }
1653 static bool classof(const SDNode *N) {
1654 return N->getOpcode() == ISD::SRCVALUE;
1658 class MDNodeSDNode : public SDNode {
1660 friend class SelectionDAG;
1661 explicit MDNodeSDNode(const MDNode *md)
1662 : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
1666 const MDNode *getMD() const { return MD; }
1668 static bool classof(const SDNode *N) {
1669 return N->getOpcode() == ISD::MDNODE_SDNODE;
1673 class RegisterSDNode : public SDNode {
1675 friend class SelectionDAG;
1676 RegisterSDNode(unsigned reg, EVT VT)
1677 : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {
1681 unsigned getReg() const { return Reg; }
1683 static bool classof(const SDNode *N) {
1684 return N->getOpcode() == ISD::Register;
1688 class RegisterMaskSDNode : public SDNode {
1689 // The memory for RegMask is not owned by the node.
1690 const uint32_t *RegMask;
1691 friend class SelectionDAG;
1692 RegisterMaskSDNode(const uint32_t *mask)
1693 : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
1697 const uint32_t *getRegMask() const { return RegMask; }
1699 static bool classof(const SDNode *N) {
1700 return N->getOpcode() == ISD::RegisterMask;
1704 class BlockAddressSDNode : public SDNode {
1705 const BlockAddress *BA;
1707 unsigned char TargetFlags;
1708 friend class SelectionDAG;
1709 BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1710 int64_t o, unsigned char Flags)
1711 : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
1712 BA(ba), Offset(o), TargetFlags(Flags) {
1715 const BlockAddress *getBlockAddress() const { return BA; }
1716 int64_t getOffset() const { return Offset; }
1717 unsigned char getTargetFlags() const { return TargetFlags; }
1719 static bool classof(const SDNode *N) {
1720 return N->getOpcode() == ISD::BlockAddress ||
1721 N->getOpcode() == ISD::TargetBlockAddress;
1725 class EHLabelSDNode : public SDNode {
1728 friend class SelectionDAG;
1729 EHLabelSDNode(unsigned Order, DebugLoc dl, SDValue ch, MCSymbol *L)
1730 : SDNode(ISD::EH_LABEL, Order, dl, getSDVTList(MVT::Other)), Label(L) {
1731 InitOperands(&Chain, ch);
1734 MCSymbol *getLabel() const { return Label; }
1736 static bool classof(const SDNode *N) {
1737 return N->getOpcode() == ISD::EH_LABEL;
1741 class ExternalSymbolSDNode : public SDNode {
1743 unsigned char TargetFlags;
1745 friend class SelectionDAG;
1746 ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1747 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1748 0, DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {
1752 const char *getSymbol() const { return Symbol; }
1753 unsigned char getTargetFlags() const { return TargetFlags; }
1755 static bool classof(const SDNode *N) {
1756 return N->getOpcode() == ISD::ExternalSymbol ||
1757 N->getOpcode() == ISD::TargetExternalSymbol;
1761 class CondCodeSDNode : public SDNode {
1762 ISD::CondCode Condition;
1763 friend class SelectionDAG;
1764 explicit CondCodeSDNode(ISD::CondCode Cond)
1765 : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1770 ISD::CondCode get() const { return Condition; }
1772 static bool classof(const SDNode *N) {
1773 return N->getOpcode() == ISD::CONDCODE;
1777 /// NOTE: avoid using this node as this may disappear in the
1778 /// future and most targets don't support it.
1779 class CvtRndSatSDNode : public SDNode {
1780 ISD::CvtCode CvtCode;
1781 friend class SelectionDAG;
1782 explicit CvtRndSatSDNode(EVT VT, unsigned Order, DebugLoc dl,
1783 ArrayRef<SDValue> Ops, ISD::CvtCode Code)
1784 : SDNode(ISD::CONVERT_RNDSAT, Order, dl, getSDVTList(VT), Ops),
1786 assert(Ops.size() == 5 && "wrong number of operations");
1789 ISD::CvtCode getCvtCode() const { return CvtCode; }
1791 static bool classof(const SDNode *N) {
1792 return N->getOpcode() == ISD::CONVERT_RNDSAT;
1796 /// This class is used to represent EVT's, which are used
1797 /// to parameterize some operations.
1798 class VTSDNode : public SDNode {
1800 friend class SelectionDAG;
1801 explicit VTSDNode(EVT VT)
1802 : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1807 EVT getVT() const { return ValueType; }
1809 static bool classof(const SDNode *N) {
1810 return N->getOpcode() == ISD::VALUETYPE;
1814 /// Base class for LoadSDNode and StoreSDNode
1815 class LSBaseSDNode : public MemSDNode {
1816 //! Operand array for load and store
1818 \note Moving this array to the base class captures more
1819 common functionality shared between LoadSDNode and
1824 LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, DebugLoc dl,
1825 SDValue *Operands, unsigned numOperands,
1826 SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
1827 MachineMemOperand *MMO)
1828 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
1829 SubclassData |= AM << 2;
1830 assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
1831 InitOperands(Ops, Operands, numOperands);
1832 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1833 "Only indexed loads and stores have a non-undef offset operand");
1836 const SDValue &getOffset() const {
1837 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1840 /// Return the addressing mode for this load or store:
1841 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
1842 ISD::MemIndexedMode getAddressingMode() const {
1843 return ISD::MemIndexedMode((SubclassData >> 2) & 7);
1846 /// Return true if this is a pre/post inc/dec load/store.
1847 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
1849 /// Return true if this is NOT a pre/post inc/dec load/store.
1850 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
1852 static bool classof(const SDNode *N) {
1853 return N->getOpcode() == ISD::LOAD ||
1854 N->getOpcode() == ISD::STORE;
1858 /// This class is used to represent ISD::LOAD nodes.
1859 class LoadSDNode : public LSBaseSDNode {
1860 friend class SelectionDAG;
1861 LoadSDNode(SDValue *ChainPtrOff, unsigned Order, DebugLoc dl, SDVTList VTs,
1862 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
1863 MachineMemOperand *MMO)
1864 : LSBaseSDNode(ISD::LOAD, Order, dl, ChainPtrOff, 3, VTs, AM, MemVT, MMO) {
1865 SubclassData |= (unsigned short)ETy;
1866 assert(getExtensionType() == ETy && "LoadExtType encoding error!");
1867 assert(readMem() && "Load MachineMemOperand is not a load!");
1868 assert(!writeMem() && "Load MachineMemOperand is a store!");
1872 /// Return whether this is a plain node,
1873 /// or one of the varieties of value-extending loads.
1874 ISD::LoadExtType getExtensionType() const {
1875 return ISD::LoadExtType(SubclassData & 3);
1878 const SDValue &getBasePtr() const { return getOperand(1); }
1879 const SDValue &getOffset() const { return getOperand(2); }
1881 static bool classof(const SDNode *N) {
1882 return N->getOpcode() == ISD::LOAD;
1886 /// This class is used to represent ISD::STORE nodes.
1887 class StoreSDNode : public LSBaseSDNode {
1888 friend class SelectionDAG;
1889 StoreSDNode(SDValue *ChainValuePtrOff, unsigned Order, DebugLoc dl,
1890 SDVTList VTs, ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
1891 MachineMemOperand *MMO)
1892 : LSBaseSDNode(ISD::STORE, Order, dl, ChainValuePtrOff, 4,
1893 VTs, AM, MemVT, MMO) {
1894 SubclassData |= (unsigned short)isTrunc;
1895 assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
1896 assert(!readMem() && "Store MachineMemOperand is a load!");
1897 assert(writeMem() && "Store MachineMemOperand is not a store!");
1901 /// Return true if the op does a truncation before store.
1902 /// For integers this is the same as doing a TRUNCATE and storing the result.
1903 /// For floats, it is the same as doing an FP_ROUND and storing the result.
1904 bool isTruncatingStore() const { return SubclassData & 1; }
1906 const SDValue &getValue() const { return getOperand(1); }
1907 const SDValue &getBasePtr() const { return getOperand(2); }
1908 const SDValue &getOffset() const { return getOperand(3); }
1910 static bool classof(const SDNode *N) {
1911 return N->getOpcode() == ISD::STORE;
1915 /// This base class is used to represent MLOAD and MSTORE nodes
1916 class MaskedLoadStoreSDNode : public MemSDNode {
1920 friend class SelectionDAG;
1921 MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order, DebugLoc dl,
1922 SDValue *Operands, unsigned numOperands,
1923 SDVTList VTs, EVT MemVT, MachineMemOperand *MMO)
1924 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
1925 InitOperands(Ops, Operands, numOperands);
1928 // In the both nodes address is Op1, mask is Op2:
1929 // MaskedLoadSDNode (Chain, ptr, mask, src0), src0 is a passthru value
1930 // MaskedStoreSDNode (Chain, ptr, mask, data)
1931 // Mask is a vector of i1 elements
1932 const SDValue &getBasePtr() const { return getOperand(1); }
1933 const SDValue &getMask() const { return getOperand(2); }
1935 static bool classof(const SDNode *N) {
1936 return N->getOpcode() == ISD::MLOAD ||
1937 N->getOpcode() == ISD::MSTORE;
1941 /// This class is used to represent an MLOAD node
1942 class MaskedLoadSDNode : public MaskedLoadStoreSDNode {
1944 friend class SelectionDAG;
1945 MaskedLoadSDNode(unsigned Order, DebugLoc dl, SDValue *Operands,
1946 unsigned numOperands, SDVTList VTs, ISD::LoadExtType ETy,
1947 EVT MemVT, MachineMemOperand *MMO)
1948 : MaskedLoadStoreSDNode(ISD::MLOAD, Order, dl, Operands, numOperands,
1950 SubclassData |= (unsigned short)ETy;
1953 ISD::LoadExtType getExtensionType() const {
1954 return ISD::LoadExtType(SubclassData & 3);
1956 const SDValue &getSrc0() const { return getOperand(3); }
1957 static bool classof(const SDNode *N) {
1958 return N->getOpcode() == ISD::MLOAD;
1962 /// This class is used to represent an MSTORE node
1963 class MaskedStoreSDNode : public MaskedLoadStoreSDNode {
1966 friend class SelectionDAG;
1967 MaskedStoreSDNode(unsigned Order, DebugLoc dl, SDValue *Operands,
1968 unsigned numOperands, SDVTList VTs, bool isTrunc, EVT MemVT,
1969 MachineMemOperand *MMO)
1970 : MaskedLoadStoreSDNode(ISD::MSTORE, Order, dl, Operands, numOperands,
1972 SubclassData |= (unsigned short)isTrunc;
1974 /// Return true if the op does a truncation before store.
1975 /// For integers this is the same as doing a TRUNCATE and storing the result.
1976 /// For floats, it is the same as doing an FP_ROUND and storing the result.
1977 bool isTruncatingStore() const { return SubclassData & 1; }
1979 const SDValue &getValue() const { return getOperand(3); }
1981 static bool classof(const SDNode *N) {
1982 return N->getOpcode() == ISD::MSTORE;
1986 /// An SDNode that represents everything that will be needed
1987 /// to construct a MachineInstr. These nodes are created during the
1988 /// instruction selection proper phase.
1989 class MachineSDNode : public SDNode {
1991 typedef MachineMemOperand **mmo_iterator;
1994 friend class SelectionDAG;
1995 MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc DL, SDVTList VTs)
1996 : SDNode(Opc, Order, DL, VTs), MemRefs(nullptr), MemRefsEnd(nullptr) {}
1998 /// Operands for this instruction, if they fit here. If
1999 /// they don't, this field is unused.
2000 SDUse LocalOperands[4];
2002 /// Memory reference descriptions for this instruction.
2003 mmo_iterator MemRefs;
2004 mmo_iterator MemRefsEnd;
2007 mmo_iterator memoperands_begin() const { return MemRefs; }
2008 mmo_iterator memoperands_end() const { return MemRefsEnd; }
2009 bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
2011 /// Assign this MachineSDNodes's memory reference descriptor
2012 /// list. This does not transfer ownership.
2013 void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
2014 for (mmo_iterator MMI = NewMemRefs, MME = NewMemRefsEnd; MMI != MME; ++MMI)
2015 assert(*MMI && "Null mem ref detected!");
2016 MemRefs = NewMemRefs;
2017 MemRefsEnd = NewMemRefsEnd;
2020 static bool classof(const SDNode *N) {
2021 return N->isMachineOpcode();
2025 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
2026 SDNode, ptrdiff_t> {
2030 SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2032 bool operator==(const SDNodeIterator& x) const {
2033 return Operand == x.Operand;
2035 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2037 pointer operator*() const {
2038 return Node->getOperand(Operand).getNode();
2040 pointer operator->() const { return operator*(); }
2042 SDNodeIterator& operator++() { // Preincrement
2046 SDNodeIterator operator++(int) { // Postincrement
2047 SDNodeIterator tmp = *this; ++*this; return tmp;
2049 size_t operator-(SDNodeIterator Other) const {
2050 assert(Node == Other.Node &&
2051 "Cannot compare iterators of two different nodes!");
2052 return Operand - Other.Operand;
2055 static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
2056 static SDNodeIterator end (const SDNode *N) {
2057 return SDNodeIterator(N, N->getNumOperands());
2060 unsigned getOperand() const { return Operand; }
2061 const SDNode *getNode() const { return Node; }
2064 template <> struct GraphTraits<SDNode*> {
2065 typedef SDNode NodeType;
2066 typedef SDNodeIterator ChildIteratorType;
2067 static inline NodeType *getEntryNode(SDNode *N) { return N; }
2068 static inline ChildIteratorType child_begin(NodeType *N) {
2069 return SDNodeIterator::begin(N);
2071 static inline ChildIteratorType child_end(NodeType *N) {
2072 return SDNodeIterator::end(N);
2076 /// The largest SDNode class.
2077 typedef AtomicSDNode LargestSDNode;
2079 /// The SDNode class with the greatest alignment requirement.
2080 typedef GlobalAddressSDNode MostAlignedSDNode;
2083 /// Returns true if the specified node is a non-extending and unindexed load.
2084 inline bool isNormalLoad(const SDNode *N) {
2085 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2086 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2087 Ld->getAddressingMode() == ISD::UNINDEXED;
2090 /// Returns true if the specified node is a non-extending load.
2091 inline bool isNON_EXTLoad(const SDNode *N) {
2092 return isa<LoadSDNode>(N) &&
2093 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2096 /// Returns true if the specified node is a EXTLOAD.
2097 inline bool isEXTLoad(const SDNode *N) {
2098 return isa<LoadSDNode>(N) &&
2099 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2102 /// Returns true if the specified node is a SEXTLOAD.
2103 inline bool isSEXTLoad(const SDNode *N) {
2104 return isa<LoadSDNode>(N) &&
2105 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2108 /// Returns true if the specified node is a ZEXTLOAD.
2109 inline bool isZEXTLoad(const SDNode *N) {
2110 return isa<LoadSDNode>(N) &&
2111 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2114 /// Returns true if the specified node is an unindexed load.
2115 inline bool isUNINDEXEDLoad(const SDNode *N) {
2116 return isa<LoadSDNode>(N) &&
2117 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2120 /// Returns true if the specified node is a non-truncating
2121 /// and unindexed store.
2122 inline bool isNormalStore(const SDNode *N) {
2123 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2124 return St && !St->isTruncatingStore() &&
2125 St->getAddressingMode() == ISD::UNINDEXED;
2128 /// Returns true if the specified node is a non-truncating store.
2129 inline bool isNON_TRUNCStore(const SDNode *N) {
2130 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2133 /// Returns true if the specified node is a truncating store.
2134 inline bool isTRUNCStore(const SDNode *N) {
2135 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2138 /// Returns true if the specified node is an unindexed store.
2139 inline bool isUNINDEXEDStore(const SDNode *N) {
2140 return isa<StoreSDNode>(N) &&
2141 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2145 } // end llvm namespace