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/iterator_range.h"
23 #include "llvm/ADT/BitVector.h"
24 #include "llvm/ADT/FoldingSet.h"
25 #include "llvm/ADT/GraphTraits.h"
26 #include "llvm/ADT/STLExtras.h"
27 #include "llvm/ADT/SmallPtrSet.h"
28 #include "llvm/ADT/SmallVector.h"
29 #include "llvm/ADT/ilist_node.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 LLVM_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) LLVM_DELETED_FUNCTION;
263 void operator=(const SDUse &U) LLVM_DELETED_FUNCTION;
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 /// isMachineOpcode - Test if this node has a post-isel opcode, directly
421 /// corresponding to a MachineInstr opcode.
422 bool isMachineOpcode() const { return NodeType < 0; }
424 /// getMachineOpcode - This may only be called if isMachineOpcode returns
425 /// true. It returns the MachineInstr opcode value that the node's opcode
427 unsigned getMachineOpcode() const {
428 assert(isMachineOpcode() && "Not a MachineInstr opcode!");
432 /// getHasDebugValue - get this bit.
433 bool getHasDebugValue() const { return HasDebugValue; }
435 /// setHasDebugValue - set this bit.
436 void setHasDebugValue(bool b) { HasDebugValue = b; }
438 /// use_empty - Return true if there are no uses of this node.
440 bool use_empty() const { return UseList == nullptr; }
442 /// hasOneUse - Return true if there is exactly one use of this node.
444 bool hasOneUse() const {
445 return !use_empty() && std::next(use_begin()) == use_end();
448 /// use_size - Return the number of uses of this node. This method takes
449 /// time proportional to the number of uses.
451 size_t use_size() const { return std::distance(use_begin(), use_end()); }
453 /// getNodeId - Return the unique node id.
455 int getNodeId() const { return NodeId; }
457 /// setNodeId - Set unique node id.
458 void setNodeId(int Id) { NodeId = Id; }
460 /// getIROrder - Return the node ordering.
462 unsigned getIROrder() const { return IROrder; }
464 /// setIROrder - Set the node ordering.
466 void setIROrder(unsigned Order) { IROrder = Order; }
468 /// getDebugLoc - Return the source location info.
469 const DebugLoc getDebugLoc() const { return debugLoc; }
471 /// setDebugLoc - Set source location info. Try to avoid this, putting
472 /// it in the constructor is preferable.
473 void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
475 /// use_iterator - This class provides iterator support for SDUse
476 /// operands that use a specific SDNode.
478 : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
480 explicit use_iterator(SDUse *op) : Op(op) {
484 typedef std::iterator<std::forward_iterator_tag,
485 SDUse, ptrdiff_t>::reference reference;
486 typedef std::iterator<std::forward_iterator_tag,
487 SDUse, ptrdiff_t>::pointer pointer;
489 use_iterator(const use_iterator &I) : Op(I.Op) {}
490 use_iterator() : Op(nullptr) {}
492 bool operator==(const use_iterator &x) const {
495 bool operator!=(const use_iterator &x) const {
496 return !operator==(x);
499 /// atEnd - return true if this iterator is at the end of uses list.
500 bool atEnd() const { return Op == nullptr; }
502 // Iterator traversal: forward iteration only.
503 use_iterator &operator++() { // Preincrement
504 assert(Op && "Cannot increment end iterator!");
509 use_iterator operator++(int) { // Postincrement
510 use_iterator tmp = *this; ++*this; return tmp;
513 /// Retrieve a pointer to the current user node.
514 SDNode *operator*() const {
515 assert(Op && "Cannot dereference end iterator!");
516 return Op->getUser();
519 SDNode *operator->() const { return operator*(); }
521 SDUse &getUse() const { return *Op; }
523 /// getOperandNo - Retrieve the operand # of this use in its user.
525 unsigned getOperandNo() const {
526 assert(Op && "Cannot dereference end iterator!");
527 return (unsigned)(Op - Op->getUser()->OperandList);
531 /// use_begin/use_end - Provide iteration support to walk over all uses
534 use_iterator use_begin() const {
535 return use_iterator(UseList);
538 static use_iterator use_end() { return use_iterator(nullptr); }
540 inline iterator_range<use_iterator> uses() {
541 return iterator_range<use_iterator>(use_begin(), use_end());
543 inline iterator_range<use_iterator> uses() const {
544 return iterator_range<use_iterator>(use_begin(), use_end());
547 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
548 /// indicated value. This method ignores uses of other values defined by this
550 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
552 /// hasAnyUseOfValue - Return true if there are any use of the indicated
553 /// value. This method ignores uses of other values defined by this operation.
554 bool hasAnyUseOfValue(unsigned Value) const;
556 /// isOnlyUserOf - Return true if this node is the only use of N.
558 bool isOnlyUserOf(SDNode *N) const;
560 /// isOperandOf - Return true if this node is an operand of N.
562 bool isOperandOf(SDNode *N) const;
564 /// isPredecessorOf - Return true if this node is a predecessor of N.
565 /// NOTE: Implemented on top of hasPredecessor and every bit as
566 /// expensive. Use carefully.
567 bool isPredecessorOf(const SDNode *N) const {
568 return N->hasPredecessor(this);
571 /// hasPredecessor - Return true if N is a predecessor of this node.
572 /// N is either an operand of this node, or can be reached by recursively
573 /// traversing up the operands.
574 /// NOTE: This is an expensive method. Use it carefully.
575 bool hasPredecessor(const SDNode *N) const;
577 /// hasPredecesorHelper - Return true if N is a predecessor of this node.
578 /// N is either an operand of this node, or can be reached by recursively
579 /// traversing up the operands.
580 /// In this helper the Visited and worklist sets are held externally to
581 /// cache predecessors over multiple invocations. If you want to test for
582 /// multiple predecessors this method is preferable to multiple calls to
583 /// hasPredecessor. Be sure to clear Visited and Worklist if the DAG
585 /// NOTE: This is still very expensive. Use carefully.
586 bool hasPredecessorHelper(const SDNode *N,
587 SmallPtrSet<const SDNode *, 32> &Visited,
588 SmallVectorImpl<const SDNode *> &Worklist) const;
590 /// getNumOperands - Return the number of values used by this operation.
592 unsigned getNumOperands() const { return NumOperands; }
594 /// getConstantOperandVal - Helper method returns the integer value of a
595 /// ConstantSDNode operand.
596 uint64_t getConstantOperandVal(unsigned Num) const;
598 const SDValue &getOperand(unsigned Num) const {
599 assert(Num < NumOperands && "Invalid child # of SDNode!");
600 return OperandList[Num];
603 typedef SDUse* op_iterator;
604 op_iterator op_begin() const { return OperandList; }
605 op_iterator op_end() const { return OperandList+NumOperands; }
606 ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
608 SDVTList getVTList() const {
609 SDVTList X = { ValueList, NumValues };
613 /// getGluedNode - If this node has a glue operand, return the node
614 /// to which the glue operand points. Otherwise return NULL.
615 SDNode *getGluedNode() const {
616 if (getNumOperands() != 0 &&
617 getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
618 return getOperand(getNumOperands()-1).getNode();
622 // If this is a pseudo op, like copyfromreg, look to see if there is a
623 // real target node glued to it. If so, return the target node.
624 const SDNode *getGluedMachineNode() const {
625 const SDNode *FoundNode = this;
627 // Climb up glue edges until a machine-opcode node is found, or the
628 // end of the chain is reached.
629 while (!FoundNode->isMachineOpcode()) {
630 const SDNode *N = FoundNode->getGluedNode();
638 /// getGluedUser - If this node has a glue value with a user, return
639 /// the user (there is at most one). Otherwise return NULL.
640 SDNode *getGluedUser() const {
641 for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
642 if (UI.getUse().get().getValueType() == MVT::Glue)
647 /// getNumValues - Return the number of values defined/returned by this
650 unsigned getNumValues() const { return NumValues; }
652 /// getValueType - Return the type of a specified result.
654 EVT getValueType(unsigned ResNo) const {
655 assert(ResNo < NumValues && "Illegal result number!");
656 return ValueList[ResNo];
659 /// Return the type of a specified result as a simple type.
661 MVT getSimpleValueType(unsigned ResNo) const {
662 return getValueType(ResNo).getSimpleVT();
665 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
667 unsigned getValueSizeInBits(unsigned ResNo) const {
668 return getValueType(ResNo).getSizeInBits();
671 typedef const EVT* value_iterator;
672 value_iterator value_begin() const { return ValueList; }
673 value_iterator value_end() const { return ValueList+NumValues; }
675 /// getOperationName - Return the opcode of this operation for printing.
677 std::string getOperationName(const SelectionDAG *G = nullptr) const;
678 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
679 void print_types(raw_ostream &OS, const SelectionDAG *G) const;
680 void print_details(raw_ostream &OS, const SelectionDAG *G) const;
681 void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
682 void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
684 /// printrFull - Print a SelectionDAG node and all children down to
685 /// the leaves. The given SelectionDAG allows target-specific nodes
686 /// to be printed in human-readable form. Unlike printr, this will
687 /// print the whole DAG, including children that appear multiple
690 void printrFull(raw_ostream &O, const SelectionDAG *G = nullptr) const;
692 /// printrWithDepth - Print a SelectionDAG node and children up to
693 /// depth "depth." The given SelectionDAG allows target-specific
694 /// nodes to be printed in human-readable form. Unlike printr, this
695 /// will print children that appear multiple times wherever they are
698 void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
699 unsigned depth = 100) const;
702 /// dump - Dump this node, for debugging.
705 /// dumpr - Dump (recursively) this node and its use-def subgraph.
708 /// dump - Dump this node, for debugging.
709 /// The given SelectionDAG allows target-specific nodes to be printed
710 /// in human-readable form.
711 void dump(const SelectionDAG *G) const;
713 /// dumpr - Dump (recursively) this node and its use-def subgraph.
714 /// The given SelectionDAG allows target-specific nodes to be printed
715 /// in human-readable form.
716 void dumpr(const SelectionDAG *G) const;
718 /// dumprFull - printrFull to dbgs(). The given SelectionDAG allows
719 /// target-specific nodes to be printed in human-readable form.
720 /// Unlike dumpr, this will print the whole DAG, including children
721 /// that appear multiple times.
723 void dumprFull(const SelectionDAG *G = nullptr) const;
725 /// dumprWithDepth - printrWithDepth to dbgs(). The given
726 /// SelectionDAG allows target-specific nodes to be printed in
727 /// human-readable form. Unlike dumpr, this will print children
728 /// that appear multiple times wherever they are used.
730 void dumprWithDepth(const SelectionDAG *G = nullptr,
731 unsigned depth = 100) const;
733 /// Profile - Gather unique data for the node.
735 void Profile(FoldingSetNodeID &ID) const;
737 /// addUse - This method should only be used by the SDUse class.
739 void addUse(SDUse &U) { U.addToList(&UseList); }
742 static SDVTList getSDVTList(EVT VT) {
743 SDVTList Ret = { getValueTypeList(VT), 1 };
747 SDNode(unsigned Opc, unsigned Order, const DebugLoc dl, SDVTList VTs,
748 ArrayRef<SDValue> Ops)
749 : NodeType(Opc), OperandsNeedDelete(true), HasDebugValue(false),
750 SubclassData(0), NodeId(-1),
751 OperandList(Ops.size() ? new SDUse[Ops.size()] : nullptr),
752 ValueList(VTs.VTs), UseList(nullptr),
753 NumOperands(Ops.size()), NumValues(VTs.NumVTs),
754 debugLoc(dl), IROrder(Order) {
755 for (unsigned i = 0; i != Ops.size(); ++i) {
756 OperandList[i].setUser(this);
757 OperandList[i].setInitial(Ops[i]);
759 checkForCycles(this);
762 /// This constructor adds no operands itself; operands can be
763 /// set later with InitOperands.
764 SDNode(unsigned Opc, unsigned Order, const DebugLoc dl, SDVTList VTs)
765 : NodeType(Opc), OperandsNeedDelete(false), HasDebugValue(false),
766 SubclassData(0), NodeId(-1), OperandList(nullptr), ValueList(VTs.VTs),
767 UseList(nullptr), NumOperands(0), NumValues(VTs.NumVTs), debugLoc(dl),
770 /// InitOperands - Initialize the operands list of this with 1 operand.
771 void InitOperands(SDUse *Ops, const SDValue &Op0) {
772 Ops[0].setUser(this);
773 Ops[0].setInitial(Op0);
776 checkForCycles(this);
779 /// InitOperands - Initialize the operands list of this with 2 operands.
780 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1) {
781 Ops[0].setUser(this);
782 Ops[0].setInitial(Op0);
783 Ops[1].setUser(this);
784 Ops[1].setInitial(Op1);
787 checkForCycles(this);
790 /// InitOperands - Initialize the operands list of this with 3 operands.
791 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
792 const SDValue &Op2) {
793 Ops[0].setUser(this);
794 Ops[0].setInitial(Op0);
795 Ops[1].setUser(this);
796 Ops[1].setInitial(Op1);
797 Ops[2].setUser(this);
798 Ops[2].setInitial(Op2);
801 checkForCycles(this);
804 /// InitOperands - Initialize the operands list of this with 4 operands.
805 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
806 const SDValue &Op2, const SDValue &Op3) {
807 Ops[0].setUser(this);
808 Ops[0].setInitial(Op0);
809 Ops[1].setUser(this);
810 Ops[1].setInitial(Op1);
811 Ops[2].setUser(this);
812 Ops[2].setInitial(Op2);
813 Ops[3].setUser(this);
814 Ops[3].setInitial(Op3);
817 checkForCycles(this);
820 /// InitOperands - Initialize the operands list of this with N operands.
821 void InitOperands(SDUse *Ops, const SDValue *Vals, unsigned N) {
822 for (unsigned i = 0; i != N; ++i) {
823 Ops[i].setUser(this);
824 Ops[i].setInitial(Vals[i]);
828 checkForCycles(this);
831 /// DropOperands - Release the operands and set this node to have
836 /// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
837 /// into SDNode creation functions.
838 /// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
839 /// from the original Instruction, and IROrder is the ordinal position of
841 /// When an SDNode is created after the DAG is being built, both DebugLoc and
842 /// the IROrder are propagated from the original SDNode.
843 /// So SDLoc class provides two constructors besides the default one, one to
844 /// be used by the DAGBuilder, the other to be used by others.
847 // Ptr could be used for either Instruction* or SDNode*. It is used for
848 // Instruction* if IROrder is not -1.
853 SDLoc() : Ptr(nullptr), IROrder(0) {}
854 SDLoc(const SDNode *N) : Ptr(N), IROrder(-1) {
855 assert(N && "null SDNode");
857 SDLoc(const SDValue V) : Ptr(V.getNode()), IROrder(-1) {
858 assert(Ptr && "null SDNode");
860 SDLoc(const Instruction *I, int Order) : Ptr(I), IROrder(Order) {
861 assert(Order >= 0 && "bad IROrder");
863 unsigned getIROrder() {
864 if (IROrder >= 0 || Ptr == nullptr) {
865 return (unsigned)IROrder;
867 const SDNode *N = (const SDNode*)(Ptr);
868 return N->getIROrder();
870 DebugLoc getDebugLoc() {
875 const Instruction *I = (const Instruction*)(Ptr);
876 return I->getDebugLoc();
878 const SDNode *N = (const SDNode*)(Ptr);
879 return N->getDebugLoc();
884 // Define inline functions from the SDValue class.
886 inline SDValue::SDValue(SDNode *node, unsigned resno)
887 : Node(node), ResNo(resno) {
888 assert((!Node || ResNo < Node->getNumValues()) &&
889 "Invalid result number for the given node!");
890 assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
893 inline unsigned SDValue::getOpcode() const {
894 return Node->getOpcode();
896 inline EVT SDValue::getValueType() const {
897 return Node->getValueType(ResNo);
899 inline unsigned SDValue::getNumOperands() const {
900 return Node->getNumOperands();
902 inline const SDValue &SDValue::getOperand(unsigned i) const {
903 return Node->getOperand(i);
905 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
906 return Node->getConstantOperandVal(i);
908 inline bool SDValue::isTargetOpcode() const {
909 return Node->isTargetOpcode();
911 inline bool SDValue::isTargetMemoryOpcode() const {
912 return Node->isTargetMemoryOpcode();
914 inline bool SDValue::isMachineOpcode() const {
915 return Node->isMachineOpcode();
917 inline unsigned SDValue::getMachineOpcode() const {
918 return Node->getMachineOpcode();
920 inline bool SDValue::use_empty() const {
921 return !Node->hasAnyUseOfValue(ResNo);
923 inline bool SDValue::hasOneUse() const {
924 return Node->hasNUsesOfValue(1, ResNo);
926 inline const DebugLoc SDValue::getDebugLoc() const {
927 return Node->getDebugLoc();
929 inline void SDValue::dump() const {
932 inline void SDValue::dumpr() const {
933 return Node->dumpr();
935 // Define inline functions from the SDUse class.
937 inline void SDUse::set(const SDValue &V) {
938 if (Val.getNode()) removeFromList();
940 if (V.getNode()) V.getNode()->addUse(*this);
943 inline void SDUse::setInitial(const SDValue &V) {
945 V.getNode()->addUse(*this);
948 inline void SDUse::setNode(SDNode *N) {
949 if (Val.getNode()) removeFromList();
951 if (N) N->addUse(*this);
954 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
955 /// to allow co-allocation of node operands with the node itself.
956 class UnarySDNode : public SDNode {
959 UnarySDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
961 : SDNode(Opc, Order, dl, VTs) {
962 InitOperands(&Op, X);
966 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
967 /// to allow co-allocation of node operands with the node itself.
968 class BinarySDNode : public SDNode {
971 BinarySDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
972 SDValue X, SDValue Y)
973 : SDNode(Opc, Order, dl, VTs) {
974 InitOperands(Ops, X, Y);
978 /// BinaryWithFlagsSDNode - This class is an extension of BinarySDNode
979 /// used from those opcodes that have associated extra flags.
980 class BinaryWithFlagsSDNode : public BinarySDNode {
981 enum { NUW = (1 << 0), NSW = (1 << 1), EXACT = (1 << 2) };
984 BinaryWithFlagsSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
985 SDValue X, SDValue Y)
986 : BinarySDNode(Opc, Order, dl, VTs, X, Y) {}
987 /// getRawSubclassData - Return the SubclassData value, which contains an
988 /// encoding of the flags.
989 /// This function should be used to add subclass data to the NodeID value.
990 unsigned getRawSubclassData() const { return SubclassData; }
991 void setHasNoUnsignedWrap(bool b) {
992 SubclassData = (SubclassData & ~NUW) | (b ? NUW : 0);
994 void setHasNoSignedWrap(bool b) {
995 SubclassData = (SubclassData & ~NSW) | (b ? NSW : 0);
997 void setIsExact(bool b) {
998 SubclassData = (SubclassData & ~EXACT) | (b ? EXACT : 0);
1000 bool hasNoUnsignedWrap() const { return SubclassData & NUW; }
1001 bool hasNoSignedWrap() const { return SubclassData & NSW; }
1002 bool isExact() const { return SubclassData & EXACT; }
1003 static bool classof(const SDNode *N) {
1004 return isBinOpWithFlags(N->getOpcode());
1008 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1009 /// to allow co-allocation of node operands with the node itself.
1010 class TernarySDNode : public SDNode {
1013 TernarySDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1014 SDValue X, SDValue Y, SDValue Z)
1015 : SDNode(Opc, Order, dl, VTs) {
1016 InitOperands(Ops, X, Y, Z);
1021 /// HandleSDNode - This class is used to form a handle around another node that
1022 /// is persistent and is updated across invocations of replaceAllUsesWith on its
1023 /// operand. This node should be directly created by end-users and not added to
1024 /// the AllNodes list.
1025 class HandleSDNode : public SDNode {
1028 explicit HandleSDNode(SDValue X)
1029 : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1030 InitOperands(&Op, X);
1033 const SDValue &getValue() const { return Op; }
1036 class AddrSpaceCastSDNode : public UnarySDNode {
1038 unsigned SrcAddrSpace;
1039 unsigned DestAddrSpace;
1042 AddrSpaceCastSDNode(unsigned Order, DebugLoc dl, EVT VT, SDValue X,
1043 unsigned SrcAS, unsigned DestAS);
1045 unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1046 unsigned getDestAddressSpace() const { return DestAddrSpace; }
1048 static bool classof(const SDNode *N) {
1049 return N->getOpcode() == ISD::ADDRSPACECAST;
1053 /// Abstact virtual class for operations for memory operations
1054 class MemSDNode : public SDNode {
1056 // MemoryVT - VT of in-memory value.
1060 /// MMO - Memory reference information.
1061 MachineMemOperand *MMO;
1064 MemSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1065 EVT MemoryVT, MachineMemOperand *MMO);
1067 MemSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1068 ArrayRef<SDValue> Ops, EVT MemoryVT, MachineMemOperand *MMO);
1070 bool readMem() const { return MMO->isLoad(); }
1071 bool writeMem() const { return MMO->isStore(); }
1073 /// Returns alignment and volatility of the memory access
1074 unsigned getOriginalAlignment() const {
1075 return MMO->getBaseAlignment();
1077 unsigned getAlignment() const {
1078 return MMO->getAlignment();
1081 /// getRawSubclassData - Return the SubclassData value, which contains an
1082 /// encoding of the volatile flag, as well as bits used by subclasses. This
1083 /// function should only be used to compute a FoldingSetNodeID value.
1084 unsigned getRawSubclassData() const {
1085 return SubclassData;
1088 // We access subclass data here so that we can check consistency
1089 // with MachineMemOperand information.
1090 bool isVolatile() const { return (SubclassData >> 5) & 1; }
1091 bool isNonTemporal() const { return (SubclassData >> 6) & 1; }
1092 bool isInvariant() const { return (SubclassData >> 7) & 1; }
1094 AtomicOrdering getOrdering() const {
1095 return AtomicOrdering((SubclassData >> 8) & 15);
1097 SynchronizationScope getSynchScope() const {
1098 return SynchronizationScope((SubclassData >> 12) & 1);
1101 // Returns the offset from the location of the access.
1102 int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1104 /// Returns the AA info that describes the dereference.
1105 AAMDNodes getAAInfo() const { return MMO->getAAInfo(); }
1107 /// Returns the Ranges that describes the dereference.
1108 const MDNode *getRanges() const { return MMO->getRanges(); }
1110 /// getMemoryVT - Return the type of the in-memory value.
1111 EVT getMemoryVT() const { return MemoryVT; }
1113 /// getMemOperand - Return a MachineMemOperand object describing the memory
1114 /// reference performed by operation.
1115 MachineMemOperand *getMemOperand() const { return MMO; }
1117 const MachinePointerInfo &getPointerInfo() const {
1118 return MMO->getPointerInfo();
1121 /// getAddressSpace - Return the address space for the associated pointer
1122 unsigned getAddressSpace() const {
1123 return getPointerInfo().getAddrSpace();
1126 /// refineAlignment - Update this MemSDNode's MachineMemOperand information
1127 /// to reflect the alignment of NewMMO, if it has a greater alignment.
1128 /// This must only be used when the new alignment applies to all users of
1129 /// this MachineMemOperand.
1130 void refineAlignment(const MachineMemOperand *NewMMO) {
1131 MMO->refineAlignment(NewMMO);
1134 const SDValue &getChain() const { return getOperand(0); }
1135 const SDValue &getBasePtr() const {
1136 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1139 // Methods to support isa and dyn_cast
1140 static bool classof(const SDNode *N) {
1141 // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1142 // with either an intrinsic or a target opcode.
1143 return N->getOpcode() == ISD::LOAD ||
1144 N->getOpcode() == ISD::STORE ||
1145 N->getOpcode() == ISD::PREFETCH ||
1146 N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1147 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1148 N->getOpcode() == ISD::ATOMIC_SWAP ||
1149 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1150 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1151 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1152 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1153 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1154 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1155 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1156 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1157 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1158 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1159 N->getOpcode() == ISD::ATOMIC_LOAD ||
1160 N->getOpcode() == ISD::ATOMIC_STORE ||
1161 N->isTargetMemoryOpcode();
1165 /// AtomicSDNode - A SDNode reprenting atomic operations.
1167 class AtomicSDNode : public MemSDNode {
1170 /// For cmpxchg instructions, the ordering requirements when a store does not
1172 AtomicOrdering FailureOrdering;
1174 void InitAtomic(AtomicOrdering SuccessOrdering,
1175 AtomicOrdering FailureOrdering,
1176 SynchronizationScope SynchScope) {
1177 // This must match encodeMemSDNodeFlags() in SelectionDAG.cpp.
1178 assert((SuccessOrdering & 15) == SuccessOrdering &&
1179 "Ordering may not require more than 4 bits!");
1180 assert((FailureOrdering & 15) == FailureOrdering &&
1181 "Ordering may not require more than 4 bits!");
1182 assert((SynchScope & 1) == SynchScope &&
1183 "SynchScope may not require more than 1 bit!");
1184 SubclassData |= SuccessOrdering << 8;
1185 SubclassData |= SynchScope << 12;
1186 this->FailureOrdering = FailureOrdering;
1187 assert(getSuccessOrdering() == SuccessOrdering &&
1188 "Ordering encoding error!");
1189 assert(getFailureOrdering() == FailureOrdering &&
1190 "Ordering encoding error!");
1191 assert(getSynchScope() == SynchScope && "Synch-scope encoding error!");
1195 // Opc: opcode for atomic
1196 // VTL: value type list
1197 // Chain: memory chain for operaand
1198 // Ptr: address to update as a SDValue
1199 // Cmp: compare value
1201 // SrcVal: address to update as a Value (used for MemOperand)
1202 // Align: alignment of memory
1203 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
1204 EVT MemVT, SDValue Chain, SDValue Ptr, SDValue Cmp, SDValue Swp,
1205 MachineMemOperand *MMO, AtomicOrdering Ordering,
1206 SynchronizationScope SynchScope)
1207 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1208 InitAtomic(Ordering, Ordering, SynchScope);
1209 InitOperands(Ops, Chain, Ptr, Cmp, Swp);
1211 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
1213 SDValue Chain, SDValue Ptr,
1214 SDValue Val, MachineMemOperand *MMO,
1215 AtomicOrdering Ordering, SynchronizationScope SynchScope)
1216 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1217 InitAtomic(Ordering, Ordering, SynchScope);
1218 InitOperands(Ops, Chain, Ptr, Val);
1220 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
1222 SDValue Chain, SDValue Ptr,
1223 MachineMemOperand *MMO,
1224 AtomicOrdering Ordering, SynchronizationScope SynchScope)
1225 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1226 InitAtomic(Ordering, Ordering, SynchScope);
1227 InitOperands(Ops, Chain, Ptr);
1229 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL, EVT MemVT,
1230 const SDValue* AllOps, SDUse *DynOps, unsigned NumOps,
1231 MachineMemOperand *MMO,
1232 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
1233 SynchronizationScope SynchScope)
1234 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1235 InitAtomic(SuccessOrdering, FailureOrdering, SynchScope);
1236 assert((DynOps || NumOps <= array_lengthof(Ops)) &&
1237 "Too many ops for internal storage!");
1238 InitOperands(DynOps ? DynOps : Ops, AllOps, NumOps);
1241 const SDValue &getBasePtr() const { return getOperand(1); }
1242 const SDValue &getVal() const { return getOperand(2); }
1244 AtomicOrdering getSuccessOrdering() const {
1245 return getOrdering();
1248 // Not quite enough room in SubclassData for everything, so failure gets its
1250 AtomicOrdering getFailureOrdering() const {
1251 return FailureOrdering;
1254 bool isCompareAndSwap() const {
1255 unsigned Op = getOpcode();
1256 return Op == ISD::ATOMIC_CMP_SWAP || Op == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS;
1259 // Methods to support isa and dyn_cast
1260 static bool classof(const SDNode *N) {
1261 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1262 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1263 N->getOpcode() == ISD::ATOMIC_SWAP ||
1264 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1265 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1266 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1267 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1268 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1269 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1270 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1271 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1272 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1273 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1274 N->getOpcode() == ISD::ATOMIC_LOAD ||
1275 N->getOpcode() == ISD::ATOMIC_STORE;
1279 /// MemIntrinsicSDNode - This SDNode is used for target intrinsics that touch
1280 /// memory and need an associated MachineMemOperand. Its opcode may be
1281 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1282 /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1283 class MemIntrinsicSDNode : public MemSDNode {
1285 MemIntrinsicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1286 ArrayRef<SDValue> Ops, EVT MemoryVT,
1287 MachineMemOperand *MMO)
1288 : MemSDNode(Opc, Order, dl, VTs, Ops, MemoryVT, MMO) {
1291 // Methods to support isa and dyn_cast
1292 static bool classof(const SDNode *N) {
1293 // We lower some target intrinsics to their target opcode
1294 // early a node with a target opcode can be of this class
1295 return N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
1296 N->getOpcode() == ISD::INTRINSIC_VOID ||
1297 N->getOpcode() == ISD::PREFETCH ||
1298 N->isTargetMemoryOpcode();
1302 /// ShuffleVectorSDNode - This SDNode is used to implement the code generator
1303 /// support for the llvm IR shufflevector instruction. It combines elements
1304 /// from two input vectors into a new input vector, with the selection and
1305 /// ordering of elements determined by an array of integers, referred to as
1306 /// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1307 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1308 /// An index of -1 is treated as undef, such that the code generator may put
1309 /// any value in the corresponding element of the result.
1310 class ShuffleVectorSDNode : public SDNode {
1313 // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1314 // is freed when the SelectionDAG object is destroyed.
1317 friend class SelectionDAG;
1318 ShuffleVectorSDNode(EVT VT, unsigned Order, DebugLoc dl, SDValue N1,
1319 SDValue N2, const int *M)
1320 : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {
1321 InitOperands(Ops, N1, N2);
1325 ArrayRef<int> getMask() const {
1326 EVT VT = getValueType(0);
1327 return makeArrayRef(Mask, VT.getVectorNumElements());
1329 int getMaskElt(unsigned Idx) const {
1330 assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1334 bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1335 int getSplatIndex() const {
1336 assert(isSplat() && "Cannot get splat index for non-splat!");
1337 EVT VT = getValueType(0);
1338 for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
1342 llvm_unreachable("Splat with all undef indices?");
1344 static bool isSplatMask(const int *Mask, EVT VT);
1346 static bool classof(const SDNode *N) {
1347 return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1351 class ConstantSDNode : public SDNode {
1352 const ConstantInt *Value;
1353 friend class SelectionDAG;
1354 ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val, EVT VT)
1355 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant,
1356 0, DebugLoc(), getSDVTList(VT)), Value(val) {
1357 SubclassData |= (uint16_t)isOpaque;
1361 const ConstantInt *getConstantIntValue() const { return Value; }
1362 const APInt &getAPIntValue() const { return Value->getValue(); }
1363 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1364 int64_t getSExtValue() const { return Value->getSExtValue(); }
1366 bool isOne() const { return Value->isOne(); }
1367 bool isNullValue() const { return Value->isNullValue(); }
1368 bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1370 bool isOpaque() const { return SubclassData & 1; }
1372 static bool classof(const SDNode *N) {
1373 return N->getOpcode() == ISD::Constant ||
1374 N->getOpcode() == ISD::TargetConstant;
1378 class ConstantFPSDNode : public SDNode {
1379 const ConstantFP *Value;
1380 friend class SelectionDAG;
1381 ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1382 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1383 0, DebugLoc(), getSDVTList(VT)), Value(val) {
1387 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1388 const ConstantFP *getConstantFPValue() const { return Value; }
1390 /// isZero - Return true if the value is positive or negative zero.
1391 bool isZero() const { return Value->isZero(); }
1393 /// isNaN - Return true if the value is a NaN.
1394 bool isNaN() const { return Value->isNaN(); }
1396 /// isExactlyValue - We don't rely on operator== working on double values, as
1397 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1398 /// As such, this method can be used to do an exact bit-for-bit comparison of
1399 /// two floating point values.
1401 /// We leave the version with the double argument here because it's just so
1402 /// convenient to write "2.0" and the like. Without this function we'd
1403 /// have to duplicate its logic everywhere it's called.
1404 bool isExactlyValue(double V) const {
1407 Tmp.convert(Value->getValueAPF().getSemantics(),
1408 APFloat::rmNearestTiesToEven, &ignored);
1409 return isExactlyValue(Tmp);
1411 bool isExactlyValue(const APFloat& V) const;
1413 static bool isValueValidForType(EVT VT, const APFloat& Val);
1415 static bool classof(const SDNode *N) {
1416 return N->getOpcode() == ISD::ConstantFP ||
1417 N->getOpcode() == ISD::TargetConstantFP;
1421 class GlobalAddressSDNode : public SDNode {
1422 const GlobalValue *TheGlobal;
1424 unsigned char TargetFlags;
1425 friend class SelectionDAG;
1426 GlobalAddressSDNode(unsigned Opc, unsigned Order, DebugLoc DL,
1427 const GlobalValue *GA, EVT VT, int64_t o,
1428 unsigned char TargetFlags);
1431 const GlobalValue *getGlobal() const { return TheGlobal; }
1432 int64_t getOffset() const { return Offset; }
1433 unsigned char getTargetFlags() const { return TargetFlags; }
1434 // Return the address space this GlobalAddress belongs to.
1435 unsigned getAddressSpace() const;
1437 static bool classof(const SDNode *N) {
1438 return N->getOpcode() == ISD::GlobalAddress ||
1439 N->getOpcode() == ISD::TargetGlobalAddress ||
1440 N->getOpcode() == ISD::GlobalTLSAddress ||
1441 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1445 class FrameIndexSDNode : public SDNode {
1447 friend class SelectionDAG;
1448 FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1449 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1450 0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1454 int getIndex() const { return FI; }
1456 static bool classof(const SDNode *N) {
1457 return N->getOpcode() == ISD::FrameIndex ||
1458 N->getOpcode() == ISD::TargetFrameIndex;
1462 class JumpTableSDNode : public SDNode {
1464 unsigned char TargetFlags;
1465 friend class SelectionDAG;
1466 JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1467 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1468 0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1472 int getIndex() const { return JTI; }
1473 unsigned char getTargetFlags() const { return TargetFlags; }
1475 static bool classof(const SDNode *N) {
1476 return N->getOpcode() == ISD::JumpTable ||
1477 N->getOpcode() == ISD::TargetJumpTable;
1481 class ConstantPoolSDNode : public SDNode {
1483 const Constant *ConstVal;
1484 MachineConstantPoolValue *MachineCPVal;
1486 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1487 unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
1488 unsigned char TargetFlags;
1489 friend class SelectionDAG;
1490 ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1491 unsigned Align, unsigned char TF)
1492 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1493 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1495 assert(Offset >= 0 && "Offset is too large");
1498 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1499 EVT VT, int o, unsigned Align, unsigned char TF)
1500 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1501 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1503 assert(Offset >= 0 && "Offset is too large");
1504 Val.MachineCPVal = v;
1505 Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1509 bool isMachineConstantPoolEntry() const {
1513 const Constant *getConstVal() const {
1514 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1515 return Val.ConstVal;
1518 MachineConstantPoolValue *getMachineCPVal() const {
1519 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1520 return Val.MachineCPVal;
1523 int getOffset() const {
1524 return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1527 // Return the alignment of this constant pool object, which is either 0 (for
1528 // default alignment) or the desired value.
1529 unsigned getAlignment() const { return Alignment; }
1530 unsigned char getTargetFlags() const { return TargetFlags; }
1532 Type *getType() const;
1534 static bool classof(const SDNode *N) {
1535 return N->getOpcode() == ISD::ConstantPool ||
1536 N->getOpcode() == ISD::TargetConstantPool;
1540 /// Completely target-dependent object reference.
1541 class TargetIndexSDNode : public SDNode {
1542 unsigned char TargetFlags;
1545 friend class SelectionDAG;
1548 TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1549 : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
1550 TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1553 unsigned char getTargetFlags() const { return TargetFlags; }
1554 int getIndex() const { return Index; }
1555 int64_t getOffset() const { return Offset; }
1557 static bool classof(const SDNode *N) {
1558 return N->getOpcode() == ISD::TargetIndex;
1562 class BasicBlockSDNode : public SDNode {
1563 MachineBasicBlock *MBB;
1564 friend class SelectionDAG;
1565 /// Debug info is meaningful and potentially useful here, but we create
1566 /// blocks out of order when they're jumped to, which makes it a bit
1567 /// harder. Let's see if we need it first.
1568 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1569 : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
1573 MachineBasicBlock *getBasicBlock() const { return MBB; }
1575 static bool classof(const SDNode *N) {
1576 return N->getOpcode() == ISD::BasicBlock;
1580 /// BuildVectorSDNode - A "pseudo-class" with methods for operating on
1582 class BuildVectorSDNode : public SDNode {
1583 // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1584 explicit BuildVectorSDNode() LLVM_DELETED_FUNCTION;
1586 /// isConstantSplat - Check if this is a constant splat, and if so, find the
1587 /// smallest element size that splats the vector. If MinSplatBits is
1588 /// nonzero, the element size must be at least that large. Note that the
1589 /// splat element may be the entire vector (i.e., a one element vector).
1590 /// Returns the splat element value in SplatValue. Any undefined bits in
1591 /// that value are zero, and the corresponding bits in the SplatUndef mask
1592 /// are set. The SplatBitSize value is set to the splat element size in
1593 /// bits. HasAnyUndefs is set to true if any bits in the vector are
1594 /// undefined. isBigEndian describes the endianness of the target.
1595 bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1596 unsigned &SplatBitSize, bool &HasAnyUndefs,
1597 unsigned MinSplatBits = 0,
1598 bool isBigEndian = false) const;
1600 /// \brief Returns the splatted value or a null value if this is not a splat.
1602 /// If passed a non-null UndefElements bitvector, it will resize it to match
1603 /// the vector width and set the bits where elements are undef.
1604 SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
1606 /// \brief Returns the splatted constant or null if this is not a constant
1609 /// If passed a non-null UndefElements bitvector, it will resize it to match
1610 /// the vector width and set the bits where elements are undef.
1612 getConstantSplatNode(BitVector *UndefElements = nullptr) const;
1614 /// \brief Returns the splatted constant FP or null if this is not a constant
1617 /// If passed a non-null UndefElements bitvector, it will resize it to match
1618 /// the vector width and set the bits where elements are undef.
1620 getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
1622 bool isConstant() const;
1624 static inline bool classof(const SDNode *N) {
1625 return N->getOpcode() == ISD::BUILD_VECTOR;
1629 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1630 /// used when the SelectionDAG needs to make a simple reference to something
1631 /// in the LLVM IR representation.
1633 class SrcValueSDNode : public SDNode {
1635 friend class SelectionDAG;
1636 /// Create a SrcValue for a general value.
1637 explicit SrcValueSDNode(const Value *v)
1638 : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1641 /// getValue - return the contained Value.
1642 const Value *getValue() const { return V; }
1644 static bool classof(const SDNode *N) {
1645 return N->getOpcode() == ISD::SRCVALUE;
1649 class MDNodeSDNode : public SDNode {
1651 friend class SelectionDAG;
1652 explicit MDNodeSDNode(const MDNode *md)
1653 : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
1657 const MDNode *getMD() const { return MD; }
1659 static bool classof(const SDNode *N) {
1660 return N->getOpcode() == ISD::MDNODE_SDNODE;
1664 class RegisterSDNode : public SDNode {
1666 friend class SelectionDAG;
1667 RegisterSDNode(unsigned reg, EVT VT)
1668 : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {
1672 unsigned getReg() const { return Reg; }
1674 static bool classof(const SDNode *N) {
1675 return N->getOpcode() == ISD::Register;
1679 class RegisterMaskSDNode : public SDNode {
1680 // The memory for RegMask is not owned by the node.
1681 const uint32_t *RegMask;
1682 friend class SelectionDAG;
1683 RegisterMaskSDNode(const uint32_t *mask)
1684 : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
1688 const uint32_t *getRegMask() const { return RegMask; }
1690 static bool classof(const SDNode *N) {
1691 return N->getOpcode() == ISD::RegisterMask;
1695 class BlockAddressSDNode : public SDNode {
1696 const BlockAddress *BA;
1698 unsigned char TargetFlags;
1699 friend class SelectionDAG;
1700 BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1701 int64_t o, unsigned char Flags)
1702 : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
1703 BA(ba), Offset(o), TargetFlags(Flags) {
1706 const BlockAddress *getBlockAddress() const { return BA; }
1707 int64_t getOffset() const { return Offset; }
1708 unsigned char getTargetFlags() const { return TargetFlags; }
1710 static bool classof(const SDNode *N) {
1711 return N->getOpcode() == ISD::BlockAddress ||
1712 N->getOpcode() == ISD::TargetBlockAddress;
1716 class EHLabelSDNode : public SDNode {
1719 friend class SelectionDAG;
1720 EHLabelSDNode(unsigned Order, DebugLoc dl, SDValue ch, MCSymbol *L)
1721 : SDNode(ISD::EH_LABEL, Order, dl, getSDVTList(MVT::Other)), Label(L) {
1722 InitOperands(&Chain, ch);
1725 MCSymbol *getLabel() const { return Label; }
1727 static bool classof(const SDNode *N) {
1728 return N->getOpcode() == ISD::EH_LABEL;
1732 class ExternalSymbolSDNode : public SDNode {
1734 unsigned char TargetFlags;
1736 friend class SelectionDAG;
1737 ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1738 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1739 0, DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {
1743 const char *getSymbol() const { return Symbol; }
1744 unsigned char getTargetFlags() const { return TargetFlags; }
1746 static bool classof(const SDNode *N) {
1747 return N->getOpcode() == ISD::ExternalSymbol ||
1748 N->getOpcode() == ISD::TargetExternalSymbol;
1752 class CondCodeSDNode : public SDNode {
1753 ISD::CondCode Condition;
1754 friend class SelectionDAG;
1755 explicit CondCodeSDNode(ISD::CondCode Cond)
1756 : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1761 ISD::CondCode get() const { return Condition; }
1763 static bool classof(const SDNode *N) {
1764 return N->getOpcode() == ISD::CONDCODE;
1768 /// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
1769 /// future and most targets don't support it.
1770 class CvtRndSatSDNode : public SDNode {
1771 ISD::CvtCode CvtCode;
1772 friend class SelectionDAG;
1773 explicit CvtRndSatSDNode(EVT VT, unsigned Order, DebugLoc dl,
1774 ArrayRef<SDValue> Ops, ISD::CvtCode Code)
1775 : SDNode(ISD::CONVERT_RNDSAT, Order, dl, getSDVTList(VT), Ops),
1777 assert(Ops.size() == 5 && "wrong number of operations");
1780 ISD::CvtCode getCvtCode() const { return CvtCode; }
1782 static bool classof(const SDNode *N) {
1783 return N->getOpcode() == ISD::CONVERT_RNDSAT;
1787 /// VTSDNode - This class is used to represent EVT's, which are used
1788 /// to parameterize some operations.
1789 class VTSDNode : public SDNode {
1791 friend class SelectionDAG;
1792 explicit VTSDNode(EVT VT)
1793 : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1798 EVT getVT() const { return ValueType; }
1800 static bool classof(const SDNode *N) {
1801 return N->getOpcode() == ISD::VALUETYPE;
1805 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1807 class LSBaseSDNode : public MemSDNode {
1808 //! Operand array for load and store
1810 \note Moving this array to the base class captures more
1811 common functionality shared between LoadSDNode and
1816 LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, DebugLoc dl,
1817 SDValue *Operands, unsigned numOperands,
1818 SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
1819 MachineMemOperand *MMO)
1820 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
1821 SubclassData |= AM << 2;
1822 assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
1823 InitOperands(Ops, Operands, numOperands);
1824 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1825 "Only indexed loads and stores have a non-undef offset operand");
1828 const SDValue &getOffset() const {
1829 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1832 /// getAddressingMode - Return the addressing mode for this load or store:
1833 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
1834 ISD::MemIndexedMode getAddressingMode() const {
1835 return ISD::MemIndexedMode((SubclassData >> 2) & 7);
1838 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1839 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
1841 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1842 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
1844 static bool classof(const SDNode *N) {
1845 return N->getOpcode() == ISD::LOAD ||
1846 N->getOpcode() == ISD::STORE;
1850 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1852 class LoadSDNode : public LSBaseSDNode {
1853 friend class SelectionDAG;
1854 LoadSDNode(SDValue *ChainPtrOff, unsigned Order, DebugLoc dl, SDVTList VTs,
1855 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
1856 MachineMemOperand *MMO)
1857 : LSBaseSDNode(ISD::LOAD, Order, dl, ChainPtrOff, 3, VTs, AM, MemVT, MMO) {
1858 SubclassData |= (unsigned short)ETy;
1859 assert(getExtensionType() == ETy && "LoadExtType encoding error!");
1860 assert(readMem() && "Load MachineMemOperand is not a load!");
1861 assert(!writeMem() && "Load MachineMemOperand is a store!");
1865 /// getExtensionType - Return whether this is a plain node,
1866 /// or one of the varieties of value-extending loads.
1867 ISD::LoadExtType getExtensionType() const {
1868 return ISD::LoadExtType(SubclassData & 3);
1871 const SDValue &getBasePtr() const { return getOperand(1); }
1872 const SDValue &getOffset() const { return getOperand(2); }
1874 static bool classof(const SDNode *N) {
1875 return N->getOpcode() == ISD::LOAD;
1879 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1881 class StoreSDNode : public LSBaseSDNode {
1882 friend class SelectionDAG;
1883 StoreSDNode(SDValue *ChainValuePtrOff, unsigned Order, DebugLoc dl,
1884 SDVTList VTs, ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
1885 MachineMemOperand *MMO)
1886 : LSBaseSDNode(ISD::STORE, Order, dl, ChainValuePtrOff, 4,
1887 VTs, AM, MemVT, MMO) {
1888 SubclassData |= (unsigned short)isTrunc;
1889 assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
1890 assert(!readMem() && "Store MachineMemOperand is a load!");
1891 assert(writeMem() && "Store MachineMemOperand is not a store!");
1895 /// isTruncatingStore - Return true if the op does a truncation before store.
1896 /// For integers this is the same as doing a TRUNCATE and storing the result.
1897 /// For floats, it is the same as doing an FP_ROUND and storing the result.
1898 bool isTruncatingStore() const { return SubclassData & 1; }
1900 const SDValue &getValue() const { return getOperand(1); }
1901 const SDValue &getBasePtr() const { return getOperand(2); }
1902 const SDValue &getOffset() const { return getOperand(3); }
1904 static bool classof(const SDNode *N) {
1905 return N->getOpcode() == ISD::STORE;
1909 /// MachineSDNode - An SDNode that represents everything that will be needed
1910 /// to construct a MachineInstr. These nodes are created during the
1911 /// instruction selection proper phase.
1913 class MachineSDNode : public SDNode {
1915 typedef MachineMemOperand **mmo_iterator;
1918 friend class SelectionDAG;
1919 MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc DL, SDVTList VTs)
1920 : SDNode(Opc, Order, DL, VTs), MemRefs(nullptr), MemRefsEnd(nullptr) {}
1922 /// LocalOperands - Operands for this instruction, if they fit here. If
1923 /// they don't, this field is unused.
1924 SDUse LocalOperands[4];
1926 /// MemRefs - Memory reference descriptions for this instruction.
1927 mmo_iterator MemRefs;
1928 mmo_iterator MemRefsEnd;
1931 mmo_iterator memoperands_begin() const { return MemRefs; }
1932 mmo_iterator memoperands_end() const { return MemRefsEnd; }
1933 bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
1935 /// setMemRefs - Assign this MachineSDNodes's memory reference descriptor
1936 /// list. This does not transfer ownership.
1937 void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
1938 for (mmo_iterator MMI = NewMemRefs, MME = NewMemRefsEnd; MMI != MME; ++MMI)
1939 assert(*MMI && "Null mem ref detected!");
1940 MemRefs = NewMemRefs;
1941 MemRefsEnd = NewMemRefsEnd;
1944 static bool classof(const SDNode *N) {
1945 return N->isMachineOpcode();
1949 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
1950 SDNode, ptrdiff_t> {
1954 SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1956 bool operator==(const SDNodeIterator& x) const {
1957 return Operand == x.Operand;
1959 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1961 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1962 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1963 Operand = I.Operand;
1967 pointer operator*() const {
1968 return Node->getOperand(Operand).getNode();
1970 pointer operator->() const { return operator*(); }
1972 SDNodeIterator& operator++() { // Preincrement
1976 SDNodeIterator operator++(int) { // Postincrement
1977 SDNodeIterator tmp = *this; ++*this; return tmp;
1979 size_t operator-(SDNodeIterator Other) const {
1980 assert(Node == Other.Node &&
1981 "Cannot compare iterators of two different nodes!");
1982 return Operand - Other.Operand;
1985 static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
1986 static SDNodeIterator end (const SDNode *N) {
1987 return SDNodeIterator(N, N->getNumOperands());
1990 unsigned getOperand() const { return Operand; }
1991 const SDNode *getNode() const { return Node; }
1994 template <> struct GraphTraits<SDNode*> {
1995 typedef SDNode NodeType;
1996 typedef SDNodeIterator ChildIteratorType;
1997 static inline NodeType *getEntryNode(SDNode *N) { return N; }
1998 static inline ChildIteratorType child_begin(NodeType *N) {
1999 return SDNodeIterator::begin(N);
2001 static inline ChildIteratorType child_end(NodeType *N) {
2002 return SDNodeIterator::end(N);
2006 /// LargestSDNode - The largest SDNode class.
2008 typedef AtomicSDNode LargestSDNode;
2010 /// MostAlignedSDNode - The SDNode class with the greatest alignment
2013 typedef GlobalAddressSDNode MostAlignedSDNode;
2016 /// isNormalLoad - Returns true if the specified node is a non-extending
2017 /// and unindexed load.
2018 inline bool isNormalLoad(const SDNode *N) {
2019 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2020 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2021 Ld->getAddressingMode() == ISD::UNINDEXED;
2024 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2026 inline bool isNON_EXTLoad(const SDNode *N) {
2027 return isa<LoadSDNode>(N) &&
2028 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2031 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2033 inline bool isEXTLoad(const SDNode *N) {
2034 return isa<LoadSDNode>(N) &&
2035 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2038 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2040 inline bool isSEXTLoad(const SDNode *N) {
2041 return isa<LoadSDNode>(N) &&
2042 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2045 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2047 inline bool isZEXTLoad(const SDNode *N) {
2048 return isa<LoadSDNode>(N) &&
2049 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2052 /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
2054 inline bool isUNINDEXEDLoad(const SDNode *N) {
2055 return isa<LoadSDNode>(N) &&
2056 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2059 /// isNormalStore - Returns true if the specified node is a non-truncating
2060 /// and unindexed store.
2061 inline bool isNormalStore(const SDNode *N) {
2062 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2063 return St && !St->isTruncatingStore() &&
2064 St->getAddressingMode() == ISD::UNINDEXED;
2067 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2069 inline bool isNON_TRUNCStore(const SDNode *N) {
2070 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2073 /// isTRUNCStore - Returns true if the specified node is a truncating
2075 inline bool isTRUNCStore(const SDNode *N) {
2076 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2079 /// isUNINDEXEDStore - Returns true if the specified node is an
2080 /// unindexed store.
2081 inline bool isUNINDEXEDStore(const SDNode *N) {
2082 return isa<StoreSDNode>(N) &&
2083 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2087 } // end llvm namespace