1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the SDNode class and derived classes, which are used to
11 // represent the nodes and operations present in a SelectionDAG. These nodes
12 // and operations are machine code level operations, with some similarities to
13 // the GCC RTL representation.
15 // Clients should include the SelectionDAG.h file instead of this file directly.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
22 #include "llvm/ADT/APFloat.h"
23 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/ADT/BitVector.h"
25 #include "llvm/ADT/FoldingSet.h"
26 #include "llvm/ADT/GraphTraits.h"
27 #include "llvm/ADT/ilist_node.h"
28 #include "llvm/ADT/iterator.h"
29 #include "llvm/ADT/iterator_range.h"
30 #include "llvm/ADT/SmallPtrSet.h"
31 #include "llvm/ADT/SmallVector.h"
32 #include "llvm/CodeGen/ISDOpcodes.h"
33 #include "llvm/CodeGen/MachineMemOperand.h"
34 #include "llvm/CodeGen/MachineValueType.h"
35 #include "llvm/CodeGen/ValueTypes.h"
36 #include "llvm/IR/Constants.h"
37 #include "llvm/IR/DebugLoc.h"
38 #include "llvm/IR/Instruction.h"
39 #include "llvm/IR/Instructions.h"
40 #include "llvm/Support/AlignOf.h"
41 #include "llvm/Support/AtomicOrdering.h"
42 #include "llvm/Support/Casting.h"
43 #include "llvm/Support/ErrorHandling.h"
58 class MachineBasicBlock;
59 class MachineConstantPoolValue;
63 template <typename T> struct DenseMapInfo;
65 void checkForCycles(const SDNode *N, const SelectionDAG *DAG = nullptr,
68 /// This represents a list of ValueType's that has been intern'd by
69 /// a SelectionDAG. Instances of this simple value class are returned by
70 /// SelectionDAG::getVTList(...).
81 /// If N is a BUILD_VECTOR node whose elements are all the same constant or
82 /// undefined, return true and return the constant value in \p SplatValue.
83 bool isConstantSplatVector(const SDNode *N, APInt &SplatValue);
85 /// Return true if the specified node is a BUILD_VECTOR where all of the
86 /// elements are ~0 or undef.
87 bool isBuildVectorAllOnes(const SDNode *N);
89 /// Return true if the specified node is a BUILD_VECTOR where all of the
90 /// elements are 0 or undef.
91 bool isBuildVectorAllZeros(const SDNode *N);
93 /// Return true if the specified node is a BUILD_VECTOR node of all
94 /// ConstantSDNode or undef.
95 bool isBuildVectorOfConstantSDNodes(const SDNode *N);
97 /// Return true if the specified node is a BUILD_VECTOR node of all
98 /// ConstantFPSDNode or undef.
99 bool isBuildVectorOfConstantFPSDNodes(const SDNode *N);
101 /// Return true if the node has at least one operand and all operands of the
102 /// specified node are ISD::UNDEF.
103 bool allOperandsUndef(const SDNode *N);
105 } // end namespace ISD
107 //===----------------------------------------------------------------------===//
108 /// Unlike LLVM values, Selection DAG nodes may return multiple
109 /// values as the result of a computation. Many nodes return multiple values,
110 /// from loads (which define a token and a return value) to ADDC (which returns
111 /// a result and a carry value), to calls (which may return an arbitrary number
114 /// As such, each use of a SelectionDAG computation must indicate the node that
115 /// computes it as well as which return value to use from that node. This pair
116 /// of information is represented with the SDValue value type.
119 friend struct DenseMapInfo<SDValue>;
121 SDNode *Node; // The node defining the value we are using.
122 unsigned ResNo; // Which return value of the node we are using.
125 SDValue() : Node(nullptr), ResNo(0) {}
126 SDValue(SDNode *node, unsigned resno);
128 /// get the index which selects a specific result in the SDNode
129 unsigned getResNo() const { return ResNo; }
131 /// get the SDNode which holds the desired result
132 SDNode *getNode() const { return Node; }
135 void setNode(SDNode *N) { Node = N; }
137 inline SDNode *operator->() const { return Node; }
139 bool operator==(const SDValue &O) const {
140 return Node == O.Node && ResNo == O.ResNo;
142 bool operator!=(const SDValue &O) const {
143 return !operator==(O);
145 bool operator<(const SDValue &O) const {
146 return std::tie(Node, ResNo) < std::tie(O.Node, O.ResNo);
148 explicit operator bool() const {
149 return Node != nullptr;
152 SDValue getValue(unsigned R) const {
153 return SDValue(Node, R);
156 /// Return true if this node is an operand of N.
157 bool isOperandOf(const SDNode *N) const;
159 /// Return the ValueType of the referenced return value.
160 inline EVT getValueType() const;
162 /// Return the simple ValueType of the referenced return value.
163 MVT getSimpleValueType() const {
164 return getValueType().getSimpleVT();
167 /// Returns the size of the value in bits.
168 unsigned getValueSizeInBits() const {
169 return getValueType().getSizeInBits();
172 unsigned getScalarValueSizeInBits() const {
173 return getValueType().getScalarType().getSizeInBits();
176 // Forwarding methods - These forward to the corresponding methods in SDNode.
177 inline unsigned getOpcode() const;
178 inline unsigned getNumOperands() const;
179 inline const SDValue &getOperand(unsigned i) const;
180 inline uint64_t getConstantOperandVal(unsigned i) const;
181 inline bool isTargetMemoryOpcode() const;
182 inline bool isTargetOpcode() const;
183 inline bool isMachineOpcode() const;
184 inline bool isUndef() const;
185 inline unsigned getMachineOpcode() const;
186 inline const DebugLoc &getDebugLoc() const;
187 inline void dump() const;
188 inline void dumpr() const;
190 /// Return true if this operand (which must be a chain) reaches the
191 /// specified operand without crossing any side-effecting instructions.
192 /// In practice, this looks through token factors and non-volatile loads.
193 /// In order to remain efficient, this only
194 /// looks a couple of nodes in, it does not do an exhaustive search.
195 bool reachesChainWithoutSideEffects(SDValue Dest,
196 unsigned Depth = 2) const;
198 /// Return true if there are no nodes using value ResNo of Node.
199 inline bool use_empty() const;
201 /// Return true if there is exactly one node using value ResNo of Node.
202 inline bool hasOneUse() const;
205 template<> struct DenseMapInfo<SDValue> {
206 static inline SDValue getEmptyKey() {
212 static inline SDValue getTombstoneKey() {
218 static unsigned getHashValue(const SDValue &Val) {
219 return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
220 (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
223 static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
227 template <> struct isPodLike<SDValue> { static const bool value = true; };
229 /// Allow casting operators to work directly on
230 /// SDValues as if they were SDNode*'s.
231 template<> struct simplify_type<SDValue> {
232 typedef SDNode* SimpleType;
233 static SimpleType getSimplifiedValue(SDValue &Val) {
234 return Val.getNode();
237 template<> struct simplify_type<const SDValue> {
238 typedef /*const*/ SDNode* SimpleType;
239 static SimpleType getSimplifiedValue(const SDValue &Val) {
240 return Val.getNode();
244 /// Represents a use of a SDNode. This class holds an SDValue,
245 /// which records the SDNode being used and the result number, a
246 /// pointer to the SDNode using the value, and Next and Prev pointers,
247 /// which link together all the uses of an SDNode.
250 /// Val - The value being used.
252 /// User - The user of this value.
254 /// Prev, Next - Pointers to the uses list of the SDNode referred by
258 SDUse(const SDUse &U) = delete;
259 void operator=(const SDUse &U) = delete;
262 SDUse() : User(nullptr), Prev(nullptr), Next(nullptr) {}
264 /// Normally SDUse will just implicitly convert to an SDValue that it holds.
265 operator const SDValue&() const { return Val; }
267 /// If implicit conversion to SDValue doesn't work, the get() method returns
269 const SDValue &get() const { return Val; }
271 /// This returns the SDNode that contains this Use.
272 SDNode *getUser() { return User; }
274 /// Get the next SDUse in the use list.
275 SDUse *getNext() const { return Next; }
277 /// Convenience function for get().getNode().
278 SDNode *getNode() const { return Val.getNode(); }
279 /// Convenience function for get().getResNo().
280 unsigned getResNo() const { return Val.getResNo(); }
281 /// Convenience function for get().getValueType().
282 EVT getValueType() const { return Val.getValueType(); }
284 /// Convenience function for get().operator==
285 bool operator==(const SDValue &V) const {
289 /// Convenience function for get().operator!=
290 bool operator!=(const SDValue &V) const {
294 /// Convenience function for get().operator<
295 bool operator<(const SDValue &V) const {
300 friend class SelectionDAG;
302 // TODO: unfriend HandleSDNode once we fix its operand handling.
303 friend class HandleSDNode;
305 void setUser(SDNode *p) { User = p; }
307 /// Remove this use from its existing use list, assign it the
308 /// given value, and add it to the new value's node's use list.
309 inline void set(const SDValue &V);
310 /// Like set, but only supports initializing a newly-allocated
311 /// SDUse with a non-null value.
312 inline void setInitial(const SDValue &V);
313 /// Like set, but only sets the Node portion of the value,
314 /// leaving the ResNo portion unmodified.
315 inline void setNode(SDNode *N);
317 void addToList(SDUse **List) {
319 if (Next) Next->Prev = &Next;
324 void removeFromList() {
326 if (Next) Next->Prev = Prev;
330 /// simplify_type specializations - Allow casting operators to work directly on
331 /// SDValues as if they were SDNode*'s.
332 template<> struct simplify_type<SDUse> {
333 typedef SDNode* SimpleType;
334 static SimpleType getSimplifiedValue(SDUse &Val) {
335 return Val.getNode();
339 /// These are IR-level optimization flags that may be propagated to SDNodes.
340 /// TODO: This data structure should be shared by the IR optimizer and the
344 bool NoUnsignedWrap : 1;
345 bool NoSignedWrap : 1;
347 bool UnsafeAlgebra : 1;
350 bool NoSignedZeros : 1;
351 bool AllowReciprocal : 1;
352 bool VectorReduction : 1;
355 /// Default constructor turns off all optimization flags.
357 NoUnsignedWrap = false;
358 NoSignedWrap = false;
360 UnsafeAlgebra = false;
363 NoSignedZeros = false;
364 AllowReciprocal = false;
365 VectorReduction = false;
368 // These are mutators for each flag.
369 void setNoUnsignedWrap(bool b) { NoUnsignedWrap = b; }
370 void setNoSignedWrap(bool b) { NoSignedWrap = b; }
371 void setExact(bool b) { Exact = b; }
372 void setUnsafeAlgebra(bool b) { UnsafeAlgebra = b; }
373 void setNoNaNs(bool b) { NoNaNs = b; }
374 void setNoInfs(bool b) { NoInfs = b; }
375 void setNoSignedZeros(bool b) { NoSignedZeros = b; }
376 void setAllowReciprocal(bool b) { AllowReciprocal = b; }
377 void setVectorReduction(bool b) { VectorReduction = b; }
379 // These are accessors for each flag.
380 bool hasNoUnsignedWrap() const { return NoUnsignedWrap; }
381 bool hasNoSignedWrap() const { return NoSignedWrap; }
382 bool hasExact() const { return Exact; }
383 bool hasUnsafeAlgebra() const { return UnsafeAlgebra; }
384 bool hasNoNaNs() const { return NoNaNs; }
385 bool hasNoInfs() const { return NoInfs; }
386 bool hasNoSignedZeros() const { return NoSignedZeros; }
387 bool hasAllowReciprocal() const { return AllowReciprocal; }
388 bool hasVectorReduction() const { return VectorReduction; }
390 /// Clear any flags in this flag set that aren't also set in Flags.
391 void intersectWith(const SDNodeFlags *Flags) {
392 NoUnsignedWrap &= Flags->NoUnsignedWrap;
393 NoSignedWrap &= Flags->NoSignedWrap;
394 Exact &= Flags->Exact;
395 UnsafeAlgebra &= Flags->UnsafeAlgebra;
396 NoNaNs &= Flags->NoNaNs;
397 NoInfs &= Flags->NoInfs;
398 NoSignedZeros &= Flags->NoSignedZeros;
399 AllowReciprocal &= Flags->AllowReciprocal;
403 /// Represents one node in the SelectionDAG.
405 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
407 /// The operation that this node performs.
411 // We define a set of mini-helper classes to help us interpret the bits in our
412 // SubclassData. These are designed to fit within a uint16_t so they pack
415 class SDNodeBitfields {
417 friend class MemIntrinsicSDNode;
418 friend class MemSDNode;
420 uint16_t HasDebugValue : 1;
421 uint16_t IsMemIntrinsic : 1;
423 enum { NumSDNodeBits = 2 };
425 class ConstantSDNodeBitfields {
426 friend class ConstantSDNode;
428 uint16_t : NumSDNodeBits;
430 uint16_t IsOpaque : 1;
433 class MemSDNodeBitfields {
434 friend class MemSDNode;
435 friend class MemIntrinsicSDNode;
436 friend class AtomicSDNode;
438 uint16_t : NumSDNodeBits;
440 uint16_t IsVolatile : 1;
441 uint16_t IsNonTemporal : 1;
442 uint16_t IsDereferenceable : 1;
443 uint16_t IsInvariant : 1;
445 enum { NumMemSDNodeBits = NumSDNodeBits + 4 };
447 class LSBaseSDNodeBitfields {
448 friend class LSBaseSDNode;
449 uint16_t : NumMemSDNodeBits;
451 uint16_t AddressingMode : 3; // enum ISD::MemIndexedMode
453 enum { NumLSBaseSDNodeBits = NumMemSDNodeBits + 3 };
455 class LoadSDNodeBitfields {
456 friend class LoadSDNode;
457 friend class MaskedLoadSDNode;
459 uint16_t : NumLSBaseSDNodeBits;
461 uint16_t ExtTy : 2; // enum ISD::LoadExtType
462 uint16_t IsExpanding : 1;
465 class StoreSDNodeBitfields {
466 friend class StoreSDNode;
467 friend class MaskedStoreSDNode;
469 uint16_t : NumLSBaseSDNodeBits;
471 uint16_t IsTruncating : 1;
472 uint16_t IsCompressing : 1;
476 char RawSDNodeBits[sizeof(uint16_t)];
477 SDNodeBitfields SDNodeBits;
478 ConstantSDNodeBitfields ConstantSDNodeBits;
479 MemSDNodeBitfields MemSDNodeBits;
480 LSBaseSDNodeBitfields LSBaseSDNodeBits;
481 LoadSDNodeBitfields LoadSDNodeBits;
482 StoreSDNodeBitfields StoreSDNodeBits;
485 // RawSDNodeBits must cover the entirety of the union. This means that all of
486 // the union's members must have size <= RawSDNodeBits. We write the RHS as
487 // "2" instead of sizeof(RawSDNodeBits) because MSVC can't handle the latter.
488 static_assert(sizeof(SDNodeBitfields) <= 2, "field too wide");
489 static_assert(sizeof(ConstantSDNodeBitfields) <= 2, "field too wide");
490 static_assert(sizeof(MemSDNodeBitfields) <= 2, "field too wide");
491 static_assert(sizeof(LSBaseSDNodeBitfields) <= 2, "field too wide");
492 static_assert(sizeof(LoadSDNodeBitfields) <= 4, "field too wide");
493 static_assert(sizeof(StoreSDNodeBitfields) <= 2, "field too wide");
496 /// Unique id per SDNode in the DAG.
499 /// The values that are used by this operation.
502 /// The types of the values this node defines. SDNode's may
503 /// define multiple values simultaneously.
504 const EVT *ValueList;
506 /// List of uses for this SDNode.
509 /// The number of entries in the Operand/Value list.
510 unsigned short NumOperands, NumValues;
512 // The ordering of the SDNodes. It roughly corresponds to the ordering of the
513 // original LLVM instructions.
514 // This is used for turning off scheduling, because we'll forgo
515 // the normal scheduling algorithms and output the instructions according to
519 /// Source line information.
522 /// Return a pointer to the specified value type.
523 static const EVT *getValueTypeList(EVT VT);
525 friend class SelectionDAG;
526 // TODO: unfriend HandleSDNode once we fix its operand handling.
527 friend class HandleSDNode;
530 /// Unique and persistent id per SDNode in the DAG.
531 /// Used for debug printing.
532 uint16_t PersistentId;
534 //===--------------------------------------------------------------------===//
538 /// Return the SelectionDAG opcode value for this node. For
539 /// pre-isel nodes (those for which isMachineOpcode returns false), these
540 /// are the opcode values in the ISD and <target>ISD namespaces. For
541 /// post-isel opcodes, see getMachineOpcode.
542 unsigned getOpcode() const { return (unsigned short)NodeType; }
544 /// Test if this node has a target-specific opcode (in the
545 /// \<target\>ISD namespace).
546 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
548 /// Test if this node has a target-specific
549 /// memory-referencing opcode (in the \<target\>ISD namespace and
550 /// greater than FIRST_TARGET_MEMORY_OPCODE).
551 bool isTargetMemoryOpcode() const {
552 return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
555 /// Return true if the type of the node type undefined.
556 bool isUndef() const { return NodeType == ISD::UNDEF; }
558 /// Test if this node is a memory intrinsic (with valid pointer information).
559 /// INTRINSIC_W_CHAIN and INTRINSIC_VOID nodes are sometimes created for
560 /// non-memory intrinsics (with chains) that are not really instances of
561 /// MemSDNode. For such nodes, we need some extra state to determine the
562 /// proper classof relationship.
563 bool isMemIntrinsic() const {
564 return (NodeType == ISD::INTRINSIC_W_CHAIN ||
565 NodeType == ISD::INTRINSIC_VOID) &&
566 SDNodeBits.IsMemIntrinsic;
569 /// Test if this node has a post-isel opcode, directly
570 /// corresponding to a MachineInstr opcode.
571 bool isMachineOpcode() const { return NodeType < 0; }
573 /// This may only be called if isMachineOpcode returns
574 /// true. It returns the MachineInstr opcode value that the node's opcode
576 unsigned getMachineOpcode() const {
577 assert(isMachineOpcode() && "Not a MachineInstr opcode!");
581 bool getHasDebugValue() const { return SDNodeBits.HasDebugValue; }
582 void setHasDebugValue(bool b) { SDNodeBits.HasDebugValue = b; }
584 /// Return true if there are no uses of this node.
585 bool use_empty() const { return UseList == nullptr; }
587 /// Return true if there is exactly one use of this node.
588 bool hasOneUse() const {
589 return !use_empty() && std::next(use_begin()) == use_end();
592 /// Return the number of uses of this node. This method takes
593 /// time proportional to the number of uses.
594 size_t use_size() const { return std::distance(use_begin(), use_end()); }
596 /// Return the unique node id.
597 int getNodeId() const { return NodeId; }
599 /// Set unique node id.
600 void setNodeId(int Id) { NodeId = Id; }
602 /// Return the node ordering.
603 unsigned getIROrder() const { return IROrder; }
605 /// Set the node ordering.
606 void setIROrder(unsigned Order) { IROrder = Order; }
608 /// Return the source location info.
609 const DebugLoc &getDebugLoc() const { return debugLoc; }
611 /// Set source location info. Try to avoid this, putting
612 /// it in the constructor is preferable.
613 void setDebugLoc(DebugLoc dl) { debugLoc = std::move(dl); }
615 /// This class provides iterator support for SDUse
616 /// operands that use a specific SDNode.
618 : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
623 explicit use_iterator(SDUse *op) : Op(op) {}
626 typedef std::iterator<std::forward_iterator_tag,
627 SDUse, ptrdiff_t>::reference reference;
628 typedef std::iterator<std::forward_iterator_tag,
629 SDUse, ptrdiff_t>::pointer pointer;
631 use_iterator(const use_iterator &I) : Op(I.Op) {}
632 use_iterator() : Op(nullptr) {}
634 bool operator==(const use_iterator &x) const {
637 bool operator!=(const use_iterator &x) const {
638 return !operator==(x);
641 /// Return true if this iterator is at the end of uses list.
642 bool atEnd() const { return Op == nullptr; }
644 // Iterator traversal: forward iteration only.
645 use_iterator &operator++() { // Preincrement
646 assert(Op && "Cannot increment end iterator!");
651 use_iterator operator++(int) { // Postincrement
652 use_iterator tmp = *this; ++*this; return tmp;
655 /// Retrieve a pointer to the current user node.
656 SDNode *operator*() const {
657 assert(Op && "Cannot dereference end iterator!");
658 return Op->getUser();
661 SDNode *operator->() const { return operator*(); }
663 SDUse &getUse() const { return *Op; }
665 /// Retrieve the operand # of this use in its user.
666 unsigned getOperandNo() const {
667 assert(Op && "Cannot dereference end iterator!");
668 return (unsigned)(Op - Op->getUser()->OperandList);
672 /// Provide iteration support to walk over all uses of an SDNode.
673 use_iterator use_begin() const {
674 return use_iterator(UseList);
677 static use_iterator use_end() { return use_iterator(nullptr); }
679 inline iterator_range<use_iterator> uses() {
680 return make_range(use_begin(), use_end());
682 inline iterator_range<use_iterator> uses() const {
683 return make_range(use_begin(), use_end());
686 /// Return true if there are exactly NUSES uses of the indicated value.
687 /// This method ignores uses of other values defined by this operation.
688 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
690 /// Return true if there are any use of the indicated value.
691 /// This method ignores uses of other values defined by this operation.
692 bool hasAnyUseOfValue(unsigned Value) const;
694 /// Return true if this node is the only use of N.
695 bool isOnlyUserOf(const SDNode *N) const;
697 /// Return true if this node is an operand of N.
698 bool isOperandOf(const SDNode *N) const;
700 /// Return true if this node is a predecessor of N.
701 /// NOTE: Implemented on top of hasPredecessor and every bit as
702 /// expensive. Use carefully.
703 bool isPredecessorOf(const SDNode *N) const {
704 return N->hasPredecessor(this);
707 /// Return true if N is a predecessor of this node.
708 /// N is either an operand of this node, or can be reached by recursively
709 /// traversing up the operands.
710 /// NOTE: This is an expensive method. Use it carefully.
711 bool hasPredecessor(const SDNode *N) const;
713 /// Returns true if N is a predecessor of any node in Worklist. This
714 /// helper keeps Visited and Worklist sets externally to allow unions
715 /// searches to be performed in parallel, caching of results across
716 /// queries and incremental addition to Worklist. Stops early if N is
717 /// found but will resume. Remember to clear Visited and Worklists
719 static bool hasPredecessorHelper(const SDNode *N,
720 SmallPtrSetImpl<const SDNode *> &Visited,
721 SmallVectorImpl<const SDNode *> &Worklist) {
722 if (Visited.count(N))
724 while (!Worklist.empty()) {
725 const SDNode *M = Worklist.pop_back_val();
727 for (const SDValue &OpV : M->op_values()) {
728 SDNode *Op = OpV.getNode();
729 if (Visited.insert(Op).second)
730 Worklist.push_back(Op);
740 /// Return the number of values used by this operation.
741 unsigned getNumOperands() const { return NumOperands; }
743 /// Helper method returns the integer value of a ConstantSDNode operand.
744 uint64_t getConstantOperandVal(unsigned Num) const;
746 const SDValue &getOperand(unsigned Num) const {
747 assert(Num < NumOperands && "Invalid child # of SDNode!");
748 return OperandList[Num];
751 typedef SDUse* op_iterator;
753 op_iterator op_begin() const { return OperandList; }
754 op_iterator op_end() const { return OperandList+NumOperands; }
755 ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
757 /// Iterator for directly iterating over the operand SDValue's.
758 struct value_op_iterator
759 : iterator_adaptor_base<value_op_iterator, op_iterator,
760 std::random_access_iterator_tag, SDValue,
761 ptrdiff_t, value_op_iterator *,
762 value_op_iterator *> {
763 explicit value_op_iterator(SDUse *U = nullptr)
764 : iterator_adaptor_base(U) {}
766 const SDValue &operator*() const { return I->get(); }
769 iterator_range<value_op_iterator> op_values() const {
770 return make_range(value_op_iterator(op_begin()),
771 value_op_iterator(op_end()));
774 SDVTList getVTList() const {
775 SDVTList X = { ValueList, NumValues };
779 /// If this node has a glue operand, return the node
780 /// to which the glue operand points. Otherwise return NULL.
781 SDNode *getGluedNode() const {
782 if (getNumOperands() != 0 &&
783 getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
784 return getOperand(getNumOperands()-1).getNode();
788 /// If this node has a glue value with a user, return
789 /// the user (there is at most one). Otherwise return NULL.
790 SDNode *getGluedUser() const {
791 for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
792 if (UI.getUse().get().getValueType() == MVT::Glue)
797 /// This could be defined as a virtual function and implemented more simply
798 /// and directly, but it is not to avoid creating a vtable for this class.
799 const SDNodeFlags *getFlags() const;
801 /// Clear any flags in this node that aren't also set in Flags.
802 void intersectFlagsWith(const SDNodeFlags *Flags);
804 /// Return the number of values defined/returned by this operator.
805 unsigned getNumValues() const { return NumValues; }
807 /// Return the type of a specified result.
808 EVT getValueType(unsigned ResNo) const {
809 assert(ResNo < NumValues && "Illegal result number!");
810 return ValueList[ResNo];
813 /// Return the type of a specified result as a simple type.
814 MVT getSimpleValueType(unsigned ResNo) const {
815 return getValueType(ResNo).getSimpleVT();
818 /// Returns MVT::getSizeInBits(getValueType(ResNo)).
819 unsigned getValueSizeInBits(unsigned ResNo) const {
820 return getValueType(ResNo).getSizeInBits();
823 typedef const EVT* value_iterator;
824 value_iterator value_begin() const { return ValueList; }
825 value_iterator value_end() const { return ValueList+NumValues; }
827 /// Return the opcode of this operation for printing.
828 std::string getOperationName(const SelectionDAG *G = nullptr) const;
829 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
830 void print_types(raw_ostream &OS, const SelectionDAG *G) const;
831 void print_details(raw_ostream &OS, const SelectionDAG *G) const;
832 void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
833 void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
835 /// Print a SelectionDAG node and all children down to
836 /// the leaves. The given SelectionDAG allows target-specific nodes
837 /// to be printed in human-readable form. Unlike printr, this will
838 /// print the whole DAG, including children that appear multiple
841 void printrFull(raw_ostream &O, const SelectionDAG *G = nullptr) const;
843 /// Print a SelectionDAG node and children up to
844 /// depth "depth." The given SelectionDAG allows target-specific
845 /// nodes to be printed in human-readable form. Unlike printr, this
846 /// will print children that appear multiple times wherever they are
849 void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
850 unsigned depth = 100) const;
852 /// Dump this node, for debugging.
855 /// Dump (recursively) this node and its use-def subgraph.
858 /// Dump this node, for debugging.
859 /// The given SelectionDAG allows target-specific nodes to be printed
860 /// in human-readable form.
861 void dump(const SelectionDAG *G) const;
863 /// Dump (recursively) this node and its use-def subgraph.
864 /// The given SelectionDAG allows target-specific nodes to be printed
865 /// in human-readable form.
866 void dumpr(const SelectionDAG *G) const;
868 /// printrFull to dbgs(). The given SelectionDAG allows
869 /// target-specific nodes to be printed in human-readable form.
870 /// Unlike dumpr, this will print the whole DAG, including children
871 /// that appear multiple times.
872 void dumprFull(const SelectionDAG *G = nullptr) const;
874 /// printrWithDepth to dbgs(). The given
875 /// SelectionDAG allows target-specific nodes to be printed in
876 /// human-readable form. Unlike dumpr, this will print children
877 /// that appear multiple times wherever they are used.
879 void dumprWithDepth(const SelectionDAG *G = nullptr,
880 unsigned depth = 100) const;
882 /// Gather unique data for the node.
883 void Profile(FoldingSetNodeID &ID) const;
885 /// This method should only be used by the SDUse class.
886 void addUse(SDUse &U) { U.addToList(&UseList); }
889 static SDVTList getSDVTList(EVT VT) {
890 SDVTList Ret = { getValueTypeList(VT), 1 };
894 /// Create an SDNode.
896 /// SDNodes are created without any operands, and never own the operand
897 /// storage. To add operands, see SelectionDAG::createOperands.
898 SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
899 : NodeType(Opc), NodeId(-1), OperandList(nullptr), ValueList(VTs.VTs),
900 UseList(nullptr), NumOperands(0), NumValues(VTs.NumVTs), IROrder(Order),
901 debugLoc(std::move(dl)) {
902 memset(&RawSDNodeBits, 0, sizeof(RawSDNodeBits));
903 assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
904 assert(NumValues == VTs.NumVTs &&
905 "NumValues wasn't wide enough for its operands!");
908 /// Release the operands and set this node to have zero operands.
912 /// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
913 /// into SDNode creation functions.
914 /// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
915 /// from the original Instruction, and IROrder is the ordinal position of
917 /// When an SDNode is created after the DAG is being built, both DebugLoc and
918 /// the IROrder are propagated from the original SDNode.
919 /// So SDLoc class provides two constructors besides the default one, one to
920 /// be used by the DAGBuilder, the other to be used by others.
928 SDLoc(const SDNode *N) : DL(N->getDebugLoc()), IROrder(N->getIROrder()) {}
929 SDLoc(const SDValue V) : SDLoc(V.getNode()) {}
930 SDLoc(const Instruction *I, int Order) : IROrder(Order) {
931 assert(Order >= 0 && "bad IROrder");
933 DL = I->getDebugLoc();
936 unsigned getIROrder() const { return IROrder; }
937 const DebugLoc &getDebugLoc() const { return DL; }
940 // Define inline functions from the SDValue class.
942 inline SDValue::SDValue(SDNode *node, unsigned resno)
943 : Node(node), ResNo(resno) {
944 // Explicitly check for !ResNo to avoid use-after-free, because there are
945 // callers that use SDValue(N, 0) with a deleted N to indicate successful
947 assert((!Node || !ResNo || ResNo < Node->getNumValues()) &&
948 "Invalid result number for the given node!");
949 assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
952 inline unsigned SDValue::getOpcode() const {
953 return Node->getOpcode();
956 inline EVT SDValue::getValueType() const {
957 return Node->getValueType(ResNo);
960 inline unsigned SDValue::getNumOperands() const {
961 return Node->getNumOperands();
964 inline const SDValue &SDValue::getOperand(unsigned i) const {
965 return Node->getOperand(i);
968 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
969 return Node->getConstantOperandVal(i);
972 inline bool SDValue::isTargetOpcode() const {
973 return Node->isTargetOpcode();
976 inline bool SDValue::isTargetMemoryOpcode() const {
977 return Node->isTargetMemoryOpcode();
980 inline bool SDValue::isMachineOpcode() const {
981 return Node->isMachineOpcode();
984 inline unsigned SDValue::getMachineOpcode() const {
985 return Node->getMachineOpcode();
988 inline bool SDValue::isUndef() const {
989 return Node->isUndef();
992 inline bool SDValue::use_empty() const {
993 return !Node->hasAnyUseOfValue(ResNo);
996 inline bool SDValue::hasOneUse() const {
997 return Node->hasNUsesOfValue(1, ResNo);
1000 inline const DebugLoc &SDValue::getDebugLoc() const {
1001 return Node->getDebugLoc();
1004 inline void SDValue::dump() const {
1005 return Node->dump();
1008 inline void SDValue::dumpr() const {
1009 return Node->dumpr();
1012 // Define inline functions from the SDUse class.
1014 inline void SDUse::set(const SDValue &V) {
1015 if (Val.getNode()) removeFromList();
1017 if (V.getNode()) V.getNode()->addUse(*this);
1020 inline void SDUse::setInitial(const SDValue &V) {
1022 V.getNode()->addUse(*this);
1025 inline void SDUse::setNode(SDNode *N) {
1026 if (Val.getNode()) removeFromList();
1028 if (N) N->addUse(*this);
1031 /// Returns true if the opcode is a binary operation with flags.
1032 static bool isBinOpWithFlags(unsigned Opcode) {
1053 /// This class is an extension of BinarySDNode
1054 /// used from those opcodes that have associated extra flags.
1055 class BinaryWithFlagsSDNode : public SDNode {
1059 BinaryWithFlagsSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl,
1060 SDVTList VTs, const SDNodeFlags &NodeFlags)
1061 : SDNode(Opc, Order, dl, VTs), Flags(NodeFlags) {}
1063 static bool classof(const SDNode *N) {
1064 return isBinOpWithFlags(N->getOpcode());
1068 /// This class is used to form a handle around another node that
1069 /// is persistent and is updated across invocations of replaceAllUsesWith on its
1070 /// operand. This node should be directly created by end-users and not added to
1071 /// the AllNodes list.
1072 class HandleSDNode : public SDNode {
1076 explicit HandleSDNode(SDValue X)
1077 : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1078 // HandleSDNodes are never inserted into the DAG, so they won't be
1079 // auto-numbered. Use ID 65535 as a sentinel.
1080 PersistentId = 0xffff;
1082 // Manually set up the operand list. This node type is special in that it's
1083 // always stack allocated and SelectionDAG does not manage its operands.
1084 // TODO: This should either (a) not be in the SDNode hierarchy, or (b) not
1093 const SDValue &getValue() const { return Op; }
1096 class AddrSpaceCastSDNode : public SDNode {
1098 unsigned SrcAddrSpace;
1099 unsigned DestAddrSpace;
1102 AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, EVT VT,
1103 unsigned SrcAS, unsigned DestAS);
1105 unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1106 unsigned getDestAddressSpace() const { return DestAddrSpace; }
1108 static bool classof(const SDNode *N) {
1109 return N->getOpcode() == ISD::ADDRSPACECAST;
1113 /// This is an abstract virtual class for memory operations.
1114 class MemSDNode : public SDNode {
1116 // VT of in-memory value.
1120 /// Memory reference information.
1121 MachineMemOperand *MMO;
1124 MemSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs,
1125 EVT MemoryVT, MachineMemOperand *MMO);
1127 bool readMem() const { return MMO->isLoad(); }
1128 bool writeMem() const { return MMO->isStore(); }
1130 /// Returns alignment and volatility of the memory access
1131 unsigned getOriginalAlignment() const {
1132 return MMO->getBaseAlignment();
1134 unsigned getAlignment() const {
1135 return MMO->getAlignment();
1138 /// Return the SubclassData value, without HasDebugValue. This contains an
1139 /// encoding of the volatile flag, as well as bits used by subclasses. This
1140 /// function should only be used to compute a FoldingSetNodeID value.
1141 /// The HasDebugValue bit is masked out because CSE map needs to match
1142 /// nodes with debug info with nodes without debug info.
1143 unsigned getRawSubclassData() const {
1146 char RawSDNodeBits[sizeof(uint16_t)];
1147 SDNodeBitfields SDNodeBits;
1149 memcpy(&RawSDNodeBits, &this->RawSDNodeBits, sizeof(this->RawSDNodeBits));
1150 SDNodeBits.HasDebugValue = 0;
1151 memcpy(&Data, &RawSDNodeBits, sizeof(RawSDNodeBits));
1155 bool isVolatile() const { return MemSDNodeBits.IsVolatile; }
1156 bool isNonTemporal() const { return MemSDNodeBits.IsNonTemporal; }
1157 bool isDereferenceable() const { return MemSDNodeBits.IsDereferenceable; }
1158 bool isInvariant() const { return MemSDNodeBits.IsInvariant; }
1160 // Returns the offset from the location of the access.
1161 int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1163 /// Returns the AA info that describes the dereference.
1164 AAMDNodes getAAInfo() const { return MMO->getAAInfo(); }
1166 /// Returns the Ranges that describes the dereference.
1167 const MDNode *getRanges() const { return MMO->getRanges(); }
1169 /// Return the synchronization scope for this memory operation.
1170 SynchronizationScope getSynchScope() const { return MMO->getSynchScope(); }
1172 /// Return the atomic ordering requirements for this memory operation. For
1173 /// cmpxchg atomic operations, return the atomic ordering requirements when
1175 AtomicOrdering getOrdering() const { return MMO->getOrdering(); }
1177 /// Return the type of the in-memory value.
1178 EVT getMemoryVT() const { return MemoryVT; }
1180 /// Return a MachineMemOperand object describing the memory
1181 /// reference performed by operation.
1182 MachineMemOperand *getMemOperand() const { return MMO; }
1184 const MachinePointerInfo &getPointerInfo() const {
1185 return MMO->getPointerInfo();
1188 /// Return the address space for the associated pointer
1189 unsigned getAddressSpace() const {
1190 return getPointerInfo().getAddrSpace();
1193 /// Update this MemSDNode's MachineMemOperand information
1194 /// to reflect the alignment of NewMMO, if it has a greater alignment.
1195 /// This must only be used when the new alignment applies to all users of
1196 /// this MachineMemOperand.
1197 void refineAlignment(const MachineMemOperand *NewMMO) {
1198 MMO->refineAlignment(NewMMO);
1201 const SDValue &getChain() const { return getOperand(0); }
1202 const SDValue &getBasePtr() const {
1203 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1206 // Methods to support isa and dyn_cast
1207 static bool classof(const SDNode *N) {
1208 // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1209 // with either an intrinsic or a target opcode.
1210 return N->getOpcode() == ISD::LOAD ||
1211 N->getOpcode() == ISD::STORE ||
1212 N->getOpcode() == ISD::PREFETCH ||
1213 N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1214 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1215 N->getOpcode() == ISD::ATOMIC_SWAP ||
1216 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1217 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1218 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1219 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1220 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1221 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1222 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1223 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1224 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1225 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1226 N->getOpcode() == ISD::ATOMIC_LOAD ||
1227 N->getOpcode() == ISD::ATOMIC_STORE ||
1228 N->getOpcode() == ISD::MLOAD ||
1229 N->getOpcode() == ISD::MSTORE ||
1230 N->getOpcode() == ISD::MGATHER ||
1231 N->getOpcode() == ISD::MSCATTER ||
1232 N->isMemIntrinsic() ||
1233 N->isTargetMemoryOpcode();
1237 /// This is an SDNode representing atomic operations.
1238 class AtomicSDNode : public MemSDNode {
1240 AtomicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTL,
1241 EVT MemVT, MachineMemOperand *MMO)
1242 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {}
1244 const SDValue &getBasePtr() const { return getOperand(1); }
1245 const SDValue &getVal() const { return getOperand(2); }
1247 /// Returns true if this SDNode represents cmpxchg atomic operation, false
1249 bool isCompareAndSwap() const {
1250 unsigned Op = getOpcode();
1251 return Op == ISD::ATOMIC_CMP_SWAP ||
1252 Op == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS;
1255 /// For cmpxchg atomic operations, return the atomic ordering requirements
1256 /// when store does not occur.
1257 AtomicOrdering getFailureOrdering() const {
1258 assert(isCompareAndSwap() && "Must be cmpxchg operation");
1259 return MMO->getFailureOrdering();
1262 // Methods to support isa and dyn_cast
1263 static bool classof(const SDNode *N) {
1264 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1265 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1266 N->getOpcode() == ISD::ATOMIC_SWAP ||
1267 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1268 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1269 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1270 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1271 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1272 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1273 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1274 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1275 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1276 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1277 N->getOpcode() == ISD::ATOMIC_LOAD ||
1278 N->getOpcode() == ISD::ATOMIC_STORE;
1282 /// This SDNode is used for target intrinsics that touch
1283 /// memory and need an associated MachineMemOperand. Its opcode may be
1284 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1285 /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1286 class MemIntrinsicSDNode : public MemSDNode {
1288 MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl,
1289 SDVTList VTs, EVT MemoryVT, MachineMemOperand *MMO)
1290 : MemSDNode(Opc, Order, dl, VTs, MemoryVT, MMO) {
1291 SDNodeBits.IsMemIntrinsic = true;
1294 // Methods to support isa and dyn_cast
1295 static bool classof(const SDNode *N) {
1296 // We lower some target intrinsics to their target opcode
1297 // early a node with a target opcode can be of this class
1298 return N->isMemIntrinsic() ||
1299 N->getOpcode() == ISD::PREFETCH ||
1300 N->isTargetMemoryOpcode();
1304 /// 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 {
1313 // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1314 // is freed when the SelectionDAG object is destroyed.
1318 friend class SelectionDAG;
1320 ShuffleVectorSDNode(EVT VT, unsigned Order, const DebugLoc &dl, const int *M)
1321 : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {}
1324 ArrayRef<int> getMask() const {
1325 EVT VT = getValueType(0);
1326 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)); }
1336 int getSplatIndex() const {
1337 assert(isSplat() && "Cannot get splat index for non-splat!");
1338 EVT VT = getValueType(0);
1339 for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
1343 llvm_unreachable("Splat with all undef indices?");
1346 static bool isSplatMask(const int *Mask, EVT VT);
1348 /// Change values in a shuffle permute mask assuming
1349 /// the two vector operands have swapped position.
1350 static void commuteMask(MutableArrayRef<int> Mask) {
1351 unsigned NumElems = Mask.size();
1352 for (unsigned i = 0; i != NumElems; ++i) {
1356 else if (idx < (int)NumElems)
1357 Mask[i] = idx + NumElems;
1359 Mask[i] = idx - NumElems;
1363 static bool classof(const SDNode *N) {
1364 return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1368 class ConstantSDNode : public SDNode {
1369 const ConstantInt *Value;
1371 friend class SelectionDAG;
1373 ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val,
1374 const DebugLoc &DL, EVT VT)
1375 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, 0, DL,
1378 ConstantSDNodeBits.IsOpaque = isOpaque;
1382 const ConstantInt *getConstantIntValue() const { return Value; }
1383 const APInt &getAPIntValue() const { return Value->getValue(); }
1384 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1385 int64_t getSExtValue() const { return Value->getSExtValue(); }
1387 bool isOne() const { return Value->isOne(); }
1388 bool isNullValue() const { return Value->isNullValue(); }
1389 bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1391 bool isOpaque() const { return ConstantSDNodeBits.IsOpaque; }
1393 static bool classof(const SDNode *N) {
1394 return N->getOpcode() == ISD::Constant ||
1395 N->getOpcode() == ISD::TargetConstant;
1399 class ConstantFPSDNode : public SDNode {
1400 const ConstantFP *Value;
1402 friend class SelectionDAG;
1404 ConstantFPSDNode(bool isTarget, const ConstantFP *val, const DebugLoc &DL,
1406 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 0, DL,
1411 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1412 const ConstantFP *getConstantFPValue() const { return Value; }
1414 /// Return true if the value is positive or negative zero.
1415 bool isZero() const { return Value->isZero(); }
1417 /// Return true if the value is a NaN.
1418 bool isNaN() const { return Value->isNaN(); }
1420 /// Return true if the value is an infinity
1421 bool isInfinity() const { return Value->isInfinity(); }
1423 /// Return true if the value is negative.
1424 bool isNegative() const { return Value->isNegative(); }
1426 /// We don't rely on operator== working on double values, as
1427 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1428 /// As such, this method can be used to do an exact bit-for-bit comparison of
1429 /// two floating point values.
1431 /// We leave the version with the double argument here because it's just so
1432 /// convenient to write "2.0" and the like. Without this function we'd
1433 /// have to duplicate its logic everywhere it's called.
1434 bool isExactlyValue(double V) const {
1437 Tmp.convert(Value->getValueAPF().getSemantics(),
1438 APFloat::rmNearestTiesToEven, &ignored);
1439 return isExactlyValue(Tmp);
1441 bool isExactlyValue(const APFloat& V) const;
1443 static bool isValueValidForType(EVT VT, const APFloat& Val);
1445 static bool classof(const SDNode *N) {
1446 return N->getOpcode() == ISD::ConstantFP ||
1447 N->getOpcode() == ISD::TargetConstantFP;
1451 /// Returns true if \p V is a constant integer zero.
1452 bool isNullConstant(SDValue V);
1454 /// Returns true if \p V is an FP constant with a value of positive zero.
1455 bool isNullFPConstant(SDValue V);
1457 /// Returns true if \p V is an integer constant with all bits set.
1458 bool isAllOnesConstant(SDValue V);
1460 /// Returns true if \p V is a constant integer one.
1461 bool isOneConstant(SDValue V);
1463 /// Returns true if \p V is a bitwise not operation. Assumes that an all ones
1464 /// constant is canonicalized to be operand 1.
1465 bool isBitwiseNot(SDValue V);
1467 /// Returns the SDNode if it is a constant splat BuildVector or constant int.
1468 ConstantSDNode *isConstOrConstSplat(SDValue V);
1470 /// Returns the SDNode if it is a constant splat BuildVector or constant float.
1471 ConstantFPSDNode *isConstOrConstSplatFP(SDValue V);
1473 class GlobalAddressSDNode : public SDNode {
1474 const GlobalValue *TheGlobal;
1476 unsigned char TargetFlags;
1477 friend class SelectionDAG;
1478 GlobalAddressSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL,
1479 const GlobalValue *GA, EVT VT, int64_t o,
1480 unsigned char TargetFlags);
1483 const GlobalValue *getGlobal() const { return TheGlobal; }
1484 int64_t getOffset() const { return Offset; }
1485 unsigned char getTargetFlags() const { return TargetFlags; }
1486 // Return the address space this GlobalAddress belongs to.
1487 unsigned getAddressSpace() const;
1489 static bool classof(const SDNode *N) {
1490 return N->getOpcode() == ISD::GlobalAddress ||
1491 N->getOpcode() == ISD::TargetGlobalAddress ||
1492 N->getOpcode() == ISD::GlobalTLSAddress ||
1493 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1497 class FrameIndexSDNode : public SDNode {
1500 friend class SelectionDAG;
1502 FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1503 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1504 0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1508 int getIndex() const { return FI; }
1510 static bool classof(const SDNode *N) {
1511 return N->getOpcode() == ISD::FrameIndex ||
1512 N->getOpcode() == ISD::TargetFrameIndex;
1516 class JumpTableSDNode : public SDNode {
1518 unsigned char TargetFlags;
1520 friend class SelectionDAG;
1522 JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1523 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1524 0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1528 int getIndex() const { return JTI; }
1529 unsigned char getTargetFlags() const { return TargetFlags; }
1531 static bool classof(const SDNode *N) {
1532 return N->getOpcode() == ISD::JumpTable ||
1533 N->getOpcode() == ISD::TargetJumpTable;
1537 class ConstantPoolSDNode : public SDNode {
1539 const Constant *ConstVal;
1540 MachineConstantPoolValue *MachineCPVal;
1542 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1543 unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
1544 unsigned char TargetFlags;
1546 friend class SelectionDAG;
1548 ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1549 unsigned Align, unsigned char TF)
1550 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1551 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1553 assert(Offset >= 0 && "Offset is too large");
1557 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1558 EVT VT, int o, unsigned Align, unsigned char TF)
1559 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1560 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1562 assert(Offset >= 0 && "Offset is too large");
1563 Val.MachineCPVal = v;
1564 Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1568 bool isMachineConstantPoolEntry() const {
1572 const Constant *getConstVal() const {
1573 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1574 return Val.ConstVal;
1577 MachineConstantPoolValue *getMachineCPVal() const {
1578 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1579 return Val.MachineCPVal;
1582 int getOffset() const {
1583 return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1586 // Return the alignment of this constant pool object, which is either 0 (for
1587 // default alignment) or the desired value.
1588 unsigned getAlignment() const { return Alignment; }
1589 unsigned char getTargetFlags() const { return TargetFlags; }
1591 Type *getType() const;
1593 static bool classof(const SDNode *N) {
1594 return N->getOpcode() == ISD::ConstantPool ||
1595 N->getOpcode() == ISD::TargetConstantPool;
1599 /// Completely target-dependent object reference.
1600 class TargetIndexSDNode : public SDNode {
1601 unsigned char TargetFlags;
1605 friend class SelectionDAG;
1608 TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1609 : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
1610 TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1612 unsigned char getTargetFlags() const { return TargetFlags; }
1613 int getIndex() const { return Index; }
1614 int64_t getOffset() const { return Offset; }
1616 static bool classof(const SDNode *N) {
1617 return N->getOpcode() == ISD::TargetIndex;
1621 class BasicBlockSDNode : public SDNode {
1622 MachineBasicBlock *MBB;
1624 friend class SelectionDAG;
1626 /// Debug info is meaningful and potentially useful here, but we create
1627 /// blocks out of order when they're jumped to, which makes it a bit
1628 /// harder. Let's see if we need it first.
1629 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1630 : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
1634 MachineBasicBlock *getBasicBlock() const { return MBB; }
1636 static bool classof(const SDNode *N) {
1637 return N->getOpcode() == ISD::BasicBlock;
1641 /// A "pseudo-class" with methods for operating on BUILD_VECTORs.
1642 class BuildVectorSDNode : public SDNode {
1643 // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1644 explicit BuildVectorSDNode() = delete;
1647 /// Check if this is a constant splat, and if so, find the
1648 /// smallest element size that splats the vector. If MinSplatBits is
1649 /// nonzero, the element size must be at least that large. Note that the
1650 /// splat element may be the entire vector (i.e., a one element vector).
1651 /// Returns the splat element value in SplatValue. Any undefined bits in
1652 /// that value are zero, and the corresponding bits in the SplatUndef mask
1653 /// are set. The SplatBitSize value is set to the splat element size in
1654 /// bits. HasAnyUndefs is set to true if any bits in the vector are
1655 /// undefined. isBigEndian describes the endianness of the target.
1656 bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1657 unsigned &SplatBitSize, bool &HasAnyUndefs,
1658 unsigned MinSplatBits = 0,
1659 bool isBigEndian = false) const;
1661 /// \brief Returns the splatted value or a null value if this is not a splat.
1663 /// If passed a non-null UndefElements bitvector, it will resize it to match
1664 /// the vector width and set the bits where elements are undef.
1665 SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
1667 /// \brief Returns the splatted constant or null if this is not a constant
1670 /// If passed a non-null UndefElements bitvector, it will resize it to match
1671 /// the vector width and set the bits where elements are undef.
1673 getConstantSplatNode(BitVector *UndefElements = nullptr) const;
1675 /// \brief Returns the splatted constant FP or null if this is not a constant
1678 /// If passed a non-null UndefElements bitvector, it will resize it to match
1679 /// the vector width and set the bits where elements are undef.
1681 getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
1683 /// \brief If this is a constant FP splat and the splatted constant FP is an
1684 /// exact power or 2, return the log base 2 integer value. Otherwise,
1687 /// The BitWidth specifies the necessary bit precision.
1688 int32_t getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements,
1689 uint32_t BitWidth) const;
1691 bool isConstant() const;
1693 static inline bool classof(const SDNode *N) {
1694 return N->getOpcode() == ISD::BUILD_VECTOR;
1698 /// An SDNode that holds an arbitrary LLVM IR Value. This is
1699 /// used when the SelectionDAG needs to make a simple reference to something
1700 /// in the LLVM IR representation.
1702 class SrcValueSDNode : public SDNode {
1705 friend class SelectionDAG;
1707 /// Create a SrcValue for a general value.
1708 explicit SrcValueSDNode(const Value *v)
1709 : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1712 /// Return the contained Value.
1713 const Value *getValue() const { return V; }
1715 static bool classof(const SDNode *N) {
1716 return N->getOpcode() == ISD::SRCVALUE;
1720 class MDNodeSDNode : public SDNode {
1723 friend class SelectionDAG;
1725 explicit MDNodeSDNode(const MDNode *md)
1726 : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
1730 const MDNode *getMD() const { return MD; }
1732 static bool classof(const SDNode *N) {
1733 return N->getOpcode() == ISD::MDNODE_SDNODE;
1737 class RegisterSDNode : public SDNode {
1740 friend class SelectionDAG;
1742 RegisterSDNode(unsigned reg, EVT VT)
1743 : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {}
1746 unsigned getReg() const { return Reg; }
1748 static bool classof(const SDNode *N) {
1749 return N->getOpcode() == ISD::Register;
1753 class RegisterMaskSDNode : public SDNode {
1754 // The memory for RegMask is not owned by the node.
1755 const uint32_t *RegMask;
1757 friend class SelectionDAG;
1759 RegisterMaskSDNode(const uint32_t *mask)
1760 : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
1764 const uint32_t *getRegMask() const { return RegMask; }
1766 static bool classof(const SDNode *N) {
1767 return N->getOpcode() == ISD::RegisterMask;
1771 class BlockAddressSDNode : public SDNode {
1772 const BlockAddress *BA;
1774 unsigned char TargetFlags;
1776 friend class SelectionDAG;
1778 BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1779 int64_t o, unsigned char Flags)
1780 : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
1781 BA(ba), Offset(o), TargetFlags(Flags) {
1785 const BlockAddress *getBlockAddress() const { return BA; }
1786 int64_t getOffset() const { return Offset; }
1787 unsigned char getTargetFlags() const { return TargetFlags; }
1789 static bool classof(const SDNode *N) {
1790 return N->getOpcode() == ISD::BlockAddress ||
1791 N->getOpcode() == ISD::TargetBlockAddress;
1795 class EHLabelSDNode : public SDNode {
1798 friend class SelectionDAG;
1800 EHLabelSDNode(unsigned Order, const DebugLoc &dl, MCSymbol *L)
1801 : SDNode(ISD::EH_LABEL, Order, dl, getSDVTList(MVT::Other)), Label(L) {}
1804 MCSymbol *getLabel() const { return Label; }
1806 static bool classof(const SDNode *N) {
1807 return N->getOpcode() == ISD::EH_LABEL;
1811 class ExternalSymbolSDNode : public SDNode {
1813 unsigned char TargetFlags;
1815 friend class SelectionDAG;
1817 ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1818 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1819 0, DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {}
1822 const char *getSymbol() const { return Symbol; }
1823 unsigned char getTargetFlags() const { return TargetFlags; }
1825 static bool classof(const SDNode *N) {
1826 return N->getOpcode() == ISD::ExternalSymbol ||
1827 N->getOpcode() == ISD::TargetExternalSymbol;
1831 class MCSymbolSDNode : public SDNode {
1834 friend class SelectionDAG;
1835 MCSymbolSDNode(MCSymbol *Symbol, EVT VT)
1836 : SDNode(ISD::MCSymbol, 0, DebugLoc(), getSDVTList(VT)), Symbol(Symbol) {}
1839 MCSymbol *getMCSymbol() const { return Symbol; }
1841 static bool classof(const SDNode *N) {
1842 return N->getOpcode() == ISD::MCSymbol;
1846 class CondCodeSDNode : public SDNode {
1847 ISD::CondCode Condition;
1849 friend class SelectionDAG;
1851 explicit CondCodeSDNode(ISD::CondCode Cond)
1852 : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1856 ISD::CondCode get() const { return Condition; }
1858 static bool classof(const SDNode *N) {
1859 return N->getOpcode() == ISD::CONDCODE;
1863 /// This class is used to represent EVT's, which are used
1864 /// to parameterize some operations.
1865 class VTSDNode : public SDNode {
1868 friend class SelectionDAG;
1870 explicit VTSDNode(EVT VT)
1871 : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1875 EVT getVT() const { return ValueType; }
1877 static bool classof(const SDNode *N) {
1878 return N->getOpcode() == ISD::VALUETYPE;
1882 /// Base class for LoadSDNode and StoreSDNode
1883 class LSBaseSDNode : public MemSDNode {
1885 LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl,
1886 SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
1887 MachineMemOperand *MMO)
1888 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
1889 LSBaseSDNodeBits.AddressingMode = AM;
1890 assert(getAddressingMode() == AM && "Value truncated");
1893 const SDValue &getOffset() const {
1894 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1897 /// Return the addressing mode for this load or store:
1898 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
1899 ISD::MemIndexedMode getAddressingMode() const {
1900 return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
1903 /// Return true if this is a pre/post inc/dec load/store.
1904 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
1906 /// Return true if this is NOT a pre/post inc/dec load/store.
1907 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
1909 static bool classof(const SDNode *N) {
1910 return N->getOpcode() == ISD::LOAD ||
1911 N->getOpcode() == ISD::STORE;
1915 /// This class is used to represent ISD::LOAD nodes.
1916 class LoadSDNode : public LSBaseSDNode {
1917 friend class SelectionDAG;
1919 LoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
1920 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
1921 MachineMemOperand *MMO)
1922 : LSBaseSDNode(ISD::LOAD, Order, dl, VTs, AM, MemVT, MMO) {
1923 LoadSDNodeBits.ExtTy = ETy;
1924 assert(readMem() && "Load MachineMemOperand is not a load!");
1925 assert(!writeMem() && "Load MachineMemOperand is a store!");
1929 /// Return whether this is a plain node,
1930 /// or one of the varieties of value-extending loads.
1931 ISD::LoadExtType getExtensionType() const {
1932 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
1935 const SDValue &getBasePtr() const { return getOperand(1); }
1936 const SDValue &getOffset() const { return getOperand(2); }
1938 static bool classof(const SDNode *N) {
1939 return N->getOpcode() == ISD::LOAD;
1943 /// This class is used to represent ISD::STORE nodes.
1944 class StoreSDNode : public LSBaseSDNode {
1945 friend class SelectionDAG;
1947 StoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
1948 ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
1949 MachineMemOperand *MMO)
1950 : LSBaseSDNode(ISD::STORE, Order, dl, VTs, AM, MemVT, MMO) {
1951 StoreSDNodeBits.IsTruncating = isTrunc;
1952 assert(!readMem() && "Store MachineMemOperand is a load!");
1953 assert(writeMem() && "Store MachineMemOperand is not a store!");
1957 /// Return true if the op does a truncation before store.
1958 /// For integers this is the same as doing a TRUNCATE and storing the result.
1959 /// For floats, it is the same as doing an FP_ROUND and storing the result.
1960 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
1962 const SDValue &getValue() const { return getOperand(1); }
1963 const SDValue &getBasePtr() const { return getOperand(2); }
1964 const SDValue &getOffset() const { return getOperand(3); }
1966 static bool classof(const SDNode *N) {
1967 return N->getOpcode() == ISD::STORE;
1971 /// This base class is used to represent MLOAD and MSTORE nodes
1972 class MaskedLoadStoreSDNode : public MemSDNode {
1974 friend class SelectionDAG;
1976 MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order,
1977 const DebugLoc &dl, SDVTList VTs, EVT MemVT,
1978 MachineMemOperand *MMO)
1979 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
1981 // In the both nodes address is Op1, mask is Op2:
1982 // MaskedLoadSDNode (Chain, ptr, mask, src0), src0 is a passthru value
1983 // MaskedStoreSDNode (Chain, ptr, mask, data)
1984 // Mask is a vector of i1 elements
1985 const SDValue &getBasePtr() const { return getOperand(1); }
1986 const SDValue &getMask() const { return getOperand(2); }
1988 static bool classof(const SDNode *N) {
1989 return N->getOpcode() == ISD::MLOAD ||
1990 N->getOpcode() == ISD::MSTORE;
1994 /// This class is used to represent an MLOAD node
1995 class MaskedLoadSDNode : public MaskedLoadStoreSDNode {
1997 friend class SelectionDAG;
1998 MaskedLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
1999 ISD::LoadExtType ETy, bool IsExpanding, EVT MemVT,
2000 MachineMemOperand *MMO)
2001 : MaskedLoadStoreSDNode(ISD::MLOAD, Order, dl, VTs, MemVT, MMO) {
2002 LoadSDNodeBits.ExtTy = ETy;
2003 LoadSDNodeBits.IsExpanding = IsExpanding;
2006 ISD::LoadExtType getExtensionType() const {
2007 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2010 const SDValue &getSrc0() const { return getOperand(3); }
2011 static bool classof(const SDNode *N) {
2012 return N->getOpcode() == ISD::MLOAD;
2015 bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
2018 /// This class is used to represent an MSTORE node
2019 class MaskedStoreSDNode : public MaskedLoadStoreSDNode {
2021 friend class SelectionDAG;
2023 MaskedStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2024 bool isTrunc, bool isCompressing, EVT MemVT,
2025 MachineMemOperand *MMO)
2026 : MaskedLoadStoreSDNode(ISD::MSTORE, Order, dl, VTs, MemVT, MMO) {
2027 StoreSDNodeBits.IsTruncating = isTrunc;
2028 StoreSDNodeBits.IsCompressing = isCompressing;
2031 /// Return true if the op does a truncation before store.
2032 /// For integers this is the same as doing a TRUNCATE and storing the result.
2033 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2034 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2036 /// Returns true if the op does a compression to the vector before storing.
2037 /// The node contiguously stores the active elements (integers or floats)
2038 /// in src (those with their respective bit set in writemask k) to unaligned
2039 /// memory at base_addr.
2040 bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
2042 const SDValue &getValue() const { return getOperand(3); }
2044 static bool classof(const SDNode *N) {
2045 return N->getOpcode() == ISD::MSTORE;
2049 /// This is a base class used to represent
2050 /// MGATHER and MSCATTER nodes
2052 class MaskedGatherScatterSDNode : public MemSDNode {
2054 friend class SelectionDAG;
2056 MaskedGatherScatterSDNode(ISD::NodeType NodeTy, unsigned Order,
2057 const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2058 MachineMemOperand *MMO)
2059 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2061 // In the both nodes address is Op1, mask is Op2:
2062 // MaskedGatherSDNode (Chain, src0, mask, base, index), src0 is a passthru value
2063 // MaskedScatterSDNode (Chain, value, mask, base, index)
2064 // Mask is a vector of i1 elements
2065 const SDValue &getBasePtr() const { return getOperand(3); }
2066 const SDValue &getIndex() const { return getOperand(4); }
2067 const SDValue &getMask() const { return getOperand(2); }
2068 const SDValue &getValue() const { return getOperand(1); }
2070 static bool classof(const SDNode *N) {
2071 return N->getOpcode() == ISD::MGATHER ||
2072 N->getOpcode() == ISD::MSCATTER;
2076 /// This class is used to represent an MGATHER node
2078 class MaskedGatherSDNode : public MaskedGatherScatterSDNode {
2080 friend class SelectionDAG;
2082 MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2083 EVT MemVT, MachineMemOperand *MMO)
2084 : MaskedGatherScatterSDNode(ISD::MGATHER, Order, dl, VTs, MemVT, MMO) {}
2086 static bool classof(const SDNode *N) {
2087 return N->getOpcode() == ISD::MGATHER;
2091 /// This class is used to represent an MSCATTER node
2093 class MaskedScatterSDNode : public MaskedGatherScatterSDNode {
2095 friend class SelectionDAG;
2097 MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2098 EVT MemVT, MachineMemOperand *MMO)
2099 : MaskedGatherScatterSDNode(ISD::MSCATTER, Order, dl, VTs, MemVT, MMO) {}
2101 static bool classof(const SDNode *N) {
2102 return N->getOpcode() == ISD::MSCATTER;
2106 /// An SDNode that represents everything that will be needed
2107 /// to construct a MachineInstr. These nodes are created during the
2108 /// instruction selection proper phase.
2109 class MachineSDNode : public SDNode {
2111 typedef MachineMemOperand **mmo_iterator;
2114 friend class SelectionDAG;
2116 MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL, SDVTList VTs)
2117 : SDNode(Opc, Order, DL, VTs), MemRefs(nullptr), MemRefsEnd(nullptr) {}
2119 /// Memory reference descriptions for this instruction.
2120 mmo_iterator MemRefs;
2121 mmo_iterator MemRefsEnd;
2124 mmo_iterator memoperands_begin() const { return MemRefs; }
2125 mmo_iterator memoperands_end() const { return MemRefsEnd; }
2126 bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
2128 /// Assign this MachineSDNodes's memory reference descriptor
2129 /// list. This does not transfer ownership.
2130 void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
2131 for (mmo_iterator MMI = NewMemRefs, MME = NewMemRefsEnd; MMI != MME; ++MMI)
2132 assert(*MMI && "Null mem ref detected!");
2133 MemRefs = NewMemRefs;
2134 MemRefsEnd = NewMemRefsEnd;
2137 static bool classof(const SDNode *N) {
2138 return N->isMachineOpcode();
2142 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
2143 SDNode, ptrdiff_t> {
2147 SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2150 bool operator==(const SDNodeIterator& x) const {
2151 return Operand == x.Operand;
2153 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2155 pointer operator*() const {
2156 return Node->getOperand(Operand).getNode();
2158 pointer operator->() const { return operator*(); }
2160 SDNodeIterator& operator++() { // Preincrement
2164 SDNodeIterator operator++(int) { // Postincrement
2165 SDNodeIterator tmp = *this; ++*this; return tmp;
2167 size_t operator-(SDNodeIterator Other) const {
2168 assert(Node == Other.Node &&
2169 "Cannot compare iterators of two different nodes!");
2170 return Operand - Other.Operand;
2173 static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
2174 static SDNodeIterator end (const SDNode *N) {
2175 return SDNodeIterator(N, N->getNumOperands());
2178 unsigned getOperand() const { return Operand; }
2179 const SDNode *getNode() const { return Node; }
2182 template <> struct GraphTraits<SDNode*> {
2183 typedef SDNode *NodeRef;
2184 typedef SDNodeIterator ChildIteratorType;
2186 static NodeRef getEntryNode(SDNode *N) { return N; }
2187 static ChildIteratorType child_begin(NodeRef N) {
2188 return SDNodeIterator::begin(N);
2190 static ChildIteratorType child_end(NodeRef N) {
2191 return SDNodeIterator::end(N);
2195 /// A representation of the largest SDNode, for use in sizeof().
2197 /// This needs to be a union because the largest node differs on 32 bit systems
2198 /// with 4 and 8 byte pointer alignment, respectively.
2199 typedef AlignedCharArrayUnion<AtomicSDNode, TargetIndexSDNode,
2200 BlockAddressSDNode, GlobalAddressSDNode>
2203 /// The SDNode class with the greatest alignment requirement.
2204 typedef GlobalAddressSDNode MostAlignedSDNode;
2208 /// Returns true if the specified node is a non-extending and unindexed load.
2209 inline bool isNormalLoad(const SDNode *N) {
2210 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2211 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2212 Ld->getAddressingMode() == ISD::UNINDEXED;
2215 /// Returns true if the specified node is a non-extending load.
2216 inline bool isNON_EXTLoad(const SDNode *N) {
2217 return isa<LoadSDNode>(N) &&
2218 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2221 /// Returns true if the specified node is a EXTLOAD.
2222 inline bool isEXTLoad(const SDNode *N) {
2223 return isa<LoadSDNode>(N) &&
2224 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2227 /// Returns true if the specified node is a SEXTLOAD.
2228 inline bool isSEXTLoad(const SDNode *N) {
2229 return isa<LoadSDNode>(N) &&
2230 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2233 /// Returns true if the specified node is a ZEXTLOAD.
2234 inline bool isZEXTLoad(const SDNode *N) {
2235 return isa<LoadSDNode>(N) &&
2236 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2239 /// Returns true if the specified node is an unindexed load.
2240 inline bool isUNINDEXEDLoad(const SDNode *N) {
2241 return isa<LoadSDNode>(N) &&
2242 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2245 /// Returns true if the specified node is a non-truncating
2246 /// and unindexed store.
2247 inline bool isNormalStore(const SDNode *N) {
2248 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2249 return St && !St->isTruncatingStore() &&
2250 St->getAddressingMode() == ISD::UNINDEXED;
2253 /// Returns true if the specified node is a non-truncating store.
2254 inline bool isNON_TRUNCStore(const SDNode *N) {
2255 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2258 /// Returns true if the specified node is a truncating store.
2259 inline bool isTRUNCStore(const SDNode *N) {
2260 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2263 /// Returns true if the specified node is an unindexed store.
2264 inline bool isUNINDEXEDStore(const SDNode *N) {
2265 return isa<StoreSDNode>(N) &&
2266 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2269 } // end namespace ISD
2271 } // end namespace llvm
2273 #endif // LLVM_CODEGEN_SELECTIONDAGNODES_H