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->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
1162 N->getOpcode() == ISD::INTRINSIC_VOID ||
1163 N->isTargetMemoryOpcode();
1167 /// AtomicSDNode - A SDNode reprenting atomic operations.
1169 class AtomicSDNode : public MemSDNode {
1172 /// For cmpxchg instructions, the ordering requirements when a store does not
1174 AtomicOrdering FailureOrdering;
1176 void InitAtomic(AtomicOrdering SuccessOrdering,
1177 AtomicOrdering FailureOrdering,
1178 SynchronizationScope SynchScope) {
1179 // This must match encodeMemSDNodeFlags() in SelectionDAG.cpp.
1180 assert((SuccessOrdering & 15) == SuccessOrdering &&
1181 "Ordering may not require more than 4 bits!");
1182 assert((FailureOrdering & 15) == FailureOrdering &&
1183 "Ordering may not require more than 4 bits!");
1184 assert((SynchScope & 1) == SynchScope &&
1185 "SynchScope may not require more than 1 bit!");
1186 SubclassData |= SuccessOrdering << 8;
1187 SubclassData |= SynchScope << 12;
1188 this->FailureOrdering = FailureOrdering;
1189 assert(getSuccessOrdering() == SuccessOrdering &&
1190 "Ordering encoding error!");
1191 assert(getFailureOrdering() == FailureOrdering &&
1192 "Ordering encoding error!");
1193 assert(getSynchScope() == SynchScope && "Synch-scope encoding error!");
1197 // Opc: opcode for atomic
1198 // VTL: value type list
1199 // Chain: memory chain for operaand
1200 // Ptr: address to update as a SDValue
1201 // Cmp: compare value
1203 // SrcVal: address to update as a Value (used for MemOperand)
1204 // Align: alignment of memory
1205 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
1206 EVT MemVT, SDValue Chain, SDValue Ptr, SDValue Cmp, SDValue Swp,
1207 MachineMemOperand *MMO, AtomicOrdering Ordering,
1208 SynchronizationScope SynchScope)
1209 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1210 InitAtomic(Ordering, Ordering, SynchScope);
1211 InitOperands(Ops, Chain, Ptr, Cmp, Swp);
1213 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
1215 SDValue Chain, SDValue Ptr,
1216 SDValue Val, MachineMemOperand *MMO,
1217 AtomicOrdering Ordering, SynchronizationScope SynchScope)
1218 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1219 InitAtomic(Ordering, Ordering, SynchScope);
1220 InitOperands(Ops, Chain, Ptr, Val);
1222 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
1224 SDValue Chain, SDValue Ptr,
1225 MachineMemOperand *MMO,
1226 AtomicOrdering Ordering, SynchronizationScope SynchScope)
1227 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1228 InitAtomic(Ordering, Ordering, SynchScope);
1229 InitOperands(Ops, Chain, Ptr);
1231 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL, EVT MemVT,
1232 const SDValue* AllOps, SDUse *DynOps, unsigned NumOps,
1233 MachineMemOperand *MMO,
1234 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
1235 SynchronizationScope SynchScope)
1236 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1237 InitAtomic(SuccessOrdering, FailureOrdering, SynchScope);
1238 assert((DynOps || NumOps <= array_lengthof(Ops)) &&
1239 "Too many ops for internal storage!");
1240 InitOperands(DynOps ? DynOps : Ops, AllOps, NumOps);
1243 const SDValue &getBasePtr() const { return getOperand(1); }
1244 const SDValue &getVal() const { return getOperand(2); }
1246 AtomicOrdering getSuccessOrdering() const {
1247 return getOrdering();
1250 // Not quite enough room in SubclassData for everything, so failure gets its
1252 AtomicOrdering getFailureOrdering() const {
1253 return FailureOrdering;
1256 bool isCompareAndSwap() const {
1257 unsigned Op = getOpcode();
1258 return Op == ISD::ATOMIC_CMP_SWAP || Op == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS;
1261 // Methods to support isa and dyn_cast
1262 static bool classof(const SDNode *N) {
1263 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1264 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1265 N->getOpcode() == ISD::ATOMIC_SWAP ||
1266 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1267 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1268 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1269 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1270 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1271 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1272 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1273 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1274 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1275 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1276 N->getOpcode() == ISD::ATOMIC_LOAD ||
1277 N->getOpcode() == ISD::ATOMIC_STORE;
1281 /// MemIntrinsicSDNode - This SDNode is used for target intrinsics that touch
1282 /// memory and need an associated MachineMemOperand. Its opcode may be
1283 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1284 /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1285 class MemIntrinsicSDNode : public MemSDNode {
1287 MemIntrinsicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1288 ArrayRef<SDValue> Ops, EVT MemoryVT,
1289 MachineMemOperand *MMO)
1290 : MemSDNode(Opc, Order, dl, VTs, Ops, MemoryVT, MMO) {
1293 // Methods to support isa and dyn_cast
1294 static bool classof(const SDNode *N) {
1295 // We lower some target intrinsics to their target opcode
1296 // early a node with a target opcode can be of this class
1297 return N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
1298 N->getOpcode() == ISD::INTRINSIC_VOID ||
1299 N->getOpcode() == ISD::PREFETCH ||
1300 N->isTargetMemoryOpcode();
1304 /// ShuffleVectorSDNode - This SDNode is used to implement the code generator
1305 /// support for the llvm IR shufflevector instruction. It combines elements
1306 /// from two input vectors into a new input vector, with the selection and
1307 /// ordering of elements determined by an array of integers, referred to as
1308 /// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1309 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1310 /// An index of -1 is treated as undef, such that the code generator may put
1311 /// any value in the corresponding element of the result.
1312 class ShuffleVectorSDNode : public SDNode {
1315 // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1316 // is freed when the SelectionDAG object is destroyed.
1319 friend class SelectionDAG;
1320 ShuffleVectorSDNode(EVT VT, unsigned Order, DebugLoc dl, SDValue N1,
1321 SDValue N2, const int *M)
1322 : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {
1323 InitOperands(Ops, N1, N2);
1327 ArrayRef<int> getMask() const {
1328 EVT VT = getValueType(0);
1329 return makeArrayRef(Mask, VT.getVectorNumElements());
1331 int getMaskElt(unsigned Idx) const {
1332 assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1336 bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1337 int getSplatIndex() const {
1338 assert(isSplat() && "Cannot get splat index for non-splat!");
1339 EVT VT = getValueType(0);
1340 for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
1344 llvm_unreachable("Splat with all undef indices?");
1346 static bool isSplatMask(const int *Mask, EVT VT);
1348 static bool classof(const SDNode *N) {
1349 return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1353 class ConstantSDNode : public SDNode {
1354 const ConstantInt *Value;
1355 friend class SelectionDAG;
1356 ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val, EVT VT)
1357 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant,
1358 0, DebugLoc(), getSDVTList(VT)), Value(val) {
1359 SubclassData |= (uint16_t)isOpaque;
1363 const ConstantInt *getConstantIntValue() const { return Value; }
1364 const APInt &getAPIntValue() const { return Value->getValue(); }
1365 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1366 int64_t getSExtValue() const { return Value->getSExtValue(); }
1368 bool isOne() const { return Value->isOne(); }
1369 bool isNullValue() const { return Value->isNullValue(); }
1370 bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1372 bool isOpaque() const { return SubclassData & 1; }
1374 static bool classof(const SDNode *N) {
1375 return N->getOpcode() == ISD::Constant ||
1376 N->getOpcode() == ISD::TargetConstant;
1380 class ConstantFPSDNode : public SDNode {
1381 const ConstantFP *Value;
1382 friend class SelectionDAG;
1383 ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1384 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1385 0, DebugLoc(), getSDVTList(VT)), Value(val) {
1389 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1390 const ConstantFP *getConstantFPValue() const { return Value; }
1392 /// isZero - Return true if the value is positive or negative zero.
1393 bool isZero() const { return Value->isZero(); }
1395 /// isNaN - Return true if the value is a NaN.
1396 bool isNaN() const { return Value->isNaN(); }
1398 /// isExactlyValue - We don't rely on operator== working on double values, as
1399 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1400 /// As such, this method can be used to do an exact bit-for-bit comparison of
1401 /// two floating point values.
1403 /// We leave the version with the double argument here because it's just so
1404 /// convenient to write "2.0" and the like. Without this function we'd
1405 /// have to duplicate its logic everywhere it's called.
1406 bool isExactlyValue(double V) const {
1409 Tmp.convert(Value->getValueAPF().getSemantics(),
1410 APFloat::rmNearestTiesToEven, &ignored);
1411 return isExactlyValue(Tmp);
1413 bool isExactlyValue(const APFloat& V) const;
1415 static bool isValueValidForType(EVT VT, const APFloat& Val);
1417 static bool classof(const SDNode *N) {
1418 return N->getOpcode() == ISD::ConstantFP ||
1419 N->getOpcode() == ISD::TargetConstantFP;
1423 class GlobalAddressSDNode : public SDNode {
1424 const GlobalValue *TheGlobal;
1426 unsigned char TargetFlags;
1427 friend class SelectionDAG;
1428 GlobalAddressSDNode(unsigned Opc, unsigned Order, DebugLoc DL,
1429 const GlobalValue *GA, EVT VT, int64_t o,
1430 unsigned char TargetFlags);
1433 const GlobalValue *getGlobal() const { return TheGlobal; }
1434 int64_t getOffset() const { return Offset; }
1435 unsigned char getTargetFlags() const { return TargetFlags; }
1436 // Return the address space this GlobalAddress belongs to.
1437 unsigned getAddressSpace() const;
1439 static bool classof(const SDNode *N) {
1440 return N->getOpcode() == ISD::GlobalAddress ||
1441 N->getOpcode() == ISD::TargetGlobalAddress ||
1442 N->getOpcode() == ISD::GlobalTLSAddress ||
1443 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1447 class FrameIndexSDNode : public SDNode {
1449 friend class SelectionDAG;
1450 FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1451 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1452 0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1456 int getIndex() const { return FI; }
1458 static bool classof(const SDNode *N) {
1459 return N->getOpcode() == ISD::FrameIndex ||
1460 N->getOpcode() == ISD::TargetFrameIndex;
1464 class JumpTableSDNode : public SDNode {
1466 unsigned char TargetFlags;
1467 friend class SelectionDAG;
1468 JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1469 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1470 0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1474 int getIndex() const { return JTI; }
1475 unsigned char getTargetFlags() const { return TargetFlags; }
1477 static bool classof(const SDNode *N) {
1478 return N->getOpcode() == ISD::JumpTable ||
1479 N->getOpcode() == ISD::TargetJumpTable;
1483 class ConstantPoolSDNode : public SDNode {
1485 const Constant *ConstVal;
1486 MachineConstantPoolValue *MachineCPVal;
1488 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1489 unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
1490 unsigned char TargetFlags;
1491 friend class SelectionDAG;
1492 ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1493 unsigned Align, unsigned char TF)
1494 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1495 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1497 assert(Offset >= 0 && "Offset is too large");
1500 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1501 EVT VT, int o, 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");
1506 Val.MachineCPVal = v;
1507 Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1511 bool isMachineConstantPoolEntry() const {
1515 const Constant *getConstVal() const {
1516 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1517 return Val.ConstVal;
1520 MachineConstantPoolValue *getMachineCPVal() const {
1521 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1522 return Val.MachineCPVal;
1525 int getOffset() const {
1526 return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1529 // Return the alignment of this constant pool object, which is either 0 (for
1530 // default alignment) or the desired value.
1531 unsigned getAlignment() const { return Alignment; }
1532 unsigned char getTargetFlags() const { return TargetFlags; }
1534 Type *getType() const;
1536 static bool classof(const SDNode *N) {
1537 return N->getOpcode() == ISD::ConstantPool ||
1538 N->getOpcode() == ISD::TargetConstantPool;
1542 /// Completely target-dependent object reference.
1543 class TargetIndexSDNode : public SDNode {
1544 unsigned char TargetFlags;
1547 friend class SelectionDAG;
1550 TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1551 : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
1552 TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1555 unsigned char getTargetFlags() const { return TargetFlags; }
1556 int getIndex() const { return Index; }
1557 int64_t getOffset() const { return Offset; }
1559 static bool classof(const SDNode *N) {
1560 return N->getOpcode() == ISD::TargetIndex;
1564 class BasicBlockSDNode : public SDNode {
1565 MachineBasicBlock *MBB;
1566 friend class SelectionDAG;
1567 /// Debug info is meaningful and potentially useful here, but we create
1568 /// blocks out of order when they're jumped to, which makes it a bit
1569 /// harder. Let's see if we need it first.
1570 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1571 : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
1575 MachineBasicBlock *getBasicBlock() const { return MBB; }
1577 static bool classof(const SDNode *N) {
1578 return N->getOpcode() == ISD::BasicBlock;
1582 /// BuildVectorSDNode - A "pseudo-class" with methods for operating on
1584 class BuildVectorSDNode : public SDNode {
1585 // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1586 explicit BuildVectorSDNode() LLVM_DELETED_FUNCTION;
1588 /// isConstantSplat - Check if this is a constant splat, and if so, find the
1589 /// smallest element size that splats the vector. If MinSplatBits is
1590 /// nonzero, the element size must be at least that large. Note that the
1591 /// splat element may be the entire vector (i.e., a one element vector).
1592 /// Returns the splat element value in SplatValue. Any undefined bits in
1593 /// that value are zero, and the corresponding bits in the SplatUndef mask
1594 /// are set. The SplatBitSize value is set to the splat element size in
1595 /// bits. HasAnyUndefs is set to true if any bits in the vector are
1596 /// undefined. isBigEndian describes the endianness of the target.
1597 bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1598 unsigned &SplatBitSize, bool &HasAnyUndefs,
1599 unsigned MinSplatBits = 0,
1600 bool isBigEndian = false) const;
1602 /// \brief Returns the splatted value or a null value if this is not a splat.
1604 /// If passed a non-null UndefElements bitvector, it will resize it to match
1605 /// the vector width and set the bits where elements are undef.
1606 SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
1608 /// \brief Returns the splatted constant or null if this is not a constant
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.
1614 getConstantSplatNode(BitVector *UndefElements = nullptr) const;
1616 /// \brief Returns the splatted constant FP or null if this is not a constant
1619 /// If passed a non-null UndefElements bitvector, it will resize it to match
1620 /// the vector width and set the bits where elements are undef.
1622 getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
1624 bool isConstant() const;
1626 static inline bool classof(const SDNode *N) {
1627 return N->getOpcode() == ISD::BUILD_VECTOR;
1631 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1632 /// used when the SelectionDAG needs to make a simple reference to something
1633 /// in the LLVM IR representation.
1635 class SrcValueSDNode : public SDNode {
1637 friend class SelectionDAG;
1638 /// Create a SrcValue for a general value.
1639 explicit SrcValueSDNode(const Value *v)
1640 : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1643 /// getValue - return the contained Value.
1644 const Value *getValue() const { return V; }
1646 static bool classof(const SDNode *N) {
1647 return N->getOpcode() == ISD::SRCVALUE;
1651 class MDNodeSDNode : public SDNode {
1653 friend class SelectionDAG;
1654 explicit MDNodeSDNode(const MDNode *md)
1655 : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
1659 const MDNode *getMD() const { return MD; }
1661 static bool classof(const SDNode *N) {
1662 return N->getOpcode() == ISD::MDNODE_SDNODE;
1666 class RegisterSDNode : public SDNode {
1668 friend class SelectionDAG;
1669 RegisterSDNode(unsigned reg, EVT VT)
1670 : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {
1674 unsigned getReg() const { return Reg; }
1676 static bool classof(const SDNode *N) {
1677 return N->getOpcode() == ISD::Register;
1681 class RegisterMaskSDNode : public SDNode {
1682 // The memory for RegMask is not owned by the node.
1683 const uint32_t *RegMask;
1684 friend class SelectionDAG;
1685 RegisterMaskSDNode(const uint32_t *mask)
1686 : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
1690 const uint32_t *getRegMask() const { return RegMask; }
1692 static bool classof(const SDNode *N) {
1693 return N->getOpcode() == ISD::RegisterMask;
1697 class BlockAddressSDNode : public SDNode {
1698 const BlockAddress *BA;
1700 unsigned char TargetFlags;
1701 friend class SelectionDAG;
1702 BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1703 int64_t o, unsigned char Flags)
1704 : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
1705 BA(ba), Offset(o), TargetFlags(Flags) {
1708 const BlockAddress *getBlockAddress() const { return BA; }
1709 int64_t getOffset() const { return Offset; }
1710 unsigned char getTargetFlags() const { return TargetFlags; }
1712 static bool classof(const SDNode *N) {
1713 return N->getOpcode() == ISD::BlockAddress ||
1714 N->getOpcode() == ISD::TargetBlockAddress;
1718 class EHLabelSDNode : public SDNode {
1721 friend class SelectionDAG;
1722 EHLabelSDNode(unsigned Order, DebugLoc dl, SDValue ch, MCSymbol *L)
1723 : SDNode(ISD::EH_LABEL, Order, dl, getSDVTList(MVT::Other)), Label(L) {
1724 InitOperands(&Chain, ch);
1727 MCSymbol *getLabel() const { return Label; }
1729 static bool classof(const SDNode *N) {
1730 return N->getOpcode() == ISD::EH_LABEL;
1734 class ExternalSymbolSDNode : public SDNode {
1736 unsigned char TargetFlags;
1738 friend class SelectionDAG;
1739 ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1740 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1741 0, DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {
1745 const char *getSymbol() const { return Symbol; }
1746 unsigned char getTargetFlags() const { return TargetFlags; }
1748 static bool classof(const SDNode *N) {
1749 return N->getOpcode() == ISD::ExternalSymbol ||
1750 N->getOpcode() == ISD::TargetExternalSymbol;
1754 class CondCodeSDNode : public SDNode {
1755 ISD::CondCode Condition;
1756 friend class SelectionDAG;
1757 explicit CondCodeSDNode(ISD::CondCode Cond)
1758 : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1763 ISD::CondCode get() const { return Condition; }
1765 static bool classof(const SDNode *N) {
1766 return N->getOpcode() == ISD::CONDCODE;
1770 /// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
1771 /// future and most targets don't support it.
1772 class CvtRndSatSDNode : public SDNode {
1773 ISD::CvtCode CvtCode;
1774 friend class SelectionDAG;
1775 explicit CvtRndSatSDNode(EVT VT, unsigned Order, DebugLoc dl,
1776 ArrayRef<SDValue> Ops, ISD::CvtCode Code)
1777 : SDNode(ISD::CONVERT_RNDSAT, Order, dl, getSDVTList(VT), Ops),
1779 assert(Ops.size() == 5 && "wrong number of operations");
1782 ISD::CvtCode getCvtCode() const { return CvtCode; }
1784 static bool classof(const SDNode *N) {
1785 return N->getOpcode() == ISD::CONVERT_RNDSAT;
1789 /// VTSDNode - This class is used to represent EVT's, which are used
1790 /// to parameterize some operations.
1791 class VTSDNode : public SDNode {
1793 friend class SelectionDAG;
1794 explicit VTSDNode(EVT VT)
1795 : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1800 EVT getVT() const { return ValueType; }
1802 static bool classof(const SDNode *N) {
1803 return N->getOpcode() == ISD::VALUETYPE;
1807 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1809 class LSBaseSDNode : public MemSDNode {
1810 //! Operand array for load and store
1812 \note Moving this array to the base class captures more
1813 common functionality shared between LoadSDNode and
1818 LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, DebugLoc dl,
1819 SDValue *Operands, unsigned numOperands,
1820 SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
1821 MachineMemOperand *MMO)
1822 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
1823 SubclassData |= AM << 2;
1824 assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
1825 InitOperands(Ops, Operands, numOperands);
1826 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1827 "Only indexed loads and stores have a non-undef offset operand");
1830 const SDValue &getOffset() const {
1831 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1834 /// getAddressingMode - Return the addressing mode for this load or store:
1835 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
1836 ISD::MemIndexedMode getAddressingMode() const {
1837 return ISD::MemIndexedMode((SubclassData >> 2) & 7);
1840 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1841 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
1843 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1844 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
1846 static bool classof(const SDNode *N) {
1847 return N->getOpcode() == ISD::LOAD ||
1848 N->getOpcode() == ISD::STORE;
1852 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1854 class LoadSDNode : public LSBaseSDNode {
1855 friend class SelectionDAG;
1856 LoadSDNode(SDValue *ChainPtrOff, unsigned Order, DebugLoc dl, SDVTList VTs,
1857 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
1858 MachineMemOperand *MMO)
1859 : LSBaseSDNode(ISD::LOAD, Order, dl, ChainPtrOff, 3, VTs, AM, MemVT, MMO) {
1860 SubclassData |= (unsigned short)ETy;
1861 assert(getExtensionType() == ETy && "LoadExtType encoding error!");
1862 assert(readMem() && "Load MachineMemOperand is not a load!");
1863 assert(!writeMem() && "Load MachineMemOperand is a store!");
1867 /// getExtensionType - Return whether this is a plain node,
1868 /// or one of the varieties of value-extending loads.
1869 ISD::LoadExtType getExtensionType() const {
1870 return ISD::LoadExtType(SubclassData & 3);
1873 const SDValue &getBasePtr() const { return getOperand(1); }
1874 const SDValue &getOffset() const { return getOperand(2); }
1876 static bool classof(const SDNode *N) {
1877 return N->getOpcode() == ISD::LOAD;
1881 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1883 class StoreSDNode : public LSBaseSDNode {
1884 friend class SelectionDAG;
1885 StoreSDNode(SDValue *ChainValuePtrOff, unsigned Order, DebugLoc dl,
1886 SDVTList VTs, ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
1887 MachineMemOperand *MMO)
1888 : LSBaseSDNode(ISD::STORE, Order, dl, ChainValuePtrOff, 4,
1889 VTs, AM, MemVT, MMO) {
1890 SubclassData |= (unsigned short)isTrunc;
1891 assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
1892 assert(!readMem() && "Store MachineMemOperand is a load!");
1893 assert(writeMem() && "Store MachineMemOperand is not a store!");
1897 /// isTruncatingStore - Return true if the op does a truncation before store.
1898 /// For integers this is the same as doing a TRUNCATE and storing the result.
1899 /// For floats, it is the same as doing an FP_ROUND and storing the result.
1900 bool isTruncatingStore() const { return SubclassData & 1; }
1902 const SDValue &getValue() const { return getOperand(1); }
1903 const SDValue &getBasePtr() const { return getOperand(2); }
1904 const SDValue &getOffset() const { return getOperand(3); }
1906 static bool classof(const SDNode *N) {
1907 return N->getOpcode() == ISD::STORE;
1911 /// MachineSDNode - An SDNode that represents everything that will be needed
1912 /// to construct a MachineInstr. These nodes are created during the
1913 /// instruction selection proper phase.
1915 class MachineSDNode : public SDNode {
1917 typedef MachineMemOperand **mmo_iterator;
1920 friend class SelectionDAG;
1921 MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc DL, SDVTList VTs)
1922 : SDNode(Opc, Order, DL, VTs), MemRefs(nullptr), MemRefsEnd(nullptr) {}
1924 /// LocalOperands - Operands for this instruction, if they fit here. If
1925 /// they don't, this field is unused.
1926 SDUse LocalOperands[4];
1928 /// MemRefs - Memory reference descriptions for this instruction.
1929 mmo_iterator MemRefs;
1930 mmo_iterator MemRefsEnd;
1933 mmo_iterator memoperands_begin() const { return MemRefs; }
1934 mmo_iterator memoperands_end() const { return MemRefsEnd; }
1935 bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
1937 /// setMemRefs - Assign this MachineSDNodes's memory reference descriptor
1938 /// list. This does not transfer ownership.
1939 void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
1940 for (mmo_iterator MMI = NewMemRefs, MME = NewMemRefsEnd; MMI != MME; ++MMI)
1941 assert(*MMI && "Null mem ref detected!");
1942 MemRefs = NewMemRefs;
1943 MemRefsEnd = NewMemRefsEnd;
1946 static bool classof(const SDNode *N) {
1947 return N->isMachineOpcode();
1951 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
1952 SDNode, ptrdiff_t> {
1956 SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1958 bool operator==(const SDNodeIterator& x) const {
1959 return Operand == x.Operand;
1961 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1963 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1964 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1965 Operand = I.Operand;
1969 pointer operator*() const {
1970 return Node->getOperand(Operand).getNode();
1972 pointer operator->() const { return operator*(); }
1974 SDNodeIterator& operator++() { // Preincrement
1978 SDNodeIterator operator++(int) { // Postincrement
1979 SDNodeIterator tmp = *this; ++*this; return tmp;
1981 size_t operator-(SDNodeIterator Other) const {
1982 assert(Node == Other.Node &&
1983 "Cannot compare iterators of two different nodes!");
1984 return Operand - Other.Operand;
1987 static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
1988 static SDNodeIterator end (const SDNode *N) {
1989 return SDNodeIterator(N, N->getNumOperands());
1992 unsigned getOperand() const { return Operand; }
1993 const SDNode *getNode() const { return Node; }
1996 template <> struct GraphTraits<SDNode*> {
1997 typedef SDNode NodeType;
1998 typedef SDNodeIterator ChildIteratorType;
1999 static inline NodeType *getEntryNode(SDNode *N) { return N; }
2000 static inline ChildIteratorType child_begin(NodeType *N) {
2001 return SDNodeIterator::begin(N);
2003 static inline ChildIteratorType child_end(NodeType *N) {
2004 return SDNodeIterator::end(N);
2008 /// LargestSDNode - The largest SDNode class.
2010 typedef AtomicSDNode LargestSDNode;
2012 /// MostAlignedSDNode - The SDNode class with the greatest alignment
2015 typedef GlobalAddressSDNode MostAlignedSDNode;
2018 /// isNormalLoad - Returns true if the specified node is a non-extending
2019 /// and unindexed load.
2020 inline bool isNormalLoad(const SDNode *N) {
2021 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2022 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2023 Ld->getAddressingMode() == ISD::UNINDEXED;
2026 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2028 inline bool isNON_EXTLoad(const SDNode *N) {
2029 return isa<LoadSDNode>(N) &&
2030 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2033 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2035 inline bool isEXTLoad(const SDNode *N) {
2036 return isa<LoadSDNode>(N) &&
2037 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2040 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2042 inline bool isSEXTLoad(const SDNode *N) {
2043 return isa<LoadSDNode>(N) &&
2044 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2047 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2049 inline bool isZEXTLoad(const SDNode *N) {
2050 return isa<LoadSDNode>(N) &&
2051 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2054 /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
2056 inline bool isUNINDEXEDLoad(const SDNode *N) {
2057 return isa<LoadSDNode>(N) &&
2058 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2061 /// isNormalStore - Returns true if the specified node is a non-truncating
2062 /// and unindexed store.
2063 inline bool isNormalStore(const SDNode *N) {
2064 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2065 return St && !St->isTruncatingStore() &&
2066 St->getAddressingMode() == ISD::UNINDEXED;
2069 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2071 inline bool isNON_TRUNCStore(const SDNode *N) {
2072 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2075 /// isTRUNCStore - Returns true if the specified node is a truncating
2077 inline bool isTRUNCStore(const SDNode *N) {
2078 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2081 /// isUNINDEXEDStore - Returns true if the specified node is an
2082 /// unindexed store.
2083 inline bool isUNINDEXEDStore(const SDNode *N) {
2084 return isa<StoreSDNode>(N) &&
2085 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2089 } // end llvm namespace